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

Commit 1ac99118 authored by Edgar Wang's avatar Edgar Wang
Browse files

Ensure the learn more string meet Accessibility requirement.

In Google Accessibility Rating, All links, controls, and buttons should
also have comprehensible text or tooltip text, so users can identify its
purpose, independent of context, such as when using the URL list from
TalkBack’s local context menu.

It's not enough clear for users that only show "Learn more", in previous
design we provided setLearnMoreContentDescription() let TalkBack speak
more information about "Learn more".
But the requirement including the text of the accessibility label and the
visible link text match.

So we should only set learnMore string that can ensure accessibility
label and text match, also show a relevant context in TalkBack's context menu.

Bug: 215045903
Test: manual
Change-Id: Id734733bb4272327bcfcc04db38c88fb5cd3131c
parent 89913957
Loading
Loading
Loading
Loading
+11 −37
Original line number Original line Diff line number Diff line
@@ -44,7 +44,6 @@ public class FooterPreference extends Preference {
    int mIconVisibility = View.VISIBLE;
    int mIconVisibility = View.VISIBLE;
    private CharSequence mContentDescription;
    private CharSequence mContentDescription;
    private CharSequence mLearnMoreText;
    private CharSequence mLearnMoreText;
    private CharSequence mLearnMoreContentDescription;
    private FooterLearnMoreSpan mLearnMoreSpan;
    private FooterLearnMoreSpan mLearnMoreSpan;


    public FooterPreference(Context context, AttributeSet attrs) {
    public FooterPreference(Context context, AttributeSet attrs) {
@@ -80,9 +79,6 @@ public class FooterPreference extends Preference {
            learnMoreText.setSpan(mLearnMoreSpan, 0,
            learnMoreText.setSpan(mLearnMoreSpan, 0,
                    learnMoreText.length(), 0);
                    learnMoreText.length(), 0);
            learnMore.setText(learnMoreText);
            learnMore.setText(learnMoreText);
            if (!TextUtils.isEmpty(mLearnMoreContentDescription)) {
                learnMore.setContentDescription(mLearnMoreContentDescription);
            }
        } else {
        } else {
            learnMore.setVisibility(View.GONE);
            learnMore.setVisibility(View.GONE);
        }
        }
@@ -139,27 +135,6 @@ public class FooterPreference extends Preference {
        }
        }
    }
    }


    /**
     * To set content description of the learn more text. This can use for talkback
     * environment if developer wants to have a customization content.
     *
     * @param learnMoreContentDescription The resource id of the content description.
     */
    public void setLearnMoreContentDescription(CharSequence learnMoreContentDescription) {
        if (!TextUtils.equals(mContentDescription, learnMoreContentDescription)) {
            mLearnMoreContentDescription = learnMoreContentDescription;
            notifyChanged();
        }
    }

    /**
     * Return the content description of learn more link.
     */
    @VisibleForTesting
    CharSequence getLearnMoreContentDescription() {
        return mLearnMoreContentDescription;
    }

    /**
    /**
     * Assign an action for the learn more link.
     * Assign an action for the learn more link.
     */
     */
@@ -201,7 +176,7 @@ public class FooterPreference extends Preference {
        private String mKey;
        private String mKey;
        private CharSequence mTitle;
        private CharSequence mTitle;
        private CharSequence mContentDescription;
        private CharSequence mContentDescription;
        private CharSequence mLearnMoreContentDescription;
        private CharSequence mLearnMoreText;


        public Builder(@NonNull Context context) {
        public Builder(@NonNull Context context) {
            mContext = context;
            mContext = context;
@@ -260,25 +235,24 @@ public class FooterPreference extends Preference {
        }
        }


        /**
        /**
         * To set content description of the learn more text. This can use for talkback
         * To set learn more string of the learn more text. This can use for talkback
         * environment if developer wants to have a customization content.
         * environment if developer wants to have a customization content.
         *
         *
         * @param learnMoreContentDescription The resource id of the content description.
         * @param learnMoreText The resource id of the learn more string.
         */
         */
        public Builder setLearnMoreContentDescription(CharSequence learnMoreContentDescription) {
        public Builder setLearnMoreText(CharSequence learnMoreText) {
            mLearnMoreContentDescription = learnMoreContentDescription;
            mLearnMoreText = learnMoreText;
            return this;
            return this;
        }
        }


        /**
        /**
         * To set content description of the {@link FooterPreference}. This can use for talkback
         * To set learn more string of the {@link FooterPreference}. This can use for talkback
         * environment if developer wants to have a customization content.
         * environment if developer wants to have a customization content.
         *
         *
         * @param learnMoreContentDescriptionResId The resource id of the content description.
         * @param learnMoreTextResId The resource id of the learn more string.
         */
         */
        public Builder setLearnMoreContentDescription(
        public Builder setLearnMoreText(@StringRes int learnMoreTextResId) {
                @StringRes int learnMoreContentDescriptionResId) {
            mLearnMoreText = mContext.getText(learnMoreTextResId);
            mLearnMoreContentDescription = mContext.getText(learnMoreContentDescriptionResId);
            return this;
            return this;
        }
        }


@@ -301,8 +275,8 @@ public class FooterPreference extends Preference {
                footerPreference.setContentDescription(mContentDescription);
                footerPreference.setContentDescription(mContentDescription);
            }
            }


            if (!TextUtils.isEmpty(mLearnMoreContentDescription)) {
            if (!TextUtils.isEmpty(mLearnMoreText)) {
                footerPreference.setLearnMoreContentDescription(mLearnMoreContentDescription);
                footerPreference.setLearnMoreText(mLearnMoreText);
            }
            }
            return footerPreference;
            return footerPreference;
        }
        }
+0 −7
Original line number Original line Diff line number Diff line
@@ -73,13 +73,6 @@ public class FooterPreferenceTest {
        assertThat(mFooterPreference.getContentDescription()).isEqualTo("test");
        assertThat(mFooterPreference.getContentDescription()).isEqualTo("test");
    }
    }


    @Test
    public void setLearnMoreContentDescription_contentSet_shouldGetSameContentDescription() {
        mFooterPreference.setLearnMoreContentDescription("test");

        assertThat(mFooterPreference.getLearnMoreContentDescription()).isEqualTo("test");
    }

    @Test
    @Test
    public void setLearnMoreAction_actionSet_shouldGetAction() {
    public void setLearnMoreAction_actionSet_shouldGetAction() {
        mFooterPreference.setLearnMoreAction(v -> {
        mFooterPreference.setLearnMoreAction(v -> {