From adf511ea99847bba50bca1e664cac24c0e48b05f Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Mon, 8 Jan 2018 13:39:35 -0800 Subject: Updated T9 search bolding to include wrapping to the next word. T9 bolding now works when the query continues past a single name and extends to the next. For example, a query of "2226" would bold "[AAA M]om". This was supported in the old search. Bug: 71384038 Test: existing + new PiperOrigin-RevId: 181211263 Change-Id: I7d7fe8be794f410e697ddbcb26c6bc10c7893e5a --- .../searchfragment/common/QueryFilteringUtil.java | 42 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) (limited to 'java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java') 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; } @@ -93,6 +91,44 @@ public class QueryFilteringUtil { return queryIndex == query.length(); } + /** + * Returns the index where query is contained in the T9 representation of the name. + * + *

Examples: + * + *

+ */ + 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. * -- cgit v1.2.3