Home | History | Annotate | Download | only in chips
      1 /*
      2  * Copyright (C) 2012 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 
     17 package com.android.ex.chips;
     18 
     19 import android.content.res.Resources;
     20 import android.net.Uri;
     21 import android.provider.ContactsContract.CommonDataKinds.Email;
     22 import android.provider.ContactsContract.CommonDataKinds.Phone;
     23 import android.provider.ContactsContract.Contacts;
     24 
     25 /**
     26  * Phone and Email queries for supporting Chips UI.
     27  */
     28 /* package */ class Queries {
     29 
     30     public static final Query PHONE = new Query(new String[] {
     31             Contacts.DISPLAY_NAME,       // 0
     32             Phone.NUMBER,                // 1
     33             Phone.TYPE,                  // 2
     34             Phone.LABEL,                 // 3
     35             Phone.CONTACT_ID,            // 4
     36             Phone._ID,                   // 5
     37             Contacts.PHOTO_THUMBNAIL_URI,// 6
     38             Contacts.DISPLAY_NAME_SOURCE // 7
     39         }, Phone.CONTENT_FILTER_URI, Phone.CONTENT_URI) {
     40 
     41             @Override
     42             public CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
     43                 return Phone.getTypeLabel(res, type, label);
     44             }
     45 
     46     };
     47 
     48     public static final Query EMAIL = new Query(new String[]{
     49             Contacts.DISPLAY_NAME,       // 0
     50             Email.DATA,                  // 1
     51             Email.TYPE,                  // 2
     52             Email.LABEL,                 // 3
     53             Email.CONTACT_ID,            // 4
     54             Email._ID,                   // 5
     55             Contacts.PHOTO_THUMBNAIL_URI,// 6
     56             Contacts.DISPLAY_NAME_SOURCE // 7
     57         }, Email.CONTENT_FILTER_URI, Email.CONTENT_URI) {
     58 
     59             @Override
     60             public CharSequence getTypeLabel(Resources res, int type, CharSequence label) {
     61                 return Email.getTypeLabel(res, type, label);
     62             }
     63 
     64     };
     65 
     66     static abstract class Query {
     67         private final String[] mProjection;
     68         private final Uri mContentFilterUri;
     69         private final Uri mContentUri;
     70 
     71         public static final int NAME = 0;                // String
     72         public static final int DESTINATION = 1;         // String
     73         public static final int DESTINATION_TYPE = 2;    // int
     74         public static final int DESTINATION_LABEL = 3;   // String
     75         public static final int CONTACT_ID = 4;          // long
     76         public static final int DATA_ID = 5;             // long
     77         public static final int PHOTO_THUMBNAIL_URI = 6; // String
     78         public static final int DISPLAY_NAME_SOURCE = 7; // int
     79 
     80         public Query (String[] projection, Uri contentFilter, Uri content) {
     81             mProjection = projection;
     82             mContentFilterUri = contentFilter;
     83             mContentUri = content;
     84         }
     85 
     86         public String[] getProjection() {
     87             return mProjection;
     88         }
     89 
     90         public Uri getContentFilterUri() {
     91             return mContentFilterUri;
     92         }
     93 
     94         public Uri getContentUri() {
     95             return mContentUri;
     96         }
     97 
     98         public abstract CharSequence getTypeLabel(Resources res, int type, CharSequence label);
     99     }
    100 }
    101