From a5b855898d3a1da2ddfbcd7b012688dae57cfcdd Mon Sep 17 00:00:00 2001 From: Dmitri Plotnikov Date: Sun, 6 Sep 2009 11:49:42 -0700 Subject: [PATCH] Re-enabling email suggestions and switching to new contacts API. --- .../android/email/EmailAddressAdapter.java | 44 ++++++------------- .../email/activity/MessageCompose.java | 10 ++--- 2 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/com/android/email/EmailAddressAdapter.java b/src/com/android/email/EmailAddressAdapter.java index 2517c28e4..fbe78094f 100644 --- a/src/com/android/email/EmailAddressAdapter.java +++ b/src/com/android/email/EmailAddressAdapter.java @@ -16,33 +16,32 @@ package com.android.email; -import android.provider.ContactsContract; +import com.android.email.mail.Address; + import android.content.ContentResolver; import android.content.Context; import android.database.Cursor; -import android.database.DatabaseUtils; -import android.provider.Contacts.ContactMethods; -import android.provider.Contacts.People; +import android.net.Uri; +import android.provider.ContactsContract.Contacts; +import android.provider.ContactsContract.Data; +import android.provider.ContactsContract.CommonDataKinds.Email; import android.view.View; import android.widget.ResourceCursorAdapter; import android.widget.TextView; -import com.android.email.mail.Address; - public class EmailAddressAdapter extends ResourceCursorAdapter { public static final int NAME_INDEX = 1; - public static final int DATA_INDEX = 2; - private static final String SORT_ORDER = People.TIMES_CONTACTED + " DESC, " + People.NAME; + private static final String SORT_ORDER = + Contacts.TIMES_CONTACTED + " DESC, " + Contacts.DISPLAY_NAME; private ContentResolver mContentResolver; private static final String[] PROJECTION = { - ContactMethods._ID, // 0 - ContactMethods.NAME, // 1 - ContactMethods.DATA - // 2 + Data._ID, // 0 + Contacts.DISPLAY_NAME, // 1 + Email.DATA // 2 }; public EmailAddressAdapter(Context context) { @@ -68,23 +67,8 @@ public class EmailAddressAdapter extends ResourceCursorAdapter { @Override public Cursor runQueryOnBackgroundThread(CharSequence constraint) { - String where = null; - - if (constraint != null) { - String filter = DatabaseUtils.sqlEscapeString(constraint.toString() + '%'); - - StringBuilder s = new StringBuilder(); - s.append("(people.name LIKE "); - s.append(filter); - s.append(") OR (contact_methods.data LIKE "); - s.append(filter); - s.append(")"); - - where = s.toString(); - } - - return mContentResolver.query( - ContactsContract.CommonDataKinds.Email.CONTENT_FILTER_EMAIL_URI, - PROJECTION, where, null, SORT_ORDER); + String filter = constraint == null ? "" : constraint.toString(); + Uri uri = Uri.withAppendedPath(Email.CONTENT_FILTER_URI, Uri.encode(filter)); + return mContentResolver.query(uri, PROJECTION, null, null, SORT_ORDER); } } diff --git a/src/com/android/email/activity/MessageCompose.java b/src/com/android/email/activity/MessageCompose.java index c95c56139..b60ab6531 100644 --- a/src/com/android/email/activity/MessageCompose.java +++ b/src/com/android/email/activity/MessageCompose.java @@ -18,6 +18,7 @@ package com.android.email.activity; import com.android.email.Controller; import com.android.email.Email; +import com.android.email.EmailAddressAdapter; import com.android.email.EmailAddressValidator; import com.android.email.R; import com.android.email.mail.Address; @@ -470,19 +471,18 @@ public class MessageCompose extends Activity implements OnClickListener, OnFocus mQuotedTextDelete.setOnClickListener(this); - // Temporarily disable addressAdapter, see BUG 2077496 - // EmailAddressAdapter addressAdapter = new EmailAddressAdapter(this); + EmailAddressAdapter addressAdapter = new EmailAddressAdapter(this); EmailAddressValidator addressValidator = new EmailAddressValidator(); - // mToView.setAdapter(addressAdapter); + mToView.setAdapter(addressAdapter); mToView.setTokenizer(new Rfc822Tokenizer()); mToView.setValidator(addressValidator); - // mCcView.setAdapter(addressAdapter); + mCcView.setAdapter(addressAdapter); mCcView.setTokenizer(new Rfc822Tokenizer()); mCcView.setValidator(addressValidator); - // mBccView.setAdapter(addressAdapter); + mBccView.setAdapter(addressAdapter); mBccView.setTokenizer(new Rfc822Tokenizer()); mBccView.setValidator(addressValidator);