ContactsCursorLoader.java revision 91ce7d2a476bd04fe525049a37a2f8b2824e9724
1/*
2 * Copyright (C) 2017 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
17package com.android.dialer.contactsfragment;
18
19import android.content.Context;
20import android.content.CursorLoader;
21import android.provider.ContactsContract.Contacts;
22
23/** Cursor Loader for {@link ContactsFragment}. */
24final class ContactsCursorLoader extends CursorLoader {
25
26  public static final int CONTACT_ID = 0;
27  public static final int CONTACT_DISPLAY_NAME = 1;
28  public static final int CONTACT_PHOTO_ID = 2;
29  public static final int CONTACT_PHOTO_URI = 3;
30  public static final int CONTACT_LOOKUP_KEY = 4;
31
32  public static final String[] CONTACTS_PROJECTION_DISPLAY_NAME_PRIMARY =
33      new String[] {
34        Contacts._ID, // 0
35        Contacts.DISPLAY_NAME_PRIMARY, // 1
36        Contacts.PHOTO_ID, // 2
37        Contacts.PHOTO_THUMBNAIL_URI, // 3
38        Contacts.LOOKUP_KEY, // 4
39      };
40
41  public static final String[] CONTACTS_PROJECTION_DISPLAY_NAME_ALTERNATIVE =
42      new String[] {
43        Contacts._ID, // 0
44        Contacts.DISPLAY_NAME_ALTERNATIVE, // 1
45        Contacts.PHOTO_ID, // 2
46        Contacts.PHOTO_THUMBNAIL_URI, // 3
47        Contacts.LOOKUP_KEY, // 4
48      };
49
50  private ContactsCursorLoader(Context context, String[] contactProjection, String sortKey) {
51    super(
52        context,
53        Contacts.CONTENT_URI
54            .buildUpon()
55            .appendQueryParameter(Contacts.EXTRA_ADDRESS_BOOK_INDEX, "true")
56            .build(),
57        contactProjection,
58        null,
59        null,
60        sortKey + " ASC");
61  }
62
63  public static ContactsCursorLoader createInstanceDisplayNamePrimary(
64      Context context, String sortKey) {
65    return new ContactsCursorLoader(context, CONTACTS_PROJECTION_DISPLAY_NAME_PRIMARY, sortKey);
66  }
67
68  public static ContactsCursorLoader createInstanceDisplayNameAlternative(
69      Context context, String sortKey) {
70    return new ContactsCursorLoader(context, CONTACTS_PROJECTION_DISPLAY_NAME_ALTERNATIVE, sortKey);
71  }
72}
73