• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 MouseScrollingAccelerationPreferenceController extends TogglePreferenceController {
31 
32     private final MetricsFeatureProvider mMetricsFeatureProvider;
33 
MouseScrollingAccelerationPreferenceController( @onNull Context context, @NonNull String key)34     public MouseScrollingAccelerationPreferenceController(
35             @NonNull Context context, @NonNull String key) {
36         super(context, key);
37         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
38     }
39 
40     @Override
isChecked()41     public boolean isChecked() {
42         return !InputSettings.isMouseScrollingAccelerationEnabled(mContext);
43     }
44 
45     @Override
setChecked(boolean isChecked)46     public boolean setChecked(boolean isChecked) {
47         InputSettings.setMouseScrollingAcceleration(mContext, !isChecked);
48         mMetricsFeatureProvider.action(mContext,
49                 isChecked ? SettingsEnums.ACTION_MOUSE_SCROLLING_ACCELERATION_DISABLED :
50                             SettingsEnums.ACTION_MOUSE_SCROLLING_ACCELERATION_ENABLED);
51         return true;
52     }
53 
54     @Override
getAvailabilityStatus()55     public int getAvailabilityStatus() {
56         if (!InputSettings.isMouseScrollingAccelerationFeatureFlagEnabled()) {
57             return UNSUPPORTED_ON_DEVICE;
58         }
59         return AVAILABLE;
60     }
61 
62     @Override
getSliceHighlightMenuRes()63     public int getSliceHighlightMenuRes() {
64         return R.string.menu_key_system;
65     }
66 }
67