Update a11y shortcut images

- Update QS, gesture, volume keys shortcut type images
- Change FAB image to animated image
- Change 2-finger double tap, triple tap animated images
- Fix the alpha value set in the FAB preview

Bug: 324312956
Test: Run and view the images
Test: atest com.android.settings.accessibility
Flag: EXEMPT low risk, resource change
Change-Id: Ic0f1953ca20fc8a3dc7b684f95ee18dae67c4f09
This commit is contained in:
Chun-Ku Lin
2024-05-11 01:17:50 +00:00
parent f91bd7ba24
commit 833bbccd30
43 changed files with 8152 additions and 593 deletions

View File

@@ -46,7 +46,6 @@ public class AccessibilityButtonPreviewPreferenceController extends BasePreferen
private final ContentResolver mContentResolver;
@VisibleForTesting
final ContentObserver mContentObserver;
private AccessibilityLayerDrawable mAccessibilityPreviewDrawable;
@VisibleForTesting
IllustrationPreference mIllustrationPreference;
@@ -108,34 +107,23 @@ public class AccessibilityButtonPreviewPreferenceController extends BasePreferen
if (AccessibilityUtil.isFloatingMenuEnabled(mContext)) {
final int size = Settings.Secure.getInt(mContentResolver,
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_SIZE, DEFAULT_SIZE);
// The alpha range when set on a drawable is [0-255]
final int opacity = (int) (Settings.Secure.getFloat(mContentResolver,
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, DEFAULT_OPACITY) * 100);
Settings.Secure.ACCESSIBILITY_FLOATING_MENU_OPACITY, DEFAULT_OPACITY) * 255);
final int floatingMenuIconId = (size == SMALL_SIZE)
? R.drawable.a11y_button_preview_small_floating_menu
: R.drawable.a11y_button_preview_large_floating_menu;
mIllustrationPreference.setImageDrawable(
getAccessibilityPreviewDrawable(floatingMenuIconId, opacity));
? R.drawable.accessibility_shortcut_type_fab_size_small_preview
: R.drawable.accessibility_shortcut_type_fab_size_large_preview;
Drawable fabDrawable = mContext.getDrawable(floatingMenuIconId);
fabDrawable.setAlpha(opacity);
mIllustrationPreference.setImageDrawable(fabDrawable);
} else if (AccessibilityUtil.isGestureNavigateEnabled(mContext)) {
mIllustrationPreference.setImageDrawable(mContext.getDrawable(
AccessibilityUtil.isTouchExploreEnabled(mContext)
? R.drawable.a11y_button_preview_three_finger
: R.drawable.a11y_button_preview_two_finger));
? R.drawable.accessibility_shortcut_type_gesture_touch_explore_on
: R.drawable.accessibility_shortcut_type_gesture));
} else {
mIllustrationPreference.setImageDrawable(
mContext.getDrawable(R.drawable.a11y_button_navigation));
mContext.getDrawable(R.drawable.accessibility_shortcut_type_navbar));
}
}
private Drawable getAccessibilityPreviewDrawable(int resId, int opacity) {
if (mAccessibilityPreviewDrawable == null) {
mAccessibilityPreviewDrawable = AccessibilityLayerDrawable.createLayerDrawable(
mContext, resId, opacity);
} else {
mAccessibilityPreviewDrawable.updateLayerDrawable(mContext, resId, opacity);
// Only change alpha (opacity) value did not change drawable id. It needs to force to
// redraw.
mAccessibilityPreviewDrawable.invalidateSelf();
}
return mAccessibilityPreviewDrawable;
}
}

View File

@@ -1,133 +0,0 @@
/*
* 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.accessibility;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import java.util.Objects;
/** LayerDrawable that contains device icon as background and given icon as foreground. */
public class AccessibilityLayerDrawable extends LayerDrawable {
private AccessibilityLayerDrawableState mState;
/**
* Creates a new layer drawable with the list of specified layers.
*
* @param layers a list of drawables to use as layers in this new drawable,
* must be non-null
*/
private AccessibilityLayerDrawable(@NonNull Drawable[] layers) {
super(layers);
}
/**
* Create the {@link LayerDrawable} that contains device icon as background and given menu icon
* with given {@code opacity} value as foreground.
*
* @param context the valid context used to get the icon
* @param resId the resource ID of the given icon
* @param opacity the opacity to apply to the given icon
* @return the drawable that combines the device icon and the given icon
*/
public static AccessibilityLayerDrawable createLayerDrawable(Context context, int resId,
int opacity) {
final Drawable bg = context.getDrawable(R.drawable.a11y_button_preview_base);
final AccessibilityLayerDrawable basicDrawable = new AccessibilityLayerDrawable(
new Drawable[]{bg, null});
basicDrawable.updateLayerDrawable(context, resId, opacity);
return basicDrawable;
}
/**
* Update the drawable with given {@code resId} drawable and {@code opacity}(alpha)
* value at index 1 layer.
*
* @param context the valid context used to get the icon
* @param resId the resource ID of the given icon
* @param opacity the opacity to apply to the given icon
*/
public void updateLayerDrawable(Context context, int resId, int opacity) {
final Drawable icon = context.getDrawable(resId);
icon.setAlpha(opacity);
this.setDrawable(/* index= */ 1, icon);
this.setConstantState(context, resId, opacity);
}
@Override
public ConstantState getConstantState() {
return mState;
}
/** Stores the constant state and data to the given drawable. */
private void setConstantState(Context context, int resId, int opacity) {
mState = new AccessibilityLayerDrawableState(context, resId, opacity);
}
/** {@link ConstantState} to store the data of {@link AccessibilityLayerDrawable}. */
@VisibleForTesting
static class AccessibilityLayerDrawableState extends ConstantState {
private final Context mContext;
private final int mResId;
private final int mOpacity;
AccessibilityLayerDrawableState(Context context, int resId, int opacity) {
mContext = context;
mResId = resId;
mOpacity = opacity;
}
@NonNull
@Override
public Drawable newDrawable() {
return createLayerDrawable(mContext, mResId, mOpacity);
}
@Override
public int getChangingConfigurations() {
return 0;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final AccessibilityLayerDrawableState that = (AccessibilityLayerDrawableState) o;
return mResId == that.mResId
&& mOpacity == that.mOpacity
&& Objects.equals(mContext, that.mContext);
}
@Override
public int hashCode() {
return Objects.hash(mContext, mResId, mOpacity);
}
}
}

View File

@@ -246,8 +246,9 @@ public final class AccessibilityShortcutsTutorial {
final ImageView imageView = view.findViewById(R.id.image);
final int gestureSettingsImageResId =
isTouchExploreEnabled ? R.drawable.a11y_gesture_navigation_three_finger_preview
: R.drawable.a11y_gesture_navigation_two_finger_preview;
isTouchExploreEnabled
? R.drawable.accessibility_shortcut_type_gesture_preview_touch_explore_on
: R.drawable.accessibility_shortcut_type_gesture_preview;
imageView.setImageResource(gestureSettingsImageResId);
final TextView textView = view.findViewById(R.id.gesture_tutorial_message);
@@ -408,7 +409,7 @@ public final class AccessibilityShortcutsTutorial {
final CharSequence title =
context.getText(R.string.accessibility_tutorial_dialog_title_volume);
final View image =
createIllustrationView(context, R.drawable.a11y_shortcut_type_hardware);
createIllustrationView(context, R.drawable.accessibility_shortcut_type_volume_keys);
final ImageView indicatorIcon =
createImageView(context, R.drawable.ic_accessibility_page_indicator);
final CharSequence instruction =
@@ -424,7 +425,7 @@ public final class AccessibilityShortcutsTutorial {
context.getText(R.string.accessibility_tutorial_dialog_title_triple);
final View image =
createIllustrationViewWithImageRawResource(context,
R.raw.a11y_shortcut_type_triple_tap);
R.raw.accessibility_shortcut_type_tripletap);
final CharSequence instruction = context.getString(
R.string.accessibility_tutorial_dialog_tripletap_instruction, 3);
final ImageView indicatorIcon =
@@ -439,10 +440,9 @@ public final class AccessibilityShortcutsTutorial {
final int numFingers = 2;
final CharSequence title = context.getString(
R.string.accessibility_tutorial_dialog_title_two_finger_double, numFingers);
// TODO(b/308088945): Update tutorial image when UX provides them
final View image =
createIllustrationViewWithImageRawResource(context,
R.raw.a11y_shortcut_type_triple_tap);
R.raw.accessibility_shortcut_type_2finger_doubletap);
final CharSequence instruction = context.getString(
R.string.accessibility_tutorial_dialog_twofinger_doubletap_instruction, numFingers);
final ImageView indicatorIcon =
@@ -459,7 +459,7 @@ public final class AccessibilityShortcutsTutorial {
context.getText(R.string.accessibility_tutorial_dialog_title_quick_setting);
final View image =
createIllustrationView(context,
R.drawable.a11y_shortcut_type_quick_settings);
R.drawable.accessibility_shortcut_type_quick_settings);
// Remove the unneeded background, since the main image already includes a background
image.findViewById(R.id.image_background).setVisibility(GONE);
final int numFingers = AccessibilityUtil.isTouchExploreEnabled(context) ? 2 : 1;
@@ -526,13 +526,14 @@ public final class AccessibilityShortcutsTutorial {
private static View createSoftwareImage(Context context) {
int resId;
if (AccessibilityUtil.isFloatingMenuEnabled(context)) {
resId = R.drawable.a11y_shortcut_type_software_floating;
return createIllustrationViewWithImageRawResource(
context, R.raw.accessibility_shortcut_type_fab);
} else if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
resId = AccessibilityUtil.isTouchExploreEnabled(context)
? R.drawable.a11y_shortcut_type_software_gesture_talkback
: R.drawable.a11y_shortcut_type_software_gesture;
? R.drawable.accessibility_shortcut_type_gesture_touch_explore_on
: R.drawable.accessibility_shortcut_type_gesture;
} else {
resId = R.drawable.a11y_shortcut_type_software;
resId = R.drawable.accessibility_shortcut_type_navbar;
}
return createIllustrationView(context, resId);
}

View File

@@ -44,8 +44,7 @@ public class FloatingButtonShortcutOptionController
if (preference instanceof ShortcutOptionPreference shortcutOptionPreference) {
shortcutOptionPreference.setTitle(
R.string.accessibility_shortcut_edit_dialog_title_software);
shortcutOptionPreference.setIntroImageResId(
R.drawable.a11y_shortcut_type_software_floating);
shortcutOptionPreference.setIntroImageRawResId(R.raw.accessibility_shortcut_type_fab);
}
}

View File

@@ -45,8 +45,8 @@ public class GestureShortcutOptionController extends SoftwareShortcutOptionPrefe
R.string.accessibility_shortcut_edit_dialog_title_software_by_gesture);
int resId = AccessibilityUtil.isTouchExploreEnabled(mContext)
? R.drawable.a11y_shortcut_type_software_gesture_talkback
: R.drawable.a11y_shortcut_type_software_gesture;
? R.drawable.accessibility_shortcut_type_gesture_touch_explore_on
: R.drawable.accessibility_shortcut_type_gesture;
shortcutOptionPreference.setIntroImageResId(resId);
}
}

View File

@@ -47,7 +47,8 @@ public class NavButtonShortcutOptionController extends SoftwareShortcutOptionPre
if (preference instanceof ShortcutOptionPreference shortcutOptionPreference) {
shortcutOptionPreference.setTitle(
R.string.accessibility_shortcut_edit_dialog_title_software);
shortcutOptionPreference.setIntroImageResId(R.drawable.a11y_shortcut_type_software);
shortcutOptionPreference.setIntroImageResId(
R.drawable.accessibility_shortcut_type_navbar);
shortcutOptionPreference.setSummaryProvider(
new Preference.SummaryProvider<ShortcutOptionPreference>() {
@Override

View File

@@ -65,7 +65,7 @@ public class QuickSettingsShortcutOptionController extends ShortcutOptionPrefere
shortcutOptionPreference.setTitle(
R.string.accessibility_shortcut_edit_dialog_title_quick_settings);
shortcutOptionPreference.setIntroImageResId(
R.drawable.a11y_shortcut_type_quick_settings);
R.drawable.accessibility_shortcut_type_quick_settings);
}
}

View File

@@ -97,7 +97,7 @@ public class ShortcutOptionPreference extends CheckBoxPreference {
result));
imageView.setAnimation(mIntroImageRawResId);
imageView.setRepeatCount(LottieDrawable.INFINITE);
LottieColorUtils.applyDynamicColors(getContext(), imageView);
LottieColorUtils.applyDynamicColors(imageView.getContext(), imageView);
imageView.playAnimation();
} else {
imageView.setImageResource(mIntroImageResId);

View File

@@ -57,7 +57,7 @@ public class TripleTapShortcutOptionController extends ShortcutOptionPreferenceC
shortcutOptionPreference.setSummary(summary);
shortcutOptionPreference.setIntroImageRawResId(
R.raw.a11y_shortcut_type_triple_tap);
R.raw.accessibility_shortcut_type_tripletap);
}
}

View File

@@ -63,9 +63,8 @@ public class TwoFingerDoubleTapShortcutOptionController
numFingers);
shortcutOptionPreference.setSummary(summary);
// TODO (b/306153204): Update shortcut image when UX provides them
shortcutOptionPreference.setIntroImageRawResId(
R.raw.a11y_shortcut_type_triple_tap);
R.raw.accessibility_shortcut_type_2finger_doubletap);
}
}

View File

@@ -53,7 +53,7 @@ public class VolumeKeysShortcutOptionController extends ShortcutOptionPreference
shortcutOptionPreference.setSummary(
R.string.accessibility_shortcut_edit_dialog_summary_hardware);
shortcutOptionPreference.setIntroImageResId(
R.drawable.a11y_shortcut_type_hardware);
R.drawable.accessibility_shortcut_type_volume_keys);
}
}