Merge "Fix flicker in Dark theme" into tm-dev am: 71fe20ea8b
am: 596644171b
am: f34bac0ee6
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18659336 Change-Id: I2d90540595b155fd0299725334c6179c6dc2d2ee Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -27,7 +27,6 @@ import androidx.preference.Preference;
|
|||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller for custom mode night mode time settings
|
* Controller for custom mode night mode time settings
|
||||||
@@ -35,7 +34,6 @@ import java.time.format.DateTimeFormatter;
|
|||||||
public class DarkModeCustomPreferenceController extends BasePreferenceController {
|
public class DarkModeCustomPreferenceController extends BasePreferenceController {
|
||||||
private static final String START_TIME_KEY = "dark_theme_start_time";
|
private static final String START_TIME_KEY = "dark_theme_start_time";
|
||||||
private static final String END_TIME_KEY = "dark_theme_end_time";
|
private static final String END_TIME_KEY = "dark_theme_end_time";
|
||||||
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
|
|
||||||
private final UiModeManager mUiModeManager;
|
private final UiModeManager mUiModeManager;
|
||||||
private TimeFormatter mFormat;
|
private TimeFormatter mFormat;
|
||||||
private DarkModeSettingsFragment mFragmet;
|
private DarkModeSettingsFragment mFragmet;
|
||||||
@@ -63,7 +61,10 @@ public class DarkModeCustomPreferenceController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return AVAILABLE;
|
return mUiModeManager.getNightMode() == MODE_NIGHT_CUSTOM
|
||||||
|
&& mUiModeManager.getNightModeCustomType()
|
||||||
|
== UiModeManager.MODE_NIGHT_CUSTOM_TYPE_SCHEDULE
|
||||||
|
? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimePickerDialog getDialog() {
|
public TimePickerDialog getDialog() {
|
||||||
@@ -88,13 +89,6 @@ public class DarkModeCustomPreferenceController extends BasePreferenceController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refreshSummary(Preference preference) {
|
protected void refreshSummary(Preference preference) {
|
||||||
if (mUiModeManager.getNightMode() != MODE_NIGHT_CUSTOM
|
|
||||||
|| mUiModeManager.getNightModeCustomType()
|
|
||||||
!= UiModeManager.MODE_NIGHT_CUSTOM_TYPE_SCHEDULE) {
|
|
||||||
preference.setVisible(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
preference.setVisible(true);
|
|
||||||
final LocalTime time;
|
final LocalTime time;
|
||||||
if (TextUtils.equals(getPreferenceKey(), START_TIME_KEY)) {
|
if (TextUtils.equals(getPreferenceKey(), START_TIME_KEY)) {
|
||||||
time = mUiModeManager.getCustomNightModeStart();
|
time = mUiModeManager.getCustomNightModeStart();
|
||||||
|
@@ -21,6 +21,7 @@ import android.os.Bundle;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
|
||||||
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.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
@@ -43,9 +44,6 @@ public class DarkModeSettingsFragment extends DashboardFragment {
|
|||||||
private DarkModeObserver mContentObserver;
|
private DarkModeObserver mContentObserver;
|
||||||
private DarkModeCustomPreferenceController mCustomStartController;
|
private DarkModeCustomPreferenceController mCustomStartController;
|
||||||
private DarkModeCustomPreferenceController mCustomEndController;
|
private DarkModeCustomPreferenceController mCustomEndController;
|
||||||
private Runnable mCallback = () -> {
|
|
||||||
updatePreferenceStates();
|
|
||||||
};
|
|
||||||
private static final int DIALOG_START_TIME = 0;
|
private static final int DIALOG_START_TIME = 0;
|
||||||
private static final int DIALOG_END_TIME = 1;
|
private static final int DIALOG_END_TIME = 1;
|
||||||
|
|
||||||
@@ -60,7 +58,12 @@ public class DarkModeSettingsFragment extends DashboardFragment {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
// Listen for changes only while visible.
|
// Listen for changes only while visible.
|
||||||
mContentObserver.subscribe(mCallback);
|
mContentObserver.subscribe(() -> {
|
||||||
|
PreferenceScreen preferenceScreen = getPreferenceScreen();
|
||||||
|
mCustomStartController.displayPreference(preferenceScreen);
|
||||||
|
mCustomEndController.displayPreference(preferenceScreen);
|
||||||
|
updatePreferenceStates();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -15,6 +15,11 @@
|
|||||||
|
|
||||||
package com.android.settings.display.darkmode;
|
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.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
@@ -71,68 +76,55 @@ public class DarkModeCustomPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_manualOn_hidePreference() {
|
public void getAvailabilityStatus_nightModeManualOn_unavailable() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_YES);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_manualOff_hidePreference() {
|
public void getAvailabilityStatus_nightModeManualOff_unavailable() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_NO);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_NO);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_customOn_showPreference() {
|
public void getAvailabilityStatus_nightModeCustomOn_available() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_customOff_showPreference() {
|
public void getAvailabilityStatus_nightModeCustomOff_available() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_customBedtimeOn_hidePreference() {
|
public void getAvailabilityStatus_nightModeCustomBedtimeOn_unavailable() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
when(mService.getNightModeCustomType())
|
when(mService.getNightModeCustomType())
|
||||||
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void nightMode_customBedtimeOff_hidePreference() {
|
public void getAvailabilityStatus_nightModeCustomBedtimeOff_unavailable() {
|
||||||
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
when(mService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_CUSTOM);
|
||||||
when(mService.getNightModeCustomType())
|
when(mService.getNightModeCustomType())
|
||||||
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
.thenReturn(UiModeManager.MODE_NIGHT_CUSTOM_TYPE_BEDTIME);
|
||||||
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
mConfig.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||||
|
|
||||||
mController.refreshSummary(mPreference);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||||
|
|
||||||
verify(mPreference).setVisible(eq(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user