Home | History | Annotate | Download | only in model
      1 /*
      2  * Copyright (C) 2010 Google Inc.
      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 
     17 package com.android.loaderapp.model;
     18 
     19 import android.content.Context;
     20 import android.content.CursorLoader;
     21 import android.net.Uri;
     22 import android.provider.ContactsContract.Contacts;
     23 
     24 /**
     25  * Helper for loading contact lists.
     26  */
     27 public class ContactsListLoader {
     28     public static final String[] COLUMNS = new String[] {
     29         Contacts._ID,                       // 0
     30         Contacts.DISPLAY_NAME_PRIMARY,      // 1
     31         Contacts.DISPLAY_NAME_ALTERNATIVE,  // 2
     32         Contacts.SORT_KEY_PRIMARY,          // 3
     33         Contacts.STARRED,                   // 4
     34         Contacts.TIMES_CONTACTED,           // 5
     35         Contacts.CONTACT_PRESENCE,          // 6
     36         Contacts.PHOTO_ID,                  // 7
     37         Contacts.LOOKUP_KEY,                // 8
     38         Contacts.PHONETIC_NAME,             // 9
     39         Contacts.HAS_PHONE_NUMBER,          // 10
     40     };
     41 
     42     public static final int COLUMN_ID = 0;
     43     public static final int COLUMN_NAME = 1;
     44     public static final int COLUMN_LOOKUP_KEY = 8;
     45 
     46     public static CursorLoader newVisibleContactsLoader(Context context) {
     47         return new CursorLoader(context, Contacts.CONTENT_URI, COLUMNS,
     48                 Contacts.IN_VISIBLE_GROUP + "=1", null, Contacts.SORT_KEY_PRIMARY);
     49     }
     50 
     51     public static CursorLoader newStrequentContactsLoader(Context context) {
     52         return new CursorLoader(context, Contacts.CONTENT_STREQUENT_URI, COLUMNS, null, null, null);
     53     }
     54 
     55     public static CursorLoader newContactGroupLoader(Context context, String groupTitle) {
     56         Uri uri = Uri.withAppendedPath(Contacts.CONTENT_GROUP_URI, groupTitle);
     57         return new CursorLoader(context, uri, COLUMNS, null, null, Contacts.SORT_KEY_PRIMARY);
     58     }
     59 }
     60