Merge "Don't use "done" for string name." into ub-chips-cranbrook
diff --git a/res/drawable-hdpi/chip_background_invalid.9.png b/res/drawable-hdpi/chip_background_invalid.9.png
index 204a3c0..2b392ec 100644
--- a/res/drawable-hdpi/chip_background_invalid.9.png
+++ b/res/drawable-hdpi/chip_background_invalid.9.png
Binary files differ
diff --git a/res/drawable-mdpi/chip_background_invalid.9.png b/res/drawable-mdpi/chip_background_invalid.9.png
index ad349bf..074673e 100644
--- a/res/drawable-mdpi/chip_background_invalid.9.png
+++ b/res/drawable-mdpi/chip_background_invalid.9.png
Binary files differ
diff --git a/res/drawable-xhdpi/chip_background_invalid.9.png b/res/drawable-xhdpi/chip_background_invalid.9.png
index be64165..c6b8aef 100644
--- a/res/drawable-xhdpi/chip_background_invalid.9.png
+++ b/res/drawable-xhdpi/chip_background_invalid.9.png
Binary files differ
diff --git a/res/drawable-xxhdpi/chip_background_invalid.9.png b/res/drawable-xxhdpi/chip_background_invalid.9.png
index 4ae403e..a1d543e 100644
--- a/res/drawable-xxhdpi/chip_background_invalid.9.png
+++ b/res/drawable-xxhdpi/chip_background_invalid.9.png
Binary files differ
diff --git a/res/layout/chips_autocomplete_recipient_dropdown_item.xml b/res/layout/chips_autocomplete_recipient_dropdown_item.xml
index 4f8427d..d15a97b 100644
--- a/res/layout/chips_autocomplete_recipient_dropdown_item.xml
+++ b/res/layout/chips_autocomplete_recipient_dropdown_item.xml
@@ -14,16 +14,37 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
- android:layout_height="@dimen/chip_dropdown_height"
- android:background="@drawable/chips_dropdown_background"
- style="@style/ChipAutocompleteWrapperStyle">
+ android:layout_height="wrap_content"
+ android:minHeight="@dimen/chip_dropdown_height"
+ android:orientation="vertical">
- <com.android.ex.chips.CircularImageView style="@style/ChipEndIconStyle" />
+ <View
+ android:id="@+id/chip_autocomplete_top_divider"
+ style="@style/ChipAutocompleteDividerStyle" />
- <TextView style="@style/ChipTitleEndIconStyle" />
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="@drawable/chips_dropdown_background"
+ style="@style/ChipAutocompleteWrapperStyle">
- <TextView style="@style/ChipSubtitleEndIconStyle" />
+ <LinearLayout style="@style/ChipTextViewLayoutStyle">
-</RelativeLayout>
\ No newline at end of file
+ <TextView style="@style/ChipTitleStyle" />
+
+ <TextView style="@style/ChipSubtitleStyle" />
+
+ </LinearLayout>
+
+ <com.android.ex.chips.CircularImageView style="@style/ChipEndIconStyle" />
+
+ </LinearLayout>
+
+ <View
+ android:id="@+id/chip_autocomplete_bottom_divider"
+ style="@style/ChipAutocompleteDividerStyle" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/chips_recipient_dropdown_item.xml b/res/layout/chips_recipient_dropdown_item.xml
index ec0740b..a0f33d6 100644
--- a/res/layout/chips_recipient_dropdown_item.xml
+++ b/res/layout/chips_recipient_dropdown_item.xml
@@ -14,7 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/chip_dropdown_height"
android:background="@drawable/chips_dropdown_background"
@@ -22,8 +22,14 @@
<com.android.ex.chips.CircularImageView style="@style/ChipStartIconStyle" />
- <TextView style="@style/ChipTitleStartIconStyle" />
+ <LinearLayout style="@style/ChipTextViewLayoutStyle">
- <TextView style="@style/ChipSubtitleStartIconStyle" />
+ <TextView style="@style/ChipTitleStyle" />
-</RelativeLayout>
\ No newline at end of file
+ <TextView style="@style/ChipSubtitleStyle" />
+
+ </LinearLayout>
+
+ <com.android.ex.chips.CircularImageView style="@style/ChipDeleteIconStyle" />
+
+</LinearLayout>
\ No newline at end of file
diff --git a/res/values-sw600dp/styles.xml b/res/values-sw600dp/styles.xml
index 00988a9..06e7608 100644
--- a/res/values-sw600dp/styles.xml
+++ b/res/values-sw600dp/styles.xml
@@ -24,8 +24,6 @@
<item name="android:background">@null</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
- <item name="android:dropDownVerticalOffset">0dip</item>
- <item name="android:dropDownHorizontalOffset">-4dip</item>
<item name="android:textAlignment" tools:ignore="NewApi">viewStart</item>
<item name="android:textDirection" tools:ignore="NewApi">locale</item>
</style>
diff --git a/res/values-v17/styles.xml b/res/values-v17/styles.xml
index 7674bad..53b5634 100644
--- a/res/values-v17/styles.xml
+++ b/res/values-v17/styles.xml
@@ -21,29 +21,22 @@
<item name="android:paddingBottom">@dimen/chip_wrapper_bottom_padding</item>
</style>
- <style name="ChipTitleStartIconStyle" parent="@style/ChipTitleBaseStyle">
- <item name="android:layout_toEndOf">@android:id/icon</item>
- </style>
-
- <style name="ChipTitleEndIconStyle" parent="@style/ChipTitleBaseStyle">
- <item name="android:layout_toStartOf">@android:id/icon</item>
- </style>
-
- <style name="ChipSubtitleStartIconStyle" parent="@style/ChipSubtitleBaseStyle">
- <item name="android:layout_toEndOf">@android:id/icon</item>
- </style>
-
- <style name="ChipSubtitleEndIconStyle" parent="@style/ChipSubtitleBaseStyle">
- <item name="android:layout_toStartOf">@android:id/icon</item>
+ <style name="ChipAutocompleteDividerStyle">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">1px</item>
+ <item name="android:background">@color/autocomplete_divider_color</item>
+ <item name="android:layout_marginStart">@dimen/chip_wrapper_start_padding</item>
</style>
<style name="ChipStartIconStyle" parent="@style/ChipIconBaseStyle">
<item name="android:layout_marginEnd">@dimen/chip_icon_margin_end</item>
- <item name="android:layout_alignParentStart">true</item>
</style>
<style name="ChipEndIconStyle" parent="@style/ChipIconBaseStyle">
<item name="android:layout_marginStart">@dimen/chip_icon_margin_end</item>
- <item name="android:layout_alignParentEnd">true</item>
+ </style>
+
+ <style name="ChipDeleteIconStyle" parent="@style/ChipDeleteIconBaseStyle">
+ <item name="android:paddingStart">20dp</item>
</style>
</resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 8b6347c..b222dfb 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -20,4 +20,6 @@
<color name="chips_dropdown_background_activated">#4285f4</color>
<color name="chips_dropdown_background_pressed">#ededed</color>
+ <color name="autocomplete_divider_color">#cccccc</color>
+
</resources>
\ No newline at end of file
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 8b671d1..7a7d817 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -19,8 +19,6 @@
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@null</item>
- <item name="android:dropDownHorizontalOffset">-16dip</item>
- <item name="android:dropDownVerticalOffset">-6dip</item>
<item name="android:dropDownWidth">match_parent</item>
<item name="android:imeOptions">actionNext|flagNoFullscreen</item>
<item name="android:inputType">textEmailAddress|textMultiLine</item>
@@ -39,46 +37,41 @@
<item name="android:paddingBottom">@dimen/chip_wrapper_bottom_padding</item>
</style>
- <style name="ChipTitleBaseStyle">
+ <style name="ChipAutocompleteDividerStyle">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">1px</item>
+ <item name="android:background">@color/autocomplete_divider_color</item>
+ <item name="android:layout_marginLeft">@dimen/chip_wrapper_start_padding</item>
+ </style>
+
+ <style name="ChipTextViewLayoutStyle">
+ <item name="android:layout_width">0dp</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_gravity">center_vertical</item>
+ <item name="android:layout_weight">1</item>
+ <item name="android:orientation">vertical</item>
+ </style>
+
+ <style name="ChipTitleStyle">
<item name="android:id">@android:id/title</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
- <item name="android:layout_gravity">center_vertical</item>
<item name="android:ellipsize">middle</item>
- <item name="android:paddingTop">1dp</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">@color/chips_dropdown_title_text</item>
<item name="android:textSize">16sp</item>
</style>
- <style name="ChipTitleStartIconStyle" parent="@style/ChipTitleBaseStyle">
- <item name="android:layout_toRightOf">@android:id/icon</item>
- </style>
-
- <style name="ChipTitleEndIconStyle" parent="@style/ChipTitleBaseStyle">
- <item name="android:layout_toLeftOf">@android:id/icon</item>
- </style>
-
- <style name="ChipSubtitleBaseStyle">
+ <style name="ChipSubtitleStyle">
<item name="android:id">@android:id/text1</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
- <item name="android:layout_alignParentBottom">true</item>
<item name="android:ellipsize">middle</item>
- <item name="android:paddingBottom">1dp</item>
<item name="android:singleLine">true</item>
<item name="android:textColor">@color/chips_dropdown_subtitle_text</item>
<item name="android:textSize">14sp</item>
</style>
- <style name="ChipSubtitleStartIconStyle" parent="@style/ChipSubtitleBaseStyle">
- <item name="android:layout_toRightOf">@android:id/icon</item>
- </style>
-
- <style name="ChipSubtitleEndIconStyle" parent="@style/ChipSubtitleBaseStyle">
- <item name="android:layout_toLeftOf">@android:id/icon</item>
- </style>
-
<style name="ChipIconBaseStyle">
<item name="android:id">@android:id/icon</item>
<item name="android:layout_width">40dp</item>
@@ -88,11 +81,21 @@
<style name="ChipStartIconStyle" parent="@style/ChipIconBaseStyle">
<item name="android:layout_marginRight">@dimen/chip_icon_margin_end</item>
- <item name="android:layout_alignParentLeft">true</item>
</style>
<style name="ChipEndIconStyle" parent="@style/ChipIconBaseStyle">
<item name="android:layout_marginLeft">@dimen/chip_icon_margin_end</item>
- <item name="android:layout_alignParentRight">true</item>
+ </style>
+
+ <style name="ChipDeleteIconBaseStyle">
+ <item name="android:id">@android:id/icon1</item>
+ <item name="android:layout_width">40dp</item>
+ <item name="android:layout_height">40dp</item>
+ <item name="android:paddingTop">10dp</item>
+ <item name="android:paddingBottom">10dp</item>
+ </style>
+
+ <style name="ChipDeleteIconStyle" parent="@style/ChipDeleteIconBaseStyle">
+ <item name="android:paddingLeft">20dp</item>
</style>
</resources>
diff --git a/src/com/android/ex/chips/CircularImageView.java b/src/com/android/ex/chips/CircularImageView.java
index 6f4d9f5..246cc96 100644
--- a/src/com/android/ex/chips/CircularImageView.java
+++ b/src/com/android/ex/chips/CircularImageView.java
@@ -10,6 +10,8 @@
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.widget.ImageView;
@@ -55,7 +57,17 @@
@Override
protected void onDraw(Canvas canvas) {
- BitmapDrawable bitmapDrawable = (BitmapDrawable) getDrawable();
+ Drawable drawable = getDrawable();
+ BitmapDrawable bitmapDrawable = null;
+ // support state list drawable by getting the current state
+ if (drawable instanceof StateListDrawable) {
+ if (((StateListDrawable) drawable).getCurrent() != null) {
+ bitmapDrawable = (BitmapDrawable) drawable.getCurrent();
+ }
+ } else {
+ bitmapDrawable = (BitmapDrawable) drawable;
+ }
+
if (bitmapDrawable == null) {
return;
}
@@ -65,7 +77,8 @@
}
source.set(0, 0, bitmap.getWidth(), bitmap.getHeight());
- destination.set(0, 0, getWidth(), getHeight());
+ destination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(),
+ getHeight() - getPaddingBottom());
drawBitmapWithCircleOnCanvas(bitmap, canvas, source, destination);
}
diff --git a/src/com/android/ex/chips/DropdownChipLayouter.java b/src/com/android/ex/chips/DropdownChipLayouter.java
index afa25f8..6c9a694 100644
--- a/src/com/android/ex/chips/DropdownChipLayouter.java
+++ b/src/com/android/ex/chips/DropdownChipLayouter.java
@@ -3,7 +3,10 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
+import android.support.annotation.DrawableRes;
+import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.text.TextUtils;
import android.text.util.Rfc822Tokenizer;
@@ -29,19 +32,34 @@
SINGLE_RECIPIENT
}
+ public interface ChipDeleteListener {
+ void onChipDelete();
+ }
+
private final LayoutInflater mInflater;
private final Context mContext;
+ private ChipDeleteListener mDeleteListener;
private Query mQuery;
public DropdownChipLayouter(LayoutInflater inflater, Context context) {
+ this(inflater, context, null);
+ }
+
+ public DropdownChipLayouter(LayoutInflater inflater, Context context,
+ ChipDeleteListener deleteListener) {
mInflater = inflater;
mContext = context;
+ mDeleteListener = deleteListener;
}
public void setQuery(Query query) {
mQuery = query;
}
+ public void setDeleteListener(ChipDeleteListener listener) {
+ mDeleteListener = listener;
+ }
+
/**
* Layouts and binds recipient information to the view. If convertView is null, inflates a new
@@ -58,18 +76,21 @@
*/
public View bindView(View convertView, ViewGroup parent, RecipientEntry entry, int position,
AdapterType type, String constraint) {
+ return bindView(convertView, parent, entry, position, type, constraint, null);
+ }
+
+ /**
+ * See {@link #bindView(View, ViewGroup, RecipientEntry, int, AdapterType, String)}
+ * @param deleteDrawable
+ */
+ public View bindView(View convertView, ViewGroup parent, RecipientEntry entry, int position,
+ AdapterType type, String constraint, StateListDrawable deleteDrawable) {
// Default to show all the information
String displayName = entry.getDisplayName();
String destination = entry.getDestination();
boolean showImage = true;
CharSequence destinationType = getDestinationType(entry);
- // If we don't have name but have destination, show destination as the main entry.
- if (displayName == null && destination != null) {
- displayName = destination;
- destination = null;
- }
-
final View itemView = reuseOrInflateView(convertView, parent, type);
final ViewHolder viewHolder = new ViewHolder(itemView);
@@ -91,6 +112,11 @@
displayName = null;
showImage = false;
}
+
+ // For BASE_RECIPIENT set all top dividers except for the first one to be GONE.
+ if (viewHolder.topDivider != null) {
+ viewHolder.topDivider.setVisibility(position == 0 ? View.VISIBLE : View.GONE);
+ }
break;
case RECIPIENT_ALTERNATES:
if (position != 0) {
@@ -108,6 +134,7 @@
bindTextToView(destination, viewHolder.destinationView);
bindTextToView(destinationType, viewHolder.destinationTypeView);
bindIconToView(showImage, entry, viewHolder.imageView, type);
+ bindDrawableToDeleteView(deleteDrawable, viewHolder.deleteView);
return itemView;
}
@@ -193,6 +220,27 @@
}
}
+ protected void bindDrawableToDeleteView(final StateListDrawable drawable, ImageView view) {
+ if (view == null) {
+ return;
+ }
+ if (drawable == null) {
+ view.setVisibility(View.GONE);
+ }
+
+ view.setImageDrawable(drawable);
+ if (mDeleteListener != null) {
+ view.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (drawable.getCurrent() != null) {
+ mDeleteListener.onChipDelete();
+ }
+ }
+ });
+ }
+ }
+
protected CharSequence getDestinationType(RecipientEntry entry) {
return mQuery.getTypeLabel(mContext.getResources(), entry.getDestinationType(),
entry.getDestinationLabel()).toString().toUpperCase();
@@ -238,7 +286,7 @@
* Returns a resource ID representing an image which should be shown when ther's no relevant
* photo is available.
*/
- protected int getDefaultPhotoResId() {
+ protected @DrawableRes int getDefaultPhotoResId() {
return R.drawable.ic_contact_picture;
}
@@ -246,7 +294,7 @@
* Returns an id for TextView in an item View for showing a display name. By default
* {@link android.R.id#title} is returned.
*/
- protected int getDisplayNameResId() {
+ protected @IdRes int getDisplayNameResId() {
return android.R.id.title;
}
@@ -255,7 +303,7 @@
* (an email address or a phone number).
* By default {@link android.R.id#text1} is returned.
*/
- protected int getDestinationResId() {
+ protected @IdRes int getDestinationResId() {
return android.R.id.text1;
}
@@ -263,7 +311,7 @@
* Returns an id for TextView in an item View for showing the type of the destination.
* By default {@link android.R.id#text2} is returned.
*/
- protected int getDestinationTypeResId() {
+ protected @IdRes int getDestinationTypeResId() {
return android.R.id.text2;
}
@@ -271,11 +319,17 @@
* Returns an id for ImageView in an item View for showing photo image for a person. In default
* {@link android.R.id#icon} is returned.
*/
- protected int getPhotoResId() {
+ protected @IdRes int getPhotoResId() {
return android.R.id.icon;
}
/**
+ * Returns an id for ImageView in an item View for showing the delete button. In default
+ * {@link android.R.id#icon1} is returned.
+ */
+ protected @IdRes int getDeleteResId() { return android.R.id.icon1; }
+
+ /**
* A holder class the view. Uses the getters in DropdownChipLayouter to find the id of the
* corresponding views.
*/
@@ -284,12 +338,16 @@
public final TextView destinationView;
public final TextView destinationTypeView;
public final ImageView imageView;
+ public final ImageView deleteView;
+ public final View topDivider;
public ViewHolder(View view) {
displayNameView = (TextView) view.findViewById(getDisplayNameResId());
destinationView = (TextView) view.findViewById(getDestinationResId());
destinationTypeView = (TextView) view.findViewById(getDestinationTypeResId());
imageView = (ImageView) view.findViewById(getPhotoResId());
+ deleteView = (ImageView) view.findViewById(getDeleteResId());
+ topDivider = view.findViewById(R.id.chip_autocomplete_top_divider);
}
}
}
diff --git a/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/src/com/android/ex/chips/RecipientAlternatesAdapter.java
index 10502b1..6569d36 100644
--- a/src/com/android/ex/chips/RecipientAlternatesAdapter.java
+++ b/src/com/android/ex/chips/RecipientAlternatesAdapter.java
@@ -21,6 +21,7 @@
import android.content.Context;
import android.database.Cursor;
import android.database.MatrixCursor;
+import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.Contacts;
@@ -63,6 +64,7 @@
public static final int QUERY_TYPE_PHONE = 1;
private final Long mDirectoryId;
private DropdownChipLayouter mDropdownChipLayouter;
+ private final StateListDrawable mDeleteDrawable;
private static final Map<String, String> sCorrectedPhotoUris = new HashMap<String, String>();
@@ -359,6 +361,13 @@
public RecipientAlternatesAdapter(Context context, long contactId, Long directoryId,
String lookupKey, long currentId, int queryMode, OnCheckedItemChangedListener listener,
DropdownChipLayouter dropdownChipLayouter) {
+ this(context, contactId, directoryId, lookupKey, currentId, queryMode, listener,
+ dropdownChipLayouter, null);
+ }
+
+ public RecipientAlternatesAdapter(Context context, long contactId, Long directoryId,
+ String lookupKey, long currentId, int queryMode, OnCheckedItemChangedListener listener,
+ DropdownChipLayouter dropdownChipLayouter, StateListDrawable deleteDrawable) {
super(context,
getCursorForConstruction(context, contactId, directoryId, lookupKey, queryMode), 0);
mCurrentId = currentId;
@@ -366,6 +375,7 @@
mCheckedItemChangedListener = listener;
mDropdownChipLayouter = dropdownChipLayouter;
+ mDeleteDrawable = deleteDrawable;
}
private static Cursor getCursorForConstruction(Context context, long contactId,
@@ -586,7 +596,7 @@
RecipientEntry entry = getRecipientEntry(position);
mDropdownChipLayouter.bindView(view, null, entry, position,
- AdapterType.RECIPIENT_ALTERNATES, null);
+ AdapterType.RECIPIENT_ALTERNATES, null, mDeleteDrawable);
}
@Override
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index a98d8bb..713fe87 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -40,6 +40,7 @@
import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.StateListDrawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
@@ -110,7 +111,7 @@
public class RecipientEditTextView extends MultiAutoCompleteTextView implements
OnItemClickListener, Callback, RecipientAlternatesAdapter.OnCheckedItemChangedListener,
GestureDetector.OnGestureListener, OnDismissListener, OnClickListener,
- TextView.OnEditorActionListener {
+ TextView.OnEditorActionListener, DropdownChipLayouter.ChipDeleteListener {
private static final char COMMIT_CHAR_COMMA = ',';
@@ -329,7 +330,8 @@
mGestureDetector = new GestureDetector(context, this);
setOnEditorActionListener(this);
- setDropdownChipLayouter(new DropdownChipLayouter(LayoutInflater.from(context), context));
+ setDropdownChipLayouter(new DropdownChipLayouter(LayoutInflater.from(context), context,
+ this));
}
private int calculateTextHeight() {
@@ -640,12 +642,7 @@
mChipBackgroundPressed);
if (bitmapContainer.loadIcon) {
- if (mDisableDelete) {
- // Show the avatar instead if we don't want to delete
- loadAvatarIcon(contact, bitmapContainer, paint);
- } else {
- drawIcon(bitmapContainer, ((BitmapDrawable) mChipDelete).getBitmap(), paint);
- }
+ loadAvatarIcon(contact, bitmapContainer, paint);
}
return bitmapContainer.bitmap;
@@ -762,8 +759,7 @@
boolean drawPhotos = isPhoneQuery() ?
contactId != RecipientEntry.INVALID_CONTACT
: (contactId != RecipientEntry.INVALID_CONTACT
- && (contactId != RecipientEntry.GENERATED_CONTACT &&
- !TextUtils.isEmpty(contact.getDisplayName())));
+ && contactId != RecipientEntry.GENERATED_CONTACT);
if (drawPhotos) {
final byte[] origPhotoBytes = contact.getPhotoBytes();
@@ -1745,12 +1741,21 @@
private ListAdapter createAlternatesAdapter(DrawableRecipientChip chip) {
return new RecipientAlternatesAdapter(getContext(), chip.getContactId(),
chip.getDirectoryId(), chip.getLookupKey(), chip.getDataId(),
- getAdapter().getQueryType(), this, mDropdownChipLayouter);
+ getAdapter().getQueryType(), this, mDropdownChipLayouter,
+ constructStateListDeleteDrawable());
}
private ListAdapter createSingleAddressAdapter(DrawableRecipientChip currentChip) {
return new SingleRecipientArrayAdapter(getContext(), currentChip.getEntry(),
- mDropdownChipLayouter);
+ mDropdownChipLayouter, constructStateListDeleteDrawable());
+ }
+
+ private StateListDrawable constructStateListDeleteDrawable() {
+ // Construct the StateListDrawable from deleteDrawable
+ StateListDrawable deleteDrawable = new StateListDrawable();
+ deleteDrawable.addState(new int[] { android.R.attr.state_activated }, mChipDelete);
+ deleteDrawable.addState(new int[0], null);
+ return deleteDrawable;
}
@Override
@@ -1873,14 +1878,13 @@
}
private CharSequence createChip(RecipientEntry entry, boolean pressed) {
- String displayText = createAddressText(entry);
+ final String displayText = createAddressText(entry);
if (TextUtils.isEmpty(displayText)) {
return null;
}
- SpannableString chipText = null;
// Always leave a blank space at the end of a chip.
- int textLength = displayText.length() - 1;
- chipText = new SpannableString(displayText);
+ final int textLength = displayText.length() - 1;
+ final SpannableString chipText = new SpannableString(displayText);
if (!mNoChips) {
try {
DrawableRecipientChip chip = constructChipSpan(entry, pressed);
@@ -2333,6 +2337,15 @@
(mAvatarPosition != AVATAR_POSITION_END && offset == getChipStart(chip)));
}
+ @Override
+ public void onChipDelete() {
+ if (mSelectedChip != null) {
+ removeChip(mSelectedChip);
+ mAddressPopup.dismiss();
+ mAlternatesPopup.dismiss();
+ }
+ }
+
/**
* Remove the chip and any text associated with it from the RecipientEditTextView.
*/
diff --git a/src/com/android/ex/chips/SingleRecipientArrayAdapter.java b/src/com/android/ex/chips/SingleRecipientArrayAdapter.java
index 192aa20..f08746e 100644
--- a/src/com/android/ex/chips/SingleRecipientArrayAdapter.java
+++ b/src/com/android/ex/chips/SingleRecipientArrayAdapter.java
@@ -17,6 +17,7 @@
package com.android.ex.chips;
import android.content.Context;
+import android.graphics.drawable.StateListDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@@ -25,19 +26,26 @@
class SingleRecipientArrayAdapter extends ArrayAdapter<RecipientEntry> {
private final DropdownChipLayouter mDropdownChipLayouter;
+ private final StateListDrawable mDeleteDrawable;
public SingleRecipientArrayAdapter(Context context, RecipientEntry entry,
- DropdownChipLayouter dropdownChipLayouter) {
+ DropdownChipLayouter dropdownChipLayouter) {
+ this(context, entry, dropdownChipLayouter, null);
+ }
+
+ public SingleRecipientArrayAdapter(Context context, RecipientEntry entry,
+ DropdownChipLayouter dropdownChipLayouter, StateListDrawable deleteDrawable) {
super(context,
dropdownChipLayouter.getAlternateItemLayoutResId(AdapterType.SINGLE_RECIPIENT),
new RecipientEntry[] { entry });
mDropdownChipLayouter = dropdownChipLayouter;
+ mDeleteDrawable = deleteDrawable;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return mDropdownChipLayouter.bindView(convertView, parent, getItem(position), position,
- AdapterType.SINGLE_RECIPIENT, null);
+ AdapterType.SINGLE_RECIPIENT, null, mDeleteDrawable);
}
}