• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.gestures;
18 
19 import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
20 
21 import android.content.Context;
22 import android.content.SharedPreferences;
23 import android.provider.Settings;
24 import android.text.TextUtils;
25 
26 import androidx.annotation.VisibleForTesting;
27 
28 public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
29 
30     @VisibleForTesting
31     static final int ON = 0;
32     @VisibleForTesting
33     static final int OFF = 1;
34 
35     private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
36 
37     private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
38 
DoubleTapPowerPreferenceController(Context context, String key)39     public DoubleTapPowerPreferenceController(Context context, String key) {
40         super(context, key);
41     }
42 
isSuggestionComplete(Context context, SharedPreferences prefs)43     public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) {
44         return !isGestureAvailable(context)
45                 || prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
46     }
47 
isGestureAvailable(Context context)48     private static boolean isGestureAvailable(Context context) {
49         return context.getResources()
50                 .getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
51     }
52 
53     @Override
getAvailabilityStatus()54     public int getAvailabilityStatus() {
55         return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
56     }
57 
58     @Override
isSliceable()59     public boolean isSliceable() {
60         return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
61     }
62 
63     @Override
getVideoPrefKey()64     protected String getVideoPrefKey() {
65         return PREF_KEY_VIDEO;
66     }
67 
68     @Override
isChecked()69     public boolean isChecked() {
70         final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
71                 SECURE_KEY, ON);
72         return cameraDisabled == ON;
73     }
74 
75     @Override
setChecked(boolean isChecked)76     public boolean setChecked(boolean isChecked) {
77         return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
78                 isChecked ? ON : OFF);
79     }
80 }
81