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

Commit ddf9d24b authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Add content descriptions for custom pages

Fixes: 131293339
Test: manual
Change-Id: Ica713b4d110f198f64be533a240b7339027c4372
parent d3a582a9
Loading
Loading
Loading
Loading
+50 −24
Original line number Diff line number Diff line
@@ -15,17 +15,17 @@
 */
package com.android.customization.widget;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
@@ -35,7 +35,6 @@ import androidx.recyclerview.widget.RecyclerView;

import com.android.customization.model.CustomizationManager;
import com.android.customization.model.CustomizationOption;
import com.android.customization.model.theme.custom.ThemeComponentOption;
import com.android.wallpaper.R;

import java.util.HashSet;
@@ -130,26 +129,19 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {

            if (holder instanceof TileViewHolder) {
                TileViewHolder tileHolder = (TileViewHolder) holder;
                if (tileHolder.labelView != null) {
                if (isActivated) {
                        if (option == mAppliedOption) {
                            CharSequence cd = mContainer.getContext().getString(
                                    R.string.option_applied_previewed_description,
                                    option.getTitle());
                            tileHolder.labelView.setContentDescription(cd);
                    if (option == mAppliedOption && mShowCheckmark) {
                        tileHolder.setContentDescription(mContainer.getContext(), option,
                            R.string.option_applied_previewed_description);
                    } else {
                            CharSequence cd = mContainer.getContext().getString(
                                    R.string.option_previewed_description, option.getTitle());
                            tileHolder.labelView.setContentDescription(cd);
                        }
                    } else if (option == mAppliedOption) {
                        CharSequence cd = mContainer.getContext().getString(
                                R.string.option_applied_description, option.getTitle());
                        tileHolder.labelView.setContentDescription(cd);
                    } else {
                        // Remove content description
                        tileHolder.labelView.setContentDescription(null);
                        tileHolder.setContentDescription(mContainer.getContext(), option,
                            R.string.option_previewed_description);
                    }
                } else if (option == mAppliedOption && mShowCheckmark) {
                    tileHolder.setContentDescription(mContainer.getContext(), option,
                        R.string.option_applied_description);
                } else {
                    tileHolder.resetContentDescription();
                }
            }
        } else {
@@ -213,9 +205,12 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
                    holder.tileView.setForeground(checkedFrame);

                    // Initialize the currently applied option
                    CharSequence cd = mContainer.getContext().getString(
                            R.string.option_applied_previewed_description, option.getTitle());
                    holder.labelView.setContentDescription(cd);
                    holder.setContentDescription(mContainer.getContext(), option,
                        R.string.option_applied_previewed_description);
                } 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 (mShowCheckmark) {
                    holder.tileView.setForeground(null);
                }
@@ -290,11 +285,42 @@ public class OptionSelectorController<T extends CustomizationOption<T>> {
    private static class TileViewHolder extends RecyclerView.ViewHolder {
        TextView labelView;
        View tileView;
        CharSequence title;

        TileViewHolder(@NonNull View itemView) {
            super(itemView);
            labelView = itemView.findViewById(R.id.option_label);
            tileView = itemView.findViewById(R.id.option_tile);
            title = null;
        }

        /**
         * Set the content description for this holder using the given string id.
         * If the option does not have a label, the description will be set on the tile view.
         * @param context The view's context
         * @param option The customization option
         * @param id Resource ID of the string to use for the content description
         */
        public void setContentDescription(Context context, CustomizationOption option, int id) {
            title = option.getTitle();
            if (TextUtils.isEmpty(title) && tileView != null) {
                title = tileView.getContentDescription();
            }

            CharSequence cd = context.getString(id, title);
            if (labelView != null && !TextUtils.isEmpty(labelView.getText())) {
                labelView.setContentDescription(cd);
            } else if (tileView != null) {
                tileView.setContentDescription(cd);
            }
        }

        public void resetContentDescription() {
            if (labelView != null && !TextUtils.isEmpty(labelView.getText())) {
                labelView.setContentDescription(title);
            } else if (tileView != null) {
                tileView.setContentDescription(title);
            }
        }
    }
}