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.annotation.NonNull; 24 25 import com.android.settings.R; 26 import com.android.settings.core.TogglePreferenceController; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; 29 30 public class TouchpadReverseScrollingPreferenceController extends TogglePreferenceController { 31 32 private final MetricsFeatureProvider mMetricsFeatureProvider; 33 TouchpadReverseScrollingPreferenceController(@onNull Context context, @NonNull String key)34 public TouchpadReverseScrollingPreferenceController(@NonNull Context context, 35 @NonNull String key) { 36 super(context, key); 37 mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); 38 } 39 40 @Override isChecked()41 public boolean isChecked() { 42 return !InputSettings.useTouchpadNaturalScrolling(mContext); 43 } 44 45 @Override setChecked(boolean isChecked)46 public boolean setChecked(boolean isChecked) { 47 InputSettings.setTouchpadNaturalScrolling(mContext, !isChecked); 48 mMetricsFeatureProvider.action( 49 mContext, SettingsEnums.ACTION_GESTURE_REVERSE_SCROLLING_CHANGED, isChecked); 50 return true; 51 } 52 53 @Override getAvailabilityStatus()54 public int getAvailabilityStatus() { 55 boolean isTouchpad = InputPeripheralsSettingsUtils.isTouchpad(); 56 return isTouchpad ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 57 } 58 59 @Override getSliceHighlightMenuRes()60 public int getSliceHighlightMenuRes() { 61 return R.string.menu_key_system; 62 } 63 } 64