Merge changes from topic "DoubleTapPowerButtonGestureSystemSettings" into main

* changes:
  Create Double Tap Power Illustrations based on target action
  Support wallet launch in Double Tap Power Gesture Settings
  Rename Double Tap Power To Open Camera Gesture Xml
  Refactor DoubleTapPowerPreferenceController
  Create Double Tap Power For Wallet Launch Preference Controller
  Create Double Tap Power Gesture For Camera Preference Controller
  Create Double Tap Power Gesture Main Switch Preference Controller
  Create DoubleTapPowerSettingsUtils
This commit is contained in:
Lorenzo Lucena Maguire
2024-12-04 06:19:12 +00:00
committed by Android (Google) Code Review
22 changed files with 1791 additions and 85 deletions

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
public class DoubleTapPowerForCameraPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable private Preference mPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mPreference == null || uri == null) {
return;
}
if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI)) {
mPreference.setEnabled(
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(
mContext));
} else if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI)) {
updateState(mPreference);
}
}
};
public DoubleTapPowerForCameraPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)
? AVAILABLE
: DISABLED_DEPENDENT_SETTING;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference)
.setChecked(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext));
}
}
@Override
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!getPreferenceKey().equals(preference.getKey())) {
return false;
}
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference).setChecked(true);
}
return true;
}
@Override
public void onStart() {
DoubleTapPowerSettingsUtils.registerObserver(mContext, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.SelectorWithWidgetPreference;
public class DoubleTapPowerForWalletPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable private Preference mPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mPreference == null || uri == null) {
return;
}
if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI)) {
mPreference.setEnabled(
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(
mContext));
} else if (uri.equals(
DoubleTapPowerSettingsUtils
.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI)) {
updateState(mPreference);
}
}
};
public DoubleTapPowerForWalletPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
if (!DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)
? AVAILABLE
: DISABLED_DEPENDENT_SETTING;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference)
.setChecked(
!DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext));
}
}
@Override
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!getPreferenceKey().equals(preference.getKey())) {
return false;
}
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
if (preference instanceof SelectorWithWidgetPreference) {
((SelectorWithWidgetPreference) preference).setChecked(true);
}
return true;
}
@Override
public void onStart() {
DoubleTapPowerSettingsUtils.registerObserver(mContext, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
import com.android.settingslib.widget.IllustrationPreference;
/** Configures the behaviour of the double tap power illustration. */
public class DoubleTapPowerIllustrationPreferenceController extends BasePreferenceController
implements LifecycleObserver, OnStart, OnStop {
@Nullable
private IllustrationPreference mIllustrationPreference;
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mIllustrationPreference != null && uri != null) {
updateState(mIllustrationPreference);
}
}
};
public DoubleTapPowerIllustrationPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mIllustrationPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void updateState(@NonNull Preference preference) {
super.updateState(preference);
((IllustrationPreference) preference)
.setLottieAnimationResId(
DoubleTapPowerSettingsUtils
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext)
? R.drawable.quickly_open_camera
: R.drawable.double_tap_power_for_wallet);
}
@Override
public void onStart() {
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI, true, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.settings.R;
import com.android.settings.widget.SettingsMainSwitchPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
/** The controller to handle double tap power button main switch enable or disable state. */
public class DoubleTapPowerMainSwitchPreferenceController
extends SettingsMainSwitchPreferenceController
implements LifecycleObserver, OnStart, OnStop {
private final ContentObserver mSettingsObserver =
new ContentObserver(new Handler(Looper.getMainLooper())) {
@Override
public void onChange(boolean selfChange, @Nullable Uri uri) {
if (mSwitchPreference == null || uri == null) {
return;
}
updateState(mSwitchPreference);
}
};
public DoubleTapPowerMainSwitchPreferenceController(
@NonNull Context context, @NonNull String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
return DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(
mContext, isChecked);
}
@Override
public void onStart() {
final ContentResolver resolver = mContext.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI, true, mSettingsObserver);
}
@Override
public void onStop() {
DoubleTapPowerSettingsUtils.unregisterObserver(mContext, mSettingsObserver);
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}

View File

@@ -21,22 +21,17 @@ import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_D
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
public class DoubleTapPowerPreferenceController extends GesturePreferenceController {
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
@VisibleForTesting
static final int ON = 0;
@VisibleForTesting
static final int OFF = 1;
public class DoubleTapPowerPreferenceController extends BasePreferenceController {
private static final String PREF_KEY_VIDEO = "gesture_double_tap_power_video";
private final String SECURE_KEY = CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
public DoubleTapPowerPreferenceController(Context context, String key) {
public DoubleTapPowerPreferenceController(@NonNull Context context, @NonNull String key) {
super(context, key);
}
@@ -45,9 +40,13 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
|| prefs.getBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, false);
}
private static boolean isGestureAvailable(Context context) {
return context.getResources()
.getBoolean(com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
private static boolean isGestureAvailable(@NonNull Context context) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
return context.getResources()
.getBoolean(
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled);
}
return DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(context);
}
@Override
@@ -56,30 +55,41 @@ public class DoubleTapPowerPreferenceController extends GesturePreferenceControl
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
public void displayPreference(@NonNull PreferenceScreen screen) {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final Preference preference = screen.findPreference(getPreferenceKey());
if (preference != null) {
preference.setTitle(R.string.double_tap_power_for_camera_title);
}
}
super.displayPreference(screen);
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
protected String getVideoPrefKey() {
return PREF_KEY_VIDEO;
}
@Override
public boolean isChecked() {
final int cameraDisabled = Settings.Secure.getInt(mContext.getContentResolver(),
SECURE_KEY, ON);
return cameraDisabled == ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(), SECURE_KEY,
isChecked ? ON : OFF);
@NonNull
public CharSequence getSummary() {
if (!android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()) {
final boolean isCameraDoubleTapPowerGestureEnabled =
Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
DoubleTapPowerToOpenCameraPreferenceController.ON)
== DoubleTapPowerToOpenCameraPreferenceController.ON;
return mContext.getText(
isCameraDoubleTapPowerGestureEnabled
? R.string.gesture_setting_on
: R.string.gesture_setting_off);
}
if (DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext)) {
final CharSequence onString =
mContext.getText(com.android.settings.R.string.gesture_setting_on);
final CharSequence actionString =
DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
mContext)
? mContext.getText(R.string.double_tap_power_camera_action_summary)
: mContext.getText(R.string.double_tap_power_wallet_action_summary);
return mContext.getString(R.string.double_tap_power_summary, onString, actionString);
}
return mContext.getText(com.android.settings.R.string.gesture_setting_off);
}
}

View File

@@ -19,6 +19,9 @@ package com.android.settings.gestures;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.SearchIndexableResource;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -27,6 +30,8 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;
import java.util.List;
@SearchIndexable
public class DoubleTapPowerSettings extends DashboardFragment {
@@ -56,9 +61,24 @@ public class DoubleTapPowerSettings extends DashboardFragment {
@Override
protected int getPreferenceScreenResId() {
return R.xml.double_tap_power_settings;
return android.service.quickaccesswallet.Flags.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
}
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider(R.xml.double_tap_power_settings);
new BaseSearchIndexProvider() {
@Override
@NonNull
public List<SearchIndexableResource> getXmlResourcesToIndex(
@NonNull Context context, boolean enabled) {
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId =
android.service.quickaccesswallet.Flags
.launchWalletOptionOnPowerDoubleTap()
? R.xml.double_tap_power_settings
: R.xml.double_tap_power_to_open_camera_settings;
return List.of(sir);
}
};
}

View File

@@ -0,0 +1,149 @@
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.provider.Settings;
import androidx.annotation.NonNull;
import com.android.internal.R;
/** Common code for double tap power settings shared between controllers. */
final class DoubleTapPowerSettingsUtils {
/** Setting storing whether the double tap power button gesture is enabled. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED =
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
static final Uri DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI =
Settings.Secure.getUriFor(DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED);
/** Setting storing the target action of the double tap power button gesture. */
private static final String DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION =
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE;
static final Uri DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI =
Settings.Secure.getUriFor(DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION);
private static final int DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE = 0;
private static final int DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE = 1;
static final int ON = 1;
static final int OFF = 0;
/**
* @return true if double tap power button gesture is available.
*/
public static boolean isDoubleTapPowerButtonGestureAvailable(@NonNull Context context) {
return context.getResources().getBoolean(R.bool.config_doubleTapPowerGestureEnabled);
}
/**
* Gets double tap power button gesture enable or disable flag from Settings provider.
*
* @return true if double tap on the power button gesture is currently enabled.
* @param context App context
*/
public static boolean isDoubleTapPowerButtonGestureEnabled(@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(), DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, ON)
== ON;
}
/**
* Sets double tap power button gesture enable or disable flag to Settings provider.
*
* @param context App context
* @param enable enable or disable double tap power button gesture.
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonGestureEnabled(
@NonNull Context context, boolean enable) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
enable ? ON : OFF);
}
/**
* @return true if double tap on the power button gesture for camera launch is currently
* enabled.
* @param context App context
*/
public static boolean isDoubleTapPowerButtonGestureForCameraLaunchEnabled(
@NonNull Context context) {
return Settings.Secure.getInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
context.getResources()
.getInteger(
com.android.internal.R.integer
.config_defaultDoubleTapPowerGestureAction))
== DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE;
}
/**
* Sets double tap power button gesture behavior to launch the camera.
*
* @param context App context
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonForCameraLaunch(@NonNull Context context) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
}
/**
* Sets double tap power button gesture behavior to launch the wallet.
*
* @param context App context
* @return {@code true} if the setting is updated.
*/
public static boolean setDoubleTapPowerButtonForWalletLaunch(@NonNull Context context) {
return Settings.Secure.putInt(
context.getContentResolver(),
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION,
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
}
/**
* Registers observer for settings state.
*
* @param observer Settings Content Observer
*/
public static void registerObserver(
@NonNull Context context, @NonNull ContentObserver observer) {
final ContentResolver resolver = context.getContentResolver();
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED_URI, true, observer);
resolver.registerContentObserver(
DOUBLE_TAP_POWER_BUTTON_GESTURE_TARGET_ACTION_URI, true, observer);
}
/** Unregisters observer. */
public static void unregisterObserver(
@NonNull Context context, @NonNull ContentObserver observer) {
final ContentResolver resolver = context.getContentResolver();
resolver.unregisterContentObserver(observer);
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (C) 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.gestures;
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
import android.content.Context;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
public class DoubleTapPowerToOpenCameraPreferenceController extends TogglePreferenceController {
static final int ON = 0;
static final int OFF = 1;
public DoubleTapPowerToOpenCameraPreferenceController(
@NonNull Context context, @NonNull String key) {
super(context, key);
}
@Override
public int getAvailabilityStatus() {
return mContext.getResources()
.getBoolean(
com.android.internal.R.bool
.config_cameraDoubleTapPowerGestureEnabled)
? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON)
== ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(
mContext.getContentResolver(),
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
isChecked ? ON : OFF);
}
@Override
public boolean isSliceable() {
return TextUtils.equals(getPreferenceKey(), "gesture_double_tap_power");
}
@Override
public boolean isPublicSlice() {
return true;
}
@Override
public int getSliceHighlightMenuRes() {
return R.string.menu_key_system;
}
}