summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkin Oguz <ekinoguz@google.com>2016-06-21 11:08:38 -0700
committerEkin Oguz <ekinoguz@google.com>2016-06-21 15:58:25 -0700
commit1a68eb2ed0497378aa39080e3ba54ddf5eff7214 (patch)
treea52b392a2abadfd369f271117cfb06b2309c2e65
parent1163a27340e6b18ef630fee4dd07c74c579c697c (diff)
downloadchips-1a68eb2ed0497378aa39080e3ba54ddf5eff7214.tar.gz
Add a function to get recipients under more span.
Currently, RecipientEditTextView only allows access to selected recipients, where hidden recipients under +1 (more chip) span are not included. Added function, getAllRecipients(), allows getting all the recipients, selected and hidden so that callers can make use of already loaded information from chips. BUG: 29519483 Change-Id: I578fdbb29d09e4d805788b0bbadcb34c6ac1069f
-rw-r--r--src/com/android/ex/chips/RecipientEditTextView.java44
1 files changed, 30 insertions, 14 deletions
diff --git a/src/com/android/ex/chips/RecipientEditTextView.java b/src/com/android/ex/chips/RecipientEditTextView.java
index bfd2e58..2d6c042 100644
--- a/src/com/android/ex/chips/RecipientEditTextView.java
+++ b/src/com/android/ex/chips/RecipientEditTextView.java
@@ -192,7 +192,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
// VisibleForTesting
ArrayList<DrawableRecipientChip> mTemporaryRecipients;
- private ArrayList<DrawableRecipientChip> mRemovedSpans;
+ private ArrayList<DrawableRecipientChip> mHiddenSpans;
// Chip copy fields.
private GestureDetector mGestureDetector;
@@ -478,6 +478,22 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
return results;
}
+ /**
+ * @return The list of {@link RecipientEntry}s that have been selected by the user and also
+ * hidden due to {@link #mMoreChip} span.
+ */
+ public List<RecipientEntry> getAllRecipients() {
+ List<RecipientEntry> results = getSelectedRecipients();
+
+ if (mHiddenSpans != null) {
+ for (DrawableRecipientChip chip : mHiddenSpans) {
+ results.add(chip.getEntry());
+ }
+ }
+
+ return results;
+ }
+
@Override
public void onSelectionChanged(int start, int end) {
// When selection changes, see if it is inside the chips area.
@@ -2207,12 +2223,12 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
int numRecipients = recipients.length;
int overage = numRecipients - CHIP_LIMIT;
MoreImageSpan moreSpan = createMoreSpan(overage);
- mRemovedSpans = new ArrayList<DrawableRecipientChip>();
+ mHiddenSpans = new ArrayList<DrawableRecipientChip>();
int totalReplaceStart = 0;
int totalReplaceEnd = 0;
Editable text = getText();
for (int i = numRecipients - overage; i < recipients.length; i++) {
- mRemovedSpans.add(recipients[i]);
+ mHiddenSpans.add(recipients[i]);
if (i == numRecipients - overage) {
totalReplaceStart = spannable.getSpanStart(recipients[i]);
}
@@ -2251,9 +2267,9 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
Spannable span = getSpannable();
span.removeSpan(mMoreChip);
mMoreChip = null;
- // Re-add the spans that were removed.
- if (mRemovedSpans != null && mRemovedSpans.size() > 0) {
- // Recreate each removed span.
+ // Re-add the spans that were hidden.
+ if (mHiddenSpans != null && mHiddenSpans.size() > 0) {
+ // Recreate each hidden span.
DrawableRecipientChip[] recipients = getSortedRecipients();
// Start the search for tokens after the last currently visible
// chip.
@@ -2262,13 +2278,13 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
int end = span.getSpanEnd(recipients[recipients.length - 1]);
Editable editable = getText();
- for (DrawableRecipientChip chip : mRemovedSpans) {
+ for (DrawableRecipientChip chip : mHiddenSpans) {
int chipStart;
int chipEnd;
String token;
// Need to find the location of the chip, again.
token = (String) chip.getOriginalText();
- // As we find the matching recipient for the remove spans,
+ // As we find the matching recipient for the hidden spans,
// reduce the size of the string we need to search.
// That way, if there are duplicates, we always find the correct
// recipient.
@@ -2280,7 +2296,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
- mRemovedSpans.clear();
+ mHiddenSpans.clear();
}
}
}
@@ -2526,7 +2542,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
}
private boolean chipsPending() {
- return mPendingChipsCount > 0 || (mRemovedSpans != null && mRemovedSpans.size() > 0);
+ return mPendingChipsCount > 0 || (mHiddenSpans != null && mHiddenSpans.size() > 0);
}
@Override
@@ -2827,8 +2843,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
new ArrayList<DrawableRecipientChip>();
final DrawableRecipientChip[] existingChips = getSortedRecipients();
Collections.addAll(originalRecipients, existingChips);
- if (mRemovedSpans != null) {
- originalRecipients.addAll(mRemovedSpans);
+ if (mHiddenSpans != null) {
+ originalRecipients.addAll(mHiddenSpans);
}
final List<DrawableRecipientChip> replacements =
@@ -2858,8 +2874,8 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements
new ArrayList<DrawableRecipientChip>();
DrawableRecipientChip[] existingChips = getSortedRecipients();
Collections.addAll(recipients, existingChips);
- if (mRemovedSpans != null) {
- recipients.addAll(mRemovedSpans);
+ if (mHiddenSpans != null) {
+ recipients.addAll(mHiddenSpans);
}
ArrayList<String> addresses = new ArrayList<String>();
for (DrawableRecipientChip chip : recipients) {