• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 static android.app.settings.SettingsEnums.ACTION_MOUSE_REVERSE_VERTICAL_SCROLLING_DISABLED;
20 import static android.app.settings.SettingsEnums.ACTION_MOUSE_REVERSE_VERTICAL_SCROLLING_ENABLED;
21 
22 import android.content.Context;
23 import android.hardware.input.InputSettings;
24 
25 import androidx.annotation.NonNull;
26 
27 import com.android.settings.R;
28 import com.android.settings.core.TogglePreferenceController;
29 import com.android.settings.overlay.FeatureFactory;
30 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
31 
32 public class MouseReverseVerticalScrollingPreferenceController extends TogglePreferenceController {
33     private final MetricsFeatureProvider mMetricsFeatureProvider;
34 
MouseReverseVerticalScrollingPreferenceController( @onNull Context context, @NonNull String key)35     public MouseReverseVerticalScrollingPreferenceController(
36             @NonNull Context context, @NonNull String key) {
37         super(context, key);
38         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
39     }
40 
41     @Override
isChecked()42     public boolean isChecked() {
43         return InputSettings.isMouseReverseVerticalScrollingEnabled(mContext);
44     }
45 
46     @Override
setChecked(boolean isChecked)47     public boolean setChecked(boolean isChecked) {
48         InputSettings.setMouseReverseVerticalScrolling(mContext, isChecked);
49         mMetricsFeatureProvider.action(mContext,
50                 isChecked ? ACTION_MOUSE_REVERSE_VERTICAL_SCROLLING_ENABLED :
51                         ACTION_MOUSE_REVERSE_VERTICAL_SCROLLING_DISABLED);
52         return true;
53     }
54 
55     @Override
getAvailabilityStatus()56     public int getAvailabilityStatus() {
57         if (!InputSettings.isMouseReverseVerticalScrollingFeatureFlagEnabled()) {
58             return UNSUPPORTED_ON_DEVICE;
59         }
60         return AVAILABLE;
61     }
62 
63     @Override
getSliceHighlightMenuRes()64     public int getSliceHighlightMenuRes() {
65         return R.string.menu_key_system;
66     }
67 }
68