Call ChipDeleted when RecipientEditTextView's parent handles a delete. am: 8cd6353bdc am: 553a9d403c am: e5ecd1888c am: 87a0f61300 am: 3097592aba
am: 334775ff70
Change-Id: Ib97353b831bc22af285fe23eb3f9f6d9bf4ac326
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index 9597aa1..7140f24 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -1828,7 +1828,24 @@
break;
}
- return super.onKeyDown(keyCode, event);
+ final DrawableRecipientChip lastRecipientChip = getLastChip();
+ boolean isHandled = super.onKeyDown(keyCode, event);
+
+ /*
+ * Hacky way to report a deleted chip:
+ * In some devices/configurations, {@link KeyEvent#KEYCODE_DEL} character is causing
+ * onKeyDown() to be called, which in turns handles the chip deletion instead of
+ * {@link RecipientTextWatcher#onTextChanged}. We want to call
+ * {@link RecipientChipDeletedListener#onRecipientChipDeleted} callback for these cases.
+ */
+ if (keyCode == KeyEvent.KEYCODE_DEL && isHandled && lastRecipientChip != null) {
+ final RecipientEntry entry = lastRecipientChip.getEntry();
+ if (!mNoChipMode && mRecipientChipDeletedListener != null && entry != null) {
+ mRecipientChipDeletedListener.onRecipientChipDeleted(entry);
+ }
+ }
+
+ return isHandled;
}
// Visible for testing.