am 5c49b0ed: Merge "Adding the ability to remove chips that match a given ReicipientEntry" into ub-chips-bagotville
* commit '5c49b0ed416aa5dfc144b95ee9bf9a7d9f420bd3':
Adding the ability to remove chips that match a given ReicipientEntry
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index fdf58a6..0fec28e 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -3063,6 +3063,22 @@
}
}
+ /**
+ * Remove all chips matching the given RecipientEntry.
+ */
+ public void removeRecipientEntry(final RecipientEntry entry) {
+ final DrawableRecipientChip[] recips = getText()
+ .getSpans(0, getText().length(), DrawableRecipientChip.class);
+
+ for (final DrawableRecipientChip recipient : recips) {
+ final RecipientEntry existingEntry = recipient.getEntry();
+ if (existingEntry != null && existingEntry.isValid() &&
+ existingEntry.isSamePerson(entry)) {
+ removeChip(recipient);
+ }
+ }
+ }
+
private static class ChipBitmapContainer {
Bitmap bitmap;
// information used for positioning the loaded icon
diff --git a/src/com/android/ex/chips/RecipientEntry.java b/src/com/android/ex/chips/RecipientEntry.java
index 2afa859..c81202e 100644
--- a/src/com/android/ex/chips/RecipientEntry.java
+++ b/src/com/android/ex/chips/RecipientEntry.java
@@ -253,4 +253,12 @@
public String toString() {
return mDisplayName + " <" + mDestination + ">, isValid=" + mIsValid;
}
+
+ /**
+ * Returns if entry represents the same person as this instance. The default implementation
+ * checks whether the contact ids are the same, and subclasses may opt to override this.
+ */
+ public boolean isSamePerson(final RecipientEntry entry) {
+ return entry != null && mContactId == entry.mContactId;
+ }
}
\ No newline at end of file