Restore the style of the screen saver widget from switch style to

button style.

The operation of the Switch is not suitable for previewing the
screen saver and will make the user confused. So we change the
style of the screen saver widget back to the button style.

Fix: 189505023
Test: manually test the screen saver
Change-Id: I4a97d91cc0b76111d4cb7b6aa202f2207ee0ca5d
This commit is contained in:
Stanley Wang
2021-12-21 17:25:38 +08:00
parent a93796f7a3
commit 446f6dd886
5 changed files with 78 additions and 47 deletions

View File

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