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

Commit e55e9c67 authored by Steven Ng's avatar Steven Ng
Browse files

Allow customization on the learn more text in FooterPreference

Before this change, the learn more text is hard-coded in the layout xml.
This change allows the caller to use an alternative text for the
learn more button.

Test: make RunSettingsLibRoboTests -j56 ROBOTEST_FILTER=com.android.settings.display.darkmode.DarkModeCustomBedtimePreferenceControllerTest
Bug: 215182463
Change-Id: Ic87afaeca595dc009c2070db666cd52b0ac1c9c8
parent ce65b04d
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public class FooterPreference extends Preference {
    @VisibleForTesting
    View.OnClickListener mLearnMoreListener;
    private CharSequence mContentDescription;
    private CharSequence mLearnMoreText;
    private CharSequence mLearnMoreContentDescription;
    private FooterLearnMoreSpan mLearnMoreSpan;

@@ -69,7 +70,12 @@ public class FooterPreference extends Preference {
        TextView learnMore = holder.itemView.findViewById(R.id.settingslib_learn_more);
        if (learnMore != null && mLearnMoreListener != null) {
            learnMore.setVisibility(View.VISIBLE);
            SpannableString learnMoreText = new SpannableString(learnMore.getText());
            if (TextUtils.isEmpty(mLearnMoreText)) {
                mLearnMoreText = learnMore.getText();
            } else {
                learnMore.setText(mLearnMoreText);
            }
            SpannableString learnMoreText = new SpannableString(mLearnMoreText);
            if (mLearnMoreSpan != null) {
                learnMoreText.removeSpan(mLearnMoreSpan);
            }
@@ -122,6 +128,18 @@ public class FooterPreference extends Preference {
        return mContentDescription;
    }

    /**
     * Sets the learn more text.
     *
     * @param learnMoreText The string of the learn more text.
     */
    public void setLearnMoreText(CharSequence learnMoreText) {
        if (!TextUtils.equals(mLearnMoreText, learnMoreText)) {
            mLearnMoreText = learnMoreText;
            notifyChanged();
        }
    }

    /**
     * To set content description of the learn more text. This can use for talkback
     * environment if developer wants to have a customization content.
+14 −0
Original line number Diff line number Diff line
@@ -63,6 +63,20 @@ public class FooterPreferenceTest {
        assertThat(mFooterPreference.getTitle()).isEqualTo("summary");
    }

    @Test
    public void setLearnMoreText_shouldSetAsTextInLearnMore() {
        final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
                LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null));
        mFooterPreference.setLearnMoreText("Custom learn more");
        mFooterPreference.setLearnMoreAction(view -> { /* do nothing */ } /* listener */);

        mFooterPreference.onBindViewHolder(holder);

        assertThat(((TextView) holder.findViewById(
                        R.id.settingslib_learn_more)).getText().toString())
                .isEqualTo("Custom learn more");
    }

    @Test
    public void setContentDescription_contentSet_shouldGetSameContentDescription() {
        mFooterPreference.setContentDescription("test");