• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.content.Context;
20 import android.provider.Settings;
21 
22 import androidx.preference.PreferenceScreen;
23 import androidx.preference.TwoStatePreference;
24 
25 import com.android.graphics.hwui.flags.Flags;
26 import com.android.settings.R;
27 import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint;
28 import com.android.settings.core.TogglePreferenceController;
29 import com.android.settings.core.instrumentation.SettingsStatsLog;
30 
31 /**
32  * PreferenceController for displaying all text in high contrast style.
33  */
34 public class HighTextContrastPreferenceController extends TogglePreferenceController implements
35         TextReadingResetController.ResetStateListener {
36     private TwoStatePreference mSwitchPreference;
37 
38     @EntryPoint
39     private int mEntryPoint;
40 
HighTextContrastPreferenceController(Context context, String preferenceKey)41     public HighTextContrastPreferenceController(Context context, String preferenceKey) {
42         super(context, preferenceKey);
43     }
44 
45     @Override
getAvailabilityStatus()46     public int getAvailabilityStatus() {
47         return AVAILABLE;
48     }
49 
50     @Override
isChecked()51     public boolean isChecked() {
52         return Settings.Secure.getInt(mContext.getContentResolver(),
53                 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1;
54     }
55 
56     @Override
setChecked(boolean isChecked)57     public boolean setChecked(boolean isChecked) {
58         SettingsStatsLog.write(
59                 SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED,
60                 AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()),
61                 isChecked ? 1 : 0,
62                 AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint));
63 
64         if (Flags.highContrastTextSmallTextRect()) {
65             // Set PROMPT_UNNECESSARY when the user modifies the HighContrastText setting
66             // This is needed for the following scenario:
67             // On Android 16, create secondary user, ACTION_PRE_BOOT_COMPLETED won't be sent to
68             // the secondary user. The user enables HCT.
69             // When updating OS to Android 17, ACTION_PRE_BOOT_COMPLETED will be sent to the
70             // secondary user when switch to the secondary user.
71             // If the prompt status is not updated in Android 16, we would automatically disable
72             // HCT and show the HCT prompt, which is an undesired behavior.
73             Settings.Secure.putInt(mContext.getContentResolver(),
74                     Settings.Secure.ACCESSIBILITY_HCT_RECT_PROMPT_STATUS,
75                     HighContrastTextMigrationReceiver.PromptState.PROMPT_UNNECESSARY);
76         }
77 
78         return Settings.Secure.putInt(mContext.getContentResolver(),
79                 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0));
80     }
81 
82     @Override
getSliceHighlightMenuRes()83     public int getSliceHighlightMenuRes() {
84         return R.string.menu_key_accessibility;
85     }
86 
87     @Override
displayPreference(PreferenceScreen screen)88     public void displayPreference(PreferenceScreen screen) {
89         super.displayPreference(screen);
90         mSwitchPreference = screen.findPreference(getPreferenceKey());
91     }
92 
93     @Override
resetState()94     public void resetState() {
95         setChecked(false);
96         updateState(mSwitchPreference);
97     }
98 
99     /**
100      * The entry point is used for logging.
101      *
102      * @param entryPoint from which settings page
103      */
setEntryPoint(@ntryPoint int entryPoint)104     void setEntryPoint(@EntryPoint int entryPoint) {
105         mEntryPoint = entryPoint;
106     }
107 }
108