Merge "Restore the style of the screen saver widget from switch style to button style." into sc-v2-dev am: bfd37d65b0 am: 0bac54a0ee

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16512667

Change-Id: I6403aec4c28473abd027bf11f977051f008bb414
This commit is contained in:
Stanley Wang
2021-12-22 09:18:00 +00:00
committed by Automerger Merge Worker
5 changed files with 78 additions and 47 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2021 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.
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="bottom"
android:paddingStart="72dp"
android:paddingEnd="72dp"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/dream_start_now_button"
style="@style/ActionPrimaryButton"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/screensaver_settings_dream_start"/>
</LinearLayout>

View File

@@ -3249,6 +3249,8 @@
<string name="screensaver_settings_when_to_dream">When to start</string> <string name="screensaver_settings_when_to_dream">When to start</string>
<!-- Dream settings screen, action label, current selected screen saver --> <!-- Dream settings screen, action label, current selected screen saver -->
<string name="screensaver_settings_current">Current screen saver</string> <string name="screensaver_settings_current">Current screen saver</string>
<!-- Dream settings screen, button label to start dreaming [CHAR LIMIT=30] -->
<string name="screensaver_settings_dream_start">Start now</string>
<!-- Dream settings screen, button label for settings for a specific screensaver --> <!-- Dream settings screen, button label for settings for a specific screensaver -->
<string name="screensaver_settings_button">Settings</string> <string name="screensaver_settings_button">Settings</string>
<!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions --> <!-- Sound & display settings screen, setting option name to change whether the screen adjusts automatically based on lighting conditions -->
@@ -13607,8 +13609,6 @@
<string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string> <string name="adaptive_brightness_main_switch_title">Use adaptive brightness</string>
<!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] --> <!-- Title for wifi calling main switch preferences. [CHAR LIMIT=50] -->
<string name="wifi_calling_main_switch_title">Use WiFi calling</string> <string name="wifi_calling_main_switch_title">Use WiFi calling</string>
<!-- Title for Screen saver main switch preferences. [CHAR LIMIT=50] -->
<string name="screen_saver_main_switch_title">Use screen saver</string>
<!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]--> <!-- Default preference title for showing all apps on device [CHAR_LIMIT=50]-->
<string name="default_see_all_apps_title">See all apps</string> <string name="default_see_all_apps_title">See all apps</string>

View File

@@ -19,11 +19,6 @@
xmlns:settings="http://schemas.android.com/apk/res-auto" xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/screensaver_settings_title"> android:title="@string/screensaver_settings_title">
<com.android.settingslib.widget.MainSwitchPreference
android:key="dream_start_now_button_container"
android:title="@string/screen_saver_main_switch_title"
settings:controller="com.android.settings.dream.StartNowPreferenceController"/>
<com.android.settings.widget.GearPreference <com.android.settings.widget.GearPreference
android:key="current_screensaver" android:key="current_screensaver"
android:title="@string/screensaver_settings_current" android:title="@string/screensaver_settings_current"
@@ -35,4 +30,12 @@
android:title="@string/screensaver_settings_when_to_dream" android:title="@string/screensaver_settings_when_to_dream"
android:fragment="com.android.settings.dream.WhenToDreamPicker" /> android:fragment="com.android.settings.dream.WhenToDreamPicker" />
<PreferenceCategory>
<com.android.settingslib.widget.LayoutPreference
android:key="dream_start_now_button_container"
android:layout="@layout/dream_start_button"
android:selectable="false"
settings:controller="com.android.settings.dream.StartNowPreferenceController" />
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -17,20 +17,23 @@
package com.android.settings.dream; package com.android.settings.dream;
import android.content.Context; import android.content.Context;
import android.widget.Button;
import androidx.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.dashboard.DashboardFragment; import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.dream.DreamBackend; import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.LayoutPreference;
/** /**
* Controller that used to enable screen saver * Controller that used to enable screen saver
*/ */
public class StartNowPreferenceController extends SettingsMainSwitchPreferenceController { public class StartNowPreferenceController extends BasePreferenceController {
private final DreamBackend mBackend; private final DreamBackend mBackend;
private final MetricsFeatureProvider mMetricsFeatureProvider; private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -47,30 +50,23 @@ public class StartNowPreferenceController extends SettingsMainSwitchPreferenceCo
} }
@Override @Override
public void updateState(Preference preference) { public void displayPreference(PreferenceScreen screen) {
mSwitchPreference.setChecked(false); super.displayPreference(screen);
mSwitchPreference.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
}
@Override final LayoutPreference pref = screen.findPreference(getPreferenceKey());
public boolean isChecked() { final Button startButton = pref.findViewById(R.id.dream_start_now_button);
return false; startButton.setOnClickListener(v -> {
} mMetricsFeatureProvider.logClickedPreference(pref,
pref.getExtras().getInt(DashboardFragment.CATEGORY));
@Override
public boolean setChecked(boolean isChecked) {
if (isChecked) {
if (mSwitchPreference != null) {
mMetricsFeatureProvider.logClickedPreference(mSwitchPreference,
mSwitchPreference.getExtras().getInt(DashboardFragment.CATEGORY));
}
mBackend.startDreaming(); mBackend.startDreaming();
} });
return true;
} }
@Override @Override
public int getSliceHighlightMenuRes() { public void updateState(Preference preference) {
return R.string.menu_key_display; super.updateState(preference);
final Button startButton = ((LayoutPreference) preference)
.findViewById(R.id.dream_start_now_button);
startButton.setEnabled(mBackend.getWhenToDreamSetting() != DreamBackend.NEVER);
} }
} }

View File

@@ -16,17 +16,18 @@
package com.android.settings.dream; package com.android.settings.dream;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.widget.Button;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.dream.DreamBackend; import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.widget.MainSwitchPreference; import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -46,7 +47,9 @@ public class StartNowPreferenceControllerTest {
@Mock @Mock
private PreferenceScreen mScreen; private PreferenceScreen mScreen;
@Mock @Mock
private MainSwitchPreference mPref; private LayoutPreference mLayoutPref;
@Mock
private Button mButton;
@Mock @Mock
private DreamBackend mBackend; private DreamBackend mBackend;
@@ -56,36 +59,29 @@ public class StartNowPreferenceControllerTest {
mContext = spy(RuntimeEnvironment.application); mContext = spy(RuntimeEnvironment.application);
mController = new StartNowPreferenceController(mContext, "key"); mController = new StartNowPreferenceController(mContext, "key");
mPref = mock(MainSwitchPreference.class); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mLayoutPref);
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPref); when(mLayoutPref.findViewById(R.id.dream_start_now_button)).thenReturn(mButton);
ReflectionHelpers.setField(mController, "mBackend", mBackend); ReflectionHelpers.setField(mController, "mBackend", mBackend);
} }
@Test @Test
public void displayPreference_shouldAddOnSwitchChangeListener() { public void updateState_neverDreaming_buttonShouldDidabled() {
mController.displayPreference(mScreen);
verify(mPref).addOnSwitchChangeListener(mController);
}
@Test
public void updateState_neverDreaming_preferenceShouldDidabled() {
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER); when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.NEVER);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateState(mPref); mController.updateState(mLayoutPref);
verify(mPref).setEnabled(false); verify(mButton).setEnabled(false);
} }
@Test @Test
public void updateState_dreamIsAvailable_preferenceShouldEnabled() { public void updateState_dreamIsAvailable_buttonShouldEnabled() {
when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER); when(mBackend.getWhenToDreamSetting()).thenReturn(DreamBackend.EITHER);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
mController.updateState(mPref); mController.updateState(mLayoutPref);
verify(mPref).setEnabled(true); verify(mButton).setEnabled(true);
} }
} }