summaryrefslogtreecommitdiffstats
path: root/src/com/android/providers/contacts/GlobalSearchSupport.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/providers/contacts/GlobalSearchSupport.java')
-rw-r--r--src/com/android/providers/contacts/GlobalSearchSupport.java139
1 files changed, 8 insertions, 131 deletions
diff --git a/src/com/android/providers/contacts/GlobalSearchSupport.java b/src/com/android/providers/contacts/GlobalSearchSupport.java
index 70dbd31..d4cddee 100644
--- a/src/com/android/providers/contacts/GlobalSearchSupport.java
+++ b/src/com/android/providers/contacts/GlobalSearchSupport.java
@@ -18,14 +18,10 @@ package com.android.providers.contacts;
import android.app.SearchManager;
import android.content.Context;
-import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
-import android.location.Country;
-import android.location.CountryDetector;
import android.net.Uri;
-import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -36,7 +32,6 @@ import android.provider.ContactsContract.StatusUpdates;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
-import com.android.i18n.phonenumbers.PhoneNumberUtil;
import com.android.providers.contacts.ContactsDatabaseHelper.AggregatedPresenceColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.ContactsColumns;
import com.android.providers.contacts.ContactsDatabaseHelper.Tables;
@@ -72,31 +67,6 @@ public class GlobalSearchSupport {
" FROM " + Tables.AGGREGATED_PRESENCE +
" WHERE " + AggregatedPresenceColumns.CONTACT_ID + "=" + ContactsColumns.CONCRETE_ID + ")";
- // Current contacts - those contacted within the last 3 days (in seconds)
- private static final long CURRENT_CONTACTS = 3 * 24 * 60 * 60;
-
- // Recent contacts - those contacted within the last 30 days (in seconds)
- private static final long RECENT_CONTACTS = 30 * 24 * 60 * 60;
-
- private static final String TIME_SINCE_LAST_CONTACTED =
- "(strftime('%s', 'now') - contacts." + Contacts.LAST_TIME_CONTACTED + "/1000)";
-
- /*
- * See {@link ContactsProvider2#EMAIL_FILTER_SORT_ORDER} for the discussion of this
- * sorting order.
- */
- private static final String SORT_ORDER =
- "(CASE WHEN contacts." + Contacts.STARRED + "=1 THEN 0 ELSE 1 END), "
- + "(CASE WHEN " + TIME_SINCE_LAST_CONTACTED + " < " + CURRENT_CONTACTS + " THEN 0 "
- + " WHEN " + TIME_SINCE_LAST_CONTACTED + " < " + RECENT_CONTACTS + " THEN 1 "
- + " ELSE 2 END),"
- + "contacts." + Contacts.TIMES_CONTACTED + " DESC, "
- + "contacts." + Contacts.DISPLAY_NAME_PRIMARY + ", "
- + "contacts." + Contacts._ID;
-
- private static final String RECENTLY_CONTACTED =
- TIME_SINCE_LAST_CONTACTED + " < " + RECENT_CONTACTS;
-
private static class SearchSuggestion {
long contactId;
String photoUri;
@@ -112,7 +82,7 @@ public class GlobalSearchSupport {
String lastAccessTime;
@SuppressWarnings({"unchecked"})
- public ArrayList asList(String[] projection) {
+ public ArrayList<?> asList(String[] projection) {
if (icon1 == null) {
if (photoUri != null) {
icon1 = photoUri.toString();
@@ -192,24 +162,13 @@ public class GlobalSearchSupport {
}
private final ContactsProvider2 mContactsProvider;
- private PhoneNumberUtil mPhoneNumberUtil;
- private CountryDetector mCountryDetector;
- private String mSimCountryIso;
@SuppressWarnings("all")
public GlobalSearchSupport(ContactsProvider2 contactsProvider) {
mContactsProvider = contactsProvider;
- mPhoneNumberUtil = PhoneNumberUtil.getInstance();
- mCountryDetector = (CountryDetector)
- mContactsProvider.getContext().getSystemService(Context.COUNTRY_DETECTOR);
TelephonyManager telman = (TelephonyManager)
mContactsProvider.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- // assuming here that the SIM never changes while the phone is booted. ok?
- mSimCountryIso = telman == null ? null : telman.getSimCountryIso();
- if (mSimCountryIso != null) {
- mSimCountryIso = mSimCountryIso.toUpperCase();
- }
// To ensure the data column position. This is dead code if properly configured.
if (Organization.COMPANY != Data.DATA1 || Phone.NUMBER != Data.DATA1
@@ -219,54 +178,20 @@ public class GlobalSearchSupport {
}
}
- private boolean isPossibleByPhoneNumberUtil(String query) {
- String currentCountry = null;
- Country current = mCountryDetector.detectCountry();
- if (current != null) {
- currentCountry = current.getCountryIso().toUpperCase();
- }
- if (currentCountry != null && mPhoneNumberUtil.isPossibleNumber(query, currentCountry)) {
- return true;
- }
- if (mSimCountryIso != null && !TextUtils.equals(currentCountry, mSimCountryIso)) {
- // use the SIM country if it's different, so we can add contacts for home numbers
- // while roaming
- return mPhoneNumberUtil.isPossibleNumber(query, mSimCountryIso);
- }
- return false;
- }
-
- private boolean isPhoneNumber(String query) {
- if (TextUtils.isEmpty(query)) {
- return false;
- }
- if (ContactsProvider2.countPhoneNumberDigits(query) > 2) {
- // 3 or more digits matching the basic pattern
- return true;
- }
- // more advanced check, for 1800-FLOWERS style numbers and the like
- return isPossibleByPhoneNumberUtil(query);
- }
-
public Cursor handleSearchSuggestionsQuery(
SQLiteDatabase db, Uri uri, String[] projection, String limit) {
- final String searchClause;
+ final MatrixCursor cursor = new MatrixCursor(
+ projection == null ? SEARCH_SUGGESTIONS_COLUMNS : projection);
- final String selection;
if (uri.getPathSegments().size() <= 1) {
- searchClause = null;
- selection = RECENTLY_CONTACTED;
+ // no search term, return empty
} else {
- searchClause = uri.getLastPathSegment();
- selection = null;
+ String selection = null;
+ String searchClause = uri.getLastPathSegment();
+ addSearchSuggestionsBasedOnFilter(
+ cursor, db, projection, selection, searchClause, limit);
}
- MatrixCursor cursor = new MatrixCursor(
- projection == null ? SEARCH_SUGGESTIONS_COLUMNS : projection);
- addSearchSuggestionsBasedOnFilter(cursor, db, projection, selection, searchClause, limit);
- if (isPhoneNumber(searchClause)) {
- addSearchSuggestionsBasedOnPhoneNumber(cursor, searchClause, projection);
- }
return cursor;
}
@@ -294,53 +219,6 @@ public class GlobalSearchSupport {
db, projection, ContactsColumns.CONCRETE_ID + "=" + contactId, filter, null);
}
- private Cursor addSearchSuggestionsBasedOnPhoneNumber(MatrixCursor cursor,
- String searchClause, String[] projection) {
- Resources r = mContactsProvider.getContext().getResources();
- String s;
- int i;
-
- if (mContactsProvider.isPhone() && mContactsProvider.isVoiceCapable()) {
- SearchSuggestion dialNumber = new SearchSuggestion();
- dialNumber.contactId = -1;
- s = r.getString(com.android.internal.R.string.dial_number_using, searchClause);
- i = s.indexOf('\n');
- if (i < 0) {
- dialNumber.text1 = s;
- dialNumber.text2 = "";
- } else {
- dialNumber.text1 = s.substring(0, i);
- dialNumber.text2 = s.substring(i + 1);
- }
- dialNumber.icon1 = String.valueOf(com.android.internal.R.drawable.call_contact);
- dialNumber.intentData = "tel:" + searchClause;
- dialNumber.intentAction =
- ContactsContract.Intents.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED;
- dialNumber.lookupKey = SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT; // shortcut id
- cursor.addRow(dialNumber.asList(projection));
- }
-
- SearchSuggestion createContact = new SearchSuggestion();
- createContact.contactId = -2;
- s = r.getString(com.android.internal.R.string.create_contact_using, searchClause);
- i = s.indexOf('\n');
- if (i < 0) {
- createContact.text1 = s;
- createContact.text2 = "";
- } else {
- createContact.text1 = s.substring(0, i);
- createContact.text2 = s.substring(i + 1);
- }
- createContact.icon1 = String.valueOf(com.android.internal.R.drawable.create_contact);
- createContact.intentData = "tel:" + searchClause;
- createContact.intentAction =
- ContactsContract.Intents.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED;
- createContact.lookupKey = SearchManager.SUGGEST_NEVER_MAKE_SHORTCUT; // shortcut id
- cursor.addRow(createContact.asList(projection));
-
- return cursor;
- }
-
private Cursor addSearchSuggestionsBasedOnFilter(MatrixCursor cursor, SQLiteDatabase db,
String[] projection, String selection, String filter, String limit) {
StringBuilder sb = new StringBuilder();
@@ -366,7 +244,6 @@ public class GlobalSearchSupport {
if (selection != null) {
sb.append(" WHERE ").append(selection);
}
- sb.append(" ORDER BY " + SORT_ORDER);
if (limit != null) {
sb.append(" LIMIT " + limit);
}