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 */ 16 package com.android.contacts.list; 17 18 import android.content.ContentUris; 19 import android.content.Context; 20 import android.content.CursorLoader; 21 import android.database.Cursor; 22 import android.net.Uri; 23 import android.provider.Contacts.People; 24 import android.view.View; 25 import android.view.ViewGroup; 26 27 /** 28 * A cursor adapter for the People.CONTENT_TYPE content type. 29 */ 30 @SuppressWarnings("deprecation") 31 public class LegacyContactListAdapter extends ContactEntryListAdapter { 32 33 static final String[] PEOPLE_PROJECTION = new String[] { 34 People._ID, // 0 35 People.DISPLAY_NAME, // 1 36 People.PHONETIC_NAME, // 2 37 People.STARRED, // 3 38 People.PRESENCE_STATUS, // 4 39 }; 40 41 protected static final int PERSON_ID_COLUMN_INDEX = 0; 42 protected static final int PERSON_DISPLAY_NAME_COLUMN_INDEX = 1; 43 protected static final int PERSON_PHONETIC_NAME_COLUMN_INDEX = 2; 44 protected static final int PERSON_STARRED_COLUMN_INDEX = 3; 45 protected static final int PERSON_PRESENCE_STATUS_COLUMN_INDEX = 4; 46 47 private CharSequence mUnknownNameText; 48 49 public LegacyContactListAdapter(Context context) { 50 super(context); 51 mUnknownNameText = context.getText(android.R.string.unknownName); 52 } 53 54 @Override 55 public void configureLoader(CursorLoader loader, long directoryId) { 56 loader.setUri(People.CONTENT_URI); 57 loader.setProjection(PEOPLE_PROJECTION); 58 loader.setSortOrder(People.DISPLAY_NAME); 59 } 60 61 @Override 62 public String getContactDisplayName(int position) { 63 return ((Cursor)getItem(position)).getString(PERSON_DISPLAY_NAME_COLUMN_INDEX); 64 } 65 66 public Uri getPersonUri(int position) { 67 Cursor cursor = ((Cursor)getItem(position)); 68 long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX); 69 return ContentUris.withAppendedId(People.CONTENT_URI, personId); 70 } 71 72 @Override 73 protected View newView(Context context, int partition, Cursor cursor, int position, 74 ViewGroup parent) { 75 final ContactListItemView view = new ContactListItemView(context, null); 76 view.setUnknownNameText(mUnknownNameText); 77 return view; 78 } 79 80 @Override 81 protected void bindView(View itemView, int partition, Cursor cursor, int position) { 82 ContactListItemView view = (ContactListItemView)itemView; 83 bindName(view, cursor); 84 bindPresence(view, cursor); 85 } 86 87 protected void bindName(final ContactListItemView view, Cursor cursor) { 88 view.showDisplayName(cursor, PERSON_DISPLAY_NAME_COLUMN_INDEX, 89 getContactNameDisplayOrder()); 90 view.showPhoneticName(cursor, PERSON_PHONETIC_NAME_COLUMN_INDEX); 91 } 92 93 protected void bindPresence(final ContactListItemView view, Cursor cursor) { 94 view.showPresenceAndStatusMessage(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0); 95 } 96 } 97