1 /* 2 * Copyright (C) 2020 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 package com.android.settings.accessibility; 17 18 import static com.android.settings.accessibility.AccessibilityUtil.State.OFF; 19 import static com.android.settings.accessibility.AccessibilityUtil.State.ON; 20 21 import android.content.ContentResolver; 22 import android.content.Context; 23 import android.os.UserHandle; 24 import android.provider.Settings; 25 26 import com.android.settings.R; 27 import com.android.settings.core.TogglePreferenceController; 28 29 /** 30 * Settings page for accessibility shortcut 31 */ 32 public class AccessibilityShortcutPreferenceController extends TogglePreferenceController { 33 AccessibilityShortcutPreferenceController(Context context, String preferenceKey)34 public AccessibilityShortcutPreferenceController(Context context, String preferenceKey) { 35 super(context, preferenceKey); 36 } 37 38 @Override isChecked()39 public boolean isChecked() { 40 final ContentResolver cr = mContext.getContentResolver(); 41 // The shortcut is enabled by default on the lock screen as long as the user has 42 // enabled the shortcut with the warning dialog 43 final int dialogShown = Settings.Secure.getInt( 44 cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_DIALOG_SHOWN, OFF); 45 final boolean enabledFromLockScreen = Settings.Secure.getInt( 46 cr, Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, dialogShown) == ON; 47 return enabledFromLockScreen; 48 } 49 50 @Override setChecked(boolean isChecked)51 public boolean setChecked(boolean isChecked) { 52 return Settings.Secure.putIntForUser(mContext.getContentResolver(), 53 Settings.Secure.ACCESSIBILITY_SHORTCUT_ON_LOCK_SCREEN, isChecked ? ON : OFF, 54 UserHandle.USER_CURRENT); 55 } 56 57 @Override getAvailabilityStatus()58 public int getAvailabilityStatus() { 59 return AVAILABLE; 60 } 61 62 @Override getSliceHighlightMenuRes()63 public int getSliceHighlightMenuRes() { 64 return R.string.menu_key_accessibility; 65 } 66 } 67