Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bd0d5f76 authored by John Pan's avatar John Pan Committed by Automerger Merge Worker
Browse files

Talkback change for grid option am: c476673f am: 6ed8ed8d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ThemePicker/+/16405854

Change-Id: Ia09339939756cfda4e4f53c72aacef22747605e2
parents 7813f7dd 6ed8ed8d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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>

+8 −0
Original line number Diff line number Diff line
@@ -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);

+31 −41
Original line number Diff line number Diff line
@@ -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
                if (currentlyPreviewed) {
                    holder.setContentDescription(mContainer.getContext(), option,
                            R.string.option_applied_previewed_description);
                } else {
                    holder.setContentDescription(mContainer.getContext(), option,
                            R.string.option_applied_description);
                }
            }
        };