Loading src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +38 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; import androidx.preference.TwoStatePreference; Loading @@ -41,6 +42,7 @@ import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SeekBarPreference; import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexableRaw; import java.util.ArrayList; import java.util.List; Loading @@ -52,6 +54,10 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre private static final String TAG = "ToggleReduceBrightColorsPreferenceFragment"; private static final String KEY_INTENSITY = "rbc_intensity"; private static final String KEY_PERSIST = "rbc_persist"; @VisibleForTesting static final String KEY_SHORTCUT = "rbc_shortcut"; @VisibleForTesting static final String KEY_SWITCH = "rbc_switch"; private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY = Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED; Loading Loading @@ -197,11 +203,43 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre } } @Override protected String getUseServicePreferenceKey() { return KEY_SWITCH; } @Override protected String getShortcutPreferenceKey() { return KEY_SHORTCUT; } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.reduce_bright_colors_settings) { @Override protected boolean isPageSearchEnabled(Context context) { return ColorDisplayManager.isReduceBrightColorsAvailable(context); } @Override public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { final List<SearchIndexableRaw> rawData = super.getRawDataToIndex(context, enabled); if (Flags.fixA11ySettingsSearch()) { SearchIndexableRaw shortcutRaw = new SearchIndexableRaw(context); shortcutRaw.key = KEY_SHORTCUT; shortcutRaw.title = context.getString( R.string.reduce_bright_colors_shortcut_title); rawData.add(shortcutRaw); SearchIndexableRaw mainSwitchRaw = new SearchIndexableRaw(context); mainSwitchRaw.key = KEY_SWITCH; mainSwitchRaw.title = context.getString( R.string.reduce_bright_colors_switch_title); rawData.add(mainSwitchRaw); } return rawData; } }; } tests/robotests/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragmentTest.java 0 → 100644 +70 −0 Original line number Diff line number Diff line /* * 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.accessibility; import static com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment.KEY_SHORTCUT; import static com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment.KEY_SWITCH; import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; import com.android.settingslib.search.SearchIndexableRaw; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import java.util.ArrayList; import java.util.List; /** Tests for {@link ToggleReduceBrightColorsPreferenceFragment} */ @RunWith(RobolectricTestRunner.class) public class ToggleReduceBrightColorsPreferenceFragmentTest { @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private final Context mContext = ApplicationProvider.getApplicationContext(); @Test @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) public void getRawDataToIndex_flagOn_returnPreferencesCreatedInCodes() { String[] expectedKeys = {KEY_SHORTCUT, KEY_SWITCH}; String[] expectedTitles = { mContext.getString(R.string.reduce_bright_colors_shortcut_title), mContext.getString(R.string.reduce_bright_colors_switch_title)}; List<String> keysResultList = new ArrayList<>(); List<String> titlesResultList = new ArrayList<>(); List<SearchIndexableRaw> rawData = ToggleReduceBrightColorsPreferenceFragment .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true); for (SearchIndexableRaw rawDataItem : rawData) { keysResultList.add(rawDataItem.key); titlesResultList.add(rawDataItem.title); } // Verify that `getRawDataToIndex` includes the preferences created in codes assertThat(keysResultList).containsAtLeastElementsIn(expectedKeys); assertThat(titlesResultList).containsAtLeastElementsIn(expectedTitles); } } Loading
src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragment.java +38 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.VisibleForTesting; import androidx.preference.PreferenceCategory; import androidx.preference.TwoStatePreference; Loading @@ -41,6 +42,7 @@ import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.widget.SeekBarPreference; import com.android.settings.widget.SettingsMainSwitchPreference; import com.android.settingslib.search.SearchIndexable; import com.android.settingslib.search.SearchIndexableRaw; import java.util.ArrayList; import java.util.List; Loading @@ -52,6 +54,10 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre private static final String TAG = "ToggleReduceBrightColorsPreferenceFragment"; private static final String KEY_INTENSITY = "rbc_intensity"; private static final String KEY_PERSIST = "rbc_persist"; @VisibleForTesting static final String KEY_SHORTCUT = "rbc_shortcut"; @VisibleForTesting static final String KEY_SWITCH = "rbc_switch"; private static final String REDUCE_BRIGHT_COLORS_ACTIVATED_KEY = Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED; Loading Loading @@ -197,11 +203,43 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre } } @Override protected String getUseServicePreferenceKey() { return KEY_SWITCH; } @Override protected String getShortcutPreferenceKey() { return KEY_SHORTCUT; } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider(R.xml.reduce_bright_colors_settings) { @Override protected boolean isPageSearchEnabled(Context context) { return ColorDisplayManager.isReduceBrightColorsAvailable(context); } @Override public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) { final List<SearchIndexableRaw> rawData = super.getRawDataToIndex(context, enabled); if (Flags.fixA11ySettingsSearch()) { SearchIndexableRaw shortcutRaw = new SearchIndexableRaw(context); shortcutRaw.key = KEY_SHORTCUT; shortcutRaw.title = context.getString( R.string.reduce_bright_colors_shortcut_title); rawData.add(shortcutRaw); SearchIndexableRaw mainSwitchRaw = new SearchIndexableRaw(context); mainSwitchRaw.key = KEY_SWITCH; mainSwitchRaw.title = context.getString( R.string.reduce_bright_colors_switch_title); rawData.add(mainSwitchRaw); } return rawData; } }; }
tests/robotests/src/com/android/settings/accessibility/ToggleReduceBrightColorsPreferenceFragmentTest.java 0 → 100644 +70 −0 Original line number Diff line number Diff line /* * 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.accessibility; import static com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment.KEY_SHORTCUT; import static com.android.settings.accessibility.ToggleReduceBrightColorsPreferenceFragment.KEY_SWITCH; import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; import com.android.settingslib.search.SearchIndexableRaw; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import java.util.ArrayList; import java.util.List; /** Tests for {@link ToggleReduceBrightColorsPreferenceFragment} */ @RunWith(RobolectricTestRunner.class) public class ToggleReduceBrightColorsPreferenceFragmentTest { @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); private final Context mContext = ApplicationProvider.getApplicationContext(); @Test @EnableFlags(Flags.FLAG_FIX_A11Y_SETTINGS_SEARCH) public void getRawDataToIndex_flagOn_returnPreferencesCreatedInCodes() { String[] expectedKeys = {KEY_SHORTCUT, KEY_SWITCH}; String[] expectedTitles = { mContext.getString(R.string.reduce_bright_colors_shortcut_title), mContext.getString(R.string.reduce_bright_colors_switch_title)}; List<String> keysResultList = new ArrayList<>(); List<String> titlesResultList = new ArrayList<>(); List<SearchIndexableRaw> rawData = ToggleReduceBrightColorsPreferenceFragment .SEARCH_INDEX_DATA_PROVIDER.getRawDataToIndex(mContext, /* enabled= */ true); for (SearchIndexableRaw rawDataItem : rawData) { keysResultList.add(rawDataItem.key); titlesResultList.add(rawDataItem.title); } // Verify that `getRawDataToIndex` includes the preferences created in codes assertThat(keysResultList).containsAtLeastElementsIn(expectedKeys); assertThat(titlesResultList).containsAtLeastElementsIn(expectedTitles); } }