Merge "Add ability of setting content description for footer" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
11d6467edd
@@ -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);
|
||||
@@ -52,6 +53,7 @@ public class FooterPreference extends Preference {
|
||||
title.setMovementMethod(new LinkMovementMethod());
|
||||
title.setClickable(false);
|
||||
title.setLongClickable(false);
|
||||
title.setContentDescription(mContentDescription);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -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) {
|
||||
@@ -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;
|
||||
@@ -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) {
|
||||
@@ -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) {
|
||||
@@ -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) {
|
||||
@@ -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}.
|
||||
*/
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user