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

Commit d3b22ed7 authored by Angela Wang's avatar Angela Wang
Browse files

Add content description to ButtonInfo for accessibility

This allows TalkBack to announce a message different from the button's
visible text. It enhances accessibility by providing more contextual or
descriptive information for screen reader users.

Flag: EXEMPT bugfix
Bug: 419160629
Test: manually test with TalkBack on, screenshots attached in bug
Change-Id: I0072a5c52e3e26f7691eec7207e72aefa88604f5
parent 5c33b4ba
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()) {