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