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 static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_DISABLED_MODE; 22 23 import android.content.Context; 24 import android.content.SharedPreferences; 25 import android.provider.Settings; 26 27 import androidx.annotation.NonNull; 28 import androidx.preference.Preference; 29 import androidx.preference.PreferenceScreen; 30 31 import com.android.settings.R; 32 import com.android.settings.core.BasePreferenceController; 33 34 public class DoubleTapPowerPreferenceController extends BasePreferenceController { 35 DoubleTapPowerPreferenceController(@onNull Context context, @NonNull String key)36 public DoubleTapPowerPreferenceController(@NonNull Context context, @NonNull String key) { 37 super(context, key); 38 } 39 isSuggestionComplete(Context context, SharedPreferences prefs)40 public static boolean isSuggestionComplete(Context context, SharedPreferences prefs) { 41 return !isGestureAvailable(context) 42 || prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, 43 false); 44 } 45 isGestureAvailable(@onNull Context context)46 private static boolean isGestureAvailable(@NonNull Context context) { 47 if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) { 48 return context.getResources() 49 .getBoolean( 50 com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled); 51 } 52 return context.getResources() 53 .getInteger( 54 com.android.internal.R.integer.config_doubleTapPowerGestureMode) 55 != DOUBLE_TAP_POWER_DISABLED_MODE; 56 } 57 58 @Override getAvailabilityStatus()59 public int getAvailabilityStatus() { 60 return isGestureAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 61 } 62 63 @Override displayPreference(@onNull PreferenceScreen screen)64 public void displayPreference(@NonNull PreferenceScreen screen) { 65 if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap() 66 || !DoubleTapPowerSettingsUtils 67 .isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) { 68 final Preference preference = screen.findPreference(getPreferenceKey()); 69 if (preference != null) { 70 preference.setTitle(R.string.double_tap_power_for_camera_title); 71 } 72 } 73 super.displayPreference(screen); 74 } 75 76 @Override 77 @NonNull getSummary()78 public CharSequence getSummary() { 79 if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap() 80 || !DoubleTapPowerSettingsUtils 81 .isMultiTargetDoubleTapPowerButtonGestureAvailable(mContext)) { 82 final boolean isCameraDoubleTapPowerGestureEnabled = 83 Settings.Secure.getInt( 84 mContext.getContentResolver(), 85 CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, 86 DoubleTapPowerToOpenCameraPreferenceController.ON) 87 == DoubleTapPowerToOpenCameraPreferenceController.ON; 88 return mContext.getText( 89 isCameraDoubleTapPowerGestureEnabled 90 ? R.string.gesture_setting_on 91 : R.string.gesture_setting_off); 92 } 93 if (DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)) { 94 final CharSequence onString = 95 mContext.getText(com.android.settings.R.string.gesture_setting_on); 96 final CharSequence actionString = 97 DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled( 98 mContext) 99 ? mContext.getText(R.string.double_tap_power_camera_action_summary) 100 : mContext.getText(R.string.double_tap_power_wallet_action_summary); 101 return mContext.getString(R.string.double_tap_power_summary, onString, actionString); 102 } 103 return mContext.getText(com.android.settings.R.string.gesture_setting_off); 104 } 105 } 106