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