diff options
author | Scott Kennedy <skennedy@google.com> | 2013-02-15 18:22:05 -0800 |
---|---|---|
committer | Scott Kennedy <skennedy@google.com> | 2013-02-19 10:04:03 -0800 |
commit | 2727f969d0ce46cdd16cd77e1dc21f3a636217d2 (patch) | |
tree | 588ed5d0ec5e90f4650bc2e17a2a7e542cf9f77f /chips/src | |
parent | 7b1c6d7dea5f4e3fcb3eb4f137b2e510b394ea79 (diff) | |
download | android_frameworks_ex-2727f969d0ce46cdd16cd77e1dc21f3a636217d2.tar.gz android_frameworks_ex-2727f969d0ce46cdd16cd77e1dc21f3a636217d2.tar.bz2 android_frameworks_ex-2727f969d0ce46cdd16cd77e1dc21f3a636217d2.zip |
Ensure all addresses turn into chips
If an address wasn't properly resolved, it was left as text. This
change processes all unresolved addresses into chips.
Bug: 8201904
Change-Id: Iae7718d97c7c1167bdc464ef372b171743524712
Diffstat (limited to 'chips/src')
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java | 23 | ||||
-rw-r--r-- | chips/src/com/android/ex/chips/RecipientEditTextView.java | 36 |
2 files changed, 54 insertions, 5 deletions
diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java index 00f1ff4..49e2d5c 100644 --- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java +++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java @@ -41,6 +41,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; /** * RecipientAlternatesAdapter backs the RecipientEditTextView for managing contacts @@ -63,7 +65,11 @@ public class RecipientAlternatesAdapter extends CursorAdapter { private Query mQuery; public interface RecipientMatchCallback { - public void matchesFound(HashMap<String, RecipientEntry> results); + public void matchesFound(Map<String, RecipientEntry> results); + /** + * Called with all addresses that could not be resolved to valid recipients. + */ + public void matchesNotFound(Set<String> addresses); } public static void getMatchingRecipients(Context context, ArrayList<String> inAddresses, @@ -126,6 +132,7 @@ public class RecipientAlternatesAdapter extends CursorAdapter { } // See if any entries did not resolve; if so, we need to check other // directories + final Set<String> matchesNotFound = new HashSet<String>(); if (recipientEntries.size() < addresses.size()) { final List<DirectorySearchParams> paramsList; Cursor directoryCursor = context.getContentResolver().query(DirectoryListQuery.URI, @@ -139,6 +146,9 @@ public class RecipientAlternatesAdapter extends CursorAdapter { unresolvedAddresses.add(address); } } + + matchesNotFound.addAll(unresolvedAddresses); + Cursor directoryContactsCursor = null; for (String unresolvedAddress : unresolvedAddresses) { for (int i = 0; i < paramsList.size(); i++) { @@ -158,13 +168,22 @@ public class RecipientAlternatesAdapter extends CursorAdapter { } if (directoryContactsCursor != null) { try { - callback.matchesFound(processContactEntries(directoryContactsCursor)); + final Map<String, RecipientEntry> entries = + processContactEntries(directoryContactsCursor); + + for (final String address : entries.keySet()) { + matchesNotFound.remove(address); + } + + callback.matchesFound(entries); } finally { directoryContactsCursor.close(); } } } } + + callback.matchesNotFound(matchesNotFound); } private static HashMap<String, RecipientEntry> processContactEntries(Cursor c) { diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index cfd6b25..9202265 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -86,9 +86,9 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -2450,7 +2450,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements new RecipientMatchCallback() { @Override - public void matchesFound(HashMap<String, RecipientEntry> entries) { + public void matchesFound(Map<String, RecipientEntry> entries) { final ArrayList<RecipientChip> replacements = new ArrayList<RecipientChip>(); for (final RecipientChip temp : originalRecipients) { @@ -2469,6 +2469,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements replacements.add(null); } } + processReplacements(replacements); + } + + private void processReplacements(final List<RecipientChip> replacements) { if (replacements != null && replacements.size() > 0) { mHandler.post(new Runnable() { @Override @@ -2518,6 +2522,28 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements }); } } + + @Override + public void matchesNotFound(final Set<String> addresses) { + final List<RecipientChip> replacements = + new ArrayList<RecipientChip>(addresses.size()); + + for (final RecipientChip temp : originalRecipients) { + if (RecipientEntry.isCreatedRecipient(temp.getEntry() + .getContactId()) + && getSpannable().getSpanStart(temp) != -1) { + if (addresses.contains(temp.getEntry().getDestination())) { + replacements.add(createFreeChip(temp.getEntry())); + } else { + replacements.add(null); + } + } else { + replacements.add(null); + } + } + + processReplacements(replacements); + } }); return null; } @@ -2545,7 +2571,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements new RecipientMatchCallback() { @Override - public void matchesFound(HashMap<String, RecipientEntry> entries) { + public void matchesFound(Map<String, RecipientEntry> entries) { for (final RecipientChip temp : originalRecipients) { if (RecipientEntry.isCreatedRecipient(temp.getEntry() .getContactId()) @@ -2573,6 +2599,10 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } } + @Override + public void matchesNotFound(final Set<String> addresses) { + // No action required + } }); return null; } |