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