Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 1 | /* |
| 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 Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 16 | package com.android.contacts; |
Yorke Lee | b465dca | 2014-02-11 12:35:06 -0800 | [diff] [blame] | 17 | |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 18 | import android.content.Context; |
| 19 | import android.content.CursorLoader; |
| 20 | import android.net.Uri; |
| 21 | import android.provider.ContactsContract; |
| 22 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 23 | import android.provider.ContactsContract.Contacts; |
| 24 | |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 25 | import com.google.common.annotations.VisibleForTesting; |
| 26 | |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Used to create {@link CursorLoader}s to load different groups of |
| 29 | * {@link com.android.contacts.list.ContactTileView}. |
| 30 | */ |
| 31 | public 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 Lee | 5472268 | 2013-09-24 15:57:02 -0700 | [diff] [blame] | 45 | public final static int IS_DEFAULT_NUMBER = 8; |
| 46 | public final static int PINNED = 9; |
Yorke Lee | 544e5a4 | 2013-09-23 20:29:04 -0700 | [diff] [blame] | 47 | // The _ID field returned for strequent items actually contains data._id instead of |
Yorke Lee | 71b4676 | 2013-07-31 16:21:48 -0700 | [diff] [blame] | 48 | // contacts._id because the query is performed on the data table. In order to obtain the |
Yorke Lee | 544e5a4 | 2013-09-23 20:29:04 -0700 | [diff] [blame] | 49 | // contact id for strequent items, we thus have to use Phone.contact_id instead. |
Yorke Lee | 5472268 | 2013-09-24 15:57:02 -0700 | [diff] [blame] | 50 | public final static int CONTACT_ID_FOR_DATA = 10; |
Brandon Maxwell | ff1be30 | 2015-10-28 15:33:43 -0700 | [diff] [blame] | 51 | public final static int DISPLAY_NAME_ALTERNATIVE = 11; |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 52 | |
| 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 Lee | b465dca | 2014-02-11 12:35:06 -0800 | [diff] [blame] | 69 | @VisibleForTesting |
| 70 | public static final String[] COLUMNS_PHONE_ONLY = new String[] { |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 71 | Contacts._ID, // ..........................................0 |
Brandon Maxwell | ff1be30 | 2015-10-28 15:33:43 -0700 | [diff] [blame] | 72 | Contacts.DISPLAY_NAME_PRIMARY, // .........................1 |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 73 | Contacts.STARRED, // ......................................2 |
| 74 | Contacts.PHOTO_URI, // ....................................3 |
| 75 | Contacts.LOOKUP_KEY, // ...................................4 |
| 76 | Phone.NUMBER, // ..........................................5 |
| 77 | Phone.TYPE, // ............................................6 |
Yorke Lee | 71b4676 | 2013-07-31 16:21:48 -0700 | [diff] [blame] | 78 | Phone.LABEL, // ...........................................7 |
Yorke Lee | 5472268 | 2013-09-24 15:57:02 -0700 | [diff] [blame] | 79 | Phone.IS_SUPER_PRIMARY, //.................................8 |
| 80 | Contacts.PINNED, // .......................................9 |
Brandon Maxwell | ff1be30 | 2015-10-28 15:33:43 -0700 | [diff] [blame] | 81 | Phone.CONTACT_ID, //.......................................10 |
| 82 | Contacts.DISPLAY_NAME_ALTERNATIVE, // .....................11 |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
Chiao Cheng | f4b9084 | 2012-12-11 18:10:10 -0800 | [diff] [blame] | 85 | private static final String STARRED_ORDER = Contacts.DISPLAY_NAME+" COLLATE NOCASE ASC"; |
| 86 | |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 87 | public static CursorLoader createStrequentLoader(Context context) { |
Chiao Cheng | f4b9084 | 2012-12-11 18:10:10 -0800 | [diff] [blame] | 88 | return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS, null, null, |
| 89 | STARRED_ORDER); |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 90 | } |
| 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 Cheng | f4b9084 | 2012-12-11 18:10:10 -0800 | [diff] [blame] | 100 | return new CursorLoader(context, Contacts.CONTENT_URI, COLUMNS, Contacts.STARRED + "=?", |
| 101 | new String[]{"1"}, STARRED_ORDER); |
Chiao Cheng | a6b4c79 | 2012-10-31 15:18:29 -0700 | [diff] [blame] | 102 | } |
| 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 | } |