Merge "Duplicate dark mode settings to accessibility display settings"
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 9cb73a2..da103c5 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -58,6 +58,14 @@
android:title="@string/screen_zoom_title"
settings:searchable="false"/>
+ <ListPreference
+ android:key="dark_ui_mode_accessibility"
+ android:title="@string/dark_ui_mode"
+ android:dialogTitle="@string/dark_ui_mode_title"
+ android:entries="@array/dark_ui_mode_entries"
+ android:entryValues="@array/dark_ui_mode_values"
+ settings:searchable="false" />
+
<Preference
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
android:key="magnification_preference_screen"
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index ee0cb7d..921af04 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -57,6 +57,7 @@
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.display.DarkUIPreferenceController;
import com.android.settings.display.ToggleFontSizePreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -133,6 +134,8 @@
"accessibility_content_timeout_preference_fragment";
private static final String ACCESSIBILITY_CONTROL_TIMEOUT_PREFERENCE =
"accessibility_control_timeout_preference_fragment";
+ private static final String DARK_UI_MODE_PREFERENCE =
+ "dark_ui_mode_accessibility";
// Extras passed to sub-fragments.
@@ -236,6 +239,8 @@
private SwitchPreference mToggleInversionPreference;
private ColorInversionPreferenceController mInversionPreferenceController;
private AccessibilityHearingAidPreferenceController mHearingAidPreferenceController;
+ private ListPreference mDarkUIModePreference;
+ private DarkUIPreferenceController mDarkUIPreferenceController;
private int mLongPressTimeoutDefault;
@@ -501,6 +506,13 @@
// Vibrations.
mVibrationPreferenceScreen = findPreference(VIBRATION_PREFERENCE_SCREEN);
+
+ // Dark Mode.
+ mDarkUIModePreference = findPreference(DARK_UI_MODE_PREFERENCE);
+ mDarkUIPreferenceController = new DarkUIPreferenceController(getContext(),
+ DARK_UI_MODE_PREFERENCE);
+ mDarkUIPreferenceController.displayPreference(getPreferenceScreen());
+ mDarkUIModePreference.setSummary(mDarkUIPreferenceController.getSummary());
}
private void updateAllPreferences() {
@@ -683,6 +695,9 @@
// If the quick setting is enabled, the preference MUST be enabled.
mInversionPreferenceController.updateState(mToggleInversionPreference);
+ // Dark Mode
+ mDarkUIPreferenceController.updateState(mDarkUIModePreference);
+
// Power button ends calls.
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)
&& Utils.isVoiceCapable(getActivity())) {
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index 96d5bf5..8c53019 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -21,14 +21,17 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import android.app.UiModeManager;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Vibrator;
import android.provider.Settings;
+import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.display.DarkUIPreferenceController;
import com.android.settings.testutils.XmlTestUtils;
import org.junit.Before;
@@ -47,10 +50,13 @@
"accessibility_content_timeout_preference_fragment";
private static final String ACCESSIBILITY_CONTROL_TIMEOUT_PREFERENCE =
"accessibility_control_timeout_preference_fragment";
+ private static final String DARK_UI_MODE_PREFERENCE =
+ "dark_ui_mode_accessibility";
private Context mContext;
private ContentResolver mContentResolver;
private AccessibilitySettings mSettings;
+ private UiModeManager mUiModeManager;
@Before
public void setup() {
@@ -59,6 +65,7 @@
mContentResolver = mContext.getContentResolver();
mSettings = spy(new AccessibilitySettings());
doReturn(mContext).when(mSettings).getContext();
+ mUiModeManager = mContext.getSystemService(UiModeManager.class);
}
@Test
@@ -146,4 +153,29 @@
assertThat(preference.getSummary()).isEqualTo(mContext.getResources().getString(resId));
}
+
+ @Test
+ public void testDarkUIModePreferenceSummary_shouldUpdateSummary() {
+ final ListPreference darkUIModePreference = new ListPreference(mContext);
+ final DarkUIPreferenceController mController;
+ doReturn(darkUIModePreference).when(mSettings).findPreference(
+ DARK_UI_MODE_PREFERENCE);
+ mController = new DarkUIPreferenceController(mContext, DARK_UI_MODE_PREFERENCE);
+ final String darkUIModeDescription = modeToDescription(mUiModeManager.getNightMode());
+ darkUIModePreference.setSummary(mController.getSummary());
+
+ assertThat(darkUIModePreference.getSummary()).isEqualTo(darkUIModeDescription);
+ }
+
+ private String modeToDescription(int mode) {
+ String[] values = mContext.getResources().getStringArray(R.array.dark_ui_mode_entries);
+ switch (mode) {
+ case UiModeManager.MODE_NIGHT_YES:
+ return values[0];
+ case UiModeManager.MODE_NIGHT_NO:
+ case UiModeManager.MODE_NIGHT_AUTO:
+ default:
+ return values[1];
+ }
+ }
}