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:
committed by
Android (Google) Code Review
commit
56e536f4d9
36
res/drawable-night/double_tap_power_for_wallet.xml
Normal file
36
res/drawable-night/double_tap_power_for_wallet.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
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
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="412dp"
|
||||
android:height="300dp"
|
||||
android:viewportHeight="300"
|
||||
android:viewportWidth="412">
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M384.2 300H27.8C12.5 300 0 287.2 0 271.5V28.5C0 12.8 12.5 0 27.8 0H384.3C399.5 0 412 12.8 412 28.5V271.7C412 287.2 399.5 300 384.2 300Z" />
|
||||
<path
|
||||
android:fillColor="#D2E3FC"
|
||||
android:pathData="M272.5 77.2V82.9C277.9 82.9 282.3 87.3 282.3 92.7C282.3 98.1 277.9 102.5 272.5 102.5V108.2C281.1 108.2 288 101.2 288 92.7C288 84.2 281 77.2 272.5 77.2Z" />
|
||||
<path
|
||||
android:fillColor="#669DF6"
|
||||
android:pathData="M282.3 92.7C282.3 87.3 277.9 82.9 272.5 82.9V102.6C277.9 102.6 282.3 98.2 282.3 92.7Z" />
|
||||
<path
|
||||
android:fillColor="#80868B"
|
||||
android:pathData="M274.9 97.7V88.2C274.9 86.9 273.8 85.8 272.5 85.8V35.9C272.5 29.3 267.2 24 260.6 24H151.3C144.7 24 139.4 29.3 139.4 35.9V264.1C139.4 270.7 144.7 276 151.3 276H260.7C267.3 276 272.6 270.7 272.6 264.1V147.6C273.9 147.6 275 146.5 275 145.2V121.4C275 120.1 273.9 119 272.6 119V100C273.9 100.1 274.9 99 274.9 97.7ZM270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
|
||||
<path
|
||||
android:fillColor="#E8EAED"
|
||||
android:pathData="M270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
android:pathData="M194.64 151.3C192.292 151.3 190.281 150.464 188.609 148.791C186.936 147.119 186.1 145.109 186.1 142.76V125.68C186.1 123.332 186.936 121.321 188.609 119.649C190.281 117.976 192.292 117.14 194.64 117.14H220.26C222.608 117.14 224.619 117.976 226.291 119.649C227.964 121.321 228.8 123.332 228.8 125.68V142.76C228.8 145.109 227.964 147.119 226.291 148.791C224.619 150.464 222.608 151.3 220.26 151.3H194.64ZM194.64 126.214H220.26C221.292 126.214 222.253 126.374 223.142 126.694C224.067 127.014 224.886 127.477 225.597 128.082V125.68C225.597 124.186 225.082 122.922 224.05 121.89C223.018 120.858 221.754 120.343 220.26 120.343H194.64C193.145 120.343 191.882 120.858 190.85 121.89C189.818 122.922 189.303 124.186 189.303 125.68V128.082C190.014 127.477 190.815 127.014 191.704 126.694C192.63 126.374 193.608 126.214 194.64 126.214ZM189.463 133.473L214.922 139.611C215.172 139.682 215.421 139.7 215.67 139.664C215.954 139.593 216.186 139.469 216.364 139.291L224.904 132.138C224.441 131.32 223.801 130.662 222.982 130.164C222.164 129.665 221.256 129.416 220.26 129.416H194.64C193.395 129.416 192.292 129.808 191.331 130.591C190.37 131.338 189.747 132.298 189.463 133.473Z" />
|
||||
</vector>
|
||||
36
res/drawable/double_tap_power_for_wallet.xml
Normal file
36
res/drawable/double_tap_power_for_wallet.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
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
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="412dp"
|
||||
android:height="300dp"
|
||||
android:viewportHeight="300"
|
||||
android:viewportWidth="412">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M384.2 300H27.8C12.5 300 0 287.2 0 271.5V28.5C0 12.8 12.5 0 27.8 0H384.3C399.5 0 412 12.8 412 28.5V271.7C412 287.2 399.5 300 384.2 300Z" />
|
||||
<path
|
||||
android:fillColor="#8AB4F8"
|
||||
android:pathData="M272.5 77.2V82.9C277.9 82.9 282.3 87.3 282.3 92.7C282.3 98.1 277.9 102.5 272.5 102.5V108.2C281.1 108.2 288 101.2 288 92.7C288 84.2 281 77.2 272.5 77.2Z" />
|
||||
<path
|
||||
android:fillColor="#669DF6"
|
||||
android:pathData="M282.3 92.7C282.3 87.3 277.9 82.9 272.5 82.9V102.6C277.9 102.6 282.3 98.2 282.3 92.7Z" />
|
||||
<path
|
||||
android:fillColor="#DADCE0"
|
||||
android:pathData="M274.9 97.7V88.2C274.9 86.9 273.8 85.8 272.5 85.8V35.9C272.5 29.3 267.2 24 260.6 24H151.3C144.7 24 139.4 29.3 139.4 35.9V264.1C139.4 270.7 144.7 276 151.3 276H260.7C267.3 276 272.6 270.7 272.6 264.1V147.6C273.9 147.6 275 146.5 275 145.2V121.4C275 120.1 273.9 119 272.6 119V100C273.9 100.1 274.9 99 274.9 97.7ZM270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
|
||||
<path
|
||||
android:fillColor="#3C4043"
|
||||
android:pathData="M270.2 264.1C270.2 269.3 265.9 273.6 260.7 273.6H151.3C146.1 273.6 141.8 269.3 141.8 264.1V35.9C141.8 30.7 146.1 26.4 151.3 26.4H260.7C265.9 26.4 270.2 30.7 270.2 35.9V264.1Z" />
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M194.64 151.3C192.292 151.3 190.281 150.464 188.609 148.791C186.936 147.119 186.1 145.109 186.1 142.76V125.68C186.1 123.332 186.936 121.321 188.609 119.649C190.281 117.976 192.292 117.14 194.64 117.14H220.26C222.608 117.14 224.619 117.976 226.291 119.649C227.964 121.321 228.8 123.332 228.8 125.68V142.76C228.8 145.109 227.964 147.119 226.291 148.791C224.619 150.464 222.608 151.3 220.26 151.3H194.64ZM194.64 126.214H220.26C221.292 126.214 222.253 126.374 223.142 126.694C224.067 127.014 224.886 127.477 225.597 128.082V125.68C225.597 124.186 225.082 122.922 224.05 121.89C223.018 120.858 221.754 120.343 220.26 120.343H194.64C193.145 120.343 191.882 120.858 190.85 121.89C189.818 122.922 189.303 124.186 189.303 125.68V128.082C190.014 127.477 190.815 127.014 191.704 126.694C192.63 126.374 193.608 126.214 194.64 126.214ZM189.463 133.473L214.922 139.611C215.172 139.682 215.421 139.7 215.67 139.664C215.954 139.593 216.186 139.469 216.364 139.291L224.904 132.138C224.441 131.32 223.801 130.662 222.982 130.164C222.164 129.665 221.256 129.416 220.26 129.416H194.64C193.395 129.416 192.292 129.808 191.331 130.591C190.37 131.338 189.747 132.298 189.463 133.473Z" />
|
||||
</vector>
|
||||
@@ -11158,6 +11158,23 @@
|
||||
<!-- Summary text for double tap power for camera [CHAR LIMIT=160]-->
|
||||
<string name="double_tap_power_for_camera_summary">To quickly open camera, press the power button twice. Works from any screen.</string>
|
||||
|
||||
<!-- Title text for double tap power gesture [CHAR LIMIT=80]-->
|
||||
<string name="double_tap_power_title">Double tap power button</string>
|
||||
<!-- Summary for double tap power settings [DO NOT TRANSLATE] -->
|
||||
<string name="double_tap_power_summary" translatable="false"><xliff:g id="double_tap_power_on_off" example="On">%1$s</xliff:g> / <xliff:g id="double_tap_power_actions" example="Access Wallet">%2$s</xliff:g></string>
|
||||
<!-- Switch label to enable/disable double tap power button gesture [CHAR LIMIT=60] -->
|
||||
<string name="double_tap_power_enabled">Use double tap</string>
|
||||
<!-- Category title for double tap power gesture [CHAR_LIMIT=80] -->
|
||||
<string name="double_tap_power_target_action_category">Double Tap Power Button</string>
|
||||
<!-- Double Tap Power Gesture camera launch action title [CHAR_LIMIT=60] -->
|
||||
<string name="double_tap_power_camera_action_title">Open Camera</string>
|
||||
<!-- Setting summary to describe double tap power button will open camera. [CHAR LIMIT=NONE] -->
|
||||
<string name="double_tap_power_camera_action_summary">Access Camera</string>
|
||||
<!-- Double Tap Power Gesture wallet launch action title [CHAR_LIMIT=60] -->
|
||||
<string name="double_tap_power_wallet_action_title">Open Wallet</string>
|
||||
<!-- Setting summary to describe double tap power button will open wallet. [CHAR LIMIT=NONE] -->
|
||||
<string name="double_tap_power_wallet_action_summary">Access Wallet</string>
|
||||
|
||||
<!-- Title text for double twist for camera mode [CHAR LIMIT=60]-->
|
||||
<string name="double_twist_for_camera_mode_title">Flip camera for selfie</string>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright (C) 2016 The Android Open Source Project
|
||||
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.
|
||||
@@ -18,19 +18,28 @@
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/double_tap_power_for_camera_title">
|
||||
|
||||
android:title="@string/double_tap_power_title">
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="gesture_double_tap_power_video"
|
||||
settings:searchable="false"
|
||||
app:lottie_rawRes="@drawable/quickly_open_camera"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="gesture_double_tap_power"
|
||||
android:title="@string/double_tap_power_for_camera_title"
|
||||
android:summary="@string/double_tap_power_for_camera_summary"
|
||||
app:keywords="@string/keywords_gesture"
|
||||
app:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController"/>
|
||||
settings:lottie_rawRes="@drawable/quickly_open_camera"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerIllustrationPreferenceController"/>
|
||||
|
||||
<com.android.settingslib.widget.MainSwitchPreference
|
||||
android:key="gesture_double_tap_power_enabled_main_switch"
|
||||
android:title="@string/double_tap_power_enabled"
|
||||
settings:keywords="@string/keywords_gesture"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerMainSwitchPreferenceController"/>
|
||||
<PreferenceCategory
|
||||
android:key="gesture_double_tap_power_actions"
|
||||
android:title="@string/double_tap_power_target_action_category">
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="gesture_double_power_tap_camera"
|
||||
android:title="@string/double_tap_power_camera_action_title"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerForCameraPreferenceController"/>
|
||||
<com.android.settingslib.widget.SelectorWithWidgetPreference
|
||||
android:key="gesture_double_power_tap_wallet"
|
||||
android:title="@string/double_tap_power_wallet_action_title"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerForWalletPreferenceController"/>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
||||
35
res/xml/double_tap_power_to_open_camera_settings.xml
Normal file
35
res/xml/double_tap_power_to_open_camera_settings.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/double_tap_power_for_camera_title">
|
||||
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="gesture_double_tap_power_video"
|
||||
settings:searchable="false"
|
||||
settings:lottie_rawRes="@drawable/quickly_open_camera"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:key="gesture_double_tap_power"
|
||||
android:title="@string/double_tap_power_for_camera_title"
|
||||
android:summary="@string/double_tap_power_for_camera_summary"
|
||||
settings:keywords="@string/keywords_gesture"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
<Preference
|
||||
android:key="gesture_double_tap_power_input_summary"
|
||||
android:title="@string/double_tap_power_for_camera_title"
|
||||
android:title="@string/double_tap_power_title"
|
||||
android:fragment="com.android.settings.gestures.DoubleTapPowerSettings"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.gestures.DoubleTapPowerPreferenceController" />
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DoubleTapPowerForCameraPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_double_power_tap_launch_camera";
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DoubleTapPowerForCameraPreferenceController mController;
|
||||
private SelectorWithWidgetPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new DoubleTapPowerForCameraPreferenceController(mContext, KEY);
|
||||
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_launchCameraEnabled_preferenceChecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_launchCameraDisabled_preferenceNotChecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerCameraLaunchEnabled_preferenceEnabled() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.SelectorWithWidgetPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DoubleTapPowerForWalletPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_double_power_tap_launch_wallet";
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DoubleTapPowerForWalletPreferenceController mController;
|
||||
private SelectorWithWidgetPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new DoubleTapPowerForWalletPreferenceController(mContext, KEY);
|
||||
mPreference = new SelectorWithWidgetPreference(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_launchWalletEnabled_preferenceChecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_launchWalletDisabled_preferenceNotChecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureNotAvailable_preferenceUnsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerButtonDisabled_preferenceDisabled() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_DEPENDENT_SETTING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerWalletLaunchEnabled_preferenceEnabled() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.IllustrationPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DoubleTapPowerIllustrationPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_double_tap_power_video";
|
||||
private Application mContext;
|
||||
private IllustrationPreference mPreference;
|
||||
private DoubleTapPowerIllustrationPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = ApplicationProvider.getApplicationContext();
|
||||
mPreference = new IllustrationPreference(mContext);
|
||||
mController = new DoubleTapPowerIllustrationPreferenceController(mContext, KEY);
|
||||
|
||||
PreferenceScreen mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference(KEY)).thenReturn(mPreference);
|
||||
mController.displayPreference(mScreen);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_setDoubleTapPowerForCamera_showsCameraIllustration() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getLottieAnimationResId()).isEqualTo(R.drawable.quickly_open_camera);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_setDoubleTapPowerForWallet_showsWalletIllustration() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getLottieAnimationResId())
|
||||
.isEqualTo(R.drawable.double_tap_power_for_wallet);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* 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.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DoubleTapPowerMainSwitchPreferenceControllerTest {
|
||||
|
||||
private static final String KEY = "gesture_double_tap_power_enabled_main_switch";
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DoubleTapPowerMainSwitchPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new DoubleTapPowerMainSwitchPreferenceController(mContext, KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureAvailable_preferenceEnabled() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureUnavailable_preferenceUnsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_setDoubleTapPowerGestureEnabled_mainSwitchChecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_setDoubleTapPowerGestureDisabled_mainSwitchUnchecked() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_checkMainSwitch_doubleTapPowerGestureEnabled() {
|
||||
mController.setChecked(true);
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_uncheckMainSwitch_doubleTapPowerGestureDisabled() {
|
||||
mController.setChecked(false);
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
}
|
||||
@@ -17,23 +17,37 @@
|
||||
package com.android.settings.gestures;
|
||||
|
||||
import static android.provider.Settings.Secure.CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED;
|
||||
import static android.provider.Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED;
|
||||
|
||||
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.OFF;
|
||||
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.ON;
|
||||
import static com.android.settings.gestures.DoubleTapPowerPreferenceController.isSuggestionComplete;
|
||||
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
|
||||
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
import android.service.quickaccesswallet.Flags;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProviderImpl;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@@ -44,16 +58,22 @@ import org.robolectric.annotation.Config;
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class DoubleTapPowerPreferenceControllerTest {
|
||||
|
||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
private Context mContext;
|
||||
private ContentResolver mContentResolver;
|
||||
private DoubleTapPowerPreferenceController mController;
|
||||
private Preference mPreference;
|
||||
private PreferenceScreen mScreen;
|
||||
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = RuntimeEnvironment.getApplication();
|
||||
mContentResolver = mContext.getContentResolver();
|
||||
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
|
||||
mPreference = new Preference(mContext);
|
||||
mScreen = mock(PreferenceScreen.class);
|
||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -62,7 +82,26 @@ public class DoubleTapPowerPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsTrue_shouldReturnTrue() {
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isAvailable_flagEnabled_configIsTrue_returnsTrue() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.TRUE);
|
||||
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isAvailable_flagEnabled_configIsFalse_returnsFalse() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, Boolean.FALSE);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isAvailable_flagDisabled_configIsTrue_returnsTrue() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
|
||||
Boolean.TRUE);
|
||||
@@ -71,7 +110,8 @@ public class DoubleTapPowerPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_configIsTrue_shouldReturnFalse() {
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isAvailable_flagDisabled_configIsFalse_returnsFalse() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled,
|
||||
Boolean.FALSE);
|
||||
@@ -80,43 +120,63 @@ public class DoubleTapPowerPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_configIsNotSet_shouldReturnTrue() {
|
||||
// Set the setting to be enabled.
|
||||
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
|
||||
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenNotAvailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, false);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsChecked_configIsSet_shouldReturnFalse() {
|
||||
// Set the setting to be disabled.
|
||||
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
|
||||
mController = new DoubleTapPowerPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_enableFlag_doubleTapPower_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
|
||||
// No stored value in shared preferences if not visited yet.
|
||||
final SharedPreferences prefs =
|
||||
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionCompleted_doubleTapPower_trueWhenNotAvailable() {
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_enableFlag_doubleTapPower_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_doubleTapPowerGestureEnabled, true);
|
||||
// No stored value in shared preferences if not visited yet.
|
||||
final SharedPreferences prefs =
|
||||
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
|
||||
prefs.edit().putBoolean(DoubleTapPowerSettings.PREF_KEY_SUGGESTION_COMPLETE, true).commit();
|
||||
|
||||
assertThat(isSuggestionComplete(mContext, prefs)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenNotAvailable() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, false);
|
||||
|
||||
assertThat(isSuggestionComplete(mContext, null/* prefs */)).isTrue();
|
||||
assertThat(isSuggestionComplete(mContext, null /* prefs */)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionCompleted_doubleTapPower_falseWhenNotVisited() {
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_disableFlag_doubleTapPower_falseWhenNotVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
|
||||
// No stored value in shared preferences if not visited yet.
|
||||
final SharedPreferences prefs =
|
||||
new SuggestionFeatureProviderImpl().getSharedPrefs(mContext);
|
||||
|
||||
assertThat(isSuggestionComplete(mContext, prefs)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSuggestionCompleted_doubleTapPower_trueWhenVisited() {
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void isSuggestionCompleted_disableFlag_doubleTapPower_trueWhenVisited() {
|
||||
SettingsShadowResources.overrideResource(
|
||||
com.android.internal.R.bool.config_cameraDoubleTapPowerGestureEnabled, true);
|
||||
// No stored value in shared preferences if not visited yet.
|
||||
@@ -128,21 +188,92 @@ public class DoubleTapPowerPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final DoubleTapPowerPreferenceController controller =
|
||||
new DoubleTapPowerPreferenceController(mContext, "gesture_double_tap_power");
|
||||
assertThat(controller.isSliceable()).isTrue();
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void displayPreference_flagDisabled_doubleTapPowerLegacyTitleIsDisplayed() {
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mPreference.getTitle(),
|
||||
mContext.getText(R.string.double_tap_power_for_camera_title)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableIncorrectKey_returnsFalse() {
|
||||
final DoubleTapPowerPreferenceController controller =
|
||||
new DoubleTapPowerPreferenceController(mContext, "bad_key");
|
||||
assertThat(controller.isSliceable()).isFalse();
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getSummary_flagDisabled_doubleTapPowerEnabled_returnsOn() {
|
||||
// Set the setting to be enabled.
|
||||
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mController.getSummary(),
|
||||
mContext.getText(R.string.gesture_setting_on)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPublicSlice_returnTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getSummary_flagDisabled_doubleTapPowerDisabled_returnsOff() {
|
||||
// Set the setting to be disabled.
|
||||
Settings.Secure.putInt(mContentResolver, CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mController.getSummary(),
|
||||
mContext.getText(R.string.gesture_setting_off)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getSummary_flagEnabled_doubleTapPowerDisabled_returnsOff() {
|
||||
// Set the setting to be disabled.
|
||||
Settings.Secure.putInt(
|
||||
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 0 /* OFF */);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mController.getSummary(),
|
||||
mContext.getText(R.string.gesture_setting_off)))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getSummary_flagEnabled_doubleTapPowerEnabled_cameraTargetAction_returnsSummary() {
|
||||
// Set the setting to be enabled.
|
||||
Settings.Secure.putInt(
|
||||
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mController.getSummary(),
|
||||
mContext.getString(
|
||||
R.string.double_tap_power_summary,
|
||||
mContext.getText(R.string.gesture_setting_on),
|
||||
mContext.getText(
|
||||
R.string.double_tap_power_camera_action_summary))))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getSummary_flagEnabled_doubleTapPowerEnabled_walletTargetAction_returnsSummary() {
|
||||
// Set the setting to be enabled.
|
||||
Settings.Secure.putInt(
|
||||
mContentResolver, DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED, 1 /* ON */);
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
|
||||
|
||||
assertThat(
|
||||
TextUtils.equals(
|
||||
mController.getSummary(),
|
||||
mContext.getString(
|
||||
R.string.double_tap_power_summary,
|
||||
mContext.getText(R.string.gesture_setting_on),
|
||||
mContext.getText(
|
||||
R.string.double_tap_power_wallet_action_summary))))
|
||||
.isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,16 @@ package com.android.settings.gestures;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.platform.test.annotations.DisableFlags;
|
||||
import android.platform.test.annotations.EnableFlags;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.service.quickaccesswallet.Flags;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@@ -31,6 +38,7 @@ import java.util.List;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DoubleTapPowerSettingsTest {
|
||||
|
||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
private DoubleTapPowerSettings mSettings;
|
||||
|
||||
@Before
|
||||
@@ -39,12 +47,38 @@ public class DoubleTapPowerSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getPreferenceScreenResId_flagEnabled_returnsFlagEnabledResId() {
|
||||
assertThat(mSettings.getPreferenceScreenResId()).isEqualTo(R.xml.double_tap_power_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void getPreferenceScreenResId_flagDisabled_returnsFlagDisabledResId() {
|
||||
assertThat(mSettings.getPreferenceScreenResId())
|
||||
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void testSearchIndexProvider_flagEnabled_shouldIndexFlagEnabledResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.application, true /* enabled */);
|
||||
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.getApplication(), true /* enabled */);
|
||||
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mSettings.getPreferenceScreenResId());
|
||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(R.xml.double_tap_power_settings);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableFlags(Flags.FLAG_LAUNCH_WALLET_OPTION_ON_POWER_DOUBLE_TAP)
|
||||
public void testSearchIndexProvider_flagDisabled_shouldIndexFlagDisabledResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
DoubleTapPowerSettings.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
|
||||
RuntimeEnvironment.getApplication(), true /* enabled */);
|
||||
|
||||
assertThat(indexRes).isNotNull();
|
||||
assertThat(indexRes.get(0).xmlResId)
|
||||
.isEqualTo(R.xml.double_tap_power_to_open_camera_settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.OFF;
|
||||
import static com.android.settings.gestures.DoubleTapPowerSettingsUtils.ON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class DoubleTapPowerSettingsUtilsTest {
|
||||
|
||||
private static final int DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE = 0;
|
||||
private static final int DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE = 1;
|
||||
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureAvailable_setAvailable_returnsTrue() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(true);
|
||||
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureAvailable_setUnavailable_returnsFalse() {
|
||||
when(mResources.getBoolean(R.bool.config_doubleTapPowerGestureEnabled)).thenReturn(false);
|
||||
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureAvailable(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureEnabled_setEnabled_returnsTrue() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
|
||||
ON);
|
||||
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureEnabled_setDisabled_returnsFalse() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
|
||||
OFF);
|
||||
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureEnabled_valueNotSet_returnsTrue() {
|
||||
assertThat(DoubleTapPowerSettingsUtils.isDoubleTapPowerButtonGestureEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDoubleTapPowerButtonGestureEnabled_setEnabled_returnsEnabled() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, true);
|
||||
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
|
||||
OFF))
|
||||
.isEqualTo(ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDoubleTapPowerButtonGestureEnabled_setDisabled_returnsDisabled() {
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonGestureEnabled(mContext, false);
|
||||
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE_ENABLED,
|
||||
ON))
|
||||
.isEqualTo(OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDoubleTapPowerButtonGestureForCameraLaunchEnabled_valueSetToCamera_returnsTrue() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
|
||||
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
|
||||
|
||||
assertThat(
|
||||
DoubleTapPowerSettingsUtils
|
||||
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_valueNotSetToCamera_returnsFalse() {
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
|
||||
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
|
||||
|
||||
assertThat(
|
||||
DoubleTapPowerSettingsUtils
|
||||
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultSetToCamera_returnsTrue() {
|
||||
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
|
||||
.thenReturn(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
|
||||
|
||||
assertThat(
|
||||
DoubleTapPowerSettingsUtils
|
||||
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
isDoubleTapPowerButtonGestureForCameraLaunchEnabled_defaultNotCamera_returnsFalse() {
|
||||
when(mResources.getInteger(R.integer.config_defaultDoubleTapPowerGestureAction))
|
||||
.thenReturn(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
|
||||
|
||||
assertThat(
|
||||
DoubleTapPowerSettingsUtils
|
||||
.isDoubleTapPowerButtonGestureForCameraLaunchEnabled(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDoubleTapPowerButtonForCameraLaunch_setGestureBehaviorToCameraLaunch() {
|
||||
boolean result =
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForCameraLaunch(mContext);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
|
||||
DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE))
|
||||
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDoubleTapPowerButtonForWalletLaunch_setGestureBehaviorToWalletLaunch() {
|
||||
boolean result =
|
||||
DoubleTapPowerSettingsUtils.setDoubleTapPowerButtonForWalletLaunch(mContext);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
Settings.Secure.DOUBLE_TAP_POWER_BUTTON_GESTURE,
|
||||
DOUBLE_TAP_POWER_BUTTON_CAMERA_LAUNCH_VALUE))
|
||||
.isEqualTo(DOUBLE_TAP_POWER_BUTTON_WALLET_LAUNCH_VALUE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* 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 static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.OFF;
|
||||
import static com.android.settings.gestures.DoubleTapPowerToOpenCameraPreferenceController.ON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import com.android.internal.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@Config(shadows = SettingsShadowResources.class)
|
||||
public class DoubleTapPowerToOpenCameraPreferenceControllerTest {
|
||||
@Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
|
||||
private Context mContext;
|
||||
private Resources mResources;
|
||||
private DoubleTapPowerToOpenCameraPreferenceController mController;
|
||||
private static final String KEY_DOUBLE_TAP_POWER = "gesture_double_tap_power";
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = spy(RuntimeEnvironment.getApplication());
|
||||
mResources = mock(Resources.class);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController =
|
||||
new DoubleTapPowerToOpenCameraPreferenceController(mContext, KEY_DOUBLE_TAP_POWER);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SettingsShadowResources.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureDisabled_preferenceUnsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_cameraDoubleTapPowerGestureEnabled))
|
||||
.thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_setDoubleTapPowerGestureEnabled_preferenceSupported() {
|
||||
when(mResources.getBoolean(R.bool.config_cameraDoubleTapPowerGestureEnabled))
|
||||
.thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_configIsNotSet_returnsTrue() {
|
||||
// Set the setting to be enabled.
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_setConfigFalse_returnsFalse() {
|
||||
// Set the setting to be disabled.
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, OFF);
|
||||
|
||||
assertThat(mController.isChecked()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isChecked_setConfigTrue_returnsFalse() {
|
||||
// Set the setting to be disabled.
|
||||
Settings.Secure.putInt(
|
||||
mContext.getContentResolver(), CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED, ON);
|
||||
|
||||
assertThat(mController.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_checkToggle_cameraDoubleTapPowerGestureEnabled() {
|
||||
mController.setChecked(true);
|
||||
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
|
||||
OFF))
|
||||
.isEqualTo(ON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setChecked_uncheckToggle_cameraDoubleTapPowerGestureDisabled() {
|
||||
mController.setChecked(false);
|
||||
|
||||
assertThat(
|
||||
Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED,
|
||||
ON))
|
||||
.isEqualTo(OFF);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableCorrectKey_returnsTrue() {
|
||||
final DoubleTapPowerToOpenCameraPreferenceController controller =
|
||||
new DoubleTapPowerToOpenCameraPreferenceController(
|
||||
mContext, "gesture_double_tap_power");
|
||||
|
||||
assertThat(controller.isSliceable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSliceableIncorrectKey_returnsFalse() {
|
||||
final DoubleTapPowerToOpenCameraPreferenceController controller =
|
||||
new DoubleTapPowerToOpenCameraPreferenceController(mContext, "bad_key");
|
||||
|
||||
assertThat(controller.isSliceable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isPublicSlice_returnTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user