diff options
Diffstat (limited to 'src/com/android/customization/widget/OptionSelectorController.java')
-rw-r--r-- | src/com/android/customization/widget/OptionSelectorController.java | 72 |
1 files changed, 31 insertions, 41 deletions
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); + } } }; |