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

Commit 95bd1b13 authored by Angela Wang's avatar Angela Wang Committed by Android (Google) Code Review
Browse files

Merge "Add content description to ButtonInfo for accessibility" into main

parents af2a9e60 d3b22ed7
Loading
Loading
Loading
Loading
+53 −1
Original line number Diff line number Diff line
@@ -272,6 +272,18 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
        return this;
    }

    /**
     * Sets the content description in button1.
     */
    public ActionButtonsPreference setButton1Description(@StringRes int textResId) {
        final String newDescription = getContext().getString(textResId);
        if (!TextUtils.equals(newDescription, mButton1Info.mContentDescription)) {
            mButton1Info.mContentDescription = newDescription;
            notifyChanged();
        }
        return this;
    }

    /**
     * Sets the drawable to be displayed above of text in button1.
     */
@@ -337,6 +349,18 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
        return this;
    }

    /**
     * Sets the content description in button2.
     */
    public ActionButtonsPreference setButton2Description(@StringRes int textResId) {
        final String newDescription = getContext().getString(textResId);
        if (!TextUtils.equals(newDescription, mButton2Info.mContentDescription)) {
            mButton2Info.mContentDescription = newDescription;
            notifyChanged();
        }
        return this;
    }

    /**
     * Sets the drawable to be displayed above of text in button2.
     */
@@ -402,6 +426,18 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
        return this;
    }

    /**
     * Sets the content description in button3.
     */
    public ActionButtonsPreference setButton3Description(@StringRes int textResId) {
        final String newDescription = getContext().getString(textResId);
        if (!TextUtils.equals(newDescription, mButton3Info.mContentDescription)) {
            mButton3Info.mContentDescription = newDescription;
            notifyChanged();
        }
        return this;
    }

    /**
     * Sets the drawable to be displayed above of text in button3.
     */
@@ -467,6 +503,18 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
        return this;
    }

    /**
     * Sets the content description in button4.
     */
    public ActionButtonsPreference setButton4Description(@StringRes int textResId) {
        final String newDescription = getContext().getString(textResId);
        if (!TextUtils.equals(newDescription, mButton4Info.mContentDescription)) {
            mButton4Info.mContentDescription = newDescription;
            notifyChanged();
        }
        return this;
    }

    /**
     * Sets the drawable to be displayed above of text in button4.
     */
@@ -536,6 +584,7 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
        private TextView mTextView;
        private LinearLayout mActionLayout;
        private CharSequence mText;
        private CharSequence mContentDescription;
        private Drawable mIcon;
        private View.OnClickListener mListener;
        private boolean mIsEnabled = true;
@@ -553,13 +602,16 @@ public class ActionButtonsPreference extends Preference implements GroupSectionD
                mTextView.setOnClickListener(mListener);
                mActionLayout.setEnabled(mIsEnabled);
                mActionLayout.setOnClickListener(mListener);
                mActionLayout.setContentDescription(mText);
                mActionLayout.setContentDescription(
                        TextUtils.isEmpty(mContentDescription) ? mText : mContentDescription);
            } else {
                mButton.setText(mText);
                mButton.setCompoundDrawablesWithIntrinsicBounds(
                        null /* left */, mIcon /* top */, null /* right */, null /* bottom */);
                mButton.setOnClickListener(mListener);
                mButton.setEnabled(mIsEnabled);
                mButton.setContentDescription(
                        TextUtils.isEmpty(mContentDescription) ? mText : mContentDescription);
            }

            if (shouldBeVisible()) {