1 /* 2 * Copyright (C) 2023 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 android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.hardware.input.InputSettings; 22 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.core.SliderPreferenceController; 26 import com.android.settings.overlay.FeatureFactory; 27 import com.android.settings.widget.SeekBarPreference; 28 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 29 30 public class TrackpadPointerSpeedPreferenceController extends SliderPreferenceController { 31 32 private SeekBarPreference mPreference; 33 private MetricsFeatureProvider mMetricsFeatureProvider; 34 TrackpadPointerSpeedPreferenceController(Context context, String key)35 public TrackpadPointerSpeedPreferenceController(Context context, String key) { 36 super(context, key); 37 mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); 38 } 39 40 @Override displayPreference(PreferenceScreen screen)41 public void displayPreference(PreferenceScreen screen) { 42 super.displayPreference(screen); 43 mPreference = screen.findPreference(getPreferenceKey()); 44 mPreference.setMax(getMax()); 45 mPreference.setMin(getMin()); 46 mPreference.setProgress(getSliderPosition()); 47 updateState(mPreference); 48 } 49 50 @Override getAvailabilityStatus()51 public int getAvailabilityStatus() { 52 return AVAILABLE; 53 } 54 55 @Override setSliderPosition(int position)56 public boolean setSliderPosition(int position) { 57 if (position < getMin() || position > getMax()) { 58 return false; 59 } 60 InputSettings.setTouchpadPointerSpeed(mContext, position); 61 mMetricsFeatureProvider.action( 62 mContext, SettingsEnums.ACTION_GESTURE_POINTER_SPEED_CHANGED, position); 63 return true; 64 } 65 66 @Override getSliderPosition()67 public int getSliderPosition() { 68 return InputSettings.getTouchpadPointerSpeed(mContext); 69 } 70 71 @Override getMin()72 public int getMin() { 73 return InputSettings.MIN_POINTER_SPEED; 74 } 75 76 @Override getMax()77 public int getMax() { 78 return InputSettings.MAX_POINTER_SPEED; 79 } 80 } 81