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.Intent; 23 import android.content.SharedPreferences; 24 import android.provider.Settings; 25 import android.support.annotation.VisibleForTesting; 26 import android.text.TextUtils; 27 28 import com.android.settings.R; 29 import com.android.settings.search.DatabaseIndexingUtils; 30 import com.android.settings.search.InlineSwitchPayload; 31 import com.android.settings.search.ResultPayload; 32 33 public class DoubleTapPowerPreferenceController extends GesturePreferenceController { 34 35 @VisibleForTesting 36 static final int ON = 0; 37 @VisibleForTesting 38 static final int OFF = 1; 39 40 private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video"; 41 private final String mDoubleTapPowerKey; 42 43 private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED; 44 DoubleTapPowerPreferenceController(Context context, String key)45 public DoubleTapPowerPreferenceController(Context context, String key) { 46 super(context, key); 47 mDoubleTapPowerKey = key; 48 } 49 isSuggestionComplete(Context context, SharedPreferences prefs)50 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 51 return !isGestureAvailable(context) 52 || prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, false); 53 } 54 isGestureAvailable(Context context)55 private static boolean isGestureAvailable(Context context) { 56 return context.getResources() 57 .getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled); 58 } 59 60 @Override getAvailabilityStatus()61 public int getAvailabilityStatus() { 62 return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 63 } 64 65 @Override isSliceable()66 public boolean isSliceable() { 67 return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power"); 68 } 69 70 @Override getVideoPrefKey()71 protected String getVideoPrefKey() { 72 return PREF_KEY_VIDEO; 73 } 74 75 @Override isChecked()76 public boolean isChecked() { 77 final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(), 78 SECURE_KEY, ON); 79 return cameraDisabled == ON; 80 } 81 82 @Override setChecked(boolean isChecked)83 public boolean setChecked(boolean isChecked) { 84 return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY, 85 isChecked ? ON : OFF); 86 } 87 88 @Override 89 //TODO (b/69808376): Remove result payload getResultPayload()90 public ResultPayload getResultPayload() { 91 final Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(mContext, 92 DoubleTapPowerSettings.class.getName(), mDoubleTapPowerKey, 93 mContext.getString(R.string.display_settings)); 94 95 return new InlineSwitchPayload(SECURE_KEY, ResultPayload.SettingsSource.SECURE, 96 ON /* onValue */, intent, isAvailable(), ON /* defaultValue */); 97 } 98 } 99