Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [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 | */ |
| 16 | package com.android.contacts.common; |
| 17 | |
| 18 | import android.content.Context; |
sail | 3331545 | 2017-06-29 08:46:43 -0700 | [diff] [blame] | 19 | import android.content.CursorLoader; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 20 | import android.net.Uri; |
| 21 | import android.provider.ContactsContract; |
| 22 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 23 | import android.provider.ContactsContract.Contacts; |
| 24 | import android.support.annotation.VisibleForTesting; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Used to create {@link CursorLoader} which finds contacts information from the strequents table. |
| 28 | * |
| 29 | * <p>Only returns contacts with phone numbers. |
| 30 | */ |
| 31 | public final class ContactTileLoaderFactory { |
| 32 | |
| 33 | /** |
| 34 | * The _ID field returned for strequent items actually contains data._id instead of contacts._id |
| 35 | * because the query is performed on the data table. In order to obtain the contact id for |
| 36 | * strequent items, use Phone.contact_id instead. |
| 37 | */ |
| 38 | @VisibleForTesting |
| 39 | public static final String[] COLUMNS_PHONE_ONLY = |
| 40 | new String[] { |
| 41 | Contacts._ID, |
| 42 | Contacts.DISPLAY_NAME_PRIMARY, |
| 43 | Contacts.STARRED, |
| 44 | Contacts.PHOTO_URI, |
| 45 | Contacts.LOOKUP_KEY, |
| 46 | Phone.NUMBER, |
| 47 | Phone.TYPE, |
| 48 | Phone.LABEL, |
| 49 | Phone.IS_SUPER_PRIMARY, |
| 50 | Contacts.PINNED, |
| 51 | Phone.CONTACT_ID, |
| 52 | Contacts.DISPLAY_NAME_ALTERNATIVE, |
| 53 | }; |
| 54 | |
| 55 | public static CursorLoader createStrequentPhoneOnlyLoader(Context context) { |
| 56 | Uri uri = |
| 57 | Contacts.CONTENT_STREQUENT_URI |
| 58 | .buildUpon() |
| 59 | .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true") |
| 60 | .build(); |
| 61 | |
| 62 | return new CursorLoader(context, uri, COLUMNS_PHONE_ONLY, null, null, null); |
| 63 | } |
| 64 | } |