Loading packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +19 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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. Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -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"); Loading Loading
packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +19 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } Loading Loading @@ -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. Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -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"); Loading