1 /* 2 * Copyright (C) 2012 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 17 package com.android.contacts.list; 18 19 import android.content.Context; 20 import android.database.Cursor; 21 22 import com.android.contacts.GroupMemberLoader; 23 import com.android.contacts.common.list.ContactTileAdapter; 24 import com.android.contacts.common.list.ContactTileView; 25 import com.google.common.collect.Lists; 26 27 import java.util.ArrayList; 28 29 /** 30 * Tile adapter for groups. 31 */ 32 public class GroupMemberTileAdapter extends ContactTileAdapter { 33 34 public GroupMemberTileAdapter(Context context, ContactTileView.Listener listener, int numCols) { 35 super(context, listener, numCols, DisplayType.GROUP_MEMBERS); 36 } 37 38 @Override 39 protected void bindColumnIndices() { 40 mIdIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_ID; 41 mLookupIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_LOOKUP_KEY; 42 mPhotoUriIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PHOTO_URI; 43 mNameIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_DISPLAY_NAME_PRIMARY; 44 mPresenceIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_PRESENCE_STATUS; 45 mStatusIndex = GroupMemberLoader.GroupDetailQuery.CONTACT_STATUS; 46 } 47 48 @Override 49 protected void saveNumFrequentsFromCursor(Cursor cursor) { 50 mNumFrequents = 0; 51 } 52 53 @Override 54 public int getItemViewType(int position) { 55 return ViewTypes.STARRED; 56 } 57 58 @Override 59 protected int getDividerPosition(Cursor cursor) { 60 // No divider 61 return -1; 62 } 63 64 @Override 65 public int getCount() { 66 if (mContactCursor == null || mContactCursor.isClosed()) { 67 return 0; 68 } 69 70 return getRowCount(mContactCursor.getCount()); 71 } 72 73 @Override 74 public ArrayList<ContactEntry> getItem(int position) { 75 final ArrayList<ContactEntry> resultList = Lists.newArrayListWithCapacity(mColumnCount); 76 int contactIndex = position * mColumnCount; 77 78 for (int columnCounter = 0; columnCounter < mColumnCount; columnCounter++) { 79 resultList.add(createContactEntryFromCursor(mContactCursor, contactIndex)); 80 contactIndex++; 81 } 82 return resultList; 83 } 84 } 85