blob: b5c96df6d5135e8791646c487720540ade283190 [file] [log] [blame]
Dmitri Plotnikova3569b22010-05-07 10:50:52 -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 Plotnikova3569b22010-05-07 10:50:52 -070018import android.content.ContentUris;
19import android.content.Context;
Jeff Hamilton3c462912010-05-15 02:20:01 -050020import android.content.CursorLoader;
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070021import android.database.Cursor;
22import android.net.Uri;
23import android.provider.Contacts.People;
24import android.provider.Contacts.Phones;
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070025import android.provider.ContactsContract.CommonDataKinds.Phone;
26import android.view.View;
27import android.view.ViewGroup;
28
Chiao Chenga0233a02012-11-01 16:41:08 -070029import com.android.contacts.common.list.ContactEntryListAdapter;
30import com.android.contacts.common.list.ContactListItemView;
31
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070032/**
33 * A cursor adapter for the Phones.CONTENT_TYPE content type.
34 */
35@SuppressWarnings("deprecation")
36public class LegacyPhoneNumberListAdapter extends ContactEntryListAdapter {
37
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070038 private static final String[] PHONES_PROJECTION = new String[] {
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070039 Phones._ID, // 0
40 Phones.TYPE, // 1
41 Phones.LABEL, // 2
42 Phones.NUMBER, // 3
43 People.DISPLAY_NAME, // 4
44 People.PHONETIC_NAME, // 5
45 };
46
Dmitri Plotnikovc28390b2010-05-07 11:20:32 -070047 private static final int PHONE_ID_COLUMN_INDEX = 0;
48 private static final int PHONE_TYPE_COLUMN_INDEX = 1;
49 private static final int PHONE_LABEL_COLUMN_INDEX = 2;
50 private static final int PHONE_NUMBER_COLUMN_INDEX = 3;
51 private static final int PHONE_DISPLAY_NAME_COLUMN_INDEX = 4;
52 private static final int PHONE_PHONETIC_NAME_COLUMN_INDEX = 5;
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070053
54 private CharSequence mUnknownNameText;
55
56 public LegacyPhoneNumberListAdapter(Context context) {
57 super(context);
58 mUnknownNameText = context.getText(android.R.string.unknownName);
59 }
60
61 @Override
Dmitri Plotnikovd5061fe2010-06-07 15:06:58 -070062 public void configureLoader(CursorLoader loader, long directoryId) {
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070063 loader.setUri(Phones.CONTENT_URI);
64 loader.setProjection(PHONES_PROJECTION);
65 loader.setSortOrder(Phones.DISPLAY_NAME);
66 }
67
68 @Override
Dmitri Plotnikove1247222010-06-02 18:14:21 -070069 public String getContactDisplayName(int position) {
70 return ((Cursor)getItem(position)).getString(PHONE_DISPLAY_NAME_COLUMN_INDEX);
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070071 }
72
Dmitri Plotnikove1247222010-06-02 18:14:21 -070073 public Uri getPhoneUri(int position) {
74 Cursor cursor = ((Cursor)getItem(position));
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070075 long id = cursor.getLong(PHONE_ID_COLUMN_INDEX);
76 return ContentUris.withAppendedId(Phones.CONTENT_URI, id);
77 }
78
79 @Override
Andrew Lee551da172014-04-28 11:43:47 -070080 protected ContactListItemView newView(
81 Context context, int partition, Cursor cursor, int position, ViewGroup parent) {
82 final ContactListItemView view =
83 super.newView(context, partition, cursor, position, parent);
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070084 view.setUnknownNameText(mUnknownNameText);
85 return view;
86 }
87
88 @Override
Dmitri Plotnikove1247222010-06-02 18:14:21 -070089 protected void bindView(View itemView, int partition, Cursor cursor, int position) {
Brian Attwellc9e81072014-09-15 11:08:19 -070090 super.bindView(itemView, partition, cursor, position);
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070091 ContactListItemView view = (ContactListItemView)itemView;
92 bindName(view, cursor);
Brian Attwell56151b82014-09-03 20:14:47 -070093 bindViewId(view, cursor, PHONE_ID_COLUMN_INDEX);
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070094 bindPhoneNumber(view, cursor);
95 }
96
97 protected void bindName(final ContactListItemView view, Cursor cursor) {
Daisuke Miyakawaed90ea52011-10-31 09:22:52 -070098 view.showDisplayName(cursor, PHONE_DISPLAY_NAME_COLUMN_INDEX, getContactNameDisplayOrder());
Dmitri Plotnikova3569b22010-05-07 10:50:52 -070099 view.showPhoneticName(cursor, PHONE_PHONETIC_NAME_COLUMN_INDEX);
100 }
101
102 protected void bindPhoneNumber(ContactListItemView view, Cursor cursor) {
103 CharSequence label = null;
104 if (!cursor.isNull(PHONE_TYPE_COLUMN_INDEX)) {
105 final int type = cursor.getInt(PHONE_TYPE_COLUMN_INDEX);
106 final String customLabel = cursor.getString(PHONE_LABEL_COLUMN_INDEX);
107
108 // TODO cache
109 label = Phone.getTypeLabel(getContext().getResources(), type, customLabel);
110 }
111 view.setLabel(label);
Andrew Leec6d2f862014-03-31 14:39:55 -0700112 view.setPhoneNumber(cursor.getString(PHONE_NUMBER_COLUMN_INDEX), /* countryIso */ null);
Dmitri Plotnikova3569b22010-05-07 10:50:52 -0700113 }
114}