Merge changes I97841c5b,I64e47f92 into main
* changes: feat(EDT): Update the preference interaction and visiblity logic feat(EDT): Migrate entry into Display Settings
This commit is contained in:
@@ -5460,9 +5460,9 @@
|
||||
<!-- Summary for the accessibility preference for enabling/disabling large icons for mouse/trackpad pointers. [CHAR LIMIT=60] -->
|
||||
<string name="accessibility_toggle_large_pointer_icon_summary">Make the mouse pointer more noticeable</string>
|
||||
<!-- Title for the accessibility preference for forcing all apps to use dark theme. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_force_invert_title">Make all apps dark</string>
|
||||
<string name="accessibility_force_invert_title">Make more apps dark</string>
|
||||
<!-- Summary for the accessibility preference for forcing all apps to use dark theme. [CHAR LIMIT=100] -->
|
||||
<string name="accessibility_force_invert_summary">Applies to apps without their own dark theme. Some apps may have display issues, like inverted colors.</string>
|
||||
<string name="accessibility_force_invert_summary">Automatically convert light theme apps to dark theme</string>
|
||||
<!-- Title for the accessibility preference for disabling animations. [CHAR LIMIT=35] -->
|
||||
<string name="accessibility_disable_animations">Remove animations</string>
|
||||
<!-- Summary for the accessibility preference for disabling animations. [CHAR LIMIT=60] -->
|
||||
|
@@ -51,14 +51,6 @@
|
||||
settings:controller="com.android.settings.display.DarkUIPreferenceController"
|
||||
settings:searchable="false"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:icon="@drawable/ic_dark_ui"
|
||||
android:key="toggle_force_invert"
|
||||
android:persistent="false"
|
||||
android:summary="@string/accessibility_force_invert_summary"
|
||||
android:title="@string/accessibility_force_invert_title"
|
||||
settings:controller="com.android.settings.accessibility.ToggleForceInvertPreferenceController"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:icon="@drawable/ic_accessibility_animation"
|
||||
android:key="animator_duration_scale"
|
||||
|
@@ -35,13 +35,22 @@
|
||||
android:title="@string/twilight_mode_location_off_dialog_message"
|
||||
settings:controller="com.android.settings.display.TwilightLocationPreferenceController"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="display_category"
|
||||
android:title="@string/accessibility_screen_option">
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="toggle_force_invert"
|
||||
android:summary="@string/accessibility_force_invert_summary"
|
||||
android:title="@string/accessibility_force_invert_title"
|
||||
settings:controller="com.android.settings.accessibility.ToggleForceInvertPreferenceController"/>
|
||||
|
||||
<DropDownPreference
|
||||
android:key="dark_ui_auto_mode"
|
||||
android:title="@string/dark_ui_auto_mode_title"
|
||||
android:summary="%s"
|
||||
android:entries="@array/dark_ui_scheduler_preference_titles"
|
||||
android:entryValues="@array/dark_ui_scheduler_preference_titles"
|
||||
settings:allowDividerAbove="true"
|
||||
settings:controller="com.android.settings.display.darkmode.DarkModeScheduleSelectorController"
|
||||
settings:keywords="@string/keywords_dark_ui_mode"/>
|
||||
|
||||
@@ -54,6 +63,7 @@
|
||||
android:key="dark_theme_end_time"
|
||||
android:title="@string/night_display_end_time_title"
|
||||
settings:searchable="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<com.android.settingslib.widget.FooterPreference
|
||||
android:key="dark_theme_custom_bedtime_footer"
|
||||
|
@@ -22,7 +22,6 @@ import android.hardware.display.ColorDisplayManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.Flags;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -30,7 +29,6 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
@@ -51,8 +49,6 @@ public class ColorAndMotionFragment extends DashboardFragment {
|
||||
// Preferences
|
||||
private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference";
|
||||
private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon";
|
||||
@VisibleForTesting
|
||||
static final String TOGGLE_FORCE_INVERT = "toggle_force_invert";
|
||||
|
||||
private Preference mDisplayDaltonizerPreferenceScreen;
|
||||
private TwoStatePreference mToggleDisableAnimationsPreference;
|
||||
@@ -77,9 +73,6 @@ public class ColorAndMotionFragment extends DashboardFragment {
|
||||
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE);
|
||||
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS);
|
||||
mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_QS_TARGETS);
|
||||
if (Flags.forceInvertColor()) {
|
||||
mShortcutFeatureKeys.add(ToggleForceInvertPreferenceController.SETTINGS_KEY);
|
||||
}
|
||||
|
||||
mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler());
|
||||
mSettingsContentObserver.registerKeysToObserverCallback(mShortcutFeatureKeys,
|
||||
|
@@ -16,11 +16,16 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.OFF;
|
||||
import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.Flags;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
@@ -28,27 +33,28 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
/** A toggle preference controller for force invert (force dark). */
|
||||
public class ToggleForceInvertPreferenceController extends TogglePreferenceController {
|
||||
|
||||
public static final String SETTINGS_KEY =
|
||||
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED;
|
||||
|
||||
@VisibleForTesting
|
||||
static final int ON = 1;
|
||||
@VisibleForTesting
|
||||
static final int OFF = 0;
|
||||
|
||||
public ToggleForceInvertPreferenceController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(), SETTINGS_KEY, OFF) != OFF;
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, OFF) != OFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
SETTINGS_KEY, isChecked ? ON : OFF);
|
||||
Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, isChecked ? ON : OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(@NonNull Preference preference) {
|
||||
super.updateState(preference);
|
||||
final boolean isDarkModeActivated = (mContext.getResources().getConfiguration().uiMode
|
||||
& Configuration.UI_MODE_NIGHT_YES) != 0;
|
||||
preference.setEnabled(isDarkModeActivated);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,14 +16,10 @@
|
||||
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
import static android.view.accessibility.Flags.FLAG_FORCE_INVERT_COLOR;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
|
||||
@@ -73,20 +69,6 @@ public class ColorAndMotionFragmentTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(FLAG_FORCE_INVERT_COLOR)
|
||||
public void forceInvertEnabled_getNonIndexableKeys_existInXmlLayout() {
|
||||
final List<String> niks = ColorAndMotionFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
final List<String> keys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.accessibility_color_and_motion);
|
||||
|
||||
assertThat(niks).doesNotContain(ColorAndMotionFragment.TOGGLE_FORCE_INVERT);
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(FLAG_FORCE_INVERT_COLOR)
|
||||
public void getNonIndexableKeys_existInXmlLayout() {
|
||||
final List<String> niks = ColorAndMotionFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
@@ -94,7 +76,6 @@ public class ColorAndMotionFragmentTest {
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.accessibility_color_and_motion);
|
||||
|
||||
assertThat(niks).contains(ColorAndMotionFragment.TOGGLE_FORCE_INVERT);
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
}
|
||||
|
@@ -23,13 +23,18 @@ import static com.android.settings.accessibility.AccessibilityUtil.State.ON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -52,10 +57,7 @@ public class ToggleForceInvertPreferenceControllerTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mController = new ToggleForceInvertPreferenceController(
|
||||
mContext,
|
||||
ColorAndMotionFragment.TOGGLE_FORCE_INVERT
|
||||
);
|
||||
mController = new ToggleForceInvertPreferenceController(mContext, "toggle_force_invert");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,6 +74,30 @@ public class ToggleForceInvertPreferenceControllerTest {
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_darkModeOn_preferenceEnabled() {
|
||||
Configuration config = mContext.getResources().getConfiguration();
|
||||
config.uiMode = Configuration.UI_MODE_NIGHT_YES;
|
||||
mContext.getResources().updateConfiguration(config, null);
|
||||
|
||||
Preference preference = mock(Preference.class);
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setEnabled(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_darkModeOff_preferenceDisabled() {
|
||||
Configuration config = mContext.getResources().getConfiguration();
|
||||
config.uiMode = Configuration.UI_MODE_NIGHT_NO;
|
||||
mContext.getResources().updateConfiguration(config, null);
|
||||
|
||||
Preference preference = mock(Preference.class);
|
||||
mController.updateState(preference);
|
||||
|
||||
verify(preference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void settingOff_reflectsCorrectValue() {
|
||||
setEnabled(false);
|
||||
|
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) 2024 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.display.darkmode;
|
||||
|
||||
import static android.view.accessibility.Flags.FLAG_FORCE_INVERT_COLOR;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.XmlTestUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Tests for {@link DarkModeSettingsFragment}. */
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DarkModeSettingsFragmentTest {
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
private DarkModeSettingsFragment mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mFragment = new DarkModeSettingsFragment();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMetricsCategory_returnsCorrectCategory() {
|
||||
assertThat(mFragment.getMetricsCategory()).isEqualTo(
|
||||
SettingsEnums.DARK_UI_SETTINGS);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPreferenceScreenResId_returnsCorrectXml() {
|
||||
assertThat(mFragment.getPreferenceScreenResId()).isEqualTo(
|
||||
R.xml.dark_mode_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLogTag_returnsCorrectTag() {
|
||||
assertThat(mFragment.getLogTag()).isEqualTo("DarkModeSettingsFrag");
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled(FLAG_FORCE_INVERT_COLOR)
|
||||
public void getNonIndexableKeys_forceInvertEnabled_existInXmlLayout() {
|
||||
final List<String> niks = DarkModeSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
final List<String> keys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.dark_mode_settings);
|
||||
|
||||
assertThat(niks).doesNotContain("toggle_force_invert");
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled(FLAG_FORCE_INVERT_COLOR)
|
||||
public void getNonIndexableKeys_existInXmlLayout() {
|
||||
final List<String> niks = DarkModeSettingsFragment.SEARCH_INDEX_DATA_PROVIDER
|
||||
.getNonIndexableKeys(mContext);
|
||||
final List<String> keys =
|
||||
XmlTestUtils.getKeysFromPreferenceXml(mContext,
|
||||
R.xml.dark_mode_settings);
|
||||
|
||||
assertThat(niks).contains("toggle_force_invert");
|
||||
assertThat(keys).containsAtLeastElementsIn(niks);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user