am 07c0fcd1: am 93e48b10: am 0764e983: am 4a0aacfe: am d4ae44ec: Added support to choose vertical alignment for image spans.

* commit '07c0fcd10aeb14c6ae9b7edf13176ad35abbb884':
  Added support to choose vertical alignment for image spans.
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 96d995a..d3500aa 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -27,5 +27,9 @@
         <attr name="chipPadding" format="reference" />
         <attr name="disableDelete" format="boolean" />
         <attr name="invalidChipBackground" format="reference" />
+        <attr name="imageSpanAlignment">
+            <enum name="bottom" value = "0"/>
+            <enum name="baseline" value = "1"/>
+        </attr>
     </declare-styleable>
 </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 eca0afb..5d5216e 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -160,6 +160,17 @@
 
     private static final int AVATAR_POSITION_START = 1;
 
+    /**
+     * Enumerator for image span alignment. See attr.xml for more details.
+     * 0 for bottom, 1 for baseline.
+     */
+    private int mImageSpanAlignment;
+
+    private static final int IMAGE_SPAN_ALIGNMENT_BOTTOM = 0;
+
+    private static final int IMAGE_SPAN_ALIGNMENT_BASELINE = 1;
+
+
     private boolean mDisableDelete;
 
     private Tokenizer mTokenizer;
@@ -621,7 +632,8 @@
         float[] widths = new float[1];
         paint.getTextWidths(" ", widths);
         CharSequence ellipsizedText = ellipsizeText(createChipDisplayText(contact), paint,
-                calculateAvailableWidth() - iconWidth - widths[0]);
+                calculateAvailableWidth() - iconWidth - widths[0] - backgroundPadding.left
+                    - backgroundPadding.right);;
         int textWidth = (int) paint.measureText(ellipsizedText, 0, ellipsizedText.length());
 
         // Make sure there is a minimum chip width so the user can ALWAYS
@@ -753,13 +765,25 @@
         // Pass the full text, un-ellipsized, to the chip.
         Drawable result = new BitmapDrawable(getResources(), tmpBitmap);
         result.setBounds(0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight());
-        DrawableRecipientChip recipientChip = new VisibleRecipientChip(result, contact);
+        DrawableRecipientChip recipientChip =
+                new VisibleRecipientChip(result, contact, getImageSpanAlignment());
         // Return text to the original size.
         paint.setTextSize(defaultSize);
         paint.setColor(defaultColor);
         return recipientChip;
     }
 
+    private int getImageSpanAlignment() {
+        switch (mImageSpanAlignment) {
+            case IMAGE_SPAN_ALIGNMENT_BASELINE:
+                return ImageSpan.ALIGN_BASELINE;
+            case IMAGE_SPAN_ALIGNMENT_BOTTOM:
+                return ImageSpan.ALIGN_BOTTOM;
+            default:
+                return ImageSpan.ALIGN_BOTTOM;
+        }
+    }
+
     /**
      * Calculate the bottom of the line the chip will be located on using:
      * 1) which line the chip appears on
@@ -824,6 +848,7 @@
             mInvalidChipBackground = r.getDrawable(R.drawable.chip_background_invalid);
         }
         mAvatarPosition = a.getInt(R.styleable.RecipientEditTextView_avatarPosition, 0);
+        mImageSpanAlignment = a.getInt(R.styleable.RecipientEditTextView_imageSpanAlignment, 0);
         mDisableDelete = a.getBoolean(R.styleable.RecipientEditTextView_disableDelete, false);
 
         mLineSpacingExtra =  r.getDimension(R.dimen.line_spacing_extra);
diff --git a/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java b/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
index ce32e3d..5a82f28 100644
--- a/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
+++ b/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
@@ -19,7 +19,6 @@
 import android.graphics.Canvas;
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
-import android.text.style.DynamicDrawableSpan;
 import android.text.style.ImageSpan;
 
 import com.android.ex.chips.RecipientEntry;
@@ -31,8 +30,9 @@
 public class VisibleRecipientChip extends ImageSpan implements DrawableRecipientChip {
     private final SimpleRecipientChip mDelegate;
 
-    public VisibleRecipientChip(final Drawable drawable, final RecipientEntry entry) {
-        super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
+    public VisibleRecipientChip(final Drawable drawable, final RecipientEntry entry,
+            final int verticalAlignment) {
+        super(drawable, verticalAlignment);
 
         mDelegate = new SimpleRecipientChip(entry);
     }