• 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"); you may not use this file
5  * except in compliance with the License. You may obtain a copy of the License at
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the
10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11  * KIND, either express or implied. See the License for the specific language governing
12  * permissions and limitations under the License.
13  */
14 package com.android.settings.display;
15 
16 import android.content.Context;
17 import android.os.SystemProperties;
18 import android.provider.Settings;
19 import android.support.v14.preference.SwitchPreference;
20 import android.support.v7.preference.Preference;
21 
22 import com.android.settings.core.PreferenceControllerMixin;
23 import com.android.settingslib.core.AbstractPreferenceController;
24 
25 import static android.provider.Settings.Secure.CAMERA_GESTURE_DISABLED;
26 
27 public class CameraGesturePreferenceController extends AbstractPreferenceController implements
28         PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
29 
30     private static final String KEY_CAMERA_GESTURE = "camera_gesture";
31 
CameraGesturePreferenceController(Context context)32     public CameraGesturePreferenceController(Context context) {
33         super(context);
34     }
35 
36     @Override
getPreferenceKey()37     public String getPreferenceKey() {
38         return KEY_CAMERA_GESTURE;
39     }
40 
41     @Override
updateState(Preference preference)42     public void updateState(Preference preference) {
43         int value = Settings.Secure.getInt(mContext.getContentResolver(),
44                 CAMERA_GESTURE_DISABLED, 0);
45         ((SwitchPreference) preference).setChecked(value == 0);
46     }
47 
48     @Override
isAvailable()49     public boolean isAvailable() {
50         boolean configSet = mContext.getResources().getInteger(
51                 com.android.internal.R.integer.config_cameraLaunchGestureSensorType) != -1;
52         return configSet
53                 && !SystemProperties.getBoolean("gesture.disable_camera_launch", false);
54     }
55 
56     @Override
onPreferenceChange(Preference preference, Object newValue)57     public boolean onPreferenceChange(Preference preference, Object newValue) {
58         boolean value = (Boolean) newValue;
59         Settings.Secure.putInt(mContext.getContentResolver(), CAMERA_GESTURE_DISABLED,
60                 value ? 0 : 1 /* Backwards because setting is for disabling */);
61         return true;
62     }
63 }
64