LegacyContactListAdapter.java revision 413772711054c9fca8bf0c22bc81f613c883ae7e
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.android.contacts.list; 17 18import android.app.patterns.CursorLoader; 19import android.content.ContentUris; 20import android.content.Context; 21import android.database.Cursor; 22import android.net.Uri; 23import android.provider.Contacts.People; 24import android.provider.ContactsContract.Contacts; 25import android.view.View; 26import android.view.ViewGroup; 27import android.widget.ListView; 28 29/** 30 * A cursor adapter for the People.CONTENT_TYPE content type. 31 */ 32@SuppressWarnings("deprecation") 33public class LegacyContactListAdapter extends ContactEntryListAdapter { 34 35 static final String[] PEOPLE_PROJECTION = new String[] { 36 People._ID, // 0 37 People.DISPLAY_NAME, // 1 38 People.PHONETIC_NAME, // 2 39 People.STARRED, // 3 40 People.PRESENCE_STATUS, // 4 41 }; 42 43 protected static final int PERSON_ID_COLUMN_INDEX = 0; 44 protected static final int PERSON_DISPLAY_NAME_COLUMN_INDEX = 1; 45 protected static final int PERSON_PHONETIC_NAME_COLUMN_INDEX = 2; 46 protected static final int PERSON_STARRED_COLUMN_INDEX = 3; 47 protected static final int PERSON_PRESENCE_STATUS_COLUMN_INDEX = 4; 48 49 private CharSequence mUnknownNameText; 50 51 public LegacyContactListAdapter(Context context) { 52 super(context); 53 mUnknownNameText = context.getText(android.R.string.unknownName); 54 } 55 56 @Override 57 public void configureLoader(CursorLoader loader) { 58 loader.setUri(People.CONTENT_URI); 59 loader.setProjection(PEOPLE_PROJECTION); 60 loader.setSortOrder(People.DISPLAY_NAME); 61 } 62 63 public boolean isContactStarred() { 64 return getCursor().getInt(PERSON_STARRED_COLUMN_INDEX) != 0; 65 } 66 67 @Override 68 public String getContactDisplayName() { 69 return getCursor().getString(PERSON_DISPLAY_NAME_COLUMN_INDEX); 70 } 71 72 /** 73 * Builds the {@link Contacts#CONTENT_LOOKUP_URI} for the given 74 * {@link ListView} position. 75 */ 76 public Uri getPersonUri() { 77 Cursor cursor = getCursor(); 78 long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX); 79 return ContentUris.withAppendedId(People.CONTENT_URI, personId); 80 } 81 82 @Override 83 public View newView(Context context, Cursor cursor, ViewGroup parent) { 84 final ContactListItemView view = new ContactListItemView(context, null); 85 view.setUnknownNameText(mUnknownNameText); 86 return view; 87 } 88 89 @Override 90 public void bindView(View itemView, Context context, Cursor cursor) { 91 ContactListItemView view = (ContactListItemView)itemView; 92 bindName(view, cursor); 93 bindPresence(view, cursor); 94 } 95 96 protected void bindName(final ContactListItemView view, Cursor cursor) { 97 view.showDisplayName(cursor, PERSON_DISPLAY_NAME_COLUMN_INDEX, false, 0); 98 view.showPhoneticName(cursor, PERSON_PHONETIC_NAME_COLUMN_INDEX); 99 } 100 101 protected void bindPresence(final ContactListItemView view, Cursor cursor) { 102 view.showPresence(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX); 103 } 104} 105