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.settings.R; 26 import com.android.settings.accessibility.TextReadingPreferenceFragment.EntryPoint; 27 import com.android.settings.core.TogglePreferenceController; 28 import com.android.settings.core.instrumentation.SettingsStatsLog; 29 30 /** 31 * PreferenceController for displaying all text in high contrast style. 32 */ 33 public class HighTextContrastPreferenceController extends TogglePreferenceController implements 34 TextReadingResetController.ResetStateListener { 35 private TwoStatePreference mSwitchPreference; 36 37 @EntryPoint 38 private int mEntryPoint; 39 HighTextContrastPreferenceController(Context context, String preferenceKey)40 public HighTextContrastPreferenceController(Context context, String preferenceKey) { 41 super(context, preferenceKey); 42 } 43 44 @Override getAvailabilityStatus()45 public int getAvailabilityStatus() { 46 return AVAILABLE; 47 } 48 49 @Override isChecked()50 public boolean isChecked() { 51 return Settings.Secure.getInt(mContext.getContentResolver(), 52 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, 0) == 1; 53 } 54 55 @Override setChecked(boolean isChecked)56 public boolean setChecked(boolean isChecked) { 57 SettingsStatsLog.write( 58 SettingsStatsLog.ACCESSIBILITY_TEXT_READING_OPTIONS_CHANGED, 59 AccessibilityStatsLogUtils.convertToItemKeyName(getPreferenceKey()), 60 isChecked ? 1 : 0, 61 AccessibilityStatsLogUtils.convertToEntryPoint(mEntryPoint)); 62 63 return Settings.Secure.putInt(mContext.getContentResolver(), 64 Settings.Secure.ACCESSIBILITY_HIGH_TEXT_CONTRAST_ENABLED, (isChecked ? 1 : 0)); 65 } 66 67 @Override getSliceHighlightMenuRes()68 public int getSliceHighlightMenuRes() { 69 return R.string.menu_key_accessibility; 70 } 71 72 @Override displayPreference(PreferenceScreen screen)73 public void displayPreference(PreferenceScreen screen) { 74 super.displayPreference(screen); 75 mSwitchPreference = screen.findPreference(getPreferenceKey()); 76 } 77 78 @Override resetState()79 public void resetState() { 80 setChecked(false); 81 updateState(mSwitchPreference); 82 } 83 84 /** 85 * The entry point is used for logging. 86 * 87 * @param entryPoint from which settings page 88 */ setEntryPoint(@ntryPoint int entryPoint)89 void setEntryPoint(@EntryPoint int entryPoint) { 90 mEntryPoint = entryPoint; 91 } 92 } 93