aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Brophy <mbrophy@google.com>2011-08-22 17:33:53 +0100
committerMark Brophy <mbrophy@google.com>2011-09-30 16:28:41 +0100
commit20e99644372a288beabe8d9d9481f34e2f4045d8 (patch)
tree48bb1d22c10e928195c2416a3785fa498682a2cd
parentfcc7025b595564cff1bf211cd4089411e9b2f827 (diff)
downloadContactsProvider-20e99644372a288beabe8d9d9481f34e2f4045d8.tar.gz
Handle complex phone numbers in ContactsProvider.
Use i18n.phonenumber.PhoneNumberUtil to check whether the query is a phone number. Bug: 5396858 Change-Id: If389f6d996c6789630d91834d45778f420c6dde3
-rw-r--r--src/com/android/providers/contacts/GlobalSearchSupport.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/com/android/providers/contacts/GlobalSearchSupport.java b/src/com/android/providers/contacts/GlobalSearchSupport.java
index efaf7b8c..5d4d2730 100644
--- a/src/com/android/providers/contacts/GlobalSearchSupport.java
+++ b/src/com/android/providers/contacts/GlobalSearchSupport.java
@@ -32,12 +32,15 @@ import android.provider.ContactsContract.SearchSnippetColumns;
import android.provider.ContactsContract.StatusUpdates;
import android.text.TextUtils;
+import com.android.i18n.phonenumbers.PhoneNumberUtil;
+import com.android.i18n.phonenumbers.NumberParseException;
import com.android.providers.contacts.ContactsDatabaseHelper.AggregatedPresenceColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.ContactsColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.Tables;
import com.android.providers.contacts.ContactsDatabaseHelper.Views;
import java.util.ArrayList;
+import java.util.Locale;
/**
* Support for global search integration for Contacts.
@@ -176,10 +179,12 @@ public class GlobalSearchSupport {
}
private final ContactsProvider2 mContactsProvider;
+ private final PhoneNumberUtil mPhoneNumberUtil;
@SuppressWarnings("all")
public GlobalSearchSupport(ContactsProvider2 contactsProvider) {
mContactsProvider = contactsProvider;
+ mPhoneNumberUtil = PhoneNumberUtil.getInstance();
// To ensure the data column position. This is dead code if properly configured.
if (Organization.COMPANY != Data.DATA1 || Phone.NUMBER != Data.DATA1
@@ -201,8 +206,7 @@ public class GlobalSearchSupport {
selection = null;
}
- if (!TextUtils.isEmpty(searchClause) && TextUtils.isDigitsOnly(searchClause)
- && mContactsProvider.isPhone()) {
+ if (mContactsProvider.isPhone() && isPhoneNumber(searchClause)) {
return buildCursorForSearchSuggestionsBasedOnPhoneNumber(searchClause);
} else {
return buildCursorForSearchSuggestionsBasedOnFilter(
@@ -210,6 +214,10 @@ public class GlobalSearchSupport {
}
}
+ private boolean isPhoneNumber(String query) {
+ return mPhoneNumberUtil.isPossibleNumber(query, Locale.getDefault().getCountry());
+ }
+
/**
* Returns a search suggestions cursor for the contact bearing the provided lookup key. If the
* lookup key cannot be found in the database, the contact name is decoded from the lookup key