diff options
author | Mindy Pereira <mindyp@google.com> | 2011-09-26 16:11:41 -0700 |
---|---|---|
committer | Mindy Pereira <mindyp@google.com> | 2011-09-27 09:01:34 -0700 |
commit | ae7e41106f289f2668c54fff6c457c6fc91ab4a9 (patch) | |
tree | d2d65362c9cfc97696bc456ce5076344438bbe34 /chips/src | |
parent | 53958d6d0ba2a0765fd3d272295b81c6d89a68d8 (diff) | |
download | android_frameworks_ex-ae7e41106f289f2668c54fff6c457c6fc91ab4a9.tar.gz android_frameworks_ex-ae7e41106f289f2668c54fff6c457c6fc91ab4a9.tar.bz2 android_frameworks_ex-ae7e41106f289f2668c54fff6c457c6fc91ab4a9.zip |
Add more tests.
Tests verifying where a chip is position, removing a chip,
and creating a chip.
Change-Id: I2e9c6719a6efc365ab73c4d3c32bb29209b73e48
Diffstat (limited to 'chips/src')
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 53 |
1 files changed, 29 insertions, 24 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index cedc60a..f4573c6 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -484,16 +484,18 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements photo = mDefaultContactPhoto; } // Draw the photo on the left side. - Matrix matrix = new Matrix(); - RectF src = new RectF(0, 0, photo.getWidth(), photo.getHeight()); - Rect backgroundPadding = new Rect(); - mChipBackground.getPadding(backgroundPadding); - RectF dst = new RectF(width - iconWidth + backgroundPadding.left, - 0 + backgroundPadding.top, - width - backgroundPadding.right, - height - backgroundPadding.bottom); - matrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); - canvas.drawBitmap(photo, matrix, paint); + if (photo != null) { + RectF src = new RectF(0, 0, photo.getWidth(), photo.getHeight()); + Rect backgroundPadding = new Rect(); + mChipBackground.getPadding(backgroundPadding); + RectF dst = new RectF(width - iconWidth + backgroundPadding.left, + 0 + backgroundPadding.top, + width - backgroundPadding.right, + height - backgroundPadding.bottom); + Matrix matrix = new Matrix(); + matrix.setRectToRect(src, dst, Matrix.ScaleToFit.FILL); + canvas.drawBitmap(photo, matrix, paint); + } } else { // Don't leave any space for the icon. It isn't being drawn. iconWidth = 0; @@ -604,6 +606,17 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements mMoreItem = moreItem; } + + // Visible for testing. + /* package */ void setChipBackground(Drawable chipBackground) { + mChipBackground = chipBackground; + } + + // Visible for testing. + /* package */ void setChipHeight(int height) { + mChipHeight = height; + } + /** * Set whether to shrink the recipients field such that at most * one line of recipients chips are shown when the field loses @@ -1704,6 +1717,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements public boolean matchesChip(RecipientChip chip, int offset) { int start = getChipStart(chip); int end = getChipEnd(chip); + if (start == -1 || end == -1) { return false; } @@ -1729,23 +1743,19 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements /** * Remove the chip and any text associated with it from the RecipientEditTextView. */ - private void removeChip(RecipientChip chip) { + // Visible for testing. + /*pacakge*/ void removeChip(RecipientChip chip) { Spannable spannable = getSpannable(); int spanStart = spannable.getSpanStart(chip); int spanEnd = spannable.getSpanEnd(chip); Editable text = getText(); - int toDelete = spanEnd; boolean wasSelected = chip == mSelectedChip; // Clear that there is a selected chip before updating any text. if (wasSelected) { mSelectedChip = null; } - // Always remove trailing spaces when removing a chip. - while (toDelete >= 0 && toDelete < text.length() && text.charAt(toDelete) == ' ') { - toDelete++; - } spannable.removeSpan(chip); - text.delete(spanStart, toDelete); + text.delete(spanStart, spanEnd); if (wasSelected) { clearSelectedChip(); } @@ -1769,14 +1779,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements Log.e(TAG, "The chip to replace does not exist but should."); editable.insert(0, chipText); } else { - // There may be a space to replace with this chip's new associated - // space. Check for it. - int toReplace = end; - while (toReplace >= 0 && toReplace < editable.length() - && editable.charAt(toReplace) == ' ') { - toReplace++; + if (!TextUtils.isEmpty(chipText)) { + editable.replace(start, end, chipText); } - editable.replace(start, toReplace, chipText); } setCursorVisible(true); if (wasSelected) { |