Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -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 | a3569b2 | 2010-05-07 10:50:52 -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 | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 21 | import android.database.Cursor; |
| 22 | import android.net.Uri; |
| 23 | import android.provider.Contacts.People; |
| 24 | import android.provider.Contacts.Phones; |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 25 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 26 | import android.view.View; |
| 27 | import android.view.ViewGroup; |
| 28 | |
| 29 | /** |
| 30 | * A cursor adapter for the Phones.CONTENT_TYPE content type. |
| 31 | */ |
| 32 | @SuppressWarnings("deprecation") |
| 33 | public class LegacyPhoneNumberListAdapter extends ContactEntryListAdapter { |
| 34 | |
Dmitri Plotnikov | c28390b | 2010-05-07 11:20:32 -0700 | [diff] [blame] | 35 | private static final String[] PHONES_PROJECTION = new String[] { |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 36 | Phones._ID, // 0 |
| 37 | Phones.TYPE, // 1 |
| 38 | Phones.LABEL, // 2 |
| 39 | Phones.NUMBER, // 3 |
| 40 | People.DISPLAY_NAME, // 4 |
| 41 | People.PHONETIC_NAME, // 5 |
| 42 | }; |
| 43 | |
Dmitri Plotnikov | c28390b | 2010-05-07 11:20:32 -0700 | [diff] [blame] | 44 | private static final int PHONE_ID_COLUMN_INDEX = 0; |
| 45 | private static final int PHONE_TYPE_COLUMN_INDEX = 1; |
| 46 | private static final int PHONE_LABEL_COLUMN_INDEX = 2; |
| 47 | private static final int PHONE_NUMBER_COLUMN_INDEX = 3; |
| 48 | private static final int PHONE_DISPLAY_NAME_COLUMN_INDEX = 4; |
| 49 | private static final int PHONE_PHONETIC_NAME_COLUMN_INDEX = 5; |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 50 | |
| 51 | private CharSequence mUnknownNameText; |
| 52 | |
| 53 | public LegacyPhoneNumberListAdapter(Context context) { |
| 54 | super(context); |
| 55 | mUnknownNameText = context.getText(android.R.string.unknownName); |
| 56 | } |
| 57 | |
| 58 | @Override |
Dmitri Plotnikov | d5061fe | 2010-06-07 15:06:58 -0700 | [diff] [blame] | 59 | public void configureLoader(CursorLoader loader, long directoryId) { |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 60 | loader.setUri(Phones.CONTENT_URI); |
| 61 | loader.setProjection(PHONES_PROJECTION); |
| 62 | loader.setSortOrder(Phones.DISPLAY_NAME); |
| 63 | } |
| 64 | |
| 65 | @Override |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 66 | public String getContactDisplayName(int position) { |
| 67 | return ((Cursor)getItem(position)).getString(PHONE_DISPLAY_NAME_COLUMN_INDEX); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 70 | public Uri getPhoneUri(int position) { |
| 71 | Cursor cursor = ((Cursor)getItem(position)); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 72 | long id = cursor.getLong(PHONE_ID_COLUMN_INDEX); |
| 73 | return ContentUris.withAppendedId(Phones.CONTENT_URI, id); |
| 74 | } |
| 75 | |
| 76 | @Override |
Andrew Lee | 551da17 | 2014-04-28 11:43:47 -0700 | [diff] [blame] | 77 | protected ContactListItemView newView( |
| 78 | Context context, int partition, Cursor cursor, int position, ViewGroup parent) { |
| 79 | final ContactListItemView view = |
| 80 | super.newView(context, partition, cursor, position, parent); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 81 | view.setUnknownNameText(mUnknownNameText); |
| 82 | return view; |
| 83 | } |
| 84 | |
| 85 | @Override |
Dmitri Plotnikov | e124722 | 2010-06-02 18:14:21 -0700 | [diff] [blame] | 86 | protected void bindView(View itemView, int partition, Cursor cursor, int position) { |
Brian Attwell | c9e8107 | 2014-09-15 11:08:19 -0700 | [diff] [blame] | 87 | super.bindView(itemView, partition, cursor, position); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 88 | ContactListItemView view = (ContactListItemView)itemView; |
| 89 | bindName(view, cursor); |
Brian Attwell | 56151b8 | 2014-09-03 20:14:47 -0700 | [diff] [blame] | 90 | bindViewId(view, cursor, PHONE_ID_COLUMN_INDEX); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 91 | bindPhoneNumber(view, cursor); |
| 92 | } |
| 93 | |
| 94 | protected void bindName(final ContactListItemView view, Cursor cursor) { |
Daisuke Miyakawa | ed90ea5 | 2011-10-31 09:22:52 -0700 | [diff] [blame] | 95 | view.showDisplayName(cursor, PHONE_DISPLAY_NAME_COLUMN_INDEX, getContactNameDisplayOrder()); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 96 | view.showPhoneticName(cursor, PHONE_PHONETIC_NAME_COLUMN_INDEX); |
| 97 | } |
| 98 | |
| 99 | protected void bindPhoneNumber(ContactListItemView view, Cursor cursor) { |
| 100 | CharSequence label = null; |
| 101 | if (!cursor.isNull(PHONE_TYPE_COLUMN_INDEX)) { |
| 102 | final int type = cursor.getInt(PHONE_TYPE_COLUMN_INDEX); |
| 103 | final String customLabel = cursor.getString(PHONE_LABEL_COLUMN_INDEX); |
| 104 | |
| 105 | // TODO cache |
| 106 | label = Phone.getTypeLabel(getContext().getResources(), type, customLabel); |
| 107 | } |
| 108 | view.setLabel(label); |
Andrew Lee | c6d2f86 | 2014-03-31 14:39:55 -0700 | [diff] [blame] | 109 | view.setPhoneNumber(cursor.getString(PHONE_NUMBER_COLUMN_INDEX), /* countryIso */ null); |
Dmitri Plotnikov | a3569b2 | 2010-05-07 10:50:52 -0700 | [diff] [blame] | 110 | } |
| 111 | } |