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.development; 18 19 import android.content.Context; 20 import android.hardware.input.InputSettings; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 import androidx.annotation.VisibleForTesting; 25 import androidx.preference.Preference; 26 import androidx.preference.SwitchPreference; 27 28 import com.android.settings.core.PreferenceControllerMixin; 29 import com.android.settingslib.development.DeveloperOptionsPreferenceController; 30 31 /** PreferenceController that controls the "Show touchpad input" developer option. */ 32 public class TouchpadVisualizerPreferenceController extends 33 DeveloperOptionsPreferenceController implements 34 Preference.OnPreferenceChangeListener, PreferenceControllerMixin { 35 36 private static final String TOUCHPAD_VISUALIZER_KEY = "touchpad_visualizer"; 37 TouchpadVisualizerPreferenceController(@onNull Context context)38 public TouchpadVisualizerPreferenceController(@NonNull Context context) { 39 super(context); 40 } 41 42 @Override getPreferenceKey()43 public @NonNull String getPreferenceKey() { 44 return TOUCHPAD_VISUALIZER_KEY; 45 } 46 47 @Override isAvailable()48 public boolean isAvailable(){ 49 return InputSettings.isTouchpadVisualizerFeatureFlagEnabled(); 50 } 51 52 @Override onPreferenceChange(@onNull Preference preference, @Nullable Object newValue)53 public boolean onPreferenceChange(@NonNull Preference preference, @Nullable Object newValue) { 54 final boolean isEnabled = newValue != null ? (Boolean) newValue : false; 55 InputSettings.setTouchpadVisualizer(mContext, isEnabled); 56 57 return true; 58 } 59 60 @Override updateState(@onNull Preference preference)61 public void updateState(@NonNull Preference preference) { 62 boolean touchpadVisualizerEnabled = InputSettings.useTouchpadVisualizer(mContext); 63 ((SwitchPreference) mPreference).setChecked(touchpadVisualizerEnabled); 64 } 65 66 @Override onDeveloperOptionsSwitchDisabled()67 protected void onDeveloperOptionsSwitchDisabled() { 68 super.onDeveloperOptionsSwitchDisabled(); 69 InputSettings.setTouchpadVisualizer(mContext, false); 70 71 ((SwitchPreference) mPreference).setChecked(false); 72 } 73 }