diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-01-09 16:40:28 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-01-09 16:40:28 +0000 |
commit | 8c19b0ac8f79eb7f653ee3e07018ca7342f4e190 (patch) | |
tree | 92e2a480370fd53fdb210d1035a6c3d666628819 /java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java | |
parent | 455a7c27d5c5d4c25236d940f088a25a5bf57c2a (diff) | |
parent | 517fbff5c15c9270323b4099a39514d2487eec99 (diff) |
Merge changes Iddf5ef33,I1b718e30,I0c7386f6,I81069948,I3bec477d, ...
* changes:
Update strings for Duo "Set up" and "Invite" buttons
Hide emergency calls in the call log
Simplifying implementation of the coalescing logic in the new call log.
Updating Dialer v16 licenses.
Use ContactsContract.PhoneLookup for invalid numbers in Cp2PhoneLookup.
Add RTT call chat window.
Updated T9 search bolding to include wrapping to the next word.
Initial setup of voicemail error messages
Automated rollback of changelist 178323108
Add "delete" option in the 3-dot menu of the new call log
Diffstat (limited to 'java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java')
-rw-r--r-- | java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java index c4ff27545..9add44c8a 100644 --- a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java +++ b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java @@ -69,9 +69,7 @@ public class QueryFilteringUtil { } query = digitsOnly(query); - Pattern pattern = Pattern.compile("(^|\\s)" + Pattern.quote(query)); - if (pattern.matcher(getT9Representation(name, context)).find()) { - // query matches the start of a T9 name (i.e. 75 -> "Jessica [Jo]nes") + if (getIndexOfT9Substring(query, name, context) != -1) { return true; } @@ -94,6 +92,44 @@ public class QueryFilteringUtil { } /** + * Returns the index where query is contained in the T9 representation of the name. + * + * <p>Examples: + * + * <ul> + * <li>#getIndexOfT9Substring("76", "John Smith") returns 5, 76 -> 'Sm' + * <li>#nameMatchesT9Query("2226", "AAA Mom") returns 0, 2226 -> 'AAAM' + * <li>#nameMatchesT9Query("2", "Jessica Jones") returns -1, Neither 'Jessica' nor 'Jones' start + * with A, B or C + * </ul> + */ + public static int getIndexOfT9Substring(String query, String name, Context context) { + query = digitsOnly(query); + String t9Name = getT9Representation(name, context); + String t9NameDigitsOnly = digitsOnly(t9Name); + if (t9NameDigitsOnly.startsWith(query)) { + return 0; + } + + int nonLetterCount = 0; + for (int i = 1; i < t9NameDigitsOnly.length(); i++) { + char cur = t9Name.charAt(i); + if (!Character.isDigit(cur)) { + nonLetterCount++; + continue; + } + + // If the previous character isn't a digit and the current is, check for a match + char prev = t9Name.charAt(i - 1); + int offset = i - nonLetterCount; + if (!Character.isDigit(prev) && t9NameDigitsOnly.startsWith(query, offset)) { + return i; + } + } + return -1; + } + + /** * Returns true if the subparts of the name (split by white space) begin with the query. * * <p>Examples: |