Queries.java revision 80f4abfb682426384e88fb1dddc682be1c8a6c7f
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 17package com.android.ex.chips; 18 19import android.content.res.Resources; 20import android.net.Uri; 21import android.provider.ContactsContract.Contacts; 22import android.provider.ContactsContract.CommonDataKinds.Email; 23import android.provider.ContactsContract.CommonDataKinds.Phone; 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 }, Phone.CONTENT_FILTER_URI, Phone.CONTENT_URI) { 39 40 @Override 41 public CharSequence getTypeLabel(Resources res, int type, CharSequence label) { 42 return Phone.getTypeLabel(res, type, label); 43 } 44 45 }; 46 47 public static final Query EMAIL = new Query(new String[]{ 48 Contacts.DISPLAY_NAME, // 0 49 Email.DATA, // 1 50 Email.TYPE, // 2 51 Email.LABEL, // 3 52 Email.CONTACT_ID, // 4 53 Email._ID, // 5 54 Contacts.PHOTO_THUMBNAIL_URI // 6 55 56 }, Email.CONTENT_FILTER_URI, Email.CONTENT_URI) { 57 58 @Override 59 public CharSequence getTypeLabel(Resources res, int type, CharSequence label) { 60 return Email.getTypeLabel(res, type, label); 61 } 62 63 }; 64 65 static abstract class Query { 66 private final String[] mProjection; 67 private final Uri mContentFilterUri; 68 private final Uri mContentUri; 69 70 public static final int NAME = 0; 71 public static final int DESTINATION = 1; 72 public static final int DESTINATION_TYPE = 2; 73 public static final int DESTINATION_LABEL = 3; 74 public static final int CONTACT_ID = 4; 75 public static final int DATA_ID = 5; 76 public static final int PHOTO_THUMBNAIL_URI = 6; 77 78 public Query (String[] projection, Uri contentFilter, Uri content) { 79 mProjection = projection; 80 mContentFilterUri = contentFilter; 81 mContentUri = content; 82 } 83 84 public String[] getProjection() { 85 return mProjection; 86 } 87 88 public Uri getContentFilterUri() { 89 return mContentFilterUri; 90 } 91 92 public Uri getContentUri() { 93 return mContentUri; 94 } 95 96 public abstract CharSequence getTypeLabel(Resources res, int type, CharSequence label); 97 } 98} 99