• 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 android.content.Context;
20 import android.provider.Settings;
21 import android.support.v7.preference.Preference;
22 
23 import com.android.settings.core.lifecycle.Lifecycle;
24 
25 public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
26 
27     private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
28     private final String mDoubleTapPowerKey;
29 
DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key)30     public DoubleTapPowerPreferenceController(Context context, Lifecycle lifecycle, String key) {
31         super(context, lifecycle);
32         mDoubleTapPowerKey = key;
33     }
34 
35     @Override
isAvailable()36     public boolean isAvailable() {
37         return mContext.getResources().getBoolean(
38                 com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
39     }
40 
41     @Override
getVideoPrefKey()42     protected String getVideoPrefKey() {
43         return PREF_KEY_VIDEO;
44     }
45 
46     @Override
getPreferenceKey()47     public String getPreferenceKey() {
48         return mDoubleTapPowerKey;
49     }
50 
51     @Override
onPreferenceChange(Preference preference, Object newValue)52     public boolean onPreferenceChange(Preference preference, Object newValue) {
53         boolean enabled = (boolean) newValue;
54         Settings.Secure.putInt(mContext.getContentResolver(),
55                 Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, enabled ? 0 : 1);
56         return true;
57     }
58 
59     @Override
isSwitchPrefEnabled()60     protected boolean isSwitchPrefEnabled() {
61         final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
62                 Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 0);
63         return cameraDisabled == 0;
64     }
65 }
66