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.PreferenceController; 23 24 import static android.provider.Settings.Secure.CAMERA_GESTURE_DISABLED; 25 26 public class CameraGesturePreferenceController extends PreferenceController implements 27 Preference.OnPreferenceChangeListener { 28 29 private static final String KEY_CAMERA_GESTURE = "camera_gesture"; 30 31 public CameraGesturePreferenceController(Context context) { 32 super(context); 33 } 34 35 @Override 36 public String getPreferenceKey() { 37 return KEY_CAMERA_GESTURE; 38 } 39 40 @Override 41 public void updateState(Preference preference) { 42 int value = Settings.Secure.getInt(mContext.getContentResolver(), 43 CAMERA_GESTURE_DISABLED, 0); 44 ((SwitchPreference) preference).setChecked(value == 0); 45 } 46 47 @Override 48 public boolean isAvailable() { 49 boolean configSet = mContext.getResources().getInteger( 50 com.android.internal.R.integer.config_cameraLaunchGestureSensorType) != -1; 51 return configSet 52 && !SystemProperties.getBoolean("gesture.disable_camera_launch", false); 53 } 54 55 @Override 56 public boolean onPreferenceChange(Preference preference, Object newValue) { 57 boolean value = (Boolean) newValue; 58 Settings.Secure.putInt(mContext.getContentResolver(), CAMERA_GESTURE_DISABLED, 59 value ? 0 : 1 /* Backwards because setting is for disabling */); 60 return true; 61 } 62 } 63