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

Commit 20f853ca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow customization on the learn more text in FooterPreference"

parents 6381c8ea e55e9c67
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");