[Issue 2061094] Upgrading ContactDictionary to new API

main
Dmitri Plotnikov 2009-08-27 11:24:26 -07:00
parent 6a001f58da
commit 41fc8f4a18
1 changed files with 13 additions and 14 deletions

View File

@ -24,30 +24,29 @@ import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.database.Cursor; import android.database.Cursor;
import android.provider.Contacts; import android.provider.ContactsContract.Contacts;
import android.provider.Contacts.People;
import android.util.Log; import android.util.Log;
public class ContactsDictionary extends ExpandableDictionary { public class ContactsDictionary extends ExpandableDictionary {
private static final String[] PROJECTION = { private static final String[] PROJECTION = {
People._ID, Contacts._ID,
People.NAME, Contacts.DISPLAY_NAME,
}; };
private static final int INDEX_NAME = 1; private static final int INDEX_NAME = 1;
private ContentObserver mObserver; private ContentObserver mObserver;
private boolean mRequiresReload; private boolean mRequiresReload;
public ContactsDictionary(Context context) { public ContactsDictionary(Context context) {
super(context); super(context);
// Perform a managed query. The Activity will handle closing and requerying the cursor // Perform a managed query. The Activity will handle closing and requerying the cursor
// when needed. // when needed.
ContentResolver cres = context.getContentResolver(); ContentResolver cres = context.getContentResolver();
cres.registerContentObserver(People.CONTENT_URI, true, mObserver = new ContentObserver(null) { cres.registerContentObserver(Contacts.CONTENT_URI, true, mObserver = new ContentObserver(null) {
@Override @Override
public void onChange(boolean self) { public void onChange(boolean self) {
mRequiresReload = true; mRequiresReload = true;
@ -56,17 +55,17 @@ public class ContactsDictionary extends ExpandableDictionary {
loadDictionary(); loadDictionary();
} }
public synchronized void close() { public synchronized void close() {
if (mObserver != null) { if (mObserver != null) {
getContext().getContentResolver().unregisterContentObserver(mObserver); getContext().getContentResolver().unregisterContentObserver(mObserver);
mObserver = null; mObserver = null;
} }
} }
private synchronized void loadDictionary() { private synchronized void loadDictionary() {
Cursor cursor = getContext().getContentResolver() Cursor cursor = getContext().getContentResolver()
.query(People.CONTENT_URI, PROJECTION, null, null, null); .query(Contacts.CONTENT_URI, PROJECTION, null, null, null);
if (cursor != null) { if (cursor != null) {
addWords(cursor); addWords(cursor);
} }