summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Pan <johnpan@google.com>2021-12-08 16:29:24 +0800
committerJohn Pan <johnpan@google.com>2021-12-10 09:57:53 +0800
commitc476673fe4bf92558c9d7e06d5f9d1724b8b5261 (patch)
treec7b88cf17afca9a299ff6a5efa55e8451ea3c09d
parent13673f84a600bcf3292b3841d8c16229e3c2af80 (diff)
downloadThemePicker-c476673fe4bf92558c9d7e06d5f9d1724b8b5261.tar.gz
Talkback change for grid option
-Set content description when grid option not applied nor selected ex "4 x 4" -> "4 x 4, change applied or previewed" -Say "4 x 4, currently previewed" after double tap -Don't focus on apply button after double tap grid option Videos: -Before: https://drive.google.com/file/d/1-5b2bJsvof2WGaaqHjwxJnGGtJWWJUHD/view?usp=sharing&resourcekey=0-PFRWQEqtvxVRZKUC2SUEGg -After: https://drive.google.com/file/d/11kUz8uw7evHpNe-ZvSSG6-sxmUJsPtRr/view?usp=sharing&resourcekey=0-C-BrJmvPgxFmbgvkWn5yQw Bug: 207804306 Test: Manual Change-Id: I7f7b02286b35e82fab38d4b3d770211928e6e9ef
-rwxr-xr-xres/values/strings.xml3
-rw-r--r--src/com/android/customization/picker/grid/GridFragment.java8
-rw-r--r--src/com/android/customization/widget/OptionSelectorController.java72
3 files changed, 42 insertions, 41 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5109b4fa..f2d0f21b 100755
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -69,6 +69,9 @@
<!-- Content description indicating that the selected option is currently being previewed. [CHAR_LIMIT=NONE] -->
<string name="option_previewed_description"><xliff:g name="style_name">%1$s</xliff:g>, currently previewed</string>
+ <!-- Content description indicating that the focused option can be selected and previewed if clicked. [CHAR_LIMIT=NONE] -->
+ <string name="option_change_applied_previewed_description"><xliff:g name="style_name">%1$s</xliff:g>, change selected and previewed</string>
+
<!-- Sample text used to show a preview of a selected font [CHAR LIMIT=3] -->
<string name="theme_font_example" translatable="false">ABC</string>
diff --git a/src/com/android/customization/picker/grid/GridFragment.java b/src/com/android/customization/picker/grid/GridFragment.java
index e09bcbe6..9896edc8 100644
--- a/src/com/android/customization/picker/grid/GridFragment.java
+++ b/src/com/android/customization/picker/grid/GridFragment.java
@@ -17,12 +17,14 @@ package com.android.customization.picker.grid;
import static com.android.wallpaper.widget.BottomActionBar.BottomAction.APPLY_TEXT;
+import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
+import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -109,6 +111,12 @@ public class GridFragment extends AppbarFragment {
setUpToolbar(view);
mContent = view.findViewById(R.id.content_section);
mOptionsContainer = view.findViewById(R.id.options_container);
+ AccessibilityManager accessibilityManager =
+ (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
+ if (accessibilityManager.isEnabled()) {
+ // Make Talkback focus won't reset when notifyDataSetChange
+ mOptionsContainer.setItemAnimator(null);
+ }
mLoading = view.findViewById(R.id.loading_indicator);
mError = view.findViewById(R.id.error_section);
diff --git a/src/com/android/customization/widget/OptionSelectorController.java b/src/com/android/customization/widget/OptionSelectorController.java
index aa54f4f4..0f1b6a66 100644
--- a/src/com/android/customization/widget/OptionSelectorController.java
+++ b/src/com/android/customization/widget/OptionSelectorController.java
@@ -116,8 +116,6 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
if (!mOptions.contains(option)) {
throw new IllegalArgumentException("Invalid option");
}
- updateActivatedStatus(mSelectedOption, false);
- updateActivatedStatus(option, true);
T lastSelectedOption = mSelectedOption;
mSelectedOption = option;
mAdapter.notifyItemChanged(mOptions.indexOf(option));
@@ -151,38 +149,6 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
}
}
- private void updateActivatedStatus(T option, boolean isActivated) {
- int index = mOptions.indexOf(option);
- if (index < 0) {
- return;
- }
- RecyclerView.ViewHolder holder = mContainer.findViewHolderForAdapterPosition(index);
- if (holder != null && holder.itemView != null) {
- holder.itemView.setActivated(isActivated);
-
- if (holder instanceof TileViewHolder) {
- TileViewHolder tileHolder = (TileViewHolder) holder;
- if (isActivated) {
- if (option == mAppliedOption && mCheckmarkStyle != CheckmarkStyle.NONE) {
- tileHolder.setContentDescription(mContainer.getContext(), option,
- R.string.option_applied_previewed_description);
- } else {
- tileHolder.setContentDescription(mContainer.getContext(), option,
- R.string.option_previewed_description);
- }
- } else if (option == mAppliedOption && mCheckmarkStyle != CheckmarkStyle.NONE) {
- tileHolder.setContentDescription(mContainer.getContext(), option,
- R.string.option_applied_description);
- } else {
- tileHolder.resetContentDescription();
- }
- }
- } else {
- // Item is not visible, make sure the item is re-bound when it becomes visible
- mAdapter.notifyItemChanged(index);
- }
- }
-
/**
* Notify that a given option has changed.
* @param option the option that changed
@@ -228,7 +194,16 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
}
holder.itemView.setActivated(option.equals(mSelectedOption));
option.bindThumbnailTile(holder.tileView);
- holder.itemView.setOnClickListener(view -> setSelectedOption(option));
+ holder.itemView.setOnClickListener(view -> {
+ setSelectedOption(option);
+ String title = option.getTitle();
+ int stringId = R.string.option_previewed_description;
+ if (mSelectedOption.equals(mAppliedOption)) {
+ stringId = R.string.option_applied_previewed_description;
+ }
+ CharSequence cd = holder.itemView.getContext().getString(stringId, title);
+ view.announceForAccessibility(cd);
+ });
Resources res = mContainer.getContext().getResources();
if (mCheckmarkStyle == CheckmarkStyle.CORNER && option.equals(mAppliedOption)) {
@@ -237,14 +212,14 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
mContainer.getContext().getTheme()),
Gravity.BOTTOM | Gravity.RIGHT,
res.getDimensionPixelSize(R.dimen.check_size),
- res.getDimensionPixelOffset(R.dimen.check_offset));
+ res.getDimensionPixelOffset(R.dimen.check_offset), true);
} else if (mCheckmarkStyle == CheckmarkStyle.CENTER
&& option.equals(mAppliedOption)) {
drawCheckmark(option, holder,
res.getDrawable(R.drawable.check_circle_grey_large,
mContainer.getContext().getTheme()),
Gravity.CENTER, res.getDimensionPixelSize(R.dimen.center_check_size),
- 0);
+ 0, true);
} else if (mCheckmarkStyle == CheckmarkStyle.CENTER_CHANGE_COLOR_WHEN_NOT_SELECTED
&& option.equals(mAppliedOption)) {
int drawableRes = option.equals(mSelectedOption)
@@ -254,12 +229,22 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
res.getDrawable(drawableRes,
mContainer.getContext().getTheme()),
Gravity.CENTER, res.getDimensionPixelSize(R.dimen.center_check_size),
- 0);
+ 0, option.equals(mSelectedOption));
} else if (option.equals(mAppliedOption)) {
// Initialize with "previewed" description if we don't show checkmark
holder.setContentDescription(mContainer.getContext(), option,
R.string.option_previewed_description);
} else if (mCheckmarkStyle != CheckmarkStyle.NONE) {
+ if (mCheckmarkStyle == CheckmarkStyle.CENTER_CHANGE_COLOR_WHEN_NOT_SELECTED) {
+ if (option.equals(mSelectedOption)) {
+ holder.setContentDescription(mContainer.getContext(), option,
+ R.string.option_previewed_description);
+ } else {
+ holder.setContentDescription(mContainer.getContext(), option,
+ R.string.option_change_applied_previewed_description);
+ }
+ }
+
holder.tileView.setForeground(null);
}
}
@@ -271,7 +256,7 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
private void drawCheckmark(CustomizationOption<?> option, TileViewHolder holder,
Drawable checkmark, int gravity, @Dimension int checkSize,
- @Dimension int checkOffset) {
+ @Dimension int checkOffset, boolean currentlyPreviewed) {
Drawable frame = holder.tileView.getForeground();
Drawable[] layers = {frame, checkmark};
if (frame == null) {
@@ -289,8 +274,13 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
holder.tileView.setForeground(checkedFrame);
// Initialize the currently applied option
- holder.setContentDescription(mContainer.getContext(), option,
- R.string.option_applied_previewed_description);
+ if (currentlyPreviewed) {
+ holder.setContentDescription(mContainer.getContext(), option,
+ R.string.option_applied_previewed_description);
+ } else {
+ holder.setContentDescription(mContainer.getContext(), option,
+ R.string.option_applied_description);
+ }
}
};