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; 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 25 /** 26 * Used to create {@link CursorLoader}s to load different groups of 27 * {@link com.android.contacts.list.ContactTileView}. 28 */ 29 public 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 public final static int CONTACT_PRESENCE = 5; 37 public final static int CONTACT_STATUS = 6; 38 39 // Only used for StrequentPhoneOnlyLoader 40 public final static int PHONE_NUMBER = 5; 41 public final static int PHONE_NUMBER_TYPE = 6; 42 public final static int PHONE_NUMBER_LABEL = 7; 43 44 private static final String[] COLUMNS = new String[] { 45 Contacts._ID, // ..........................................0 46 Contacts.DISPLAY_NAME, // .................................1 47 Contacts.STARRED, // ......................................2 48 Contacts.PHOTO_URI, // ....................................3 49 Contacts.LOOKUP_KEY, // ...................................4 50 Contacts.CONTACT_PRESENCE, // .............................5 51 Contacts.CONTACT_STATUS, // ...............................6 52 }; 53 54 /** 55 * Projection used for the {@link Contacts#CONTENT_STREQUENT_URI} 56 * query when {@link ContactsContract#STREQUENT_PHONE_ONLY} flag 57 * is set to true. The main difference is the lack of presence 58 * and status data and the addition of phone number and label. 59 */ 60 private static final String[] COLUMNS_PHONE_ONLY = new String[] { 61 Contacts._ID, // ..........................................0 62 Contacts.DISPLAY_NAME, // .................................1 63 Contacts.STARRED, // ......................................2 64 Contacts.PHOTO_URI, // ....................................3 65 Contacts.LOOKUP_KEY, // ...................................4 66 Phone.NUMBER, // ..........................................5 67 Phone.TYPE, // ............................................6 68 Phone.LABEL // ............................................7 69 }; 70 71 private static final String STARRED_ORDER = Contacts.DISPLAY_NAME+" COLLATE NOCASE ASC"; 72 createStrequentLoader(Context context)73 public static CursorLoader createStrequentLoader(Context context) { 74 return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS, null, null, 75 STARRED_ORDER); 76 } 77 createStrequentPhoneOnlyLoader(Context context)78 public static CursorLoader createStrequentPhoneOnlyLoader(Context context) { 79 Uri uri = Contacts.CONTENT_STREQUENT_URI.buildUpon() 80 .appendQueryParameter(ContactsContract.STREQUENT_PHONE_ONLY, "true").build(); 81 82 return new CursorLoader(context, uri, COLUMNS_PHONE_ONLY, null, null, null); 83 } 84 createStarredLoader(Context context)85 public static CursorLoader createStarredLoader(Context context) { 86 return new CursorLoader(context, Contacts.CONTENT_URI, COLUMNS, Contacts.STARRED + "=?", 87 new String[]{"1"}, STARRED_ORDER); 88 } 89 createFrequentLoader(Context context)90 public static CursorLoader createFrequentLoader(Context context) { 91 return new CursorLoader(context, Contacts.CONTENT_FREQUENT_URI, COLUMNS, 92 Contacts.STARRED + "=?", new String[]{"0"}, null); 93 } 94 } 95