blob: e2945f6d1f6f4872b901861d2330e74acd41bcac [file] [log] [blame]
Frank Sposaro5f34b2e2011-06-21 15:54:30 -07001/*
2 * Copyright (C) 2011 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;
17
18import com.android.contacts.list.ContactListAdapter;
19
20import android.content.Context;
21import android.content.CursorLoader;
22import android.net.Uri;
23import android.provider.ContactsContract;
24import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
25import android.provider.ContactsContract.Contacts;
26import android.provider.ContactsContract.Data;
27import android.provider.ContactsContract.Directory;
28
29import java.util.ArrayList;
30import java.util.List;
31
32/**
33 * Group Member loader. Loads all group members from the given groupId
34 */
35public final class GroupMemberLoader extends CursorLoader {
36
37 /**
38 * Projection map is taken from {@link ContactListAdapter}
39 */
40 private final String[] PROJECTION_DATA = new String[] {
41 // TODO: Pull Projection_data out into util class
42 Data.CONTACT_ID, // 0
Katherine Kuan2d851cc2011-07-05 16:23:27 -070043 Data.RAW_CONTACT_ID, // 1
44 Data.DISPLAY_NAME_PRIMARY, // 2
45 Data.DISPLAY_NAME_ALTERNATIVE, // 3
46 Data.SORT_KEY_PRIMARY, // 4
47 Data.STARRED, // 5
48 Data.CONTACT_PRESENCE, // 6
49 Data.CONTACT_CHAT_CAPABILITY, // 7
50 Data.PHOTO_ID, // 8
Dave Santoro0a2a5db2011-06-29 00:37:06 -070051 Data.PHOTO_URI, // 9
52 Data.PHOTO_THUMBNAIL_URI, // 10
53 Data.LOOKUP_KEY, // 11
54 Data.PHONETIC_NAME, // 12
55 Data.HAS_PHONE_NUMBER, // 13
Frank Sposaro5f34b2e2011-06-21 15:54:30 -070056 };
57
58 private final long mGroupId;
59
60 public static final int CONTACT_ID_COLUMN_INDEX = 0;
Katherine Kuan2d851cc2011-07-05 16:23:27 -070061 public static final int RAW_CONTACT_ID_COLUMN_INDEX = 1;
62 public static final int CONTACT_DISPLAY_NAME_PRIMARY_COLUMN_INDEX = 2;
63 public static final int CONTACT_DISPLAY_NAME_ALTERNATIVE_COLUMN_INDEX = 3;
64 public static final int CONTACT_SORT_KEY_PRIMARY_COLUMN_INDEX = 4;
65 public static final int CONTACT_STARRED_COLUMN_INDEX = 5;
66 public static final int CONTACT_PRESENCE_STATUS_COLUMN_INDEX = 6;
67 public static final int CONTACT_CHAT_CAPABILITY_COLUMN_INDEX = 7;
68 public static final int CONTACT_PHOTO_ID_COLUMN_INDEX = 8;
69 public static final int CONTACT_PHOTO_URI_COLUMN_INDEX = 9;
Dave Santoro0a2a5db2011-06-29 00:37:06 -070070 public static final int CONTACT_PHOTO_THUMBNAIL_URI_COLUMN_INDEX = 10;
Katherine Kuan2d851cc2011-07-05 16:23:27 -070071 public static final int CONTACT_LOOKUP_KEY_COLUMN_INDEX = 10;
72 public static final int CONTACT_PHONETIC_NAME_COLUMN_INDEX = 11;
73 public static final int CONTACT_HAS_PHONE_COLUMN_INDEX = 12;
Frank Sposaro5f34b2e2011-06-21 15:54:30 -070074
75 public GroupMemberLoader(Context context, long groupId) {
76 super(context);
77 mGroupId = groupId;
78 setUri(createUri());
79 setProjection(PROJECTION_DATA);
80 setSelection(createSelection());
81 setSelectionArgs(createSelectionArgs());
82 setSortOrder(Contacts.SORT_KEY_ALTERNATIVE);
83 }
84
85 private Uri createUri() {
86 Uri uri = Data.CONTENT_URI;
87 uri = uri.buildUpon().appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
88 String.valueOf(Directory.DEFAULT)).build();
Frank Sposaro5f34b2e2011-06-21 15:54:30 -070089 return uri;
90 }
91
92 private String createSelection() {
93 StringBuilder selection = new StringBuilder();
94 selection.append(Data.MIMETYPE + "=?" + " AND " + GroupMembership.GROUP_ROW_ID + "=?");
95 return selection.toString();
96 }
97
98 private String[] createSelectionArgs() {
99 List<String> selectionArgs = new ArrayList<String>();
100 selectionArgs.add(GroupMembership.CONTENT_ITEM_TYPE);
101 selectionArgs.add(String.valueOf(mGroupId));
102 return selectionArgs.toArray(new String[0]);
103 }
104}