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.provider.Settings;
22 
23 import com.android.settings.R;
24 import com.android.settings.core.TogglePreferenceController;
25 import com.android.settings.overlay.FeatureFactory;
26 import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
27 
28 public class TrackpadGoBackPreferenceController extends TogglePreferenceController {
29 
30     private static final String SETTING_KEY = Settings.Secure.TRACKPAD_GESTURE_BACK_ENABLED;
31 
32     private MetricsFeatureProvider mMetricsFeatureProvider;
33 
TrackpadGoBackPreferenceController(Context context, String key)34     public TrackpadGoBackPreferenceController(Context context, String key) {
35         super(context, key);
36         mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
37     }
38 
39     @Override
isChecked()40     public boolean isChecked() {
41         return Settings.Secure.getInt(mContext.getContentResolver(), SETTING_KEY, 1) != 0;
42     }
43 
44     @Override
setChecked(boolean isChecked)45     public boolean setChecked(boolean isChecked) {
46         Settings.Secure.putInt(mContext.getContentResolver(), SETTING_KEY, isChecked ? 1 : 0);
47         mMetricsFeatureProvider.action(
48                 mContext, SettingsEnums.ACTION_GESTURE_GO_BACK_CHANGED, isChecked);
49         return true;
50     }
51 
52     @Override
getAvailabilityStatus()53     public int getAvailabilityStatus() {
54         return AVAILABLE;
55     }
56 
57     @Override
getSliceHighlightMenuRes()58     public int getSliceHighlightMenuRes() {
59         return R.string.menu_key_system;
60     }
61 }
62