Add home controls button to screensaver settings
Toggle will allow users to disable showing home controls over their screensaver. Bug: 271330583 Test: make -j64 RunSettingsRoboTests Change-Id: I9600cdb85d85253c859c88f12c1d074e1082bf97
This commit is contained in:
@@ -14461,6 +14461,10 @@
|
||||
<string name="dream_complications_toggle_title">Show additional information</string>
|
||||
<!-- The summary of what overlays this toggle controls [CHAR LIMIT=none] -->
|
||||
<string name="dream_complications_toggle_summary">Display things like the time, weather, or other information on the screen saver</string>
|
||||
<!-- The title of the toggle which enables/disables the home controls button on top of the screen saver [CHAR LIMIT=none] -->
|
||||
<string name="dream_home_controls_toggle_title">Show home controls</string>
|
||||
<!-- The summary of the home controls toggle [CHAR LIMIT=none] -->
|
||||
<string name="dream_home_controls_toggle_summary">Show home controls button from the screen saver</string>
|
||||
<!-- The title of the category to show for the screensaver miscellaneous settings [CHAR LIMIT=none] -->
|
||||
<string name="dream_more_settings_category">More settings</string>
|
||||
<!-- The title of the screen saver setup page [CHAR LIMIT=none] -->
|
||||
|
@@ -46,6 +46,12 @@
|
||||
android:summary="@string/dream_complications_toggle_summary"
|
||||
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="dream_home_controls_toggle"
|
||||
android:title="@string/dream_home_controls_toggle_title"
|
||||
android:summary="@string/dream_home_controls_toggle_summary"
|
||||
settings:controller="com.android.settings.dream.DreamHomeControlsPreferenceController"/>
|
||||
|
||||
<com.android.settings.applications.SpacePreference
|
||||
android:layout_height="16dp" />
|
||||
|
||||
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
/**
|
||||
* Controller for the {@link androidx.preference.SwitchPreference} which controls if dream
|
||||
* overlays should be enabled.
|
||||
*/
|
||||
public class DreamHomeControlsPreferenceController extends TogglePreferenceController {
|
||||
private final DreamBackend mBackend;
|
||||
|
||||
public DreamHomeControlsPreferenceController(Context context, String key) {
|
||||
this(context, key, DreamBackend.getInstance(context));
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public DreamHomeControlsPreferenceController(Context context, String key,
|
||||
DreamBackend dreamBackend) {
|
||||
super(context, key);
|
||||
mBackend = dreamBackend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final boolean supported =
|
||||
mBackend.getSupportedComplications()
|
||||
.contains(DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
return supported ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mBackend.getEnabledComplications().contains(
|
||||
DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mBackend.setHomeControlsEnabled(isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceHighlightMenuRes() {
|
||||
return R.string.menu_key_display;
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dream;
|
||||
|
||||
import static com.android.settingslib.dream.DreamBackend.COMPLICATION_TYPE_HOME_CONTROLS;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.ArraySet;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settingslib.dream.DreamBackend;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
import org.robolectric.shadows.ShadowSettings;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowSettings.ShadowSecure.class})
|
||||
public class DreamHomeControlsPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private PreferenceScreen mScreen;
|
||||
private DreamHomeControlsPreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private DreamBackend mBackend;
|
||||
private ShadowContentResolver mShadowContentResolver;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mShadowContentResolver = Shadow.extract(mContext.getContentResolver());
|
||||
mBackend = new DreamBackend(mContext);
|
||||
mController = new DreamHomeControlsPreferenceController(mContext, "key", mBackend);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
// Make home controls supported by default
|
||||
mBackend.setSupportedComplications(
|
||||
new ArraySet<>(new Integer[]{COMPLICATION_TYPE_HOME_CONTROLS}));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowSettings.ShadowSecure.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetChecked_setTrue_enablesSetting() {
|
||||
mBackend.setHomeControlsEnabled(false);
|
||||
assertThat(mBackend.getEnabledComplications())
|
||||
.doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
|
||||
mController.setChecked(true);
|
||||
assertThat(mBackend.getEnabledComplications())
|
||||
.contains(COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetChecked_setFalse_disablesSetting() {
|
||||
mBackend.setHomeControlsEnabled(true);
|
||||
assertThat(mBackend.getEnabledComplications())
|
||||
.contains(COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
|
||||
mController.setChecked(false);
|
||||
assertThat(mBackend.getEnabledComplications())
|
||||
.doesNotContain(COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_returnsFalse() {
|
||||
mBackend.setHomeControlsEnabled(false);
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_returnsTrue() {
|
||||
mBackend.setHomeControlsEnabled(true);
|
||||
assertThat(mBackend.getEnabledComplications())
|
||||
.contains(COMPLICATION_TYPE_HOME_CONTROLS);
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user