From fc0eb8ccebcc7846db5e8b5c5430070055679bfa Mon Sep 17 00:00:00 2001 From: Eric Erfanian Date: Thu, 31 Aug 2017 06:57:16 -0700 Subject: Update Dialer source to latest internal Google revision. Previously, Android's Dialer app was developed in an internal Google source control system and only exported to public during AOSP drops. The Dialer team is now switching to a public development model similar to the telephony team. This CL represents all internal Google changes that were committed to Dialer between the public O release and today's tip of tree on internal master. This CL squashes those changes into a single commit. In subsequent changes, changes will be exported on a per-commit basis. (cherry picked from commit 2ca4318cc1ee57dda907ba2069bd61d162b1baef and amended to match paths of dependencies under prebuilts/maven_repo/bumptech/com/github/bumptech/glide/.) This CL was generated using these commands from a repository at stage-stage-master at revision ea7b4dc89590ffa3332766a531e0eab6ffb9aebd ("Merge "Update Dialer source to latest internal Google revision." am: c39ea3c55f -s ours"): git diff --binary 2ca4318cc1ee57dda907ba2069bd61d162b1baef | git apply -R --index git commit -c 2ca4318cc1ee57dda907ba2069bd61d162b1baef Test: make, flash install, run Change-Id: I529aaeb88535b9533c0ae4ef4e6c1222d4e0f1c8 PiperOrigin-RevId: 167068436 --- .../dialer/searchfragment/common/Projections.java | 6 +- .../searchfragment/common/QueryBoldingUtil.java | 65 +++++++++++----------- .../searchfragment/common/QueryFilteringUtil.java | 40 ++++++++++--- .../searchfragment/common/RowClickListener.java | 43 ++++++++++++++ .../dialer/searchfragment/common/SearchCursor.java | 38 +++++++++++++ .../searchfragment/common/res/values/dimens.xml | 1 - 6 files changed, 149 insertions(+), 44 deletions(-) create mode 100644 java/com/android/dialer/searchfragment/common/RowClickListener.java create mode 100644 java/com/android/dialer/searchfragment/common/SearchCursor.java (limited to 'java/com/android/dialer/searchfragment/common') diff --git a/java/com/android/dialer/searchfragment/common/Projections.java b/java/com/android/dialer/searchfragment/common/Projections.java index 37e20d195..078c3e5e6 100644 --- a/java/com/android/dialer/searchfragment/common/Projections.java +++ b/java/com/android/dialer/searchfragment/common/Projections.java @@ -30,9 +30,10 @@ public class Projections { public static final int PHONE_PHOTO_URI = 6; public static final int PHONE_LOOKUP_KEY = 7; public static final int PHONE_CARRIER_PRESENCE = 8; + public static final int PHONE_CONTACT_ID = 9; @SuppressWarnings("unused") - public static final int PHONE_SORT_KEY = 9; + public static final int PHONE_SORT_KEY = 10; public static final String[] PHONE_PROJECTION = new String[] { @@ -45,6 +46,7 @@ public class Projections { Phone.PHOTO_THUMBNAIL_URI, // 6 Phone.LOOKUP_KEY, // 7 Phone.CARRIER_PRESENCE, // 8 - Phone.SORT_KEY_PRIMARY // 9 + Phone.CONTACT_ID, // 9 + Phone.SORT_KEY_PRIMARY // 10 }; } diff --git a/java/com/android/dialer/searchfragment/common/QueryBoldingUtil.java b/java/com/android/dialer/searchfragment/common/QueryBoldingUtil.java index 7bdd69567..4413252f4 100644 --- a/java/com/android/dialer/searchfragment/common/QueryBoldingUtil.java +++ b/java/com/android/dialer/searchfragment/common/QueryBoldingUtil.java @@ -23,6 +23,8 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.TextUtils; import android.text.style.StyleSpan; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** Utility class for handling bolding queries contained in string. */ public class QueryBoldingUtil { @@ -30,7 +32,7 @@ public class QueryBoldingUtil { /** * Compares a name and query and returns a {@link CharSequence} with bolded characters. * - *

Some example: + *

Some example of matches: * *

* + *

Some examples of non-matches: + * + *

+ * * @param query containing any characters * @param name of a contact/string that query will compare to * @return name with query bolded if query can be found in the name. @@ -47,43 +56,31 @@ public class QueryBoldingUtil { return name; } - int index = -1; - int numberOfBoldedCharacters = 0; - - if (QueryFilteringUtil.nameMatchesT9Query(query, name)) { - // Bold the characters that match the t9 query - String t9 = QueryFilteringUtil.getT9Representation(name); - index = QueryFilteringUtil.indexOfQueryNonDigitsIgnored(query, t9); - if (index == -1) { - return getNameWithInitialsBolded(query, name); - } - numberOfBoldedCharacters = query.length(); - - for (int i = 0; i < query.length(); i++) { - char c = query.charAt(i); - if (!Character.isDigit(c)) { - numberOfBoldedCharacters--; - } - } - - for (int i = 0; i < index + numberOfBoldedCharacters; i++) { - if (!Character.isLetterOrDigit(name.charAt(i))) { - if (i < index) { - index++; - } else { - numberOfBoldedCharacters++; - } - } + if (!QueryFilteringUtil.nameMatchesT9Query(query, name)) { + Pattern pattern = Pattern.compile("(^|\\s)" + Pattern.quote(query.toLowerCase())); + Matcher matcher = pattern.matcher(name.toLowerCase()); + if (matcher.find()) { + // query matches the start of a name (i.e. "jo" -> "Jessica [Jo]nes") + return getBoldedString(name, matcher.start(), query.length()); + } else { + // query not found in name + return name; } } - if (index == -1) { - // Bold the query as an exact match in the name - index = name.toLowerCase().indexOf(query); - numberOfBoldedCharacters = query.length(); + Pattern pattern = Pattern.compile("(^|\\s)" + Pattern.quote(query.toLowerCase())); + Matcher matcher = pattern.matcher(QueryFilteringUtil.getT9Representation(name)); + if (matcher.find()) { + // query matches the start of a T9 name (i.e. 75 -> "Jessica [Jo]nes") + int index = matcher.start(); + // TODO(calderwoodra): investigate why this is consistently off by one. + index = index == 0 ? 0 : index + 1; + return getBoldedString(name, index, query.length()); + + } else { + // query match the T9 initials (i.e. 222 -> "[A]l [B]ob [C]harlie") + return getNameWithInitialsBolded(query, name); } - - return index == -1 ? name : getBoldedString(name, index, numberOfBoldedCharacters); } private static CharSequence getNameWithInitialsBolded(String query, String name) { diff --git a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java index b23315b15..775f8deec 100644 --- a/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java +++ b/java/com/android/dialer/searchfragment/common/QueryFilteringUtil.java @@ -25,25 +25,34 @@ import java.util.regex.Pattern; public class QueryFilteringUtil { /** Matches strings with "-", "(", ")", 2-9 of at least length one. */ - static final Pattern T9_PATTERN = Pattern.compile("[\\-()2-9]+"); + private static final Pattern T9_PATTERN = Pattern.compile("[\\-()2-9]+"); /** - * @return true if the query is of T9 format and the name's T9 representation belongs to the - * query; false otherwise. + * Returns true if the query is of T9 format and the name's T9 representation belongs to the query + * + *

Examples: + * + *

*/ public static boolean nameMatchesT9Query(String query, String name) { if (!T9_PATTERN.matcher(query).matches()) { return false; } - // Substring - if (indexOfQueryNonDigitsIgnored(query, getT9Representation(name)) != -1) { + query = digitsOnly(query); + Pattern pattern = Pattern.compile("(^|\\s)" + Pattern.quote(query)); + if (pattern.matcher(getT9Representation(name)).find()) { + // query matches the start of a T9 name (i.e. 75 -> "Jessica [Jo]nes") return true; } // Check matches initials - // TODO investigate faster implementation - query = digitsOnly(query); + // TODO(calderwoodra) investigate faster implementation int queryIndex = 0; String[] names = name.toLowerCase().split("\\s"); @@ -60,6 +69,23 @@ public class QueryFilteringUtil { return queryIndex == query.length(); } + /** + * Returns true if the subparts of the name (split by white space) begin with the query. + * + *

Examples: + * + *

+ */ + public static boolean nameContainsQuery(String query, String name) { + return Pattern.compile("(^|\\s)" + Pattern.quote(query.toLowerCase())) + .matcher(name.toLowerCase()) + .find(); + } + /** @return true if the number belongs to the query. */ public static boolean numberMatchesNumberQuery(String query, String number) { return PhoneNumberUtils.isGlobalPhoneNumber(query) diff --git a/java/com/android/dialer/searchfragment/common/RowClickListener.java b/java/com/android/dialer/searchfragment/common/RowClickListener.java new file mode 100644 index 000000000..e82f3f7bb --- /dev/null +++ b/java/com/android/dialer/searchfragment/common/RowClickListener.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.searchfragment.common; + +import com.android.dialer.dialercontact.DialerContact; + +/** Interface of possible actions that can be performed by search elements. */ +public interface RowClickListener { + + /** + * Places a traditional voice call. + * + * @param ranking position in the list relative to the other elements + */ + void placeVoiceCall(String phoneNumber, int ranking); + + /** + * Places an IMS video call. + * + * @param ranking position in the list relative to the other elements + */ + void placeVideoCall(String phoneNumber, int ranking); + + /** Places a Duo video call. */ + void placeDuoCall(String phoneNumber); + + /** Opens the enriched calling/call composer interface. */ + void openCallAndShare(DialerContact dialerContact); +} diff --git a/java/com/android/dialer/searchfragment/common/SearchCursor.java b/java/com/android/dialer/searchfragment/common/SearchCursor.java new file mode 100644 index 000000000..368ee09d6 --- /dev/null +++ b/java/com/android/dialer/searchfragment/common/SearchCursor.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.searchfragment.common; + +import android.database.Cursor; +import android.support.annotation.NonNull; + +/** Base cursor interface needed for all cursors used in search. */ +public interface SearchCursor extends Cursor { + + String[] HEADER_PROJECTION = {"header_text"}; + + int HEADER_TEXT_POSITION = 0; + + /** Returns true if the current cursor position is a header */ + boolean isHeader(); + + /** + * Notifies the cursor that the query has updated. + * + * @return true if the data set has changed. + */ + boolean updateQuery(@NonNull String query); +} diff --git a/java/com/android/dialer/searchfragment/common/res/values/dimens.xml b/java/com/android/dialer/searchfragment/common/res/values/dimens.xml index d5459ddb3..f6664163c 100644 --- a/java/com/android/dialer/searchfragment/common/res/values/dimens.xml +++ b/java/com/android/dialer/searchfragment/common/res/values/dimens.xml @@ -19,5 +19,4 @@ 8dp 8dp 16dp - 16sp \ No newline at end of file -- cgit v1.2.3