feat(EDT): Migrate entry into Display Settings

The EDT toggle will be an subsetting in the DarkTheme settings page
- When the Dark Theme main toggle is on, we check the EDT setting to
decide applying normal DarkTheme or EDT now.
- The EDT preference is disabled when DarkTheme is off

Bug: 368721320
Flag: android.view.accessibility.force_invert_color
Test: atest ToggleForceInvertPreferenceControllerTest
            DarkModeSettingsFragmentTest
Change-Id: I64e47f92b14ee24a91f469cb55c7bb1285f05c62
This commit is contained in:
Menghan Li
2024-12-20 03:13:01 +00:00
parent 6123cb9aeb
commit 9aa9199f08
7 changed files with 129 additions and 57 deletions

View File

@@ -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);
}
}

View File

@@ -52,10 +52,7 @@ public class ToggleForceInvertPreferenceControllerTest {
@Before
public void setUp() {
mController = new ToggleForceInvertPreferenceController(
mContext,
ColorAndMotionFragment.TOGGLE_FORCE_INVERT
);
mController = new ToggleForceInvertPreferenceController(mContext, "toggle_force_invert");
}
@Test

View File

@@ -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);
}
}