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 TouchpadTapToClickPreferenceController extends TogglePreferenceController { 31 32 private final MetricsFeatureProvider mMetricsFeatureProvider; 33 TouchpadTapToClickPreferenceController(@onNull Context context, @NonNull String key)34 public TouchpadTapToClickPreferenceController(@NonNull Context context, @NonNull String key) { 35 super(context, key); 36 mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider(); 37 } 38 39 @Override isChecked()40 public boolean isChecked() { 41 return InputSettings.useTouchpadTapToClick(mContext); 42 } 43 44 @Override setChecked(boolean isChecked)45 public boolean setChecked(boolean isChecked) { 46 InputSettings.setTouchpadTapToClick(mContext, isChecked); 47 mMetricsFeatureProvider.action( 48 mContext, SettingsEnums.ACTION_GESTURE_TAP_TO_CLICK_CHANGED, isChecked); 49 return true; 50 } 51 52 @Override getAvailabilityStatus()53 public int getAvailabilityStatus() { 54 boolean isTouchpad = InputPeripheralsSettingsUtils.isTouchpad(); 55 return isTouchpad ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; 56 } 57 58 @Override getSliceHighlightMenuRes()59 public int getSliceHighlightMenuRes() { 60 return R.string.menu_key_system; 61 } 62 } 63