Visual tweaks requested by UX.

1) Text on selected chips should be white
2) new delete asset
3) new background selected asset
4) align the alternates popup with the left of the
text field regardless of the position of the chip
5) dont get the position to put the popup at until the user
has tapped it; we cant cache it as other chips changing may have
moved this chip to a different line.
Also cleaned out unused assets.
Change-Id: I7cff1b945ca7a0c7e04430c66c5976de2dee468d
diff --git a/res/drawable-hdpi/alternate_list_background.png b/res/drawable-hdpi/alternate_list_background.png
deleted file mode 100644
index ad79a76..0000000
--- a/res/drawable-hdpi/alternate_list_background.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-hdpi/check_selected.9.png b/res/drawable-hdpi/check_selected.9.png
new file mode 100644
index 0000000..60b70aa
--- /dev/null
+++ b/res/drawable-hdpi/check_selected.9.png
Binary files differ
diff --git a/res/drawable-hdpi/chip_delete.png b/res/drawable-hdpi/chip_delete.png
index e06b62d..75cde4a 100644
--- a/res/drawable-hdpi/chip_delete.png
+++ b/res/drawable-hdpi/chip_delete.png
Binary files differ
diff --git a/res/drawable-mdpi/alternate_list_background.png b/res/drawable-mdpi/alternate_list_background.png
deleted file mode 100644
index ad79a76..0000000
--- a/res/drawable-mdpi/alternate_list_background.png
+++ /dev/null
Binary files differ
diff --git a/res/drawable-mdpi/check_selected.9.png b/res/drawable-mdpi/check_selected.9.png
new file mode 100644
index 0000000..60b70aa
--- /dev/null
+++ b/res/drawable-mdpi/check_selected.9.png
Binary files differ
diff --git a/res/drawable-mdpi/chip_delete.png b/res/drawable-mdpi/chip_delete.png
index e06b62d..75cde4a 100644
--- a/res/drawable-mdpi/chip_delete.png
+++ b/res/drawable-mdpi/chip_delete.png
Binary files differ
diff --git a/res/drawable/list_item_background.xml b/res/drawable/list_item_background.xml
index 18033af..4f48441 100644
--- a/res/drawable/list_item_background.xml
+++ b/res/drawable/list_item_background.xml
@@ -15,7 +15,7 @@
 -->
 
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
-    <item android:state_activated="true"    android:drawable="@drawable/alternate_list_background" />
-    <item android:state_checked="true"    android:drawable="@drawable/alternate_list_background" />
-    <item android:state_selected="true"    android:drawable="@drawable/alternate_list_background" />
+    <item android:state_activated="true"    android:drawable="@drawable/check_selected" />
+    <item android:state_checked="true"    android:drawable="@drawable/check_selected" />
+    <item android:state_selected="true"    android:drawable="@drawable/check_selected" />
 </selector>
\ No newline at end of file
diff --git a/res/layout/chips_alternate_selected_item.xml b/res/layout/chips_alternate_selected_item.xml
deleted file mode 100644
index cbb3ad9..0000000
--- a/res/layout/chips_alternate_selected_item.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2011 The Android Open Source Project
-
-     Licensed under the Apache License, Version 2.0 (the "License");
-     you may not use this file except in compliance with the License.
-     You may obtain a copy of the License at
-
-          http://www.apache.org/licenses/LICENSE-2.0
-
-     Unless required by applicable law or agreed to in writing, software
-     distributed under the License is distributed on an "AS IS" BASIS,
-     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-     See the License for the specific language governing permissions and
-     limitations under the License.
--->
-
-<LinearLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="wrap_content"
-    android:minHeight="30dip"
-    android:orientation="horizontal"
-    android:gravity="left|center_vertical"
-    android:background="#97def8">
-    <FrameLayout
-        android:layout_width="50dip"
-        android:layout_height="wrap_content">
-        <ImageView
-            android:id="@android:id/icon"
-            android:layout_width="42dip"
-            android:layout_height="42dip"
-            android:layout_margin="4dip"
-            android:src="@drawable/ic_contact_picture"
-            android:cropToPadding="true"
-            android:scaleType="centerCrop" />
-    </FrameLayout>
-    <LinearLayout
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:orientation="vertical"
-        android:gravity="left|center_vertical">
-        <TextView android:id="@android:id/text1"
-                  android:textColor="?android:attr/textColorPrimary"
-                  android:textAppearance="?android:attr/textAppearanceMedium"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:gravity="center_vertical"
-                  android:paddingLeft="6dip"
-                  android:singleLine="true"
-                  android:ellipsize="end" />
-        <TextView android:id="@android:id/text2"
-                  android:textColor="?android:attr/textColorSecondary"
-                  android:textAppearance="?android:attr/textAppearanceSmall"
-                  android:layout_width="wrap_content"
-                  android:layout_height="wrap_content"
-                  android:gravity="center_vertical"
-                  android:paddingLeft="6dip"
-                  android:singleLine="true"
-                  android:ellipsize="end" />
-    </LinearLayout>
-    <ImageView
-        android:id="@android:id/icon"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:layout_margin="4dip"
-        android:src="@drawable/chip_checkmark"
-        android:gravity="right" />
-</LinearLayout>
diff --git a/res/values/dimen.xml b/res/values/dimen.xml
index ef1cd77..dc3aadf 100644
--- a/res/values/dimen.xml
+++ b/res/values/dimen.xml
@@ -16,6 +16,6 @@
 
 <resources>
     <dimen name="chip_padding">8dip</dimen>
-    <dimen name="chip_height">34dip</dimen>
+    <dimen name="chip_height">32dip</dimen>
     <dimen name="chip_text_size">14sp</dimen>
 </resources>
\ No newline at end of file
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index cd7912f..53f7fad 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -116,12 +116,17 @@
 
     private int mPendingChipsCount = 0;
 
+    private static int sSelectedTextColor = -1;
+
     private static final char COMMIT_CHAR_COMMA = ',';
 
     private static final char COMMIT_CHAR_SEMICOLON = ';';
 
     public RecipientEditTextView(Context context, AttributeSet attrs) {
         super(context, attrs);
+        if (sSelectedTextColor == -1) {
+            sSelectedTextColor = context.getResources().getColor(android.R.color.white);
+        }
         setSuggestionsEnabled(false);
         setOnItemClickListener(this);
         setCustomSelectionActionModeCallback(this);
@@ -258,7 +263,7 @@
         if (mChipBackgroundPressed != null) {
             mChipBackgroundPressed.setBounds(0, 0, width, height);
             mChipBackgroundPressed.draw(canvas);
-
+            paint.setColor(sSelectedTextColor);
             // Align the display text with where the user enters text.
             canvas.drawText(ellipsizedText, 0, ellipsizedText.length(), mChipPadding, height
                     - Math.abs(height - mChipFontSize)/2, paint);
@@ -350,13 +355,10 @@
         Layout layout = getLayout();
         int line = 0;
         int lineTop = getTop();
-        if (layout != null) {
-            line = layout.getLineForOffset(offset);
-            lineTop = layout.getLineTop(line);
-        }
 
         TextPaint paint = getPaint();
         float defaultSize = paint.getTextSize();
+        int defaultColor = paint.getColor();
 
         Bitmap tmpBitmap;
         if (pressed) {
@@ -373,12 +375,10 @@
         // Pass the full text, un-ellipsized, to the chip.
         Drawable result = new BitmapDrawable(getResources(), tmpBitmap);
         result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight());
-        Rect bounds = new Rect(xy[0] + offset, xy[1] + lineTop, xy[0] + tmpBitmap.getWidth(),
-                calculateLineBottom(xy[1], line, tmpBitmap.getHeight()));
-        RecipientChip recipientChip = new RecipientChip(result, contact, offset, bounds);
+        RecipientChip recipientChip = new RecipientChip(result, contact, offset);
         // Return text to the original size.
         paint.setTextSize(defaultSize);
-
+        paint.setColor(defaultColor);
         return recipientChip;
     }
 
@@ -395,8 +395,7 @@
         if (line == getLineCount() - 1) {
             bottomPadding += getPaddingBottom();
         }
-        return ((line + 1) * getLineHeight()) + yOffset + getPaddingTop()
-                + (chipHeight - getLineHeight()) + bottomPadding;
+        return yOffset + ((line + 1) * (int)mChipHeight) + getPaddingTop() + bottomPadding;
     }
 
     /**
@@ -926,8 +925,6 @@
 
         private View mAnchorView;
 
-        private int mLeft;
-
         private final long mContactId;
 
         private final long mDataId;
@@ -938,28 +935,20 @@
 
         private RecipientAlternatesAdapter mAlternatesAdapter;
 
-        private Rect mBounds;
-
         private int mStart = -1;
 
         private int mEnd = -1;
 
         private ListPopupWindow mAlternatesPopup;
 
-        public RecipientChip(Drawable drawable, RecipientEntry entry, int offset, Rect bounds) {
+        public RecipientChip(Drawable drawable, RecipientEntry entry, int offset) {
             super(drawable);
             mDisplay = entry.getDisplayName();
             mValue = entry.getDestination();
             mContactId = entry.getContactId();
             mDataId = entry.getDataId();
             mEntry = entry;
-            mBounds = bounds;
-
             mAnchorView = new View(getContext());
-            mAnchorView.setLeft(bounds.left);
-            mAnchorView.setRight(bounds.left);
-            mAnchorView.setTop(bounds.bottom);
-            mAnchorView.setBottom(bounds.bottom);
             mAnchorView.setVisibility(View.GONE);
         }
 
@@ -1002,7 +991,7 @@
         /**
          * Remove selection from this chip. Unselecting a RecipientChip will render
          * the chip without a delete icon and with an unfocused background. This
-         * is called when the RecipientChip not longer has focus.
+         * is called when the RecipientChip no longer has focus.
          */
         public void unselectChip() {
             int start = getChipStart();
@@ -1161,10 +1150,16 @@
             mAlternatesPopup = new ListPopupWindow(getContext());
 
             if (!mAlternatesPopup.isShowing()) {
+                int line = getLayout().getLineForOffset(getChipStart());
+                int[] xy = new int[2];
+                getLocationOnScreen(xy);
+                int bottom = calculateLineBottom(xy[1], line, (int) mChipHeight);
+                mAnchorView.setBottom(bottom);
+                mAnchorView.setTop(bottom);
                 mAlternatesAdapter = new RecipientAlternatesAdapter(getContext(),
                         mEntry.getContactId(), mEntry.getDataId(), mAlternatesLayout);
-                mAnchorView.setLeft(mLeft);
-                mAnchorView.setRight(mLeft);
+                // Align the alternates popup with the left side of the View, regardless
+                // of the position of the chip tapped.
                 mAlternatesPopup.setAnchorView(mAnchorView);
                 mAlternatesPopup.setAdapter(mAlternatesAdapter);
                 mAlternatesPopup.setWidth(getWidth());
@@ -1205,9 +1200,7 @@
         private boolean isInDelete(int offset, float x, float y) {
             // Figure out the bounds of this chip and whether or not
             // the user clicked in the X portion.
-            return mSelected
-                    && (offset == getChipEnd()
-                            || (x > (mBounds.right - mChipDeleteWidth) && x < mBounds.right));
+            return mSelected && offset == getChipEnd();
         }
 
         /**
@@ -1238,7 +1231,6 @@
         public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top,
                 int y, int bottom, Paint paint) {
             // Shift the bounds of this span to where it is actually drawn on the screeen.
-            mLeft = (int) x;
             super.draw(canvas, text, start, end, x, top, y, bottom, paint);
         }