Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 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 | |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 18 | import android.content.ContentUris; |
| 19 | import android.content.Context; |
Jeff Hamilton | 3c46291 | 2010-05-15 02:20:01 -0500 | [diff] [blame] | 20 | import android.content.CursorLoader; |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 21 | import android.database.Cursor; |
| 22 | import android.net.Uri; |
| 23 | import android.provider.Contacts.People; |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.ViewGroup; |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 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 |
Dmitri Plotnikov | d5061fe | 2010-06-07 15:06:58 -0700 | [diff] [blame] | 55 | public void configureLoader(CursorLoader loader, long directoryId) { |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 56 | loader.setUri(People.CONTENT_URI); |
| 57 | loader.setProjection(PEOPLE_PROJECTION); |
| 58 | loader.setSortOrder(People.DISPLAY_NAME); |
| 59 | } |
| 60 | |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 61 | @Override |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 62 | public String getContactDisplayName(int position) { |
| 63 | return ((Cursor)getItem(position)).getString(PERSON_DISPLAY_NAME_COLUMN_INDEX); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 66 | public Uri getPersonUri(int position) { |
| 67 | Cursor cursor = ((Cursor)getItem(position)); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 68 | long personId = cursor.getLong(PERSON_ID_COLUMN_INDEX); |
| 69 | return ContentUris.withAppendedId(People.CONTENT_URI, personId); |
| 70 | } |
| 71 | |
| 72 | @Override |
Andrew Lee | 551da17 | 2014-04-28 11:43:47 -0700 | [diff] [blame] | 73 | protected ContactListItemView newView( |
| 74 | Context context, int partition, Cursor cursor, int position, ViewGroup parent) { |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 75 | final ContactListItemView view = new ContactListItemView(context, null); |
| 76 | view.setUnknownNameText(mUnknownNameText); |
| 77 | return view; |
| 78 | } |
| 79 | |
| 80 | @Override |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 81 | protected void bindView(View itemView, int partition, Cursor cursor, int position) { |
Brian Attwell | c9e8107 | 2014-09-15 11:08:19 -0700 | [diff] [blame] | 82 | super.bindView(itemView, partition, cursor, position); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 83 | ContactListItemView view = (ContactListItemView)itemView; |
| 84 | bindName(view, cursor); |
Brian Attwell | 56151b8 | 2014-09-03 20:14:47 -0700 | [diff] [blame] | 85 | bindViewId(view, cursor, PERSON_ID_COLUMN_INDEX); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 86 | bindPresence(view, cursor); |
| 87 | } |
| 88 | |
| 89 | protected void bindName(final ContactListItemView view, Cursor cursor) { |
Daisuke Miyakawa | ed90ea5 | 2011-10-31 09:22:52 -0700 | [diff] [blame] | 90 | view.showDisplayName(cursor, PERSON_DISPLAY_NAME_COLUMN_INDEX, |
Dave Santoro | da5bf1c | 2011-05-03 10:30:34 -0700 | [diff] [blame] | 91 | getContactNameDisplayOrder()); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 92 | view.showPhoneticName(cursor, PERSON_PHONETIC_NAME_COLUMN_INDEX); |
| 93 | } |
| 94 | |
| 95 | protected void bindPresence(final ContactListItemView view, Cursor cursor) { |
Frank Sposaro | f443194 | 2011-08-12 14:53:22 -0700 | [diff] [blame] | 96 | view.showPresenceAndStatusMessage(cursor, PERSON_PRESENCE_STATUS_COLUMN_INDEX, 0); |
Dmitri Plotnikov | 4137727 | 2010-05-07 10:28:47 -0700 | [diff] [blame] | 97 | } |
| 98 | } |