blob: a2f98dec455a0bed21827ec0d8723aff8f44ae42 [file] [log] [blame]
Dmitri Plotnikov41377272010-05-07 10:28:47 -07001/*
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
Dmitri Plotnikov41377272010-05-07 10:28:47 -070018import android.content.ContentUris;
19import android.content.Context;
Jeff Hamilton3c462912010-05-15 02:20:01 -050020import android.content.CursorLoader;
Dmitri Plotnikov41377272010-05-07 10:28:47 -070021import android.database.Cursor;
22import android.net.Uri;
23import android.provider.Contacts.People;
Dmitri Plotnikov41377272010-05-07 10:28:47 -070024import android.view.View;
25import android.view.ViewGroup;
Dmitri Plotnikov41377272010-05-07 10:28:47 -070026
27/**
28 * A cursor adapter for the People.CONTENT_TYPE content type.
29 */
30@SuppressWarnings("deprecation")
31public 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
Dmitri Plotnikovd5061fe2010-06-07 15:06:58 -070055 public void configureLoader(CursorLoader loader, long directoryId) {
Dmitri Plotnikov41377272010-05-07 10:28:47 -070056 loader.setUri(People.CONTENT_URI);
57 loader.setProjection(PEOPLE_PROJECTION);
58 loader.setSortOrder(People.DISPLAY_NAME);
59 }
60
Dmitri Plotnikov41377272010-05-07 10:28:47 -070061 @Override
Dmitri Plotnikove1247222010-06-02 18:14:21 -070062 public String getContactDisplayName(int position) {
63 return ((Cursor)getItem(position)).getString(PERSON_DISPLAY_NAME_COLUMN_INDEX);
Dmitri Plotnikov41377272010-05-07 10:28:47 -070064 }
65
Dmitri Plotnikove1247222010-06-02 18:14:21 -070066 public Uri getPersonUri(int position) {
67 Cursor cursor = ((Cursor)getItem(position));
Dmitri Plotnikov41377272010-05-07 10:28:47 -070068 long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX);
69 return ContentUris.withAppendedId(People.CONTENT_URI, personId);
70 }
71
72 @Override
Andrew Lee551da172014-04-28 11:43:47 -070073 protected ContactListItemView newView(
74 Context context, int partition, Cursor cursor, int position, ViewGroup parent) {
Dmitri Plotnikov41377272010-05-07 10:28:47 -070075 final ContactListItemView view = new ContactListItemView(context, null);
76 view.setUnknownNameText(mUnknownNameText);
77 return view;
78 }
79
80 @Override
Dmitri Plotnikove1247222010-06-02 18:14:21 -070081 protected void bindView(View itemView, int partition, Cursor cursor, int position) {
Brian Attwellc9e81072014-09-15 11:08:19 -070082 super.bindView(itemView, partition, cursor, position);
Dmitri Plotnikov41377272010-05-07 10:28:47 -070083 ContactListItemView view = (ContactListItemView)itemView;
84 bindName(view, cursor);
Brian Attwell56151b82014-09-03 20:14:47 -070085 bindViewId(view, cursor, PERSON_ID_COLUMN_INDEX);
Dmitri Plotnikov41377272010-05-07 10:28:47 -070086 bindPresence(view, cursor);
87 }
88
89 protected void bindName(final ContactListItemView view, Cursor cursor) {
Daisuke Miyakawaed90ea52011-10-31 09:22:52 -070090 view.showDisplayName(cursor, PERSON_DISPLAY_NAME_COLUMN_INDEX,
Dave Santoroda5bf1c2011-05-03 10:30:34 -070091 getContactNameDisplayOrder());
Dmitri Plotnikov41377272010-05-07 10:28:47 -070092 view.showPhoneticName(cursor, PERSON_PHONETIC_NAME_COLUMN_INDEX);
93 }
94
95 protected void bindPresence(final ContactListItemView view, Cursor cursor) {
Frank Sposarof4431942011-08-12 14:53:22 -070096 view.showPresenceAndStatusMessage(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0);
Dmitri Plotnikov41377272010-05-07 10:28:47 -070097 }
98}