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.provider.Settings;
23 
24 import androidx.preference.Preference;
25 import androidx.preference.PreferenceCategory;
26 import androidx.preference.SwitchPreference;
27 
28 import com.android.settings.R;
29 import com.android.settings.dashboard.DashboardFragment;
30 import com.android.settings.search.BaseSearchIndexProvider;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 /** Accessibility settings for text and display. */
34 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
35 public class TextAndDisplayFragment extends DashboardFragment {
36 
37     private static final String TAG = "TextAndDisplayFragment";
38 
39     private static final String CATEGORY_EXPERIMENTAL = "experimental_category";
40 
41     // Preferences
42     private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN = "daltonizer_preference";
43     private static final String TOGGLE_DISABLE_ANIMATIONS = "toggle_disable_animations";
44     private static final String TOGGLE_LARGE_POINTER_ICON = "toggle_large_pointer_icon";
45 
46     private Preference mDisplayDaltonizerPreferenceScreen;
47     private SwitchPreference mToggleDisableAnimationsPreference;
48     private SwitchPreference mToggleLargePointerIconPreference;
49 
50     @Override
getMetricsCategory()51     public int getMetricsCategory() {
52         return SettingsEnums.ACCESSIBILITY_TEXT_AND_DISPLAY;
53     }
54 
55 
56     @Override
onCreate(Bundle icicle)57     public void onCreate(Bundle icicle) {
58         super.onCreate(icicle);
59         initializeAllPreferences();
60         updateSystemPreferences();
61     }
62 
63     @Override
getPreferenceScreenResId()64     protected int getPreferenceScreenResId() {
65         return R.xml.accessibility_text_and_display;
66     }
67 
68     @Override
getLogTag()69     protected String getLogTag() {
70         return TAG;
71     }
72 
initializeAllPreferences()73     private void initializeAllPreferences() {
74         // Display color adjustments.
75         mDisplayDaltonizerPreferenceScreen = findPreference(DISPLAY_DALTONIZER_PREFERENCE_SCREEN);
76 
77         // Disable animation.
78         mToggleDisableAnimationsPreference = findPreference(TOGGLE_DISABLE_ANIMATIONS);
79 
80         // Large pointer icon.
81         mToggleLargePointerIconPreference = findPreference(TOGGLE_LARGE_POINTER_ICON);
82     }
83 
84     /**
85      * Updates preferences related to system configurations.
86      */
updateSystemPreferences()87     private void updateSystemPreferences() {
88         final PreferenceCategory experimentalCategory = getPreferenceScreen().findPreference(
89                 CATEGORY_EXPERIMENTAL);
90         if (ColorDisplayManager.isColorTransformAccelerated(getContext())) {
91             mDisplayDaltonizerPreferenceScreen.setSummary(AccessibilityUtil.getSummary(
92                     getContext(), Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_ENABLED));
93             getPreferenceScreen().removePreference(experimentalCategory);
94         } else {
95             // Move following preferences to experimental category if device don't supports HWC
96             // hardware-accelerated color transform.
97             getPreferenceScreen().removePreference(mDisplayDaltonizerPreferenceScreen);
98             getPreferenceScreen().removePreference(mToggleDisableAnimationsPreference);
99             getPreferenceScreen().removePreference(mToggleLargePointerIconPreference);
100             experimentalCategory.addPreference(mDisplayDaltonizerPreferenceScreen);
101             experimentalCategory.addPreference(mToggleDisableAnimationsPreference);
102             experimentalCategory.addPreference(mToggleLargePointerIconPreference);
103         }
104     }
105 
106     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
107             new BaseSearchIndexProvider(R.xml.accessibility_text_and_display);
108 }
109