Fix filtering bug and reduce area that causes delete of chip.
The bug was: when the user backspaced from the end of the multiautocompletefield
to a chip, the view would bring up a popup that filtered against hte contents
of the chip. This fixes that by specifically not filtering on chip contents.
Also, dont allow taps past the end of a chip to delete the chip.
Change-Id: Idbb41756c9efd544846802ddad8c67545b8ade1f
diff --git a/src/com/android/ex/chips/RecipientEditTextViewInner.java b/src/com/android/ex/chips/RecipientEditTextViewInner.java
index abdd775..4314dc1 100644
--- a/src/com/android/ex/chips/RecipientEditTextViewInner.java
+++ b/src/com/android/ex/chips/RecipientEditTextViewInner.java
@@ -286,6 +286,28 @@
return (Spannable) getText();
}
+ /**
+ * Instead of filtering on the entire contents of the edit box,
+ * this subclass method filters on the range from
+ * {@link Tokenizer#findTokenStart} to {@link #getSelectionEnd}
+ * if the length of that range meets or exceeds {@link #getThreshold}
+ * and makes sure that the range is not already a Chip.
+ */
+ @Override
+ protected void performFiltering(CharSequence text, int keyCode) {
+ if (enoughToFilter()) {
+ int end = getSelectionEnd();
+ int start = mTokenizer.findTokenStart(text, end);
+ // If this is a RecipientChip, don't filter
+ // on its contents.
+ Spannable span = getSpannable();
+ RecipientChip[] chips = span.getSpans(start, end, RecipientChip.class);
+ if (chips != null && chips.length > 0) {
+ return;
+ }
+ }
+ super.performFiltering(text, keyCode);
+ }
@Override
public boolean onTouchEvent(MotionEvent event) {
@@ -603,7 +625,7 @@
// Figure out the bounds of this chip and whether or not
// the user clicked in the X portion.
return mSelected
- && (offset >= getChipEnd()
+ && (offset == getChipEnd()
|| (x > (mBounds.right - mChipDeleteWidth) && x < mBounds.right));
}