1 /* 2 * Copyright 2024 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.inputmethod; 18 19 import static android.app.settings.SettingsEnums.ACTION_STICKY_KEYS_DISABLED; 20 import static android.app.settings.SettingsEnums.ACTION_STICKY_KEYS_ENABLED; 21 22 import android.content.Context; 23 import android.hardware.input.InputSettings; 24 import android.net.Uri; 25 import android.provider.Settings; 26 27 import androidx.annotation.NonNull; 28 import androidx.lifecycle.LifecycleObserver; 29 import androidx.preference.PreferenceScreen; 30 import androidx.preference.TwoStatePreference; 31 32 public class KeyboardAccessibilityStickyKeysController extends 33 InputSettingPreferenceController implements 34 LifecycleObserver { 35 36 private TwoStatePreference mTwoStatePreference; 37 KeyboardAccessibilityStickyKeysController(@onNull Context context, @NonNull String key)38 public KeyboardAccessibilityStickyKeysController(@NonNull Context context, 39 @NonNull String key) { 40 super(context, key); 41 } 42 43 @Override displayPreference(@onNull PreferenceScreen screen)44 public void displayPreference(@NonNull PreferenceScreen screen) { 45 super.displayPreference(screen); 46 mTwoStatePreference = screen.findPreference(getPreferenceKey()); 47 } 48 49 @Override isChecked()50 public boolean isChecked() { 51 return InputSettings.isAccessibilityStickyKeysEnabled(mContext); 52 } 53 54 @Override setChecked(boolean isChecked)55 public boolean setChecked(boolean isChecked) { 56 InputSettings.setAccessibilityStickyKeysEnabled(mContext, 57 isChecked); 58 mMetricsFeatureProvider.action(mContext, 59 isChecked ? ACTION_STICKY_KEYS_ENABLED : ACTION_STICKY_KEYS_DISABLED); 60 return true; 61 } 62 63 @Override onInputSettingUpdated()64 protected void onInputSettingUpdated() { 65 if (mTwoStatePreference != null) { 66 mTwoStatePreference.setChecked( 67 InputSettings.isAccessibilityStickyKeysEnabled(mContext)); 68 } 69 } 70 71 @Override getSettingUri()72 protected Uri getSettingUri() { 73 return Settings.Secure.getUriFor( 74 Settings.Secure.ACCESSIBILITY_STICKY_KEYS); 75 } 76 } 77