ContactsContract.java revision 0fc0244e808925e848ee9e350a3a213bd7574249
1/*
2 * Copyright (C) 2009 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 android.provider;
18
19import android.accounts.Account;
20import android.content.ContentProviderClient;
21import android.content.ContentProviderOperation;
22import android.content.ContentResolver;
23import android.content.ContentUris;
24import android.content.Context;
25import android.content.Intent;
26import android.content.res.Resources;
27import android.database.Cursor;
28import android.graphics.BitmapFactory;
29import android.graphics.Rect;
30import android.net.Uri;
31import android.os.RemoteException;
32import android.text.TextUtils;
33import android.util.Pair;
34import android.view.View;
35
36import java.io.ByteArrayInputStream;
37import java.io.InputStream;
38
39/**
40 * The contract between the contacts provider and applications. Contains definitions
41 * for the supported URIs and columns.
42 *
43 * @hide pending API council approval
44 */
45public final class ContactsContract {
46    /** The authority for the contacts provider */
47    public static final String AUTHORITY = "com.android.contacts";
48    /** A content:// style uri to the authority for the contacts provider */
49    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
50
51    /**
52     * An optional insert, update or delete URI parameter that allows the caller
53     * to specify that it is a sync adapter. The default value is false. If true
54     * the dirty flag is not automatically set and the "syncToNetwork" parameter
55     * is set to false when calling
56     * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
57     */
58    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
59
60    public interface SyncStateColumns extends SyncStateContract.Columns {
61    }
62
63    public static final class SyncState {
64        /**
65         * This utility class cannot be instantiated
66         */
67        private SyncState() {}
68
69        public static final String CONTENT_DIRECTORY =
70                SyncStateContract.Constants.CONTENT_DIRECTORY;
71
72        /**
73         * The content:// style URI for this table
74         */
75        public static final Uri CONTENT_URI =
76                Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY);
77
78        /**
79         * @see android.provider.SyncStateContract.Helpers#get
80         */
81        public static byte[] get(ContentProviderClient provider, Account account)
82                throws RemoteException {
83            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
84        }
85
86        /**
87         * @see android.provider.SyncStateContract.Helpers#get
88         */
89        public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
90                throws RemoteException {
91            return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
92        }
93
94        /**
95         * @see android.provider.SyncStateContract.Helpers#set
96         */
97        public static void set(ContentProviderClient provider, Account account, byte[] data)
98                throws RemoteException {
99            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
100        }
101
102        /**
103         * @see android.provider.SyncStateContract.Helpers#newSetOperation
104         */
105        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
106            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
107        }
108    }
109
110    /**
111     * Generic columns for use by sync adapters. The specific functions of
112     * these columns are private to the sync adapter. Other clients of the API
113     * should not attempt to either read or write this column.
114     */
115    private interface BaseSyncColumns {
116
117        /** Generic column for use by sync adapters. */
118        public static final String SYNC1 = "sync1";
119        /** Generic column for use by sync adapters. */
120        public static final String SYNC2 = "sync2";
121        /** Generic column for use by sync adapters. */
122        public static final String SYNC3 = "sync3";
123        /** Generic column for use by sync adapters. */
124        public static final String SYNC4 = "sync4";
125    }
126
127    /**
128     * Columns that appear when each row of a table belongs to a specific
129     * account, including sync information that an account may need.
130     */
131    private interface SyncColumns extends BaseSyncColumns {
132        /**
133         * The name of the account instance to which this row belongs.
134         * <P>Type: TEXT</P>
135         */
136        public static final String ACCOUNT_NAME = "account_name";
137
138        /**
139         * The type of account to which this row belongs, which when paired with
140         * {@link #ACCOUNT_NAME} identifies a specific account.
141         * <P>Type: TEXT</P>
142         */
143        public static final String ACCOUNT_TYPE = "account_type";
144
145        /**
146         * String that uniquely identifies this row to its source account.
147         * <P>Type: TEXT</P>
148         */
149        public static final String SOURCE_ID = "sourceid";
150
151        /**
152         * Version number that is updated whenever this row or its related data
153         * changes.
154         * <P>Type: INTEGER</P>
155         */
156        public static final String VERSION = "version";
157
158        /**
159         * Flag indicating that {@link #VERSION} has changed, and this row needs
160         * to be synchronized by its owning account.
161         * <P>Type: INTEGER (boolean)</P>
162         */
163        public static final String DIRTY = "dirty";
164    }
165
166    public interface ContactOptionsColumns {
167        /**
168         * The number of times a person has been contacted
169         * <P>Type: INTEGER</P>
170         */
171        public static final String TIMES_CONTACTED = "times_contacted";
172
173        /**
174         * The last time a person was contacted.
175         * <P>Type: INTEGER</P>
176         */
177        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
178
179        /**
180         * Is the contact starred?
181         * <P>Type: INTEGER (boolean)</P>
182         */
183        public static final String STARRED = "starred";
184
185        /**
186         * A custom ringtone associated with a person. Not always present.
187         * <P>Type: TEXT (URI to the ringtone)</P>
188         */
189        public static final String CUSTOM_RINGTONE = "custom_ringtone";
190
191        /**
192         * Whether the person should always be sent to voicemail. Not always
193         * present.
194         * <P>Type: INTEGER (0 for false, 1 for true)</P>
195         */
196        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
197    }
198
199    private interface ContactsColumns {
200        /**
201         * The display name for the contact.
202         * <P>Type: TEXT</P>
203         */
204        public static final String DISPLAY_NAME = "display_name";
205
206        /**
207         * Reference to the row in the data table holding the photo.
208         * <P>Type: INTEGER REFERENCES data(_id)</P>
209         */
210        public static final String PHOTO_ID = "photo_id";
211
212        /**
213         * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of
214         * any {@link CommonDataKinds.GroupMembership} for this contact.
215         */
216        public static final String IN_VISIBLE_GROUP = "in_visible_group";
217
218        /**
219         * Contact presence status.  See {@link android.provider.Im.CommonPresenceColumns}
220         * for individual status definitions.  This column is only returned if explicitly
221         * requested in the query projection.
222         * <p>Type: NUMBER</p>
223         */
224        public static final String PRESENCE_STATUS = Presence.PRESENCE_STATUS;
225
226        /**
227         * Contact presence custom status. This column is only returned if explicitly
228         * requested in the query projection.
229         * <p>Type: TEXT</p>
230         */
231        public static final String PRESENCE_CUSTOM_STATUS = Presence.PRESENCE_CUSTOM_STATUS;
232
233        /**
234         * An indicator of whether this contact has at least one phone number. "1" if there is
235         * at least one phone number, "0" otherwise.
236         * <P>Type: INTEGER</P>
237         */
238        public static final String HAS_PHONE_NUMBER = "has_phone_number";
239
240        /**
241         * An opaque value that contains hints on how to find the contact if
242         * its row id changed as a result of a sync or aggregation.
243         */
244        public static final String LOOKUP_KEY = "lookup";
245    }
246
247    /**
248     * Constants for the contacts table, which contains a record per group
249     * of raw contact representing the same person.
250     */
251    public static class Contacts implements BaseColumns, ContactsColumns,
252            ContactOptionsColumns {
253        /**
254         * This utility class cannot be instantiated
255         */
256        private Contacts()  {}
257
258        /**
259         * The content:// style URI for this table
260         */
261        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
262
263        /**
264         * A content:// style URI for this table that should be used to create
265         * shortcuts or otherwise create long-term links to contacts. This URI
266         * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}.
267         * It can optionally also have a "/" and last known contact ID appended after
268         * that. This "complete" format is an important optimization and is highly recommended.
269         * <p>
270         * As long as the contact's row ID remains the same, this URI is
271         * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes
272         * as a result of a sync or aggregation, this URI will look up the
273         * contact using indirect information (sync IDs or constituent raw
274         * contacts).
275         * <p>
276         * Lookup key should be appended unencoded - it is stored in the encoded
277         * form, ready for use in a URI.
278         */
279        public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
280                "lookup");
281
282        /**
283         * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the
284         * requested {@link Contacts} entry.
285         *
286         * @param contactUri A {@link #CONTENT_URI} row, or an existing
287         *            {@link #CONTENT_LOOKUP_URI} to attempt refreshing.
288         */
289        public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) {
290            final Cursor c = resolver.query(contactUri, new String[] {
291                    Contacts.LOOKUP_KEY, Contacts._ID
292            }, null, null, null);
293            if (c == null) {
294                return null;
295            }
296
297            try {
298                if (c.moveToFirst()) {
299                    final String lookupKey = c.getString(0);
300                    final long contactId = c.getLong(1);
301                    return getLookupUri(contactId, lookupKey);
302                }
303            } finally {
304                c.close();
305            }
306            return null;
307        }
308
309        /**
310         * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the
311         * given {@link Contacts#_ID} and {@link Contacts#LOOKUP_KEY}.
312         */
313        public static Uri getLookupUri(long contactId, String lookupKey) {
314            return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI,
315                    lookupKey), contactId);
316        }
317
318        /**
319         * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI.
320         * <p>
321         * Returns null if the contact cannot be found.
322         */
323        public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) {
324            if (lookupUri == null) {
325                return null;
326            }
327
328            Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null);
329            if (c == null) {
330                return null;
331            }
332
333            try {
334                if (c.moveToFirst()) {
335                    long contactId = c.getLong(0);
336                    return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
337                }
338            } finally {
339                c.close();
340            }
341            return null;
342        }
343
344        /**
345         * The content:// style URI used for "type-to-filter" functionality on the
346         * {@link #CONTENT_URI} URI. The filter string will be used to match
347         * various parts of the contact name. The filter argument should be passed
348         * as an additional path segment after this URI.
349         */
350        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
351                CONTENT_URI, "filter");
352
353        /**
354         * The content:// style URI for this table joined with useful data from
355         * {@link Data}, filtered to include only starred contacts
356         * and the most frequently contacted contacts.
357         */
358        public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath(
359                CONTENT_URI, "strequent");
360
361        /**
362         * The content:// style URI used for "type-to-filter" functionality on the
363         * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match
364         * various parts of the contact name. The filter argument should be passed
365         * as an additional path segment after this URI.
366         */
367        public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath(
368                CONTENT_STREQUENT_URI, "filter");
369
370        public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath(
371                CONTENT_URI, "group");
372
373        /**
374         * The MIME type of {@link #CONTENT_URI} providing a directory of
375         * people.
376         */
377        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact";
378
379        /**
380         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
381         * person.
382         */
383        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact";
384
385        /**
386         * A sub-directory of a single contact that contains all of the constituent raw contact
387         * {@link Data} rows.
388         */
389        public static final class Data implements BaseColumns, DataColumns {
390            /**
391             * no public constructor since this is a utility class
392             */
393            private Data() {}
394
395            /**
396             * The directory twig for this sub-table
397             */
398            public static final String CONTENT_DIRECTORY = "data";
399        }
400
401        /**
402         * A sub-directory of a single contact aggregate that contains all aggregation suggestions
403         * (other contacts).  The aggregation suggestions are computed based on approximate
404         * data matches with this contact.
405         */
406        public static final class AggregationSuggestions implements BaseColumns, ContactsColumns {
407            /**
408             * No public constructor since this is a utility class
409             */
410            private AggregationSuggestions() {}
411
412            /**
413             * The directory twig for this sub-table. The URI can be followed by an optional
414             * type-to-filter, similar to {@link Contacts#CONTENT_FILTER_URI}.
415             */
416            public static final String CONTENT_DIRECTORY = "suggestions";
417        }
418
419        /**
420         * A sub-directory of a single contact that contains the contact's primary photo.
421         */
422        public static final class Photo implements BaseColumns, DataColumns {
423            /**
424             * no public constructor since this is a utility class
425             */
426            private Photo() {}
427
428            /**
429             * The directory twig for this sub-table
430             */
431            public static final String CONTENT_DIRECTORY = "photo";
432        }
433
434        /**
435         * Opens an InputStream for the person's default photo and returns the
436         * photo as a Bitmap stream.
437         *
438         * @param contactUri the contact whose photo should be used
439         */
440        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
441            Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
442            if (photoUri == null) {
443                return null;
444            }
445            Cursor cursor = cr.query(photoUri,
446                    new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
447            try {
448                if (cursor == null || !cursor.moveToNext()) {
449                    return null;
450                }
451                byte[] data = cursor.getBlob(0);
452                if (data == null) {
453                    return null;
454                }
455                return new ByteArrayInputStream(data);
456            } finally {
457                if (cursor != null) {
458                    cursor.close();
459                }
460            }
461        }
462    }
463
464    private interface RawContactsColumns {
465        /**
466         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} that this
467         * data belongs to.
468         * <P>Type: INTEGER</P>
469         */
470        public static final String CONTACT_ID = "contact_id";
471
472        /**
473         * Flag indicating that this {@link RawContacts} entry and its children has
474         * been restricted to specific platform apps.
475         * <P>Type: INTEGER (boolean)</P>
476         *
477         * @hide until finalized in future platform release
478         */
479        public static final String IS_RESTRICTED = "is_restricted";
480
481        /**
482         * The aggregation mode for this contact.
483         * <P>Type: INTEGER</P>
484         */
485        public static final String AGGREGATION_MODE = "aggregation_mode";
486
487        /**
488         * The "deleted" flag: "0" by default, "1" if the row has been marked
489         * for deletion. When {@link android.content.ContentResolver#delete} is
490         * called on a raw contact, it is marked for deletion and removed from its
491         * aggregate contact. The sync adaptor deletes the raw contact on the server and
492         * then calls ContactResolver.delete once more, this time passing the
493         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
494         * the data removal.
495         * <P>Type: INTEGER</P>
496         */
497        public static final String DELETED = "deleted";
498    }
499
500    /**
501     * Constants for the raw_contacts table, which contains the base contact
502     * information per sync source. Sync adapters and contact management apps
503     * are the primary consumers of this API.
504     */
505    public static final class RawContacts implements BaseColumns, RawContactsColumns,
506            ContactOptionsColumns, SyncColumns  {
507        /**
508         * This utility class cannot be instantiated
509         */
510        private RawContacts() {
511        }
512
513        /**
514         * The content:// style URI for this table
515         */
516        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
517
518        /**
519         * The MIME type of {@link #CONTENT_URI} providing a directory of
520         * people.
521         */
522        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
523
524        /**
525         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
526         * person.
527         */
528        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
529
530        /**
531         * Aggregation mode: aggregate asynchronously.
532         */
533        public static final int AGGREGATION_MODE_DEFAULT = 0;
534
535        /**
536         * Aggregation mode: aggregate at the time the raw contact is inserted/updated.
537         */
538        public static final int AGGREGATION_MODE_IMMEDIATE = 1;
539
540        /**
541         * If {@link #AGGREGATION_MODE} is {@link #AGGREGATION_MODE_SUSPENDED}, changes
542         * to the raw contact do not cause its aggregation to be revisited. Note that changing
543         * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to
544         * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass. Any subsequent
545         * change to the raw contact's data will.
546         */
547        public static final int AGGREGATION_MODE_SUSPENDED = 2;
548
549        /**
550         * Aggregation mode: never aggregate this raw contact (note that the raw contact will not
551         * have a corresponding Aggregate and therefore will not be included in Aggregates
552         * query results.)
553         */
554        public static final int AGGREGATION_MODE_DISABLED = 3;
555
556        /**
557         * Build a {@link Contacts#CONTENT_LOOKUP_URI} style {@link Uri} for the
558         * parent {@link Contacts} entry of the given {@link RawContacts} entry.
559         */
560        public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) {
561            // TODO: use a lighter query by joining rawcontacts with contacts in provider
562            final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY);
563            final Cursor cursor = resolver.query(dataUri, new String[] {
564                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
565            }, null, null, null);
566
567            Uri lookupUri = null;
568            try {
569                if (cursor != null && cursor.moveToFirst()) {
570                    final long contactId = cursor.getLong(0);
571                    final String lookupKey = cursor.getString(1);
572                    return Contacts.getLookupUri(contactId, lookupKey);
573                }
574            } finally {
575                if (cursor != null) cursor.close();
576            }
577            return lookupUri;
578        }
579
580        /**
581         * A sub-directory of a single raw contact that contains all of their {@link Data} rows.
582         * To access this directory append {@link Data#CONTENT_DIRECTORY} to the contact URI.
583         */
584        public static final class Data implements BaseColumns, DataColumns {
585            /**
586             * no public constructor since this is a utility class
587             */
588            private Data() {
589            }
590
591            /**
592             * The directory twig for this sub-table
593             */
594            public static final String CONTENT_DIRECTORY = "data";
595        }
596    }
597
598    private interface DataColumns {
599        /**
600         * The package name to use when creating {@link Resources} objects for
601         * this data row. This value is only designed for use when building user
602         * interfaces, and should not be used to infer the owner.
603         */
604        public static final String RES_PACKAGE = "res_package";
605
606        /**
607         * The MIME type of the item represented by this row.
608         */
609        public static final String MIMETYPE = "mimetype";
610
611        /**
612         * A reference to the {@link RawContacts#_ID}
613         * that this data belongs to.
614         */
615        public static final String RAW_CONTACT_ID = "raw_contact_id";
616
617        /**
618         * Whether this is the primary entry of its kind for the raw contact it belongs to
619         * <P>Type: INTEGER (if set, non-0 means true)</P>
620         */
621        public static final String IS_PRIMARY = "is_primary";
622
623        /**
624         * Whether this is the primary entry of its kind for the aggregate
625         * contact it belongs to. Any data record that is "super primary" must
626         * also be "primary".
627         * <P>Type: INTEGER (if set, non-0 means true)</P>
628         */
629        public static final String IS_SUPER_PRIMARY = "is_super_primary";
630
631        /**
632         * The version of this data record. This is a read-only value. The data column is
633         * guaranteed to not change without the version going up. This value is monotonically
634         * increasing.
635         * <P>Type: INTEGER</P>
636         */
637        public static final String DATA_VERSION = "data_version";
638
639        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
640        public static final String DATA1 = "data1";
641        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
642        public static final String DATA2 = "data2";
643        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
644        public static final String DATA3 = "data3";
645        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
646        public static final String DATA4 = "data4";
647        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
648        public static final String DATA5 = "data5";
649        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
650        public static final String DATA6 = "data6";
651        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
652        public static final String DATA7 = "data7";
653        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
654        public static final String DATA8 = "data8";
655        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
656        public static final String DATA9 = "data9";
657        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
658        public static final String DATA10 = "data10";
659        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
660        public static final String DATA11 = "data11";
661        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
662        public static final String DATA12 = "data12";
663        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
664        public static final String DATA13 = "data13";
665        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
666        public static final String DATA14 = "data14";
667        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
668        public static final String DATA15 = "data15";
669
670        /** Generic column for use by sync adapters. */
671        public static final String SYNC1 = "data_sync1";
672        /** Generic column for use by sync adapters. */
673        public static final String SYNC2 = "data_sync2";
674        /** Generic column for use by sync adapters. */
675        public static final String SYNC3 = "data_sync3";
676        /** Generic column for use by sync adapters. */
677        public static final String SYNC4 = "data_sync4";
678    }
679
680    /**
681     * Combines all columns returned by {@link Data} table queries.
682     */
683    private interface DataColumnsWithJoins extends BaseColumns, DataColumns, RawContactsColumns,
684            ContactsColumns, ContactOptionsColumns {
685
686    }
687
688    /**
689     * Constants for the data table, which contains data points tied to a raw contact.
690     * For example, a phone number or email address. Each row in this table contains a type
691     * definition and some generic columns. Each data type can define the meaning for each of
692     * the generic columns.
693     */
694    public final static class Data implements DataColumnsWithJoins {
695        /**
696         * This utility class cannot be instantiated
697         */
698        private Data() {}
699
700        /**
701         * The content:// style URI for this table
702         */
703        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
704
705        /**
706         * The content:// style URI for this table joined with {@link Presence}
707         * data where applicable.
708         *
709         * @hide
710         */
711        public static final Uri CONTENT_WITH_PRESENCE_URI = Uri.withAppendedPath(AUTHORITY_URI,
712                "data_with_presence");
713
714        /**
715         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
716         */
717        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
718
719        /**
720         * Build a {@link Contacts#CONTENT_LOOKUP_URI} style {@link Uri} for the
721         * parent {@link Contacts} entry of the given {@link Data} entry.
722         */
723        public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) {
724            final Cursor cursor = resolver.query(dataUri, new String[] {
725                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
726            }, null, null, null);
727
728            Uri lookupUri = null;
729            try {
730                if (cursor != null && cursor.moveToFirst()) {
731                    final long contactId = cursor.getLong(0);
732                    final String lookupKey = cursor.getString(1);
733                    return Contacts.getLookupUri(contactId, lookupKey);
734                }
735            } finally {
736                if (cursor != null) cursor.close();
737            }
738            return lookupUri;
739        }
740    }
741
742    private interface PhoneLookupColumns {
743        /**
744         * The phone number as the user entered it.
745         * <P>Type: TEXT</P>
746         */
747        public static final String NUMBER = "number";
748
749        /**
750         * The type of phone number, for example Home or Work.
751         * <P>Type: INTEGER</P>
752         */
753        public static final String TYPE = "type";
754
755        /**
756         * The user defined label for the phone number.
757         * <P>Type: TEXT</P>
758         */
759        public static final String LABEL = "label";
760    }
761
762    /**
763     * A table that represents the result of looking up a phone number, for
764     * example for caller ID. To perform a lookup you must append the number you
765     * want to find to {@link #CONTENT_FILTER_URI}.
766     */
767    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
768            ContactsColumns, ContactOptionsColumns {
769        /**
770         * This utility class cannot be instantiated
771         */
772        private PhoneLookup() {}
773
774        /**
775         * The content:// style URI for this table. Append the phone number you want to lookup
776         * to this URI and query it to perform a lookup. For example:
777         *
778         * {@code
779         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, phoneNumber);
780         * }
781         */
782        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
783                "phone_lookup");
784    }
785
786    /**
787     * Additional data mixed in with {@link Im.CommonPresenceColumns} to link
788     * back to specific {@link ContactsContract.Contacts#_ID} entries.
789     */
790    private interface PresenceColumns {
791
792        /**
793         * The unique ID for a row.
794         * <P>Type: INTEGER (long)</P>
795         */
796        public static final String _ID = "presence_id";
797
798        /**
799         * Reference to the {@link Data#_ID} entry that owns this presence.
800         * <P>Type: INTEGER</P>
801         */
802        public static final String DATA_ID = "presence_data_id";
803
804        /**
805         * <p>Type: NUMBER</p>
806         */
807        public static final String PROTOCOL = "protocol";
808
809        /**
810         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
811         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
812         * omitted if {@link #PROTOCOL} value is not
813         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
814         *
815         * <p>Type: NUMBER</p>
816         */
817        public static final String CUSTOM_PROTOCOL = "custom_protocol";
818
819        /**
820         * The IM handle the presence item is for. The handle is scoped to
821         * {@link #PROTOCOL}.
822         * <P>Type: TEXT</P>
823         */
824        public static final String IM_HANDLE = "im_handle";
825
826        /**
827         * The IM account for the local user that the presence data came from.
828         * <P>Type: TEXT</P>
829         */
830        public static final String IM_ACCOUNT = "im_account";
831    }
832
833    public static final class Presence implements PresenceColumns, Im.CommonPresenceColumns {
834        /**
835         * This utility class cannot be instantiated
836         */
837        private Presence() {
838        }
839
840        /**
841         * The content:// style URI for this table
842         */
843        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "presence");
844
845        /**
846         * Gets the resource ID for the proper presence icon.
847         *
848         * @param status the status to get the icon for
849         * @return the resource ID for the proper presence icon
850         */
851        public static final int getPresenceIconResourceId(int status) {
852            switch (status) {
853                case AVAILABLE:
854                    return android.R.drawable.presence_online;
855                case IDLE:
856                case AWAY:
857                    return android.R.drawable.presence_away;
858                case DO_NOT_DISTURB:
859                    return android.R.drawable.presence_busy;
860                case INVISIBLE:
861                    return android.R.drawable.presence_invisible;
862                case OFFLINE:
863                default:
864                    return android.R.drawable.presence_offline;
865            }
866        }
867
868        /**
869         * Returns the precedence of the status code the higher number being the higher precedence.
870         *
871         * @param status The status code.
872         * @return An integer representing the precedence, 0 being the lowest.
873         */
874        public static final int getPresencePrecedence(int status) {
875            // Keep this function here incase we want to enforce a different precedence than the
876            // natural order of the status constants.
877            return status;
878        }
879
880        /**
881         * The MIME type of {@link #CONTENT_URI} providing a directory of
882         * presence details.
883         */
884        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/im-presence";
885
886        /**
887         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
888         * presence detail.
889         */
890        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im-presence";
891    }
892
893    /**
894     * Container for definitions of common data types stored in the {@link Data} table.
895     */
896    public static final class CommonDataKinds {
897        /**
898         * The {@link Data#RES_PACKAGE} value for common data that should be
899         * shown using a default style.
900         */
901        public static final String PACKAGE_COMMON = "common";
902
903        /**
904         * The base types that all "Typed" data kinds support.
905         */
906        public interface BaseTypes {
907            /**
908             * A custom type. The custom label should be supplied by user.
909             */
910            public static int TYPE_CUSTOM = 0;
911        }
912
913        /**
914         * Columns common across the specific types.
915         */
916        private interface CommonColumns extends BaseTypes {
917            /**
918             * The data for the contact method.
919             * <P>Type: TEXT</P>
920             */
921            public static final String DATA = DataColumns.DATA1;
922
923            /**
924             * The type of data, for example Home or Work.
925             * <P>Type: INTEGER</P>
926             */
927            public static final String TYPE = DataColumns.DATA2;
928
929            /**
930             * The user defined label for the the contact method.
931             * <P>Type: TEXT</P>
932             */
933            public static final String LABEL = DataColumns.DATA3;
934        }
935
936        /**
937         * Parts of the name.
938         */
939        public static final class StructuredName implements DataColumnsWithJoins {
940            private StructuredName() {}
941
942            /** MIME type used when storing this in data table. */
943            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
944
945            /**
946             * The name that should be used to display the contact.
947             * <i>Unstructured component of the name should be consistent with
948             * its structured representation.</i>
949             * <p>
950             * Type: TEXT
951             */
952            public static final String DISPLAY_NAME = DATA1;
953
954            /**
955             * The given name for the contact.
956             * <P>Type: TEXT</P>
957             */
958            public static final String GIVEN_NAME = DATA2;
959
960            /**
961             * The family name for the contact.
962             * <P>Type: TEXT</P>
963             */
964            public static final String FAMILY_NAME = DATA3;
965
966            /**
967             * The contact's honorific prefix, e.g. "Sir"
968             * <P>Type: TEXT</P>
969             */
970            public static final String PREFIX = DATA4;
971
972            /**
973             * The contact's middle name
974             * <P>Type: TEXT</P>
975             */
976            public static final String MIDDLE_NAME = DATA5;
977
978            /**
979             * The contact's honorific suffix, e.g. "Jr"
980             */
981            public static final String SUFFIX = DATA6;
982
983            /**
984             * The phonetic version of the given name for the contact.
985             * <P>Type: TEXT</P>
986             */
987            public static final String PHONETIC_GIVEN_NAME = DATA7;
988
989            /**
990             * The phonetic version of the additional name for the contact.
991             * <P>Type: TEXT</P>
992             */
993            public static final String PHONETIC_MIDDLE_NAME = DATA8;
994
995            /**
996             * The phonetic version of the family name for the contact.
997             * <P>Type: TEXT</P>
998             */
999            public static final String PHONETIC_FAMILY_NAME = DATA9;
1000        }
1001
1002        /**
1003         * A nickname.
1004         */
1005        public static final class Nickname implements DataColumnsWithJoins, CommonColumns {
1006            private Nickname() {}
1007
1008            /** MIME type used when storing this in data table. */
1009            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
1010
1011            public static final int TYPE_DEFAULT = 1;
1012            public static final int TYPE_OTHER_NAME = 2;
1013            public static final int TYPE_MAINDEN_NAME = 3;
1014            public static final int TYPE_SHORT_NAME = 4;
1015            public static final int TYPE_INITIALS = 5;
1016
1017            /**
1018             * The name itself
1019             */
1020            public static final String NAME = DATA;
1021        }
1022
1023        /**
1024         * Common data definition for telephone numbers.
1025         */
1026        public static final class Phone implements DataColumnsWithJoins, CommonColumns {
1027            private Phone() {}
1028
1029            /** MIME type used when storing this in data table. */
1030            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
1031
1032            /**
1033             * The MIME type of {@link #CONTENT_URI} providing a directory of
1034             * phones.
1035             */
1036            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
1037
1038            /**
1039             * The content:// style URI for all data records of the
1040             * {@link Phone#CONTENT_ITEM_TYPE} MIME type, combined with the
1041             * associated raw contact and aggregate contact data.
1042             */
1043            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1044                    "phones");
1045
1046            /**
1047             * The content:// style URL for phone lookup using a filter. The filter returns
1048             * records of MIME type {@link Phone#CONTENT_ITEM_TYPE}. The filter is applied
1049             * to display names as well as phone numbers. The filter argument should be passed
1050             * as an additional path segment after this URI.
1051             */
1052            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
1053                    "filter");
1054
1055            public static final int TYPE_HOME = 1;
1056            public static final int TYPE_MOBILE = 2;
1057            public static final int TYPE_WORK = 3;
1058            public static final int TYPE_FAX_WORK = 4;
1059            public static final int TYPE_FAX_HOME = 5;
1060            public static final int TYPE_PAGER = 6;
1061            public static final int TYPE_OTHER = 7;
1062            public static final int TYPE_CALLBACK = 8;
1063            public static final int TYPE_CAR = 9;
1064            public static final int TYPE_COMPANY_MAIN = 10;
1065            public static final int TYPE_ISDN = 11;
1066            public static final int TYPE_MAIN = 12;
1067            public static final int TYPE_OTHER_FAX = 13;
1068            public static final int TYPE_RADIO = 14;
1069            public static final int TYPE_TELEX = 15;
1070            public static final int TYPE_TTY_TDD = 16;
1071            public static final int TYPE_WORK_MOBILE = 17;
1072            public static final int TYPE_WORK_PAGER = 18;
1073            public static final int TYPE_ASSISTANT = 19;
1074            public static final int TYPE_MMS = 20;
1075
1076            /**
1077             * The phone number as the user entered it.
1078             * <P>Type: TEXT</P>
1079             */
1080            public static final String NUMBER = DATA;
1081
1082            /**
1083             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
1084             */
1085            @Deprecated
1086            public static final CharSequence getDisplayLabel(Context context, int type,
1087                    CharSequence label, CharSequence[] labelArray) {
1088                return getTypeLabel(context.getResources(), type, label);
1089            }
1090
1091            /**
1092             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
1093             */
1094            @Deprecated
1095            public static final CharSequence getDisplayLabel(Context context, int type,
1096                    CharSequence label) {
1097                return getTypeLabel(context.getResources(), type, label);
1098            }
1099
1100            /**
1101             * Return the string resource that best describes the given
1102             * {@link CommonColumns#TYPE}. Will always return a valid resource.
1103             */
1104            public static final int getTypeLabelResource(int type) {
1105                switch (type) {
1106                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
1107                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
1108                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
1109                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
1110                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
1111                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
1112                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
1113                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
1114                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
1115                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
1116                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
1117                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
1118                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
1119                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
1120                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
1121                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
1122                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
1123                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
1124                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
1125                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
1126                    default: return com.android.internal.R.string.phoneTypeCustom;
1127                }
1128            }
1129
1130            /**
1131             * Return a {@link CharSequence} that best describes the given type,
1132             * possibly substituting the given {@link CommonColumns#LABEL} value
1133             * for {@link BaseTypes#TYPE_CUSTOM}.
1134             */
1135            public static final CharSequence getTypeLabel(Resources res, int type,
1136                    CharSequence label) {
1137                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
1138                    return label;
1139                } else {
1140                    final int labelRes = getTypeLabelResource(type);
1141                    return res.getText(labelRes);
1142                }
1143            }
1144        }
1145
1146        /**
1147         * Common data definition for email addresses.
1148         */
1149        public static final class Email implements DataColumnsWithJoins, CommonColumns {
1150            private Email() {}
1151
1152            /** MIME type used when storing this in data table. */
1153            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
1154
1155            /**
1156             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
1157             */
1158            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
1159
1160            /**
1161             * The content:// style URI for all data records of the
1162             * {@link Email#CONTENT_ITEM_TYPE} MIME type, combined with the
1163             * associated raw contact and aggregate contact data.
1164             */
1165            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1166                    "emails");
1167
1168            /**
1169             * The content:// style URL for looking up data rows by email address. The
1170             * lookup argument, an email address, should be passed as an additional path segment
1171             * after this URI.
1172             */
1173            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
1174                    "lookup");
1175
1176            /**
1177             * The content:// style URL for email lookup using a filter. The filter returns
1178             * records of MIME type {@link Email#CONTENT_ITEM_TYPE}. The filter is applied
1179             * to display names as well as email addresses. The filter argument should be passed
1180             * as an additional path segment after this URI.
1181             */
1182            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
1183                    "filter");
1184
1185            public static final int TYPE_HOME = 1;
1186            public static final int TYPE_WORK = 2;
1187            public static final int TYPE_OTHER = 3;
1188            public static final int TYPE_MOBILE = 4;
1189
1190            /**
1191             * The display name for the email address
1192             * <P>Type: TEXT</P>
1193             */
1194            public static final String DISPLAY_NAME = DATA4;
1195
1196            /**
1197             * Return the string resource that best describes the given
1198             * {@link CommonColumns#TYPE}. Will always return a valid resource.
1199             */
1200            public static final int getTypeLabelResource(int type) {
1201                switch (type) {
1202                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
1203                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
1204                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
1205                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
1206                    default: return com.android.internal.R.string.emailTypeCustom;
1207                }
1208            }
1209
1210            /**
1211             * Return a {@link CharSequence} that best describes the given type,
1212             * possibly substituting the given {@link CommonColumns#LABEL} value
1213             * for {@link BaseTypes#TYPE_CUSTOM}.
1214             */
1215            public static final CharSequence getTypeLabel(Resources res, int type,
1216                    CharSequence label) {
1217                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
1218                    return label;
1219                } else {
1220                    final int labelRes = getTypeLabelResource(type);
1221                    return res.getText(labelRes);
1222                }
1223            }
1224        }
1225
1226        /**
1227         * Common data definition for postal addresses.
1228         */
1229        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns {
1230            private StructuredPostal() {
1231            }
1232
1233            /** MIME type used when storing this in data table. */
1234            public static final String CONTENT_ITEM_TYPE =
1235                    "vnd.android.cursor.item/postal-address_v2";
1236
1237            /**
1238             * The MIME type of {@link #CONTENT_URI} providing a directory of
1239             * postal addresses.
1240             */
1241            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
1242
1243            /**
1244             * The content:// style URI for all data records of the
1245             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
1246             */
1247            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
1248                    "postals");
1249
1250            public static final int TYPE_HOME = 1;
1251            public static final int TYPE_WORK = 2;
1252            public static final int TYPE_OTHER = 3;
1253
1254            /**
1255             * The full, unstructured postal address. <i>This field must be
1256             * consistent with any structured data.</i>
1257             * <p>
1258             * Type: TEXT
1259             */
1260            public static final String FORMATTED_ADDRESS = DATA;
1261
1262            /**
1263             * Can be street, avenue, road, etc. This element also includes the
1264             * house number and room/apartment/flat/floor number.
1265             * <p>
1266             * Type: TEXT
1267             */
1268            public static final String STREET = DATA4;
1269
1270            /**
1271             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
1272             * usually but not always mutually exclusive with street.
1273             * <p>
1274             * Type: TEXT
1275             */
1276            public static final String POBOX = DATA5;
1277
1278            /**
1279             * This is used to disambiguate a street address when a city
1280             * contains more than one street with the same name, or to specify a
1281             * small place whose mail is routed through a larger postal town. In
1282             * China it could be a county or a minor city.
1283             * <p>
1284             * Type: TEXT
1285             */
1286            public static final String NEIGHBORHOOD = DATA6;
1287
1288            /**
1289             * Can be city, village, town, borough, etc. This is the postal town
1290             * and not necessarily the place of residence or place of business.
1291             * <p>
1292             * Type: TEXT
1293             */
1294            public static final String CITY = DATA7;
1295
1296            /**
1297             * A state, province, county (in Ireland), Land (in Germany),
1298             * departement (in France), etc.
1299             * <p>
1300             * Type: TEXT
1301             */
1302            public static final String REGION = DATA8;
1303
1304            /**
1305             * Postal code. Usually country-wide, but sometimes specific to the
1306             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
1307             * <p>
1308             * Type: TEXT
1309             */
1310            public static final String POSTCODE = DATA9;
1311
1312            /**
1313             * The name or code of the country.
1314             * <p>
1315             * Type: TEXT
1316             */
1317            public static final String COUNTRY = DATA10;
1318
1319            /**
1320             * Return the string resource that best describes the given
1321             * {@link CommonColumns#TYPE}. Will always return a valid resource.
1322             */
1323            public static final int getTypeLabelResource(int type) {
1324                switch (type) {
1325                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
1326                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
1327                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
1328                    default: return com.android.internal.R.string.postalTypeCustom;
1329                }
1330            }
1331
1332            /**
1333             * Return a {@link CharSequence} that best describes the given type,
1334             * possibly substituting the given {@link CommonColumns#LABEL} value
1335             * for {@link BaseTypes#TYPE_CUSTOM}.
1336             */
1337            public static final CharSequence getTypeLabel(Resources res, int type,
1338                    CharSequence label) {
1339                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
1340                    return label;
1341                } else {
1342                    final int labelRes = getTypeLabelResource(type);
1343                    return res.getText(labelRes);
1344                }
1345            }
1346        }
1347
1348        /**
1349         * Common data definition for IM addresses.
1350         */
1351        public static final class Im implements DataColumnsWithJoins, CommonColumns {
1352            private Im() {}
1353
1354            /** MIME type used when storing this in data table. */
1355            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
1356
1357            public static final int TYPE_HOME = 1;
1358            public static final int TYPE_WORK = 2;
1359            public static final int TYPE_OTHER = 3;
1360
1361            /**
1362             * This column should be populated with one of the defined
1363             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
1364             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
1365             * should contain the name of the custom protocol.
1366             */
1367            public static final String PROTOCOL = DATA5;
1368
1369            public static final String CUSTOM_PROTOCOL = DATA6;
1370
1371            /*
1372             * The predefined IM protocol types.
1373             */
1374            public static final int PROTOCOL_CUSTOM = -1;
1375            public static final int PROTOCOL_AIM = 0;
1376            public static final int PROTOCOL_MSN = 1;
1377            public static final int PROTOCOL_YAHOO = 2;
1378            public static final int PROTOCOL_SKYPE = 3;
1379            public static final int PROTOCOL_QQ = 4;
1380            public static final int PROTOCOL_GOOGLE_TALK = 5;
1381            public static final int PROTOCOL_ICQ = 6;
1382            public static final int PROTOCOL_JABBER = 7;
1383            public static final int PROTOCOL_NETMEETING = 8;
1384
1385            /**
1386             * Return the string resource that best describes the given
1387             * {@link CommonColumns#TYPE}. Will always return a valid resource.
1388             */
1389            public static final int getTypeLabelResource(int type) {
1390                switch (type) {
1391                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
1392                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
1393                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
1394                    default: return com.android.internal.R.string.imTypeCustom;
1395                }
1396            }
1397
1398            /**
1399             * Return a {@link CharSequence} that best describes the given type,
1400             * possibly substituting the given {@link CommonColumns#LABEL} value
1401             * for {@link BaseTypes#TYPE_CUSTOM}.
1402             */
1403            public static final CharSequence getTypeLabel(Resources res, int type,
1404                    CharSequence label) {
1405                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
1406                    return label;
1407                } else {
1408                    final int labelRes = getTypeLabelResource(type);
1409                    return res.getText(labelRes);
1410                }
1411            }
1412
1413            /**
1414             * Return the string resource that best describes the given
1415             * {@link Im#PROTOCOL}. Will always return a valid resource.
1416             */
1417            public static final int getProtocolLabelResource(int type) {
1418                switch (type) {
1419                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
1420                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
1421                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
1422                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
1423                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
1424                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
1425                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
1426                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
1427                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
1428                    default: return com.android.internal.R.string.imProtocolCustom;
1429                }
1430            }
1431
1432            /**
1433             * Return a {@link CharSequence} that best describes the given
1434             * protocol, possibly substituting the given
1435             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
1436             */
1437            public static final CharSequence getProtocolLabel(Resources res, int type,
1438                    CharSequence label) {
1439                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
1440                    return label;
1441                } else {
1442                    final int labelRes = getProtocolLabelResource(type);
1443                    return res.getText(labelRes);
1444                }
1445            }
1446        }
1447
1448        /**
1449         * Common data definition for organizations.
1450         */
1451        public static final class Organization implements DataColumnsWithJoins, CommonColumns {
1452            private Organization() {}
1453
1454            /** MIME type used when storing this in data table. */
1455            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
1456
1457            public static final int TYPE_WORK = 1;
1458            public static final int TYPE_OTHER = 2;
1459
1460            /**
1461             * The company as the user entered it.
1462             * <P>Type: TEXT</P>
1463             */
1464            public static final String COMPANY = DATA;
1465
1466            /**
1467             * The position title at this company as the user entered it.
1468             * <P>Type: TEXT</P>
1469             */
1470            public static final String TITLE = DATA4;
1471
1472            /**
1473             * The department at this company as the user entered it.
1474             * <P>Type: TEXT</P>
1475             */
1476            public static final String DEPARTMENT = DATA5;
1477
1478            /**
1479             * The job description at this company as the user entered it.
1480             * <P>Type: TEXT</P>
1481             */
1482            public static final String JOB_DESCRIPTION = DATA6;
1483
1484            /**
1485             * The symbol of this company as the user entered it.
1486             * <P>Type: TEXT</P>
1487             */
1488            public static final String SYMBOL = DATA7;
1489
1490            /**
1491             * The phonetic name of this company as the user entered it.
1492             * <P>Type: TEXT</P>
1493             */
1494            public static final String PHONETIC_NAME = DATA8;
1495
1496            /**
1497             * Return the string resource that best describes the given
1498             * {@link CommonColumns#TYPE}. Will always return a valid resource.
1499             */
1500            public static final int getTypeLabelResource(int type) {
1501                switch (type) {
1502                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
1503                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
1504                    default: return com.android.internal.R.string.orgTypeCustom;
1505                }
1506            }
1507
1508            /**
1509             * Return a {@link CharSequence} that best describes the given type,
1510             * possibly substituting the given {@link CommonColumns#LABEL} value
1511             * for {@link BaseTypes#TYPE_CUSTOM}.
1512             */
1513            public static final CharSequence getTypeLabel(Resources res, int type,
1514                    CharSequence label) {
1515                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
1516                    return label;
1517                } else {
1518                    final int labelRes = getTypeLabelResource(type);
1519                    return res.getText(labelRes);
1520                }
1521            }
1522        }
1523
1524        /**
1525         * Common data definition for miscellaneous information.
1526         */
1527        public static final class Miscellaneous implements DataColumnsWithJoins {
1528            private Miscellaneous() {}
1529
1530            /** MIME type used when storing this in data table. */
1531            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/misc";
1532
1533            /**
1534             * The birthday as the user entered it.
1535             * <P>Type: TEXT</P>
1536             */
1537            public static final String BIRTHDAY = DATA1;
1538
1539            /**
1540             * The nickname as the user entered it.
1541             * <P>Type: TEXT</P>
1542             */
1543            public static final String NICKNAME = DATA2;
1544        }
1545
1546        /**
1547         * Common data definition for relations.
1548         */
1549        public static final class Relation implements DataColumnsWithJoins, CommonColumns {
1550            private Relation() {}
1551
1552            /** MIME type used when storing this in data table. */
1553            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
1554
1555            public static final int TYPE_ASSISTANT = 1;
1556            public static final int TYPE_BROTHER = 2;
1557            public static final int TYPE_CHILD = 3;
1558            public static final int TYPE_DOMESTIC_PARTNER = 4;
1559            public static final int TYPE_FATHER = 5;
1560            public static final int TYPE_FRIEND = 6;
1561            public static final int TYPE_MANAGER = 7;
1562            public static final int TYPE_MOTHER = 8;
1563            public static final int TYPE_PARENT = 9;
1564            public static final int TYPE_PARTNER = 10;
1565            public static final int TYPE_REFERRED_BY = 11;
1566            public static final int TYPE_RELATIVE = 12;
1567            public static final int TYPE_SISTER = 13;
1568            public static final int TYPE_SPOUSE = 14;
1569
1570            /**
1571             * The name of the relative as the user entered it.
1572             * <P>Type: TEXT</P>
1573             */
1574            public static final String NAME = DATA;
1575        }
1576
1577        /**
1578         * Common data definition for events.
1579         */
1580        public static final class Event implements DataColumnsWithJoins, CommonColumns {
1581            private Event() {}
1582
1583            /** MIME type used when storing this in data table. */
1584            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/event";
1585
1586            public static final int TYPE_ANNIVERSARY = 1;
1587            public static final int TYPE_OTHER = 2;
1588
1589            /**
1590             * The event start date as the user entered it.
1591             * <P>Type: TEXT</P>
1592             */
1593            public static final String START_DATE = DATA;
1594        }
1595
1596        /**
1597         * Photo of the contact.
1598         */
1599        public static final class Photo implements DataColumnsWithJoins {
1600            private Photo() {}
1601
1602            /** MIME type used when storing this in data table. */
1603            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
1604
1605            /**
1606             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1607             * that could be inflated using {@link BitmapFactory}.
1608             * <p>
1609             * Type: BLOB
1610             */
1611            public static final String PHOTO = DATA15;
1612        }
1613
1614        /**
1615         * Notes about the contact.
1616         */
1617        public static final class Note implements DataColumnsWithJoins {
1618            private Note() {}
1619
1620            /** MIME type used when storing this in data table. */
1621            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
1622
1623            /**
1624             * The note text.
1625             * <P>Type: TEXT</P>
1626             */
1627            public static final String NOTE = DATA1;
1628        }
1629
1630        /**
1631         * Group Membership.
1632         */
1633        public static final class GroupMembership implements DataColumnsWithJoins {
1634            private GroupMembership() {}
1635
1636            /** MIME type used when storing this in data table. */
1637            public static final String CONTENT_ITEM_TYPE =
1638                    "vnd.android.cursor.item/group_membership";
1639
1640            /**
1641             * The row id of the group that this group membership refers to. Exactly one of
1642             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
1643             * <P>Type: INTEGER</P>
1644             */
1645            public static final String GROUP_ROW_ID = DATA1;
1646
1647            /**
1648             * The sourceid of the group that this group membership refers to.  Exactly one of
1649             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
1650             * <P>Type: TEXT</P>
1651             */
1652            public static final String GROUP_SOURCE_ID = "group_sourceid";
1653        }
1654
1655        /**
1656         * Website related to the contact.
1657         */
1658        public static final class Website implements DataColumnsWithJoins, CommonColumns {
1659            private Website() {}
1660
1661            /** MIME type used when storing this in data table. */
1662            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
1663
1664            public static final int TYPE_HOMEPAGE = 1;
1665            public static final int TYPE_BLOG = 2;
1666            public static final int TYPE_PROFILE = 3;
1667            public static final int TYPE_HOME = 4;
1668            public static final int TYPE_WORK = 5;
1669            public static final int TYPE_FTP = 6;
1670            public static final int TYPE_OTHER = 7;
1671
1672            /**
1673             * The website URL string.
1674             * <P>Type: TEXT</P>
1675             */
1676            public static final String URL = DATA;
1677        }
1678    }
1679
1680    // TODO: make this private before unhiding
1681    public interface GroupsColumns {
1682        /**
1683         * The display title of this group.
1684         * <p>
1685         * Type: TEXT
1686         */
1687        public static final String TITLE = "title";
1688
1689        /**
1690         * The package name to use when creating {@link Resources} objects for
1691         * this group. This value is only designed for use when building user
1692         * interfaces, and should not be used to infer the owner.
1693         */
1694        public static final String RES_PACKAGE = "res_package";
1695
1696        /**
1697         * The display title of this group to load as a resource from
1698         * {@link #RES_PACKAGE}, which may be localized.
1699         * <P>Type: TEXT</P>
1700         */
1701        public static final String TITLE_RES = "title_res";
1702
1703        /**
1704         * Notes about the group.
1705         * <p>
1706         * Type: TEXT
1707         */
1708        public static final String NOTES = "notes";
1709
1710        /**
1711         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
1712         * to the sync adapter, null otherwise.
1713         * <P>Type: TEXT</P>
1714         */
1715        public static final String SYSTEM_ID = "system_id";
1716
1717        /**
1718         * The total number of {@link Contacts} that have
1719         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
1720         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
1721         * <p>
1722         * Type: INTEGER
1723         */
1724        public static final String SUMMARY_COUNT = "summ_count";
1725
1726        /**
1727         * The total number of {@link Contacts} that have both
1728         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
1729         * Read-only value that is only present when querying
1730         * {@link Groups#CONTENT_SUMMARY_URI}.
1731         * <p>
1732         * Type: INTEGER
1733         */
1734        public static final String SUMMARY_WITH_PHONES = "summ_phones";
1735
1736        /**
1737         * Flag indicating if the contacts belonging to this group should be
1738         * visible in any user interface.
1739         * <p>
1740         * Type: INTEGER (boolean)
1741         */
1742        public static final String GROUP_VISIBLE = "group_visible";
1743
1744        /**
1745         * The "deleted" flag: "0" by default, "1" if the row has been marked
1746         * for deletion. When {@link android.content.ContentResolver#delete} is
1747         * called on a raw contact, it is marked for deletion and removed from its
1748         * aggregate contact. The sync adaptor deletes the raw contact on the server and
1749         * then calls ContactResolver.delete once more, this time setting the the
1750         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1751         * the data removal.
1752         * <P>Type: INTEGER</P>
1753         */
1754        public static final String DELETED = "deleted";
1755
1756        /**
1757         * Whether this group should be synced if the SYNC_EVERYTHING settings
1758         * is false for this group's account.
1759         * <p>
1760         * Type: INTEGER (boolean)
1761         */
1762        public static final String SHOULD_SYNC = "should_sync";
1763    }
1764
1765    /**
1766     * Constants for the groups table.
1767     */
1768    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
1769        /**
1770         * This utility class cannot be instantiated
1771         */
1772        private Groups() {
1773        }
1774
1775        /**
1776         * The content:// style URI for this table
1777         */
1778        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
1779
1780        /**
1781         * The content:// style URI for this table joined with details data from
1782         * {@link Data}.
1783         */
1784        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
1785                "groups_summary");
1786
1787        /**
1788         * The MIME type of a directory of groups.
1789         */
1790        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
1791
1792        /**
1793         * The MIME type of a single group.
1794         */
1795        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
1796    }
1797
1798    /**
1799     * Constants for the contact aggregation exceptions table, which contains
1800     * aggregation rules overriding those used by automatic aggregation.  This type only
1801     * supports query and update. Neither insert nor delete are supported.
1802     */
1803    public static final class AggregationExceptions implements BaseColumns {
1804        /**
1805         * This utility class cannot be instantiated
1806         */
1807        private AggregationExceptions() {}
1808
1809        /**
1810         * The content:// style URI for this table
1811         */
1812        public static final Uri CONTENT_URI =
1813                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
1814
1815        /**
1816         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
1817         */
1818        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
1819
1820        /**
1821         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
1822         */
1823        public static final String CONTENT_ITEM_TYPE =
1824                "vnd.android.cursor.item/aggregation_exception";
1825
1826        /**
1827         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
1828         * {@link #TYPE_AUTOMATIC}.
1829         *
1830         * <P>Type: INTEGER</P>
1831         */
1832        public static final String TYPE = "type";
1833
1834        /**
1835         * Allows the provider to automatically decide whether the specified raw contacts should
1836         * be included in the same aggregate contact or not.
1837         */
1838        public static final int TYPE_AUTOMATIC = 0;
1839
1840        /**
1841         * Makes sure that the specified raw contacts are included in the same
1842         * aggregate contact.
1843         */
1844        public static final int TYPE_KEEP_TOGETHER = 1;
1845
1846        /**
1847         * Makes sure that the specified raw contacts are NOT included in the same
1848         * aggregate contact.
1849         */
1850        public static final int TYPE_KEEP_SEPARATE = 2;
1851
1852        /**
1853         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
1854         */
1855        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
1856
1857        /**
1858         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
1859         * applies to.
1860         */
1861        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
1862    }
1863
1864    private interface SettingsColumns {
1865        /**
1866         * The name of the account instance to which this row belongs.
1867         * <P>Type: TEXT</P>
1868         */
1869        public static final String ACCOUNT_NAME = "account_name";
1870
1871        /**
1872         * The type of account to which this row belongs, which when paired with
1873         * {@link #ACCOUNT_NAME} identifies a specific account.
1874         * <P>Type: TEXT</P>
1875         */
1876        public static final String ACCOUNT_TYPE = "account_type";
1877
1878        /**
1879         * Depending on the mode defined by the sync-adapter, this flag controls
1880         * the top-level sync behavior for this data source.
1881         * <p>
1882         * Type: INTEGER (boolean)
1883         */
1884        public static final String SHOULD_SYNC = "should_sync";
1885
1886        /**
1887         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
1888         * entries should be visible in any user interface.
1889         * <p>
1890         * Type: INTEGER (boolean)
1891         */
1892        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
1893
1894        /**
1895         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
1896         * {@link Groups#SHOULD_SYNC} under this account have been marked as
1897         * unsynced.
1898         */
1899        public static final String ANY_UNSYNCED = "any_unsynced";
1900
1901        /**
1902         * Read-only count of {@link Contacts} from a specific source that have
1903         * no {@link CommonDataKinds.GroupMembership} entries.
1904         * <p>
1905         * Type: INTEGER
1906         */
1907        public static final String UNGROUPED_COUNT = "summ_count";
1908
1909        /**
1910         * Read-only count of {@link Contacts} from a specific source that have
1911         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
1912         * <p>
1913         * Type: INTEGER
1914         */
1915        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
1916    }
1917
1918    /**
1919     * Contacts-specific settings for various {@link Account}.
1920     */
1921    public static final class Settings implements SettingsColumns {
1922        /**
1923         * This utility class cannot be instantiated
1924         */
1925        private Settings() {
1926        }
1927
1928        /**
1929         * The content:// style URI for this table
1930         */
1931        public static final Uri CONTENT_URI =
1932                Uri.withAppendedPath(AUTHORITY_URI, "settings");
1933
1934        /**
1935         * The MIME-type of {@link #CONTENT_URI} providing a directory of
1936         * settings.
1937         */
1938        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
1939
1940        /**
1941         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
1942         */
1943        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
1944    }
1945
1946    /**
1947     * Helper methods to display FastTrack dialogs that allow users to pivot on
1948     * a specific {@link Contacts} entry.
1949     */
1950    public static final class FastTrack {
1951        /**
1952         * Action used to trigger person pivot dialog.
1953         * @hide
1954         */
1955        public static final String ACTION_FAST_TRACK =
1956                "com.android.contacts.action.FAST_TRACK";
1957
1958        /**
1959         * Extra used to specify pivot dialog location in screen coordinates.
1960         * @hide
1961         */
1962        public static final String EXTRA_TARGET_RECT = "target_rect";
1963
1964        /**
1965         * Extra used to specify size of pivot dialog.
1966         * @hide
1967         */
1968        public static final String EXTRA_MODE = "mode";
1969
1970        /**
1971         * Extra used to indicate a list of specific MIME-types to exclude and
1972         * not display. Stored as a {@link String} array.
1973         * @hide
1974         */
1975        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
1976
1977        /**
1978         * Small FastTrack mode, usually presented with minimal actions.
1979         */
1980        public static final int MODE_SMALL = 1;
1981
1982        /**
1983         * Medium FastTrack mode, includes actions and light summary describing
1984         * the {@link Contacts} entry being shown. This may include social
1985         * status and presence details.
1986         */
1987        public static final int MODE_MEDIUM = 2;
1988
1989        /**
1990         * Large FastTrack mode, includes actions and larger, card-like summary
1991         * of the {@link Contacts} entry being shown. This may include detailed
1992         * information, such as a photo.
1993         */
1994        public static final int MODE_LARGE = 3;
1995
1996        /**
1997         * Trigger a dialog that lists the various methods of interacting with
1998         * the requested {@link Contacts} entry. This may be based on available
1999         * {@link Data} rows under that contact, and may also include social
2000         * status and presence details.
2001         *
2002         * @param context The parent {@link Context} that may be used as the
2003         *            parent for this dialog.
2004         * @param target Specific {@link View} from your layout that this dialog
2005         *            should be centered around. In particular, if the dialog
2006         *            has a "callout" arrow, it will be pointed and centered
2007         *            around this {@link View}.
2008         * @param lookupUri A {@link Contacts#CONTENT_LOOKUP_URI} style
2009         *            {@link Uri} that describes a specific contact to feature
2010         *            in this dialog.
2011         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
2012         *            {@link #MODE_LARGE}, indicating the desired dialog size,
2013         *            when supported.
2014         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
2015         *            to exclude when showing this dialog. For example, when
2016         *            already viewing the contact details card, this can be used
2017         *            to omit the details entry from the dialog.
2018         */
2019        public static void showFastTrack(Context context, View target, Uri lookupUri, int mode,
2020                String[] excludeMimes) {
2021            // Find location and bounds of target view
2022            final int[] location = new int[2];
2023            target.getLocationOnScreen(location);
2024
2025            final Rect rect = new Rect();
2026            rect.left = location[0];
2027            rect.top = location[1];
2028            rect.right = rect.left + target.getWidth();
2029            rect.bottom = rect.top + target.getHeight();
2030
2031            // Trigger with obtained rectangle
2032            showFastTrack(context, rect, lookupUri, mode, excludeMimes);
2033        }
2034
2035        /**
2036         * Trigger a dialog that lists the various methods of interacting with
2037         * the requested {@link Contacts} entry. This may be based on available
2038         * {@link Data} rows under that contact, and may also include social
2039         * status and presence details.
2040         *
2041         * @param context The parent {@link Context} that may be used as the
2042         *            parent for this dialog.
2043         * @param target Specific {@link Rect} that this dialog should be
2044         *            centered around, in screen coordinates. In particular, if
2045         *            the dialog has a "callout" arrow, it will be pointed and
2046         *            centered around this {@link Rect}.
2047         * @param lookupUri A {@link Contacts#CONTENT_LOOKUP_URI} style
2048         *            {@link Uri} that describes a specific contact to feature
2049         *            in this dialog.
2050         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
2051         *            {@link #MODE_LARGE}, indicating the desired dialog size,
2052         *            when supported.
2053         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
2054         *            to exclude when showing this dialog. For example, when
2055         *            already viewing the contact details card, this can be used
2056         *            to omit the details entry from the dialog.
2057         */
2058        public static void showFastTrack(Context context, Rect target, Uri lookupUri, int mode,
2059                String[] excludeMimes) {
2060            // Launch pivot dialog through intent for now
2061            final Intent intent = new Intent(ACTION_FAST_TRACK);
2062            intent.setData(lookupUri);
2063            intent.putExtra(EXTRA_TARGET_RECT, target);
2064            intent.putExtra(EXTRA_MODE, mode);
2065            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
2066            context.startActivity(intent);
2067        }
2068    }
2069
2070    /**
2071     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
2072     * that involve contacts.
2073     */
2074    public static final class Intents {
2075        /**
2076         * This is the intent that is fired when a search suggestion is clicked on.
2077         */
2078        public static final String SEARCH_SUGGESTION_CLICKED =
2079                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
2080
2081        /**
2082         * This is the intent that is fired when a search suggestion for dialing a number
2083         * is clicked on.
2084         */
2085        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
2086                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
2087
2088        /**
2089         * This is the intent that is fired when a search suggestion for creating a contact
2090         * is clicked on.
2091         */
2092        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
2093                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
2094
2095        /**
2096         * Starts an Activity that lets the user pick a contact to attach an image to.
2097         * After picking the contact it launches the image cropper in face detection mode.
2098         */
2099        public static final String ATTACH_IMAGE =
2100                "com.android.contacts.action.ATTACH_IMAGE";
2101
2102        /**
2103         * Takes as input a data URI with a mailto: or tel: scheme. If a single
2104         * contact exists with the given data it will be shown. If no contact
2105         * exists, a dialog will ask the user if they want to create a new
2106         * contact with the provided details filled in. If multiple contacts
2107         * share the data the user will be prompted to pick which contact they
2108         * want to view.
2109         * <p>
2110         * For <code>mailto:</code> URIs, the scheme specific portion must be a
2111         * raw email address, such as one built using
2112         * {@link Uri#fromParts(String, String, String)}.
2113         * <p>
2114         * For <code>tel:</code> URIs, the scheme specific portion is compared
2115         * to existing numbers using the standard caller ID lookup algorithm.
2116         * The number must be properly encoded, for example using
2117         * {@link Uri#fromParts(String, String, String)}.
2118         * <p>
2119         * Any extras from the {@link Insert} class will be passed along to the
2120         * create activity if there are no contacts to show.
2121         * <p>
2122         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
2123         * prompting the user when the contact doesn't exist.
2124         */
2125        public static final String SHOW_OR_CREATE_CONTACT =
2126                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
2127
2128        /**
2129         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
2130         * contact if no matching contact found. Otherwise, default behavior is
2131         * to prompt user with dialog before creating.
2132         * <p>
2133         * Type: BOOLEAN
2134         */
2135        public static final String EXTRA_FORCE_CREATE =
2136                "com.android.contacts.action.FORCE_CREATE";
2137
2138        /**
2139         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
2140         * description to be shown when prompting user about creating a new
2141         * contact.
2142         * <p>
2143         * Type: STRING
2144         */
2145        public static final String EXTRA_CREATE_DESCRIPTION =
2146            "com.android.contacts.action.CREATE_DESCRIPTION";
2147
2148        /**
2149         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
2150         * dialog location using screen coordinates. When not specified, the
2151         * dialog will be centered.
2152         */
2153        @Deprecated
2154        public static final String EXTRA_TARGET_RECT = "target_rect";
2155
2156        /**
2157         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
2158         * desired dialog style, usually a variation on size. One of
2159         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
2160         */
2161        @Deprecated
2162        public static final String EXTRA_MODE = "mode";
2163
2164        /**
2165         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
2166         */
2167        @Deprecated
2168        public static final int MODE_SMALL = 1;
2169
2170        /**
2171         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
2172         */
2173        @Deprecated
2174        public static final int MODE_MEDIUM = 2;
2175
2176        /**
2177         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
2178         */
2179        @Deprecated
2180        public static final int MODE_LARGE = 3;
2181
2182        /**
2183         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
2184         * a list of specific MIME-types to exclude and not display. Stored as a
2185         * {@link String} array.
2186         */
2187        @Deprecated
2188        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
2189
2190        /**
2191         * Intents related to the Contacts app UI.
2192         */
2193        public static final class UI {
2194            /**
2195             * The action for the default contacts list tab.
2196             */
2197            public static final String LIST_DEFAULT =
2198                    "com.android.contacts.action.LIST_DEFAULT";
2199
2200            /**
2201             * The action for the contacts list tab.
2202             */
2203            public static final String LIST_GROUP_ACTION =
2204                    "com.android.contacts.action.LIST_GROUP";
2205
2206            /**
2207             * When in LIST_GROUP_ACTION mode, this is the group to display.
2208             */
2209            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
2210
2211            /**
2212             * The action for the all contacts list tab.
2213             */
2214            public static final String LIST_ALL_CONTACTS_ACTION =
2215                    "com.android.contacts.action.LIST_ALL_CONTACTS";
2216
2217            /**
2218             * The action for the contacts with phone numbers list tab.
2219             */
2220            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
2221                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
2222
2223            /**
2224             * The action for the starred contacts list tab.
2225             */
2226            public static final String LIST_STARRED_ACTION =
2227                    "com.android.contacts.action.LIST_STARRED";
2228
2229            /**
2230             * The action for the frequent contacts list tab.
2231             */
2232            public static final String LIST_FREQUENT_ACTION =
2233                    "com.android.contacts.action.LIST_FREQUENT";
2234
2235            /**
2236             * The action for the "strequent" contacts list tab. It first lists the starred
2237             * contacts in alphabetical order and then the frequent contacts in descending
2238             * order of the number of times they have been contacted.
2239             */
2240            public static final String LIST_STREQUENT_ACTION =
2241                    "com.android.contacts.action.LIST_STREQUENT";
2242
2243            /**
2244             * A key for to be used as an intent extra to set the activity
2245             * title to a custom String value.
2246             */
2247            public static final String TITLE_EXTRA_KEY =
2248                "com.android.contacts.extra.TITLE_EXTRA";
2249
2250            /**
2251             * Activity Action: Display a filtered list of contacts
2252             * <p>
2253             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
2254             * filtering
2255             * <p>
2256             * Output: Nothing.
2257             */
2258            public static final String FILTER_CONTACTS_ACTION =
2259                "com.android.contacts.action.FILTER_CONTACTS";
2260
2261            /**
2262             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
2263             * intents to supply the text on which to filter.
2264             */
2265            public static final String FILTER_TEXT_EXTRA_KEY =
2266                "com.android.contacts.extra.FILTER_TEXT";
2267        }
2268
2269        /**
2270         * Convenience class that contains string constants used
2271         * to create contact {@link android.content.Intent Intents}.
2272         */
2273        public static final class Insert {
2274            /** The action code to use when adding a contact */
2275            public static final String ACTION = Intent.ACTION_INSERT;
2276
2277            /**
2278             * If present, forces a bypass of quick insert mode.
2279             */
2280            public static final String FULL_MODE = "full_mode";
2281
2282            /**
2283             * The extra field for the contact name.
2284             * <P>Type: String</P>
2285             */
2286            public static final String NAME = "name";
2287
2288            // TODO add structured name values here.
2289
2290            /**
2291             * The extra field for the contact phonetic name.
2292             * <P>Type: String</P>
2293             */
2294            public static final String PHONETIC_NAME = "phonetic_name";
2295
2296            /**
2297             * The extra field for the contact company.
2298             * <P>Type: String</P>
2299             */
2300            public static final String COMPANY = "company";
2301
2302            /**
2303             * The extra field for the contact job title.
2304             * <P>Type: String</P>
2305             */
2306            public static final String JOB_TITLE = "job_title";
2307
2308            /**
2309             * The extra field for the contact notes.
2310             * <P>Type: String</P>
2311             */
2312            public static final String NOTES = "notes";
2313
2314            /**
2315             * The extra field for the contact phone number.
2316             * <P>Type: String</P>
2317             */
2318            public static final String PHONE = "phone";
2319
2320            /**
2321             * The extra field for the contact phone number type.
2322             * <P>Type: Either an integer value from
2323             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
2324             *  or a string specifying a custom label.</P>
2325             */
2326            public static final String PHONE_TYPE = "phone_type";
2327
2328            /**
2329             * The extra field for the phone isprimary flag.
2330             * <P>Type: boolean</P>
2331             */
2332            public static final String PHONE_ISPRIMARY = "phone_isprimary";
2333
2334            /**
2335             * The extra field for an optional second contact phone number.
2336             * <P>Type: String</P>
2337             */
2338            public static final String SECONDARY_PHONE = "secondary_phone";
2339
2340            /**
2341             * The extra field for an optional second contact phone number type.
2342             * <P>Type: Either an integer value from
2343             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
2344             *  or a string specifying a custom label.</P>
2345             */
2346            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
2347
2348            /**
2349             * The extra field for an optional third contact phone number.
2350             * <P>Type: String</P>
2351             */
2352            public static final String TERTIARY_PHONE = "tertiary_phone";
2353
2354            /**
2355             * The extra field for an optional third contact phone number type.
2356             * <P>Type: Either an integer value from
2357             * {@link android.provider.Contacts.PhonesColumns PhonesColumns},
2358             *  or a string specifying a custom label.</P>
2359             */
2360            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
2361
2362            /**
2363             * The extra field for the contact email address.
2364             * <P>Type: String</P>
2365             */
2366            public static final String EMAIL = "email";
2367
2368            /**
2369             * The extra field for the contact email type.
2370             * <P>Type: Either an integer value from
2371             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2372             *  or a string specifying a custom label.</P>
2373             */
2374            public static final String EMAIL_TYPE = "email_type";
2375
2376            /**
2377             * The extra field for the email isprimary flag.
2378             * <P>Type: boolean</P>
2379             */
2380            public static final String EMAIL_ISPRIMARY = "email_isprimary";
2381
2382            /**
2383             * The extra field for an optional second contact email address.
2384             * <P>Type: String</P>
2385             */
2386            public static final String SECONDARY_EMAIL = "secondary_email";
2387
2388            /**
2389             * The extra field for an optional second contact email type.
2390             * <P>Type: Either an integer value from
2391             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2392             *  or a string specifying a custom label.</P>
2393             */
2394            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
2395
2396            /**
2397             * The extra field for an optional third contact email address.
2398             * <P>Type: String</P>
2399             */
2400            public static final String TERTIARY_EMAIL = "tertiary_email";
2401
2402            /**
2403             * The extra field for an optional third contact email type.
2404             * <P>Type: Either an integer value from
2405             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2406             *  or a string specifying a custom label.</P>
2407             */
2408            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
2409
2410            /**
2411             * The extra field for the contact postal address.
2412             * <P>Type: String</P>
2413             */
2414            public static final String POSTAL = "postal";
2415
2416            /**
2417             * The extra field for the contact postal address type.
2418             * <P>Type: Either an integer value from
2419             * {@link android.provider.Contacts.ContactMethodsColumns ContactMethodsColumns}
2420             *  or a string specifying a custom label.</P>
2421             */
2422            public static final String POSTAL_TYPE = "postal_type";
2423
2424            /**
2425             * The extra field for the postal isprimary flag.
2426             * <P>Type: boolean</P>
2427             */
2428            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
2429
2430            /**
2431             * The extra field for an IM handle.
2432             * <P>Type: String</P>
2433             */
2434            public static final String IM_HANDLE = "im_handle";
2435
2436            /**
2437             * The extra field for the IM protocol
2438             * <P>Type: the result of {@link CommonDataKinds.Im#encodePredefinedImProtocol(int)}
2439             * or {@link CommonDataKinds.Im#encodeCustomImProtocol(String)}.</P>
2440             */
2441            public static final String IM_PROTOCOL = "im_protocol";
2442
2443            /**
2444             * The extra field for the IM isprimary flag.
2445             * <P>Type: boolean</P>
2446             */
2447            public static final String IM_ISPRIMARY = "im_isprimary";
2448        }
2449    }
2450
2451}
2452