blob: 566ebae5f1c61082ae42de4238339dbfa324411f [file] [log] [blame]
Chiao Chenga6b4c792012-10-31 15:18:29 -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 */
Gary Mai0a49afa2016-12-05 15:53:58 -080016package com.android.contacts;
Yorke Leeb465dca2014-02-11 12:35:06 -080017
Chiao Chenga6b4c792012-10-31 15:18:29 -070018import android.content.Context;
19import android.content.CursorLoader;
20import android.net.Uri;
21import android.provider.ContactsContract;
22import android.provider.ContactsContract.CommonDataKinds.Phone;
23import android.provider.ContactsContract.Contacts;
24
Gary Mai0a49afa2016-12-05 15:53:58 -080025import com.google.common.annotations.VisibleForTesting;
26
Chiao Chenga6b4c792012-10-31 15:18:29 -070027/**
28 * Used to create {@link CursorLoader}s to load different groups of
29 * {@link com.android.contacts.list.ContactTileView}.
30 */
31public final class ContactTileLoaderFactory {
32
33 public final static int CONTACT_ID = 0;
34 public final static int DISPLAY_NAME = 1;
35 public final static int STARRED = 2;
36 public final static int PHOTO_URI = 3;
37 public final static int LOOKUP_KEY = 4;
38 public final static int CONTACT_PRESENCE = 5;
39 public final static int CONTACT_STATUS = 6;
40
41 // Only used for StrequentPhoneOnlyLoader
42 public final static int PHONE_NUMBER = 5;
43 public final static int PHONE_NUMBER_TYPE = 6;
44 public final static int PHONE_NUMBER_LABEL = 7;
Yorke Lee54722682013-09-24 15:57:02 -070045 public final static int IS_DEFAULT_NUMBER = 8;
46 public final static int PINNED = 9;
Yorke Lee544e5a42013-09-23 20:29:04 -070047 // The _ID field returned for strequent items actually contains data._id instead of
Yorke Lee71b46762013-07-31 16:21:48 -070048 // contacts._id because the query is performed on the data table. In order to obtain the
Yorke Lee544e5a42013-09-23 20:29:04 -070049 // contact id for strequent items, we thus have to use Phone.contact_id instead.
Yorke Lee54722682013-09-24 15:57:02 -070050 public final static int CONTACT_ID_FOR_DATA = 10;
Brandon Maxwellff1be302015-10-28 15:33:43 -070051 public final static int DISPLAY_NAME_ALTERNATIVE = 11;
Chiao Chenga6b4c792012-10-31 15:18:29 -070052
53 private static final String[] COLUMNS = new String[] {
54 Contacts._ID, // ..........................................0
55 Contacts.DISPLAY_NAME, // .................................1
56 Contacts.STARRED, // ......................................2
57 Contacts.PHOTO_URI, // ....................................3
58 Contacts.LOOKUP_KEY, // ...................................4
59 Contacts.CONTACT_PRESENCE, // .............................5
60 Contacts.CONTACT_STATUS, // ...............................6
61 };
62
63 /**
64 * Projection used for the {@link Contacts#CONTENT_STREQUENT_URI}
65 * query when {@link ContactsContract#STREQUENT_PHONE_ONLY} flag
66 * is set to true. The main difference is the lack of presence
67 * and status data and the addition of phone number and label.
68 */
Yorke Leeb465dca2014-02-11 12:35:06 -080069 @VisibleForTesting
70 public static final String[] COLUMNS_PHONE_ONLY = new String[] {
Chiao Chenga6b4c792012-10-31 15:18:29 -070071 Contacts._ID, // ..........................................0
Brandon Maxwellff1be302015-10-28 15:33:43 -070072 Contacts.DISPLAY_NAME_PRIMARY, // .........................1
Chiao Chenga6b4c792012-10-31 15:18:29 -070073 Contacts.STARRED, // ......................................2
74 Contacts.PHOTO_URI, // ....................................3
75 Contacts.LOOKUP_KEY, // ...................................4
76 Phone.NUMBER, // ..........................................5
77 Phone.TYPE, // ............................................6
Yorke Lee71b46762013-07-31 16:21:48 -070078 Phone.LABEL, // ...........................................7
Yorke Lee54722682013-09-24 15:57:02 -070079 Phone.IS_SUPER_PRIMARY, //.................................8
80 Contacts.PINNED, // .......................................9
Brandon Maxwellff1be302015-10-28 15:33:43 -070081 Phone.CONTACT_ID, //.......................................10
82 Contacts.DISPLAY_NAME_ALTERNATIVE, // .....................11
Chiao Chenga6b4c792012-10-31 15:18:29 -070083 };
84
Chiao Chengf4b90842012-12-11 18:10:10 -080085 private static final String STARRED_ORDER = Contacts.DISPLAY_NAME+" COLLATE NOCASE ASC";
86
Chiao Chenga6b4c792012-10-31 15:18:29 -070087 public static CursorLoader createStrequentLoader(Context context) {
Chiao Chengf4b90842012-12-11 18:10:10 -080088 return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS, null, null,
89 STARRED_ORDER);
Chiao Chenga6b4c792012-10-31 15:18:29 -070090 }
91
92 public static CursorLoader createStrequentPhoneOnlyLoader(Context context) {
93 Uri uri = Contacts.CONTENT_STREQUENT_URI.buildUpon()
94 .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build();
95
96 return new CursorLoader(context, uri, COLUMNS_PHONE_ONLY, null, null, null);
97 }
98
99 public static CursorLoader createStarredLoader(Context context) {
Chiao Chengf4b90842012-12-11 18:10:10 -0800100 return new CursorLoader(context, Contacts.CONTENT_URI, COLUMNS, Contacts.STARRED + "=?",
101 new String[]{"1"}, STARRED_ORDER);
Chiao Chenga6b4c792012-10-31 15:18:29 -0700102 }
103
104 public static CursorLoader createFrequentLoader(Context context) {
105 return new CursorLoader(context, Contacts.CONTENT_FREQUENT_URI, COLUMNS,
106 Contacts.STARRED + "=?", new String[]{"0"}, null);
107 }
108}