Add content description to the chips delete icon
b/19102218
Change-Id: I94f6cc642a12793dc7ee38afad6589d52f262d1a
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 878cdaa..ecff60f 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -16,16 +16,14 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Text displayed when the recipientedittextview is not focused. Displays the total number of recipients since the field is shrunk to just display a portion -->
<string name="more_string">\u002B<xliff:g id="count">%1$d</xliff:g></string>
-
- <!-- Text displayed when the user long presses on a chip to copy the recipients email address.
- [CHAR LIMIT=200] -->
+ <!-- Text displayed when the user long presses on a chip to copy the recipients email address [CHAR LIMIT=200] -->
<string name="copy_email">Copy email address</string>
- <!-- Text displayed when the user long presses on a chip to copy the recipient's phone number.
- [CHAR LIMIT=200] -->
+ <!-- Text displayed when the user long presses on a chip to copy the recipient's phone number [CHAR LIMIT=200] -->
<string name="copy_number">Copy phone number</string>
- <!-- Text displayed in the enter key slot when the recipientedittextview has focus.
- [CHAR LIMIT=12] -->
+ <!-- Text displayed in the enter key slot when the recipientedittextview has focus [CHAR LIMIT=12] -->
<string name="action_label">Return</string>
<!-- Announce the number of possible recipient entries that the user can select from for accessibility purposes [CHAR LIMIT=200] -->
<string name="accessbility_suggestion_dropdown_opened">Contact suggestions opened</string>
+ <!-- Description for the delete button that removes the selected contact from the recipients [CHAR LIMIT=100] -->
+ <string name="dropdown_delete_button_desc">Remove <xliff:g id="contact">%s</xliff:g> from recipients</string>
</resources>
diff --git a/src/com/android/ex/chips/DropdownChipLayouter.java b/src/com/android/ex/chips/DropdownChipLayouter.java
index a3b809c..b9738dd 100644
--- a/src/com/android/ex/chips/DropdownChipLayouter.java
+++ b/src/com/android/ex/chips/DropdownChipLayouter.java
@@ -1,6 +1,7 @@
package com.android.ex.chips;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.StateListDrawable;
@@ -75,7 +76,9 @@
/**
* See {@link #bindView(View, ViewGroup, RecipientEntry, int, AdapterType, String)}
- * @param deleteDrawable
+ * @param deleteDrawable a {@link android.graphics.drawable.StateListDrawable} representing
+ * the delete icon. android.R.attr.state_activated should map to the delete icon, and the
+ * default state can map to a drawable of your choice (or null for no drawable).
*/
public View bindView(View convertView, ViewGroup parent, RecipientEntry entry, int position,
AdapterType type, String constraint, StateListDrawable deleteDrawable) {
@@ -128,7 +131,7 @@
bindTextToView(destination, viewHolder.destinationView);
bindTextToView(destinationType, viewHolder.destinationTypeView);
bindIconToView(showImage, entry, viewHolder.imageView, type);
- bindDrawableToDeleteView(deleteDrawable, viewHolder.deleteView);
+ bindDrawableToDeleteView(deleteDrawable, entry.getDisplayName(), viewHolder.deleteView);
return itemView;
}
@@ -214,14 +217,18 @@
}
}
- protected void bindDrawableToDeleteView(final StateListDrawable drawable, ImageView view) {
+ protected void bindDrawableToDeleteView(final StateListDrawable drawable, String recipient,
+ ImageView view) {
if (view == null) {
return;
}
if (drawable == null) {
view.setVisibility(View.GONE);
} else {
+ final Resources res = mContext.getResources();
view.setImageDrawable(drawable);
+ view.setContentDescription(
+ res.getString(R.string.dropdown_delete_button_desc, recipient));
if (mDeleteListener != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override