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