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.content.Context; 21 import android.hardware.display.ColorDisplayManager; 22 import android.os.Bundle; 23 import android.os.Handler; 24 import android.provider.Settings; 25 26 import androidx.annotation.NonNull; 27 import androidx.annotation.Nullable; 28 import androidx.preference.Preference; 29 import androidx.preference.PreferenceCategory; 30 import androidx.preference.TwoStatePreference; 31 32 import com.android.settings.R; 33 import com.android.settings.dashboard.DashboardFragment; 34 import com.android.settings.search.BaseSearchIndexProvider; 35 import com.android.settingslib.core.AbstractPreferenceController; 36 import com.android.settingslib.search.SearchIndexable; 37 38 import java.util.ArrayList; 39 import java.util.List; 40 41 /** Accessibility settings for color and motion. */ 42 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 43 public class ColorAndMotionFragment extends DashboardFragment { 44 45 private static final String TAG = "ColorAndMotionFragment"; 46 47 private static final String CATEGORY_EXPERIMENTAL = "experimental_category"; 48 49 // Preferences 50 private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference"; 51 52 private Preference mDisplayDaltonizerPreferenceScreen; 53 private TwoStatePreference mToggleDisableAnimationsPreference; 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 67 if (!isCatalystEnabled()) { 68 initializeAllPreferences(); 69 updateSystemPreferences(); 70 mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED); 71 mShortcutFeatureKeys.add(Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED); 72 73 mSettingsContentObserver = new AccessibilitySettingsContentObserver(new Handler()); 74 mSettingsContentObserver.registerKeysToObserverCallback(mShortcutFeatureKeys, 75 key -> updatePreferencesState()); 76 } 77 } 78 updatePreferencesState()79 private void updatePreferencesState() { 80 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 81 getPreferenceControllers().forEach(controllers::addAll); 82 controllers.forEach(controller -> controller.updateState( 83 findPreference(controller.getPreferenceKey()))); 84 } 85 86 @Override onStart()87 public void onStart() { 88 super.onStart(); 89 if (!isCatalystEnabled()) { 90 mSettingsContentObserver.register(getContentResolver()); 91 } 92 } 93 94 @Override onStop()95 public void onStop() { 96 super.onStop(); 97 if (!isCatalystEnabled()) { 98 mSettingsContentObserver.unregister(getContentResolver()); 99 } 100 } 101 102 @Override getPreferenceScreenResId()103 protected int getPreferenceScreenResId() { 104 return R.xml.accessibility_color_and_motion; 105 } 106 107 @Override getLogTag()108 protected String getLogTag() { 109 return TAG; 110 } 111 initializeAllPreferences()112 private void initializeAllPreferences() { 113 // Display color adjustments. 114 mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN); 115 116 // Disable animation. 117 mToggleDisableAnimationsPreference = findPreference(RemoveAnimationsPreference.KEY); 118 } 119 120 /** 121 * Updates preferences related to system configurations. 122 */ 123 // LINT.IfChange(ui_hierarchy) updateSystemPreferences()124 private void updateSystemPreferences() { 125 final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference( 126 CATEGORY_EXPERIMENTAL); 127 128 if (ColorDisplayManager.isColorTransformAccelerated(getContext())) { 129 getPreferenceScreen().removePreference(experimentalCategory); 130 } else { 131 // Move following preferences to experimental category if device don't supports HWC 132 // hardware-accelerated color transform. 133 getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen); 134 getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference); 135 experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen); 136 experimentalCategory.addPreference(mToggleDisableAnimationsPreference); 137 } 138 } 139 // LINT.ThenChange(/src/com/android/settings/accessibility/ColorAndMotionScreen.kt:ui_hierarchy) 140 141 @Nullable 142 @Override getPreferenceScreenBindingKey(@onNull Context context)143 public String getPreferenceScreenBindingKey(@NonNull Context context) { 144 return ColorAndMotionScreen.KEY; 145 } 146 147 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 148 new BaseSearchIndexProvider(R.xml.accessibility_color_and_motion); 149 } 150