diff --git a/res/values/strings.xml b/res/values/strings.xml index f8621741c5b..eff5d6a0f9e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4952,6 +4952,8 @@ Audio & on-screen text Display + + Text and display Interaction controls diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml index 6781e28a896..6efd8843ecf 100644 --- a/res/xml/accessibility_settings.xml +++ b/res/xml/accessibility_settings.xml @@ -45,52 +45,19 @@ android:title="@string/display_category_title"> + android:title="@string/accessibility_text_and_display_title" + settings:searchable="true"/> - - - - - - - - - - - - - - - - - - - - diff --git a/res/xml/accessibility_text_and_display.xml b/res/xml/accessibility_text_and_display.xml new file mode 100644 index 00000000000..7dce82636b7 --- /dev/null +++ b/res/xml/accessibility_text_and_display.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java index e5bc3f5666e..4709c66d81c 100644 --- a/src/com/android/settings/accessibility/AccessibilitySettings.java +++ b/src/com/android/settings/accessibility/AccessibilitySettings.java @@ -29,7 +29,6 @@ import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.content.pm.ServiceInfo; import android.graphics.drawable.Drawable; -import android.hardware.display.ColorDisplayManager; import android.net.Uri; import android.os.Bundle; import android.os.Handler; @@ -43,7 +42,6 @@ import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; -import androidx.preference.SwitchPreference; import com.android.internal.accessibility.AccessibilityShortcutController; import com.android.internal.content.PackageMonitor; @@ -51,7 +49,6 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.accessibility.AccessibilityUtil.AccessibilityServiceFragmentType; import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.display.DarkUIPreferenceController; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; import com.android.settingslib.RestrictedLockUtilsInternal; @@ -82,23 +79,14 @@ public class AccessibilitySettings extends DashboardFragment { private static final String CATEGORY_EXPERIMENTAL = "experimental_category"; private static final String CATEGORY_DOWNLOADED_SERVICES = "user_installed_services_category"; - private static final String[] CATEGORIES = new String[] { + private static final String[] CATEGORIES = new String[]{ CATEGORY_SCREEN_READER, CATEGORY_AUDIO_AND_CAPTIONS, CATEGORY_DISPLAY, CATEGORY_INTERACTION_CONTROL, CATEGORY_EXPERIMENTAL, CATEGORY_DOWNLOADED_SERVICES }; // Preferences - private static final String TOGGLE_INVERSION_PREFERENCE = - "toggle_inversion_preference"; - private static final String TOGGLE_LARGE_POINTER_ICON = - "toggle_large_pointer_icon"; - private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations"; private static final String DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN = "magnification_preference_screen"; - private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = - "daltonizer_preference"; - private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN = - "reduce_bright_colors_preference"; // Extras passed to sub-fragments. static final String EXTRA_PREFERENCE_KEY = "preference_key"; @@ -167,13 +155,7 @@ public class AccessibilitySettings extends DashboardFragment { private final Map mPreBundledServiceComponentToCategoryMap = new ArrayMap<>(); - private SwitchPreference mToggleLargePointerIconPreference; - private SwitchPreference mToggleDisableAnimationsPreference; private Preference mDisplayMagnificationPreferenceScreen; - private Preference mDisplayDaltonizerPreferenceScreen; - private Preference mToggleInversionPreference; - private Preference mReduceBrightColorsPreference; - /** * Check if the color transforms are color accelerated. Some transforms are experimental only @@ -226,7 +208,6 @@ public class AccessibilitySettings extends DashboardFragment { @Override public void onAttach(Context context) { super.onAttach(context); - use(DarkUIPreferenceController.class).setParentFragment(this); use(AccessibilityHearingAidPreferenceController.class) .setFragmentManager(getFragmentManager()); } @@ -259,8 +240,8 @@ public class AccessibilitySettings extends DashboardFragment { /** * Returns the summary for the current state of this accessibilityService. * - * @param context A valid context - * @param info The accessibilityService's info + * @param context A valid context + * @param info The accessibilityService's info * @param serviceEnabled Whether the accessibility service is enabled. * @return The service summary */ @@ -299,8 +280,8 @@ public class AccessibilitySettings extends DashboardFragment { /** * Returns the description for the current state of this accessibilityService. * - * @param context A valid context - * @param info The accessibilityService's info + * @param context A valid context + * @param info The accessibilityService's info * @param serviceEnabled Whether the accessibility service is enabled. * @return The service description */ @@ -325,24 +306,9 @@ public class AccessibilitySettings extends DashboardFragment { mCategoryToPrefCategoryMap.put(CATEGORIES[i], prefCategory); } - // Display inversion. - mToggleInversionPreference = findPreference(TOGGLE_INVERSION_PREFERENCE); - - // Large pointer icon. - mToggleLargePointerIconPreference = findPreference(TOGGLE_LARGE_POINTER_ICON); - - mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS); - // Display magnification. mDisplayMagnificationPreferenceScreen = findPreference( DISPLAY_MAGNIFICATION_PREFERENCE_SCREEN); - - // Display color adjustments. - mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN); - - // Reduce brightness. - mReduceBrightColorsPreference = - findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN); } private void updateAllPreferences() { @@ -392,13 +358,13 @@ public class AccessibilitySettings extends DashboardFragment { // Update the order of all the category according to the order defined in xml file. updateCategoryOrderFromArray(CATEGORY_SCREEN_READER, - R.array.config_order_screen_reader_services); + R.array.config_order_screen_reader_services); updateCategoryOrderFromArray(CATEGORY_AUDIO_AND_CAPTIONS, - R.array.config_order_audio_and_caption_services); + R.array.config_order_audio_and_caption_services); updateCategoryOrderFromArray(CATEGORY_INTERACTION_CONTROL, - R.array.config_order_interaction_control_services); + R.array.config_order_interaction_control_services); updateCategoryOrderFromArray(CATEGORY_DISPLAY, - R.array.config_order_display_services); + R.array.config_order_display_services); // Need to check each time when updateServicePreferences() called. if (downloadedServicesCategory.getPreferenceCount() == 0) { @@ -468,7 +434,7 @@ public class AccessibilitySettings extends DashboardFragment { * key with the string array of preference order which is defined in the xml. * * @param categoryKey The key of the category need to update the order - * @param key The key of the string array which defines the order of category + * @param key The key of the string array which defines the order of category */ private void updateCategoryOrderFromArray(String categoryKey, int key) { String[] services = getResources().getStringArray(key); @@ -486,39 +452,11 @@ public class AccessibilitySettings extends DashboardFragment { } } + /** + * Updates preferences related to system configurations. + */ protected void updateSystemPreferences() { - // Move color inversion and color correction preferences to Display category if device - // supports HWC hardware-accelerated color transform. - if (ColorDisplayManager.isColorTransformAccelerated(getContext())) { - PreferenceCategory experimentalCategory = - mCategoryToPrefCategoryMap.get(CATEGORY_EXPERIMENTAL); - PreferenceCategory displayCategory = - mCategoryToPrefCategoryMap.get(CATEGORY_DISPLAY); - experimentalCategory.removePreference(mToggleInversionPreference); - experimentalCategory.removePreference(mDisplayDaltonizerPreferenceScreen); - experimentalCategory.removePreference(mReduceBrightColorsPreference); - mDisplayMagnificationPreferenceScreen.setSummary( - ToggleScreenMagnificationPreferenceFragment.getServiceSummary(getContext())); - mDisplayDaltonizerPreferenceScreen.setOrder( - mDisplayMagnificationPreferenceScreen.getOrder() + 1); - mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary( - getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED)); - mToggleInversionPreference.setOrder( - mDisplayDaltonizerPreferenceScreen.getOrder() + 1); - mToggleLargePointerIconPreference.setOrder( - mToggleInversionPreference.getOrder() + 1); - mToggleDisableAnimationsPreference.setOrder( - mToggleLargePointerIconPreference.getOrder() + 1); - mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary( - getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)); - mReduceBrightColorsPreference.setOrder( - mToggleDisableAnimationsPreference.getOrder() + 1); - mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary( - getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED)); - displayCategory.addPreference(mToggleInversionPreference); - displayCategory.addPreference(mDisplayDaltonizerPreferenceScreen); - displayCategory.addPreference(mReduceBrightColorsPreference); - } + // Do nothing. } public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = diff --git a/src/com/android/settings/accessibility/TextAndDisplayFragment.java b/src/com/android/settings/accessibility/TextAndDisplayFragment.java new file mode 100644 index 00000000000..b496e3d4395 --- /dev/null +++ b/src/com/android/settings/accessibility/TextAndDisplayFragment.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2021 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 android.app.settings.SettingsEnums; +import android.content.Context; +import android.hardware.display.ColorDisplayManager; +import android.os.Bundle; +import android.provider.Settings; + +import androidx.preference.Preference; +import androidx.preference.PreferenceCategory; +import androidx.preference.SwitchPreference; + +import com.android.settings.R; +import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.display.DarkUIPreferenceController; +import com.android.settings.search.BaseSearchIndexProvider; +import com.android.settingslib.search.SearchIndexable; + +/** Accessibility settings for text and display. */ +@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) +public class TextAndDisplayFragment extends DashboardFragment { + + private static final String TAG = "TextAndDisplayFragment"; + + private static final String CATEGORY_EXPERIMENTAL = "experimental_category"; + + // Preferences + private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference"; + private static final String TOGGLE_INVERSION_PREFERENCE = "toggle_inversion_preference"; + private static final String DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN = + "reduce_bright_colors_preference"; + private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations"; + private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon"; + + private Preference mDisplayDaltonizerPreferenceScreen; + private Preference mToggleInversionPreference; + private Preference mReduceBrightColorsPreference; + private SwitchPreference mToggleDisableAnimationsPreference; + private SwitchPreference mToggleLargePointerIconPreference; + + @Override + public int getMetricsCategory() { + return SettingsEnums.ACCESSIBILITY_TEXT_AND_DISPLAY; + } + + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + initializeAllPreferences(); + updateSystemPreferences(); + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + use(DarkUIPreferenceController.class).setParentFragment(this); + } + + @Override + protected int getPreferenceScreenResId() { + return R.xml.accessibility_text_and_display; + } + + @Override + protected String getLogTag() { + return TAG; + } + + private void initializeAllPreferences() { + // Display color adjustments. + mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN); + + // Display inversion. + mToggleInversionPreference = findPreference(TOGGLE_INVERSION_PREFERENCE); + + // Reduce brightness. + mReduceBrightColorsPreference = + findPreference(DISPLAY_REDUCE_BRIGHT_COLORS_PREFERENCE_SCREEN); + + // Disable animation. + mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS); + + // Large pointer icon. + mToggleLargePointerIconPreference = findPreference(TOGGLE_LARGE_POINTER_ICON); + } + + /** + * Updates preferences related to system configurations. + */ + private void updateSystemPreferences() { + final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference( + CATEGORY_EXPERIMENTAL); + if (ColorDisplayManager.isColorTransformAccelerated(getContext())) { + mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary( + getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED)); + mToggleInversionPreference.setSummary(AccessibilityUtil.getSummary( + getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED)); + mReduceBrightColorsPreference.setSummary(AccessibilityUtil.getSummary( + getContext(), Settings.Secure.REDUCE_BRIGHT_COLORS_ACTIVATED)); + getPreferenceScreen().removePreference(experimentalCategory); + } else { + // Move following preferences to experimental category if device don't supports HWC + // hardware-accelerated color transform. + getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen); + getPreferenceScreen().removePreference(mToggleInversionPreference); + getPreferenceScreen().removePreference(mReduceBrightColorsPreference); + getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference); + getPreferenceScreen().removePreference(mToggleLargePointerIconPreference); + experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen); + experimentalCategory.addPreference(mToggleInversionPreference); + experimentalCategory.addPreference(mReduceBrightColorsPreference); + experimentalCategory.addPreference(mToggleDisableAnimationsPreference); + experimentalCategory.addPreference(mToggleLargePointerIconPreference); + } + } + + public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = + new BaseSearchIndexProvider(R.xml.accessibility_text_and_display); +} diff --git a/tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java new file mode 100644 index 00000000000..96756ecdd07 --- /dev/null +++ b/tests/robotests/src/com/android/settings/accessibility/TextAndDisplayFragmentTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2021 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.google.common.truth.Truth.assertThat; + +import android.content.Context; + +import androidx.test.core.app.ApplicationProvider; + +import com.android.settings.R; +import com.android.settings.testutils.XmlTestUtils; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; + +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +public class TextAndDisplayFragmentTest { + + private Context mContext = ApplicationProvider.getApplicationContext(); + + @Test + public void getNonIndexableKeys_existInXmlLayout() { + final List niks = TextAndDisplayFragment.SEARCH_INDEX_DATA_PROVIDER + .getNonIndexableKeys(mContext); + final List keys = + XmlTestUtils.getKeysFromPreferenceXml(mContext, + R.xml.accessibility_text_and_display); + + assertThat(keys).containsAtLeastElementsIn(niks); + } +}