1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accessibility; 18 19 import android.app.settings.SettingsEnums; 20 import android.hardware.display.ColorDisplayManager; 21 import android.os.Bundle; 22 import android.os.Handler; 23 import android.provider.Settings; 24 25 import androidx.preference.Preference; 26 import androidx.preference.PreferenceCategory; 27 import androidx.preference.SwitchPreference; 28 29 import com.android.settings.R; 30 import com.android.settings.dashboard.DashboardFragment; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settingslib.core.AbstractPreferenceController; 33 import com.android.settingslib.search.SearchIndexable; 34 35 import java.util.ArrayList; 36 import java.util.List; 37 38 /** Accessibility settings for color and motion. */ 39 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 40 public class ColorAndMotionFragment extends DashboardFragment { 41 42 private static final String TAG = "ColorAndMotionFragment"; 43 44 private static final String CATEGORY_EXPERIMENTAL = "experimental_category"; 45 46 // Preferences 47 private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference"; 48 private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations"; 49 private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon"; 50 51 private Preference mDisplayDaltonizerPreferenceScreen; 52 private SwitchPreference mToggleDisableAnimationsPreference; 53 private SwitchPreference mToggleLargePointerIconPreference; 54 private AccessibilitySettingsContentObserver mSettingsContentObserver; 55 56 private final List<String> mShortcutFeatureKeys = new ArrayList<>(); 57 58 @Override getMetricsCategory()59 public int getMetricsCategory() { 60 return SettingsEnums.ACCESSIBILITY_COLOR_AND_MOTION; 61 } 62 63 @Override onCreate(Bundle icicle)64 public void onCreate(Bundle icicle) { 65 super.onCreate(icicle); 66 initializeAllPreferences(); 67 updateSystemPreferences(); 68 69 mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED); 70 mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED); 71 72 mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler()); 73 mSettingsContentObserver.registerKeysToObserverCallback(mShortcutFeatureKeys, 74 key -> updatePreferencesState()); 75 } 76 updatePreferencesState()77 private void updatePreferencesState() { 78 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 79 getPreferenceControllers().forEach(controllers::addAll); 80 controllers.forEach(controller -> controller.updateState( 81 findPreference(controller.getPreferenceKey()))); 82 } 83 84 @Override onStart()85 public void onStart() { 86 super.onStart(); 87 88 mSettingsContentObserver.register(getContentResolver()); 89 } 90 91 @Override onStop()92 public void onStop() { 93 super.onStop(); 94 95 mSettingsContentObserver.unregister(getContentResolver()); 96 } 97 98 @Override getPreferenceScreenResId()99 protected int getPreferenceScreenResId() { 100 return R.xml.accessibility_color_and_motion; 101 } 102 103 @Override getLogTag()104 protected String getLogTag() { 105 return TAG; 106 } 107 initializeAllPreferences()108 private void initializeAllPreferences() { 109 // Display color adjustments. 110 mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN); 111 112 // Disable animation. 113 mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS); 114 115 // Large pointer icon. 116 mToggleLargePointerIconPreference = findPreference(TOGGLE_LARGE_POINTER_ICON); 117 } 118 119 /** 120 * Updates preferences related to system configurations. 121 */ updateSystemPreferences()122 private void updateSystemPreferences() { 123 final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference( 124 CATEGORY_EXPERIMENTAL); 125 if (ColorDisplayManager.isColorTransformAccelerated(getContext())) { 126 mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary( 127 getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED)); 128 getPreferenceScreen().removePreference(experimentalCategory); 129 } else { 130 // Move following preferences to experimental category if device don't supports HWC 131 // hardware-accelerated color transform. 132 getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen); 133 getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference); 134 getPreferenceScreen().removePreference(mToggleLargePointerIconPreference); 135 experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen); 136 experimentalCategory.addPreference(mToggleDisableAnimationsPreference); 137 experimentalCategory.addPreference(mToggleLargePointerIconPreference); 138 } 139 } 140 141 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 142 new BaseSearchIndexProvider(R.xml.accessibility_color_and_motion); 143 } 144