Loading packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +52 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ public class FooterPreference extends Preference { public static final String KEY_FOOTER = "footer_preference"; static final int ORDER_FOOTER = Integer.MAX_VALUE - 1; private CharSequence mContentDescription; public FooterPreference(Context context, AttributeSet attrs) { super(context, attrs, R.attr.footerPreferenceStyle); Loading @@ -52,6 +53,7 @@ public class FooterPreference extends Preference { title.setMovementMethod(new LinkMovementMethod()); title.setClickable(false); title.setLongClickable(false); title.setContentDescription(mContentDescription); } @Override Loading @@ -69,6 +71,26 @@ public class FooterPreference extends Preference { return getTitle(); } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescription The resource id of the content description. */ public void setContentDescription(CharSequence contentDescription) { if (!TextUtils.equals(mContentDescription, contentDescription)) { mContentDescription = contentDescription; notifyChanged(); } } /** * Return the content description of footer preference. */ public CharSequence getContentDescription() { return mContentDescription; } private void init() { setLayoutResource(R.layout.preference_footer); if (getIcon() == null) { Loading @@ -87,6 +109,7 @@ public class FooterPreference extends Preference { private Context mContext; private String mKey; private CharSequence mTitle; private CharSequence mContentDescription; public Builder(@NonNull Context context) { mContext = context; Loading @@ -94,6 +117,7 @@ public class FooterPreference extends Preference { /** * To set the key value of the {@link FooterPreference}. * * @param key The key value. */ public Builder setKey(@NonNull String key) { Loading @@ -103,6 +127,7 @@ public class FooterPreference extends Preference { /** * To set the title of the {@link FooterPreference}. * * @param title The title. */ public Builder setTitle(CharSequence title) { Loading @@ -112,6 +137,7 @@ public class FooterPreference extends Preference { /** * To set the title of the {@link FooterPreference}. * * @param titleResId The resource id of the title. */ public Builder setTitle(@StringRes int titleResId) { Loading @@ -119,6 +145,28 @@ public class FooterPreference extends Preference { return this; } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescription The resource id of the content description. */ public Builder setContentDescription(CharSequence contentDescription) { mContentDescription = contentDescription; return this; } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescriptionResId The resource id of the content description. */ public Builder setContentDescription(@StringRes int contentDescriptionResId) { mContentDescription = mContext.getText(contentDescriptionResId); return this; } /** * To generate the {@link FooterPreference}. */ Loading @@ -132,6 +180,10 @@ public class FooterPreference extends Preference { if (!TextUtils.isEmpty(mKey)) { footerPreference.setKey(mKey); } if (!TextUtils.isEmpty(mContentDescription)) { footerPreference.setContentDescription(mContentDescription); } return footerPreference; } } Loading packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -62,4 +62,11 @@ public class FooterPreferenceTest { assertThat(mFooterPreference.getTitle()).isEqualTo("summary"); } @Test public void setContentDescription_contentSet_shouldGetSameContentDescription() { mFooterPreference.setContentDescription("test"); assertThat(mFooterPreference.getContentDescription()).isEqualTo("test"); } } Loading
packages/SettingsLib/FooterPreference/src/com/android/settingslib/widget/FooterPreference.java +52 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ public class FooterPreference extends Preference { public static final String KEY_FOOTER = "footer_preference"; static final int ORDER_FOOTER = Integer.MAX_VALUE - 1; private CharSequence mContentDescription; public FooterPreference(Context context, AttributeSet attrs) { super(context, attrs, R.attr.footerPreferenceStyle); Loading @@ -52,6 +53,7 @@ public class FooterPreference extends Preference { title.setMovementMethod(new LinkMovementMethod()); title.setClickable(false); title.setLongClickable(false); title.setContentDescription(mContentDescription); } @Override Loading @@ -69,6 +71,26 @@ public class FooterPreference extends Preference { return getTitle(); } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescription The resource id of the content description. */ public void setContentDescription(CharSequence contentDescription) { if (!TextUtils.equals(mContentDescription, contentDescription)) { mContentDescription = contentDescription; notifyChanged(); } } /** * Return the content description of footer preference. */ public CharSequence getContentDescription() { return mContentDescription; } private void init() { setLayoutResource(R.layout.preference_footer); if (getIcon() == null) { Loading @@ -87,6 +109,7 @@ public class FooterPreference extends Preference { private Context mContext; private String mKey; private CharSequence mTitle; private CharSequence mContentDescription; public Builder(@NonNull Context context) { mContext = context; Loading @@ -94,6 +117,7 @@ public class FooterPreference extends Preference { /** * To set the key value of the {@link FooterPreference}. * * @param key The key value. */ public Builder setKey(@NonNull String key) { Loading @@ -103,6 +127,7 @@ public class FooterPreference extends Preference { /** * To set the title of the {@link FooterPreference}. * * @param title The title. */ public Builder setTitle(CharSequence title) { Loading @@ -112,6 +137,7 @@ public class FooterPreference extends Preference { /** * To set the title of the {@link FooterPreference}. * * @param titleResId The resource id of the title. */ public Builder setTitle(@StringRes int titleResId) { Loading @@ -119,6 +145,28 @@ public class FooterPreference extends Preference { return this; } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescription The resource id of the content description. */ public Builder setContentDescription(CharSequence contentDescription) { mContentDescription = contentDescription; return this; } /** * To set content description of the {@link FooterPreference}. This can use for talkback * environment if developer wants to have a customization content. * * @param contentDescriptionResId The resource id of the content description. */ public Builder setContentDescription(@StringRes int contentDescriptionResId) { mContentDescription = mContext.getText(contentDescriptionResId); return this; } /** * To generate the {@link FooterPreference}. */ Loading @@ -132,6 +180,10 @@ public class FooterPreference extends Preference { if (!TextUtils.isEmpty(mKey)) { footerPreference.setKey(mKey); } if (!TextUtils.isEmpty(mContentDescription)) { footerPreference.setContentDescription(mContentDescription); } return footerPreference; } } Loading
packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/FooterPreferenceTest.java +7 −0 Original line number Diff line number Diff line Loading @@ -62,4 +62,11 @@ public class FooterPreferenceTest { assertThat(mFooterPreference.getTitle()).isEqualTo("summary"); } @Test public void setContentDescription_contentSet_shouldGetSameContentDescription() { mFooterPreference.setContentDescription("test"); assertThat(mFooterPreference.getContentDescription()).isEqualTo("test"); } }