If there are no chips to chipify and the user hits enter, focus the next view.
Per UX and user studies.
For tab, commit and then focus the next view.
Change-Id: I9f226cb82191b4866b3ddd1c2cc4f1ae185e65e3
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 9819e02..8e0b789 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -88,8 +88,6 @@
private RecipientChip mSelectedChip;
- private int mChipDeleteWidth;
-
private int mAlternatesLayout;
private Bitmap mDefaultContactPhoto;
@@ -356,8 +354,6 @@
"Unable to render any chips as setChipDimensions was not called.");
}
Layout layout = getLayout();
- int line = 0;
- int lineTop = getTop();
TextPaint paint = getPaint();
float defaultSize = paint.getTextSize();
@@ -516,17 +512,44 @@
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_TAB:
if (event.hasNoModifiers()) {
if (commitDefault()) {
return true;
}
+ if (mSelectedChip != null) {
+ clearSelectedChip();
+ return true;
+ } else if (mSelectedChip == null) {
+ if (focusNext()) {
+ return true;
+ }
+ }
}
break;
+ case KeyEvent.KEYCODE_TAB:
+ if (event.hasNoModifiers()) {
+ if (mSelectedChip != null) {
+ clearSelectedChip();
+ } else {
+ commitDefault();
+ }
+ if (focusNext()) {
+ return true;
+ }
+ }
}
return super.onKeyUp(keyCode, event);
}
+ private boolean focusNext() {
+ View next = focusSearch(View.FOCUS_DOWN);
+ if (next != null) {
+ next.requestFocus();
+ return true;
+ }
+ return false;
+ }
+
/**
* Create a chip from the default selection. If the popup is showing, the
* default is the first item in the popup suggestions list. Otherwise, it is
@@ -565,7 +588,7 @@
editable.replace(start, end, createChip(entry, false));
dismissDropDown();
}
- return false;
+ return true;
}
}
return false;