Fix flicker in Dark theme
Currently, when schedule sets to "Turns on at bedtime", the footer will show a slid up animation when entering the page, this is because the "Start time" & "End time" preferences are hidden in onResume(). This is because these 2 preferences always return AVAILABLE in getAvailabilityStatus(), and manually update visibility in refreshSummary(), which is called each time updateState() is called. Usually the controller not set the visibility explicitly, but return CONDITIONALLY_UNAVAILABLE in getAvailabilityStatus() when they want to hide the preference. Because getAvailabilityStatus() is called in onCreate(), by using this, we can fix the flicker. Fix: 234399017 Test: visual & robo test Change-Id: I4cb7dd95d2985bd1ca4c8cb30aaebdc21a5415f8
This commit is contained in:
@@ -15,6 +15,11 @@
|
||||
|
||||
package com.android.settings.display.darkmode;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -71,68 +76,55 @@ public class DarkModeCustomPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_manualOn_hidePreference() {
|
||||
public void getAvailabilityStatus_nightModeManualOn_unavailable() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(false));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_manualOff_hidePreference() {
|
||||
public void getAvailabilityStatus_nightModeManualOff_unavailable() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_NO);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(false));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void nightMode_customOn_showPreference() {
|
||||
public void getAvailabilityStatus_nightModeCustomOn_available() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(true));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_customOff_showPreference() {
|
||||
public void getAvailabilityStatus_nightModeCustomOff_available() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(true));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_customBedtimeOn_hidePreference() {
|
||||
public void getAvailabilityStatus_nightModeCustomBedtimeOn_unavailable() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||
when(mService.getNightModeCustomType())
|
||||
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(false));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nightMode_customBedtimeOff_hidePreference() {
|
||||
public void getAvailabilityStatus_nightModeCustomBedtimeOff_unavailable() {
|
||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||
when(mService.getNightModeCustomType())
|
||||
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||
|
||||
mController.refreshSummary(mPreference);
|
||||
|
||||
verify(mPreference).setVisible(eq(false));
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user