Create Double Tap Power Illustrations based on target action
Creates illustration for when double tap power gesture is set to open wallet and preference controller to alternate illustration based on gesture target action Android Settings Feature Request: b/380287172 Test: atest DoubleTapPowerIllustrationPreferenceControllerTest Test: manually verified illustration corresponds to selected target action Bug: 381789181 FLAG: android.service.quickaccesswallet.launch_wallet_option_on_power_double_tap Change-Id: Id73a38e09bd72856d46d74f04c0c0d2b3f989929
This commit is contained in:
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>
|
@@ -22,7 +22,8 @@
|
||||
<com.android.settingslib.widget.IllustrationPreference
|
||||
android:key="gesture_double_tap_power_video"
|
||||
settings:searchable="false"
|
||||
settings:lottie_rawRes="@drawable/quickly_open_camera"/>
|
||||
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"
|
||||
|
@@ -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,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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user