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