summaryrefslogtreecommitdiffstats
path: root/chips/src/com
diff options
context:
space:
mode:
authorKevin Lin <linkevin@google.com>2014-02-26 12:29:10 -0800
committerKevin Lin <linkevin@google.com>2014-02-26 12:31:37 -0800
commitd4ae44ec6721e7819b246f70e23eb393cb8fb529 (patch)
treeecbd6bffe6f2380a4dc6861477eee9098a8b0b4d /chips/src/com
parent64becd8054a1ea648b306b0531655b435561e271 (diff)
downloadandroid_frameworks_ex-d4ae44ec6721e7819b246f70e23eb393cb8fb529.tar.gz
android_frameworks_ex-d4ae44ec6721e7819b246f70e23eb393cb8fb529.tar.bz2
android_frameworks_ex-d4ae44ec6721e7819b246f70e23eb393cb8fb529.zip
Added support to choose vertical alignment for image spans.
TESTED=phone Change-Id: I582224467b4626afd1414889166f4fbbc773897f
Diffstat (limited to 'chips/src/com')
-rw-r--r--chips/src/com/android/ex/chips/RecipientEditTextView.java29
-rw-r--r--chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java6
2 files changed, 30 insertions, 5 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java
index eca0afb..5d5216e 100644
--- a/chips/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java
@@ -160,6 +160,17 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
// 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 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
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/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java b/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
index ce32e3d..5a82f28 100644
--- a/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
+++ b/chips/src/com/android/ex/chips/recipientchip/VisibleRecipientChip.java
@@ -19,7 +19,6 @@ package com.android.ex.chips.recipientchip;
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 @@ import com.android.ex.chips.RecipientEntry;
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);
}