ContactTileLoaderFactory.java revision 0c07935a3d838ed24db7d20df839be97fe4c625a
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 */
16package com.android.contacts;
17
18import com.android.contacts.list.ContactTileView;
19
20import android.content.Context;
21import android.content.CursorLoader;
22import android.net.Uri;
23import android.provider.ContactsContract;
24import android.provider.ContactsContract.Contacts;
25
26/**
27 * Used to create {@link CursorLoader}s to load different groups of {@link ContactTileView}s
28 */
29public final class ContactTileLoaderFactory {
30
31    public final static int CONTACT_ID = 0;
32    public final static int DISPLAY_NAME = 1;
33    public final static int STARRED = 2;
34    public final static int PHOTO_URI = 3;
35    public final static int LOOKUP_KEY = 4;
36
37    private static final String[] COLUMNS = new String[] {
38        Contacts._ID,
39        Contacts.DISPLAY_NAME,
40        Contacts.STARRED,
41        Contacts.PHOTO_URI,
42        Contacts.LOOKUP_KEY
43    };
44
45    public static CursorLoader createStrequentLoader(Context context) {
46        return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS, null, null, null);
47    }
48
49    public static CursorLoader createStrequentPhoneOnlyLoader(Context context) {
50        Uri uri = Contacts.CONTENT_STREQUENT_URI.buildUpon()
51                .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build();
52
53        return new CursorLoader(context, uri, COLUMNS, null, null, null);
54    }
55
56    public static CursorLoader createStarredLoader(Context context) {
57        return new CursorLoader(context, Contacts.CONTENT_URI, COLUMNS,
58                Contacts.STARRED + "=?", new String[]{"1"}, Contacts.DISPLAY_NAME + " ASC");
59    }
60
61    public static CursorLoader createFrequentLoader(Context context) {
62        return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS,
63                 Contacts.STARRED + "=?", new String[]{"0"}, null);
64    }
65}
66