ContactsContract.java revision a31a945ba6ec41f6c5278c44a545e2254f4cd034
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.CursorEntityIterator;
27import android.content.Entity;
28import android.content.EntityIterator;
29import android.content.Intent;
30import android.content.res.Resources;
31import android.database.Cursor;
32import android.database.DatabaseUtils;
33import android.database.sqlite.SQLiteException;
34import android.graphics.Rect;
35import android.net.Uri;
36import android.os.RemoteException;
37import android.text.TextUtils;
38import android.util.DisplayMetrics;
39import android.util.Pair;
40import android.view.View;
41
42import java.io.ByteArrayInputStream;
43import java.io.InputStream;
44
45/**
46 * <p>
47 * The contract between the contacts provider and applications. Contains
48 * definitions for the supported URIs and columns. These APIs supersede
49 * {@link Contacts}.
50 * </p>
51 * <h3>Overview</h3>
52 * <p>
53 * ContactsContract defines an extensible database of contact-related
54 * information. Contact information is stored in a three-tier data model:
55 * </p>
56 * <ul>
57 * <li>
58 * A row in the {@link Data} table can store any kind of personal data, such
59 * as a phone number or email addresses.  The set of data kinds that can be
60 * stored in this table is open-ended. There is a predefined set of common
61 * kinds, but any application can add its own data kinds.
62 * </li>
63 * <li>
64 * A row in the {@link RawContacts} table represents a set of data describing a
65 * person and associated with a single account (for example, one of the user's
66 * Gmail accounts).
67 * </li>
68 * <li>
69 * A row in the {@link Contacts} table represents an aggregate of one or more
70 * RawContacts presumably describing the same person.  When data in or associated with
71 * the RawContacts table is changed, the affected aggregate contacts are updated as
72 * necessary.
73 * </li>
74 * </ul>
75 * <p>
76 * Other tables include:
77 * </p>
78 * <ul>
79 * <li>
80 * {@link Groups}, which contains information about raw contact groups
81 * such as Gmail contact groups.  The
82 * current API does not support the notion of groups spanning multiple accounts.
83 * </li>
84 * <li>
85 * {@link StatusUpdates}, which contains social status updates including IM
86 * availability.
87 * </li>
88 * <li>
89 * {@link AggregationExceptions}, which is used for manual aggregation and
90 * disaggregation of raw contacts
91 * </li>
92 * <li>
93 * {@link Settings}, which contains visibility and sync settings for accounts
94 * and groups.
95 * </li>
96 * <li>
97 * {@link SyncState}, which contains free-form data maintained on behalf of sync
98 * adapters
99 * </li>
100 * <li>
101 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li>
102 * </ul>
103 */
104@SuppressWarnings("unused")
105public final class ContactsContract {
106    /** The authority for the contacts provider */
107    public static final String AUTHORITY = "com.android.contacts";
108    /** A content:// style uri to the authority for the contacts provider */
109    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
110
111    /**
112     * An optional URI parameter for insert, update, or delete queries
113     * that allows the caller
114     * to specify that it is a sync adapter. The default value is false. If true
115     * {@link RawContacts#DIRTY} is not automatically set and the
116     * "syncToNetwork" parameter is set to false when calling
117     * {@link
118     * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
119     * This prevents an unnecessary extra synchronization, see the discussion of
120     * the delete operation in {@link RawContacts}.
121     */
122    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
123
124    /**
125     * A query parameter key used to specify the package that is requesting a query.
126     * This is used for restricting data based on package name.
127     *
128     * @hide
129     */
130    public static final String REQUESTING_PACKAGE_PARAM_KEY = "requesting_package";
131
132    /**
133     * @hide
134     */
135    public static final class Preferences {
136
137        /**
138         * A key in the {@link android.provider.Settings android.provider.Settings} provider
139         * that stores the preferred sorting order for contacts (by given name vs. by family name).
140         *
141         * @hide
142         */
143        public static final String SORT_ORDER = "android.contacts.SORT_ORDER";
144
145        /**
146         * The value for the SORT_ORDER key corresponding to sorting by given name first.
147         *
148         * @hide
149         */
150        public static final int SORT_ORDER_PRIMARY = 1;
151
152        /**
153         * The value for the SORT_ORDER key corresponding to sorting by family name first.
154         *
155         * @hide
156         */
157        public static final int SORT_ORDER_ALTERNATIVE = 2;
158
159        /**
160         * A key in the {@link android.provider.Settings android.provider.Settings} provider
161         * that stores the preferred display order for contacts (given name first vs. family
162         * name first).
163         *
164         * @hide
165         */
166        public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER";
167
168        /**
169         * The value for the DISPLAY_ORDER key corresponding to showing the given name first.
170         *
171         * @hide
172         */
173        public static final int DISPLAY_ORDER_PRIMARY = 1;
174
175        /**
176         * The value for the DISPLAY_ORDER key corresponding to showing the family name first.
177         *
178         * @hide
179         */
180        public static final int DISPLAY_ORDER_ALTERNATIVE = 2;
181    }
182
183    /**
184     * @hide should be removed when users are updated to refer to SyncState
185     * @deprecated use SyncState instead
186     */
187    @Deprecated
188    public interface SyncStateColumns extends SyncStateContract.Columns {
189    }
190
191    /**
192     * A table provided for sync adapters to use for storing private sync state data.
193     *
194     * @see SyncStateContract
195     */
196    public static final class SyncState implements SyncStateContract.Columns {
197        /**
198         * This utility class cannot be instantiated
199         */
200        private SyncState() {}
201
202        public static final String CONTENT_DIRECTORY =
203                SyncStateContract.Constants.CONTENT_DIRECTORY;
204
205        /**
206         * The content:// style URI for this table
207         */
208        public static final Uri CONTENT_URI =
209                Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY);
210
211        /**
212         * @see android.provider.SyncStateContract.Helpers#get
213         */
214        public static byte[] get(ContentProviderClient provider, Account account)
215                throws RemoteException {
216            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
217        }
218
219        /**
220         * @see android.provider.SyncStateContract.Helpers#get
221         */
222        public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
223                throws RemoteException {
224            return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
225        }
226
227        /**
228         * @see android.provider.SyncStateContract.Helpers#set
229         */
230        public static void set(ContentProviderClient provider, Account account, byte[] data)
231                throws RemoteException {
232            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
233        }
234
235        /**
236         * @see android.provider.SyncStateContract.Helpers#newSetOperation
237         */
238        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
239            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
240        }
241    }
242
243    /**
244     * Generic columns for use by sync adapters. The specific functions of
245     * these columns are private to the sync adapter. Other clients of the API
246     * should not attempt to either read or write this column.
247     *
248     * @see RawContacts
249     * @see Groups
250     */
251    protected interface BaseSyncColumns {
252
253        /** Generic column for use by sync adapters. */
254        public static final String SYNC1 = "sync1";
255        /** Generic column for use by sync adapters. */
256        public static final String SYNC2 = "sync2";
257        /** Generic column for use by sync adapters. */
258        public static final String SYNC3 = "sync3";
259        /** Generic column for use by sync adapters. */
260        public static final String SYNC4 = "sync4";
261    }
262
263    /**
264     * Columns that appear when each row of a table belongs to a specific
265     * account, including sync information that an account may need.
266     *
267     * @see RawContacts
268     * @see Groups
269     */
270    protected interface SyncColumns extends BaseSyncColumns {
271        /**
272         * The name of the account instance to which this row belongs, which when paired with
273         * {@link #ACCOUNT_TYPE} identifies a specific account.
274         * <P>Type: TEXT</P>
275         */
276        public static final String ACCOUNT_NAME = "account_name";
277
278        /**
279         * The type of account to which this row belongs, which when paired with
280         * {@link #ACCOUNT_NAME} identifies a specific account.
281         * <P>Type: TEXT</P>
282         */
283        public static final String ACCOUNT_TYPE = "account_type";
284
285        /**
286         * String that uniquely identifies this row to its source account.
287         * <P>Type: TEXT</P>
288         */
289        public static final String SOURCE_ID = "sourceid";
290
291        /**
292         * Version number that is updated whenever this row or its related data
293         * changes.
294         * <P>Type: INTEGER</P>
295         */
296        public static final String VERSION = "version";
297
298        /**
299         * Flag indicating that {@link #VERSION} has changed, and this row needs
300         * to be synchronized by its owning account.
301         * <P>Type: INTEGER (boolean)</P>
302         */
303        public static final String DIRTY = "dirty";
304    }
305
306    /**
307     * Columns of {@link ContactsContract.Contacts} that track the user's
308     * preferences for, or interactions with, the contact.
309     *
310     * @see Contacts
311     * @see RawContacts
312     * @see ContactsContract.Data
313     * @see PhoneLookup
314     * @see ContactsContract.Contacts.AggregationSuggestions
315     */
316    protected interface ContactOptionsColumns {
317        /**
318         * The number of times a contact has been contacted
319         * <P>Type: INTEGER</P>
320         */
321        public static final String TIMES_CONTACTED = "times_contacted";
322
323        /**
324         * The last time a contact was contacted.
325         * <P>Type: INTEGER</P>
326         */
327        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
328
329        /**
330         * Is the contact starred?
331         * <P>Type: INTEGER (boolean)</P>
332         */
333        public static final String STARRED = "starred";
334
335        /**
336         * URI for a custom ringtone associated with the contact. If null or missing,
337         * the default ringtone is used.
338         * <P>Type: TEXT (URI to the ringtone)</P>
339         */
340        public static final String CUSTOM_RINGTONE = "custom_ringtone";
341
342        /**
343         * Whether the contact should always be sent to voicemail. If missing,
344         * defaults to false.
345         * <P>Type: INTEGER (0 for false, 1 for true)</P>
346         */
347        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
348    }
349
350    /**
351     * Columns of {@link ContactsContract.Contacts} that refer to intrinsic
352     * properties of the contact, as opposed to the user-specified options
353     * found in {@link ContactOptionsColumns}.
354     *
355     * @see Contacts
356     * @see ContactsContract.Data
357     * @see PhoneLookup
358     * @see ContactsContract.Contacts.AggregationSuggestions
359     */
360    protected interface ContactsColumns {
361        /**
362         * The display name for the contact.
363         * <P>Type: TEXT</P>
364         */
365        public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY;
366
367        /**
368         * Reference to the row in the RawContacts table holding the contact name.
369         * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P>
370         * @hide
371         */
372        public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id";
373
374        /**
375         * Reference to the row in the data table holding the photo.
376         * <P>Type: INTEGER REFERENCES data(_id)</P>
377         */
378        public static final String PHOTO_ID = "photo_id";
379
380        /**
381         * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of
382         * any {@link CommonDataKinds.GroupMembership} for this contact.
383         */
384        public static final String IN_VISIBLE_GROUP = "in_visible_group";
385
386        /**
387         * An indicator of whether this contact has at least one phone number. "1" if there is
388         * at least one phone number, "0" otherwise.
389         * <P>Type: INTEGER</P>
390         */
391        public static final String HAS_PHONE_NUMBER = "has_phone_number";
392
393        /**
394         * An opaque value that contains hints on how to find the contact if
395         * its row id changed as a result of a sync or aggregation.
396         */
397        public static final String LOOKUP_KEY = "lookup";
398    }
399
400    /**
401     * @see Contacts
402     */
403    protected interface ContactStatusColumns {
404        /**
405         * Contact presence status. See {@link StatusUpdates} for individual status
406         * definitions.
407         * <p>Type: NUMBER</p>
408         */
409        public static final String CONTACT_PRESENCE = "contact_presence";
410
411        /**
412         * Contact's latest status update.
413         * <p>Type: TEXT</p>
414         */
415        public static final String CONTACT_STATUS = "contact_status";
416
417        /**
418         * The absolute time in milliseconds when the latest status was
419         * inserted/updated.
420         * <p>Type: NUMBER</p>
421         */
422        public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts";
423
424        /**
425         * The package containing resources for this status: label and icon.
426         * <p>Type: TEXT</p>
427         */
428        public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package";
429
430        /**
431         * The resource ID of the label describing the source of contact
432         * status, e.g. "Google Talk". This resource is scoped by the
433         * {@link #CONTACT_STATUS_RES_PACKAGE}.
434         * <p>Type: NUMBER</p>
435         */
436        public static final String CONTACT_STATUS_LABEL = "contact_status_label";
437
438        /**
439         * The resource ID of the icon for the source of contact status. This
440         * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.
441         * <p>Type: NUMBER</p>
442         */
443        public static final String CONTACT_STATUS_ICON = "contact_status_icon";
444    }
445
446    /**
447     * Constants for various styles of combining given name, family name etc into
448     * a full name.  For example, the western tradition follows the pattern
449     * 'given name' 'middle name' 'family name' with the alternative pattern being
450     * 'family name', 'given name' 'middle name'.  The CJK tradition is
451     * 'family name' 'middle name' 'given name', with Japanese favoring a space between
452     * the names and Chinese omitting the space.
453     * @hide
454     */
455    public interface FullNameStyle {
456        public static final int UNDEFINED = 0;
457        public static final int WESTERN = 1;
458
459        /**
460         * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine
461         * which specific language it belongs to: Chinese, Japanese or Korean.
462         */
463        public static final int CJK = 2;
464
465        public static final int CHINESE = 3;
466        public static final int JAPANESE = 4;
467        public static final int KOREAN = 5;
468    }
469
470    /**
471     * Constants for various styles of capturing the pronunciation of a person's name.
472     * @hide
473     */
474    public interface PhoneticNameStyle {
475        public static final int UNDEFINED = 0;
476
477        /**
478         * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly
479         * shown in UIs, but used for searches and sorting.
480         */
481        public static final int PINYIN = 3;
482
483        /**
484         * Hiragana and Katakana are two common styles of writing out the pronunciation
485         * of a Japanese names.
486         */
487        public static final int JAPANESE = 4;
488
489        /**
490         * Hangul is the Korean phonetic alphabet.
491         */
492        public static final int KOREAN = 5;
493    }
494
495    /**
496     * Types of data used to produce the display name for a contact. Listed in the order
497     * of increasing priority.
498     *
499     * @hide
500     */
501    public interface DisplayNameSources {
502        public static final int UNDEFINED = 0;
503        public static final int EMAIL = 10;
504        public static final int PHONE = 20;
505        public static final int ORGANIZATION = 30;
506        public static final int NICKNAME = 35;
507        public static final int STRUCTURED_NAME = 40;
508    }
509
510    /**
511     * Contact name and contact name metadata columns in the RawContacts table.
512     *
513     * @see Contacts
514     * @see RawContacts
515     * @hide
516     */
517    protected interface ContactNameColumns {
518
519        /**
520         * The kind of data that is used as the display name for the contact, such as
521         * structured name or email address.  See DisplayNameSources.
522         *
523         * TODO: convert DisplayNameSources to a link after it is un-hidden
524         */
525        public static final String DISPLAY_NAME_SOURCE = "display_name_source";
526
527        /**
528         * <p>
529         * The standard text shown as the contact's display name, based on the best
530         * available information for the contact (for example, it might be the email address
531         * if the name is not available).
532         * The information actually used to compute the name is stored in
533         * {@link #DISPLAY_NAME_SOURCE}.
534         * </p>
535         * <p>
536         * A contacts provider is free to choose whatever representation makes most
537         * sense for its target market.
538         * For example in the default Android Open Source Project implementation,
539         * if the display name is
540         * based on the structured name and the structured name follows
541         * the Western full-name style, then this field contains the "given name first"
542         * version of the full name.
543         * <p>
544         *
545         * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE
546         */
547        public static final String DISPLAY_NAME_PRIMARY = "display_name";
548
549        /**
550         * <p>
551         * An alternative representation of the display name, such as "family name first"
552         * instead of "given name first" for Western names.  If an alternative is not
553         * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}.
554         * </p>
555         * <p>
556         * A contacts provider is free to provide alternatives as necessary for
557         * its target market.
558         * For example the default Android Open Source Project contacts provider
559         * currently provides an
560         * alternative in a single case:  if the display name is
561         * based on the structured name and the structured name follows
562         * the Western full name style, then the field contains the "family name first"
563         * version of the full name.
564         * Other cases may be added later.
565         * </p>
566         */
567        public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt";
568
569        /**
570         * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}.  See
571         * PhoneticNameStyle.
572         *
573         * TODO: convert PhoneticNameStyle to a link after it is un-hidden
574         */
575        public static final String PHONETIC_NAME_STYLE = "phonetic_name_style";
576
577        /**
578         * <p>
579         * Pronunciation of the full name in the phonetic alphabet specified by
580         * {@link #PHONETIC_NAME_STYLE}.
581         * </p>
582         * <p>
583         * The value may be set manually by the user.
584         * This capability is is of interest only in countries
585         * with commonly used phonetic
586         * alphabets, such as Japan and Korea.  See PhoneticNameStyle.
587         * </p>
588         *
589         * TODO: convert PhoneticNameStyle to a link after it is un-hidden
590         */
591        public static final String PHONETIC_NAME = "phonetic_name";
592
593        /**
594         * Sort key that takes into account locale-based traditions for sorting
595         * names in address books.  The default
596         * sort key is {@link #DISPLAY_NAME_PRIMARY}.  For Chinese names
597         * the sort key is the name's Pinyin spelling, and for Japanese names
598         * it is the Hiragana version of the phonetic name.
599         */
600        public static final String SORT_KEY_PRIMARY = "sort_key";
601
602        /**
603         * Sort key based on the alternative representation of the full name,
604         * {@link #DISPLAY_NAME_ALTERNATIVE}.  Thus for Western names,
605         * it is the one using the "family name first" format.
606         */
607        public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt";
608    }
609
610    /**
611     * URI parameter and cursor extras that return counts of rows grouped by the
612     * address book index, which is usually the first letter of the sort key.
613     * When this parameter is supplied, the row counts are returned in the
614     * cursor extras bundle.
615     *
616     * @hide
617     */
618    public final static class ContactCounts {
619
620        /**
621         * Add this query parameter to a URI to get back row counts grouped by
622         * the address book index as cursor extras. For most languages it is the
623         * first letter of the sort key. This parameter does not affect the main
624         * content of the cursor.
625         *
626         * @hide
627         */
628        public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras";
629
630        /**
631         * The array of address book index titles, which are returned in the
632         * same order as the data in the cursor.
633         * <p>TYPE: String[]</p>
634         *
635         * @hide
636         */
637        public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles";
638
639        /**
640         * The array of group counts for the corresponding group.  Contains the same number
641         * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array.
642         * <p>TYPE: int[]</p>
643         *
644         * @hide
645         */
646        public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts";
647    }
648
649    /**
650     * Constants for the contacts table, which contains a record per aggregate
651     * of raw contacts representing the same person.
652     * <h3>Operations</h3>
653     * <dl>
654     * <dt><b>Insert</b></dt>
655     * <dd>A Contact cannot be created explicitly. When a raw contact is
656     * inserted, the provider will first try to find a Contact representing the
657     * same person. If one is found, the raw contact's
658     * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate
659     * Contact. If no match is found, the provider automatically inserts a new
660     * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column
661     * of the newly inserted raw contact.</dd>
662     * <dt><b>Update</b></dt>
663     * <dd>Only certain columns of Contact are modifiable:
664     * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED},
665     * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of
666     * these columns on the Contact also changes them on all constituent raw
667     * contacts.</dd>
668     * <dt><b>Delete</b></dt>
669     * <dd>Be careful with deleting Contacts! Deleting an aggregate contact
670     * deletes all constituent raw contacts. The corresponding sync adapters
671     * will notice the deletions of their respective raw contacts and remove
672     * them from their back end storage.</dd>
673     * <dt><b>Query</b></dt>
674     * <dd>
675     * <ul>
676     * <li>If you need to read an individual contact, consider using
677     * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li>
678     * <li>If you need to look up a contact by the phone number, use
679     * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI},
680     * which is optimized for this purpose.</li>
681     * <li>If you need to look up a contact by partial name, e.g. to produce
682     * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI.
683     * <li>If you need to look up a contact by some data element like email
684     * address, nickname, etc, use a query against the {@link ContactsContract.Data} table.
685     * The result will contain contact ID, name etc.
686     * </ul>
687     * </dd>
688     * </dl>
689     * <h2>Columns</h2>
690     * <table class="jd-sumtable">
691     * <tr>
692     * <th colspan='4'>Contacts</th>
693     * </tr>
694     * <tr>
695     * <td>long</td>
696     * <td>{@link #_ID}</td>
697     * <td>read-only</td>
698     * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td>
699     * </tr>
700     * <tr>
701     * <td>String</td>
702     * <td>{@link #LOOKUP_KEY}</td>
703     * <td>read-only</td>
704     * <td>An opaque value that contains hints on how to find the contact if its
705     * row id changed as a result of a sync or aggregation.</td>
706     * </tr>
707     * <tr>
708     * <td>long</td>
709     * <td>NAME_RAW_CONTACT_ID</td>
710     * <td>read-only</td>
711     * <td>The ID of the raw contact that contributes the display name
712     * to the aggregate contact. During aggregation one of the constituent
713     * raw contacts is chosen using a heuristic: a longer name or a name
714     * with more diacritic marks or more upper case characters is chosen.</td>
715     * </tr>
716     * <tr>
717     * <td>String</td>
718     * <td>DISPLAY_NAME_PRIMARY</td>
719     * <td>read-only</td>
720     * <td>The display name for the contact. It is the display name
721     * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID
722     * column.</td>
723     * </tr>
724     * <tr>
725     * <td>long</td>
726     * <td>{@link #PHOTO_ID}</td>
727     * <td>read-only</td>
728     * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo.
729     * That row has the mime type
730     * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field
731     * is computed automatically based on the
732     * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of
733     * that mime type.</td>
734     * </tr>
735     * <tr>
736     * <td>int</td>
737     * <td>{@link #IN_VISIBLE_GROUP}</td>
738     * <td>read-only</td>
739     * <td>An indicator of whether this contact is supposed to be visible in the
740     * UI. "1" if the contact has at least one raw contact that belongs to a
741     * visible group; "0" otherwise.</td>
742     * </tr>
743     * <tr>
744     * <td>int</td>
745     * <td>{@link #HAS_PHONE_NUMBER}</td>
746     * <td>read-only</td>
747     * <td>An indicator of whether this contact has at least one phone number.
748     * "1" if there is at least one phone number, "0" otherwise.</td>
749     * </tr>
750     * <tr>
751     * <td>int</td>
752     * <td>{@link #TIMES_CONTACTED}</td>
753     * <td>read/write</td>
754     * <td>The number of times the contact has been contacted. See
755     * {@link #markAsContacted}. When raw contacts are aggregated, this field is
756     * computed automatically as the maximum number of times contacted among all
757     * constituent raw contacts. Setting this field automatically changes the
758     * corresponding field on all constituent raw contacts.</td>
759     * </tr>
760     * <tr>
761     * <td>long</td>
762     * <td>{@link #LAST_TIME_CONTACTED}</td>
763     * <td>read/write</td>
764     * <td>The timestamp of the last time the contact was contacted. See
765     * {@link #markAsContacted}. Setting this field also automatically
766     * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated,
767     * this field is computed automatically as the latest time contacted of all
768     * constituent raw contacts. Setting this field automatically changes the
769     * corresponding field on all constituent raw contacts.</td>
770     * </tr>
771     * <tr>
772     * <td>int</td>
773     * <td>{@link #STARRED}</td>
774     * <td>read/write</td>
775     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
776     * When raw contacts are aggregated, this field is automatically computed:
777     * if any constituent raw contacts are starred, then this field is set to
778     * '1'. Setting this field automatically changes the corresponding field on
779     * all constituent raw contacts.</td>
780     * </tr>
781     * <tr>
782     * <td>String</td>
783     * <td>{@link #CUSTOM_RINGTONE}</td>
784     * <td>read/write</td>
785     * <td>A custom ringtone associated with a contact. Typically this is the
786     * URI returned by an activity launched with the
787     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td>
788     * </tr>
789     * <tr>
790     * <td>int</td>
791     * <td>{@link #SEND_TO_VOICEMAIL}</td>
792     * <td>read/write</td>
793     * <td>An indicator of whether calls from this contact should be forwarded
794     * directly to voice mail ('1') or not ('0'). When raw contacts are
795     * aggregated, this field is automatically computed: if <i>all</i>
796     * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set
797     * to '1'. Setting this field automatically changes the corresponding field
798     * on all constituent raw contacts.</td>
799     * </tr>
800     * <tr>
801     * <td>int</td>
802     * <td>{@link #CONTACT_PRESENCE}</td>
803     * <td>read-only</td>
804     * <td>Contact IM presence status. See {@link StatusUpdates} for individual
805     * status definitions. Automatically computed as the highest presence of all
806     * constituent raw contacts. The provider may choose not to store this value
807     * in persistent storage. The expectation is that presence status will be
808     * updated on a regular basic.</td>
809     * </tr>
810     * <tr>
811     * <td>String</td>
812     * <td>{@link #CONTACT_STATUS}</td>
813     * <td>read-only</td>
814     * <td>Contact's latest status update. Automatically computed as the latest
815     * of all constituent raw contacts' status updates.</td>
816     * </tr>
817     * <tr>
818     * <td>long</td>
819     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
820     * <td>read-only</td>
821     * <td>The absolute time in milliseconds when the latest status was
822     * inserted/updated.</td>
823     * </tr>
824     * <tr>
825     * <td>String</td>
826     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
827     * <td>read-only</td>
828     * <td> The package containing resources for this status: label and icon.</td>
829     * </tr>
830     * <tr>
831     * <td>long</td>
832     * <td>{@link #CONTACT_STATUS_LABEL}</td>
833     * <td>read-only</td>
834     * <td>The resource ID of the label describing the source of contact status,
835     * e.g. "Google Talk". This resource is scoped by the
836     * {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
837     * </tr>
838     * <tr>
839     * <td>long</td>
840     * <td>{@link #CONTACT_STATUS_ICON}</td>
841     * <td>read-only</td>
842     * <td>The resource ID of the icon for the source of contact status. This
843     * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
844     * </tr>
845     * </table>
846     */
847    public static class Contacts implements BaseColumns, ContactsColumns,
848            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
849        /**
850         * This utility class cannot be instantiated
851         */
852        private Contacts()  {}
853
854        /**
855         * The content:// style URI for this table
856         */
857        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
858
859        /**
860         * A content:// style URI for this table that should be used to create
861         * shortcuts or otherwise create long-term links to contacts. This URI
862         * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}.
863         * It can optionally also have a "/" and last known contact ID appended after
864         * that. This "complete" format is an important optimization and is highly recommended.
865         * <p>
866         * As long as the contact's row ID remains the same, this URI is
867         * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes
868         * as a result of a sync or aggregation, this URI will look up the
869         * contact using indirect information (sync IDs or constituent raw
870         * contacts).
871         * <p>
872         * Lookup key should be appended unencoded - it is stored in the encoded
873         * form, ready for use in a URI.
874         */
875        public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
876                "lookup");
877
878        /**
879         * Base {@link Uri} for referencing a single {@link Contacts} entry,
880         * created by appending {@link #LOOKUP_KEY} using
881         * {@link Uri#withAppendedPath(Uri, String)}. Provides
882         * {@link OpenableColumns} columns when queried, or returns the
883         * referenced contact formatted as a vCard when opened through
884         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
885         */
886        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
887                "as_vcard");
888
889        /**
890         * Base {@link Uri} for referencing multiple {@link Contacts} entry,
891         * created by appending {@link #LOOKUP_KEY} using
892         * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be
893         * encoded and joined with the colon (":") seperator. The resulting string
894         * has to be encoded again. Provides
895         * {@link OpenableColumns} columns when queried, or returns the
896         * referenced contact formatted as a vCard when opened through
897         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
898         *
899         * This is private API because we do not have a well-defined way to
900         * specify several entities yet. The format of this Uri might change in the future
901         * or the Uri might be completely removed.
902         *
903         * @hide
904         */
905        public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
906                "as_multi_vcard");
907
908        /**
909         * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the
910         * requested {@link Contacts} entry.
911         *
912         * @param contactUri A {@link #CONTENT_URI} row, or an existing
913         *            {@link #CONTENT_LOOKUP_URI} to attempt refreshing.
914         */
915        public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) {
916            final Cursor c = resolver.query(contactUri, new String[] {
917                    Contacts.LOOKUP_KEY, Contacts._ID
918            }, null, null, null);
919            if (c == null) {
920                return null;
921            }
922
923            try {
924                if (c.moveToFirst()) {
925                    final String lookupKey = c.getString(0);
926                    final long contactId = c.getLong(1);
927                    return getLookupUri(contactId, lookupKey);
928                }
929            } finally {
930                c.close();
931            }
932            return null;
933        }
934
935        /**
936         * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the
937         * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}.
938         */
939        public static Uri getLookupUri(long contactId, String lookupKey) {
940            return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI,
941                    lookupKey), contactId);
942        }
943
944        /**
945         * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI.
946         * <p>
947         * Returns null if the contact cannot be found.
948         */
949        public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) {
950            if (lookupUri == null) {
951                return null;
952            }
953
954            Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null);
955            if (c == null) {
956                return null;
957            }
958
959            try {
960                if (c.moveToFirst()) {
961                    long contactId = c.getLong(0);
962                    return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
963                }
964            } finally {
965                c.close();
966            }
967            return null;
968        }
969
970        /**
971         * Mark a contact as having been contacted.  This updates the
972         * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED} for the
973         * contact, plus the corresponding values of any associated raw
974         * contacts.
975         *
976         * @param resolver the ContentResolver to use
977         * @param contactId the person who was contacted
978         */
979        public static void markAsContacted(ContentResolver resolver, long contactId) {
980            Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId);
981            ContentValues values = new ContentValues();
982            // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified.
983            values.put(LAST_TIME_CONTACTED, System.currentTimeMillis());
984            resolver.update(uri, values, null, null);
985        }
986
987        /**
988         * The content:// style URI used for "type-to-filter" functionality on the
989         * {@link #CONTENT_URI} URI. The filter string will be used to match
990         * various parts of the contact name. The filter argument should be passed
991         * as an additional path segment after this URI.
992         */
993        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
994                CONTENT_URI, "filter");
995
996        /**
997         * The content:// style URI for this table joined with useful data from
998         * {@link ContactsContract.Data}, filtered to include only starred contacts
999         * and the most frequently contacted contacts.
1000         */
1001        public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath(
1002                CONTENT_URI, "strequent");
1003
1004        /**
1005         * The content:// style URI used for "type-to-filter" functionality on the
1006         * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match
1007         * various parts of the contact name. The filter argument should be passed
1008         * as an additional path segment after this URI.
1009         */
1010        public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath(
1011                CONTENT_STREQUENT_URI, "filter");
1012
1013        public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath(
1014                CONTENT_URI, "group");
1015
1016        /**
1017         * The MIME type of {@link #CONTENT_URI} providing a directory of
1018         * people.
1019         */
1020        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact";
1021
1022        /**
1023         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1024         * person.
1025         */
1026        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact";
1027
1028        /**
1029         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1030         * person.
1031         */
1032        public static final String CONTENT_VCARD_TYPE = "text/x-vcard";
1033
1034        /**
1035         * A sub-directory of a single contact that contains all of the constituent raw contact
1036         * {@link ContactsContract.Data} rows.
1037         */
1038        public static final class Data implements BaseColumns, DataColumns {
1039            /**
1040             * no public constructor since this is a utility class
1041             */
1042            private Data() {}
1043
1044            /**
1045             * The directory twig for this sub-table
1046             */
1047            public static final String CONTENT_DIRECTORY = "data";
1048        }
1049
1050        /**
1051         * <p>
1052         * A <i>read-only</i> sub-directory of a single contact aggregate that
1053         * contains all aggregation suggestions (other contacts). The
1054         * aggregation suggestions are computed based on approximate data
1055         * matches with this contact.
1056         * </p>
1057         * <p>
1058         * <i>Note: this query may be expensive! If you need to use it in bulk,
1059         * make sure the user experience is acceptable when the query runs for a
1060         * long time.</i>
1061         * <p>
1062         * Usage example:
1063         *
1064         * <pre>
1065         * Uri uri = Contacts.CONTENT_URI.buildUpon()
1066         *          .appendEncodedPath(String.valueOf(contactId))
1067         *          .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY)
1068         *          .appendQueryParameter(&quot;limit&quot;, &quot;3&quot;)
1069         *          .build()
1070         * Cursor cursor = getContentResolver().query(suggestionsUri,
1071         *          new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY},
1072         *          null, null, null);
1073         * </pre>
1074         *
1075         * </p>
1076         */
1077        // TODO: add ContactOptionsColumns, ContactStatusColumns
1078        public static final class AggregationSuggestions implements BaseColumns, ContactsColumns {
1079            /**
1080             * No public constructor since this is a utility class
1081             */
1082            private AggregationSuggestions() {}
1083
1084            /**
1085             * The directory twig for this sub-table. The URI can be followed by an optional
1086             * type-to-filter, similar to
1087             * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}.
1088             */
1089            public static final String CONTENT_DIRECTORY = "suggestions";
1090        }
1091
1092        /**
1093         * A <i>read-only</i> sub-directory of a single contact that contains
1094         * the contact's primary photo.
1095         * <p>
1096         * Usage example:
1097         *
1098         * <pre>
1099         * public InputStream openPhoto(long contactId) {
1100         *     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
1101         *     Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
1102         *     Cursor cursor = getContentResolver().query(photoUri,
1103         *          new String[] {Contacts.Photo.PHOTO}, null, null, null);
1104         *     if (cursor == null) {
1105         *         return null;
1106         *     }
1107         *     try {
1108         *         if (cursor.moveToFirst()) {
1109         *             byte[] data = cursor.getBlob(0);
1110         *             if (data != null) {
1111         *                 return new ByteArrayInputStream(data);
1112         *             }
1113         *         }
1114         *     } finally {
1115         *         cursor.close();
1116         *     }
1117         *     return null;
1118         * }
1119         * </pre>
1120         *
1121         * </p>
1122         * <p>You should also consider using the convenience method
1123         * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri)}
1124         * </p>
1125         */
1126        // TODO: change DataColumns to DataColumnsWithJoins
1127        public static final class Photo implements BaseColumns, DataColumns {
1128            /**
1129             * no public constructor since this is a utility class
1130             */
1131            private Photo() {}
1132
1133            /**
1134             * The directory twig for this sub-table
1135             */
1136            public static final String CONTENT_DIRECTORY = "photo";
1137
1138            /**
1139             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1140             * that could be inflated using {@link android.graphics.BitmapFactory}.
1141             * <p>
1142             * Type: BLOB
1143             * @hide TODO: Unhide in a separate CL
1144             */
1145            public static final String PHOTO = DATA15;
1146        }
1147
1148        /**
1149         * Opens an InputStream for the contacts's default photo and returns the
1150         * photo as a byte stream. If there is not photo null will be returned.
1151         *
1152         * @param contactUri the contact whose photo should be used
1153         * @return an InputStream of the photo, or null if no photo is present
1154         */
1155        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
1156            Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
1157            if (photoUri == null) {
1158                return null;
1159            }
1160            Cursor cursor = cr.query(photoUri,
1161                    new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
1162            try {
1163                if (cursor == null || !cursor.moveToNext()) {
1164                    return null;
1165                }
1166                byte[] data = cursor.getBlob(0);
1167                if (data == null) {
1168                    return null;
1169                }
1170                return new ByteArrayInputStream(data);
1171            } finally {
1172                if (cursor != null) {
1173                    cursor.close();
1174                }
1175            }
1176        }
1177    }
1178
1179    protected interface RawContactsColumns {
1180        /**
1181         * A reference to the {@link ContactsContract.Contacts#_ID} that this
1182         * data belongs to.
1183         * <P>Type: INTEGER</P>
1184         */
1185        public static final String CONTACT_ID = "contact_id";
1186
1187        /**
1188         * Flag indicating that this {@link RawContacts} entry and its children have
1189         * been restricted to specific platform apps.
1190         * <P>Type: INTEGER (boolean)</P>
1191         *
1192         * @hide until finalized in future platform release
1193         */
1194        public static final String IS_RESTRICTED = "is_restricted";
1195
1196        /**
1197         * The aggregation mode for this contact.
1198         * <P>Type: INTEGER</P>
1199         */
1200        public static final String AGGREGATION_MODE = "aggregation_mode";
1201
1202        /**
1203         * The "deleted" flag: "0" by default, "1" if the row has been marked
1204         * for deletion. When {@link android.content.ContentResolver#delete} is
1205         * called on a raw contact, it is marked for deletion and removed from its
1206         * aggregate contact. The sync adaptor deletes the raw contact on the server and
1207         * then calls ContactResolver.delete once more, this time passing the
1208         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1209         * the data removal.
1210         * <P>Type: INTEGER</P>
1211         */
1212        public static final String DELETED = "deleted";
1213
1214        /**
1215         * The "name_verified" flag: "1" means that the name fields on this raw
1216         * contact can be trusted and therefore should be used for the entire
1217         * aggregated contact.
1218         * <p>
1219         * If an aggregated contact contains more than one raw contact with a
1220         * verified name, one of those verified names is chosen at random.
1221         * If an aggregated contact contains no verified names, the
1222         * name is chosen randomly from the constituent raw contacts.
1223         * </p>
1224         * <p>
1225         * Updating this flag from "0" to "1" automatically resets it to "0" on
1226         * all other raw contacts in the same aggregated contact.
1227         * </p>
1228         * <p>
1229         * Sync adapters should only specify a value for this column when
1230         * inserting a raw contact and leave it out when doing an update.
1231         * </p>
1232         * <p>
1233         * The default value is "0"
1234         * </p>
1235         * <p>Type: INTEGER</p>
1236         *
1237         * @hide
1238         */
1239        public static final String NAME_VERIFIED = "name_verified";
1240    }
1241
1242    /**
1243     * Constants for the raw contacts table, which contains one row of contact
1244     * information for each person in each synced account. Sync adapters and
1245     * contact management apps
1246     * are the primary consumers of this API.
1247     *
1248     * <h3>Aggregation</h3>
1249     * <p>
1250     * As soon as a raw contact is inserted or whenever its constituent data
1251     * changes, the provider will check if the raw contact matches other
1252     * existing raw contacts and if so will aggregate it with those. The
1253     * aggregation is reflected in the {@link RawContacts} table by the change of the
1254     * {@link #CONTACT_ID} field, which is the reference to the aggregate contact.
1255     * </p>
1256     * <p>
1257     * Changes to the structured name, organization, phone number, email address,
1258     * or nickname trigger a re-aggregation.
1259     * </p>
1260     * <p>
1261     * See also {@link AggregationExceptions} for a mechanism to control
1262     * aggregation programmatically.
1263     * </p>
1264     *
1265     * <h3>Operations</h3>
1266     * <dl>
1267     * <dt><b>Insert</b></dt>
1268     * <dd>
1269     * <p>
1270     * Raw contacts can be inserted incrementally or in a batch.
1271     * The incremental method is more traditional but less efficient.
1272     * It should be used
1273     * only if no {@link Data} values are available at the time the raw contact is created:
1274     * <pre>
1275     * ContentValues values = new ContentValues();
1276     * values.put(RawContacts.ACCOUNT_TYPE, accountType);
1277     * values.put(RawContacts.ACCOUNT_NAME, accountName);
1278     * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
1279     * long rawContactId = ContentUris.parseId(rawContactUri);
1280     * </pre>
1281     * </p>
1282     * <p>
1283     * Once {@link Data} values become available, insert those.
1284     * For example, here's how you would insert a name:
1285     *
1286     * <pre>
1287     * values.clear();
1288     * values.put(Data.RAW_CONTACT_ID, rawContactId);
1289     * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
1290     * values.put(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;);
1291     * getContentResolver().insert(Data.CONTENT_URI, values);
1292     * </pre>
1293     * </p>
1294     * <p>
1295     * The batch method is by far preferred.  It inserts the raw contact and its
1296     * constituent data rows in a single database transaction
1297     * and causes at most one aggregation pass.
1298     * <pre>
1299     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
1300     * ...
1301     * int rawContactInsertIndex = ops.size();
1302     * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
1303     *          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
1304     *          .withValue(RawContacts.ACCOUNT_NAME, accountName)
1305     *          .build());
1306     *
1307     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
1308     *          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
1309     *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
1310     *          .withValue(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;)
1311     *          .build());
1312     *
1313     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
1314     * </pre>
1315     * </p>
1316     * <p>
1317     * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)}
1318     * to refer to the as-yet-unknown index value of the raw contact inserted in the
1319     * first operation.
1320     * </p>
1321     *
1322     * <dt><b>Update</b></dt>
1323     * <dd><p>
1324     * Raw contacts can be updated incrementally or in a batch.
1325     * Batch mode should be used whenever possible.
1326     * The procedures and considerations are analogous to those documented above for inserts.
1327     * </p></dd>
1328     * <dt><b>Delete</b></dt>
1329     * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates,
1330     * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw
1331     * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row
1332     * itself is also deleted automatically.
1333     * </p>
1334     * <p>
1335     * The invocation of {@code resolver.delete(...)}, does not immediately delete
1336     * a raw contacts row.
1337     * Instead, it sets the {@link #DELETED} flag on the raw contact and
1338     * removes the raw contact from its aggregate contact.
1339     * The sync adapter then deletes the raw contact from the server and
1340     * finalizes phone-side deletion by calling {@code resolver.delete(...)}
1341     * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p>
1342     * <p>Some sync adapters are read-only, meaning that they only sync server-side
1343     * changes to the phone, but not the reverse.  If one of those raw contacts
1344     * is marked for deletion, it will remain on the phone.  However it will be
1345     * effectively invisible, because it will not be part of any aggregate contact.
1346     * </dd>
1347     *
1348     * <dt><b>Query</b></dt>
1349     * <dd>
1350     * <p>
1351     * It is easy to find all raw contacts in a Contact:
1352     * <pre>
1353     * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
1354     *          new String[]{RawContacts._ID},
1355     *          RawContacts.CONTACT_ID + "=?",
1356     *          new String[]{String.valueOf(contactId)}, null);
1357     * </pre>
1358     * </p>
1359     * <p>
1360     * To find raw contacts within a specific account,
1361     * you can either put the account name and type in the selection or pass them as query
1362     * parameters.  The latter approach is preferable, especially when you can reuse the
1363     * URI:
1364     * <pre>
1365     * Uri rawContactUri = RawContacts.URI.buildUpon()
1366     *          .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
1367     *          .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
1368     *          .build();
1369     * Cursor c1 = getContentResolver().query(rawContactUri,
1370     *          RawContacts.STARRED + "&lt;&gt;0", null, null, null);
1371     * ...
1372     * Cursor c2 = getContentResolver().query(rawContactUri,
1373     *          RawContacts.DELETED + "&lt;&gt;0", null, null, null);
1374     * </pre>
1375     * </p>
1376     * <p>The best way to read a raw contact along with all the data associated with it is
1377     * by using the {@link Entity} directory. If the raw contact has data rows,
1378     * the Entity cursor will contain a row for each data row.  If the raw contact has no
1379     * data rows, the cursor will still contain one row with the raw contact-level information.
1380     * <pre>
1381     * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
1382     * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
1383     * Cursor c = getContentResolver().query(entityUri,
1384     *          new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
1385     *          null, null, null);
1386     * try {
1387     *     while (c.moveToNext()) {
1388     *         String sourceId = c.getString(0);
1389     *         if (!c.isNull(1)) {
1390     *             String mimeType = c.getString(2);
1391     *             String data = c.getString(3);
1392     *             ...
1393     *         }
1394     *     }
1395     * } finally {
1396     *     c.close();
1397     * }
1398     * </pre>
1399     * </p>
1400     * </dd>
1401     * </dl>
1402     * <h2>Columns</h2>
1403     *
1404     * <table class="jd-sumtable">
1405     * <tr>
1406     * <th colspan='4'>RawContacts</th>
1407     * </tr>
1408     * <tr>
1409     * <td>long</td>
1410     * <td>{@link #_ID}</td>
1411     * <td>read-only</td>
1412     * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words,
1413     * it is much better for a sync adapter to update a raw contact rather than to delete and
1414     * re-insert it.</td>
1415     * </tr>
1416     * <tr>
1417     * <td>long</td>
1418     * <td>{@link #CONTACT_ID}</td>
1419     * <td>read-only</td>
1420     * <td>The ID of the row in the {@link ContactsContract.Contacts} table
1421     * that this raw contact belongs
1422     * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled
1423     * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td>
1424     * </tr>
1425     * <tr>
1426     * <td>int</td>
1427     * <td>{@link #AGGREGATION_MODE}</td>
1428     * <td>read/write</td>
1429     * <td>A mechanism that allows programmatic control of the aggregation process. The allowed
1430     * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED}
1431     * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td>
1432     * </tr>
1433     * <tr>
1434     * <td>int</td>
1435     * <td>{@link #DELETED}</td>
1436     * <td>read/write</td>
1437     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
1438     * for deletion. When {@link android.content.ContentResolver#delete} is
1439     * called on a raw contact, it is marked for deletion and removed from its
1440     * aggregate contact. The sync adaptor deletes the raw contact on the server and
1441     * then calls ContactResolver.delete once more, this time passing the
1442     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1443     * the data removal.</td>
1444     * </tr>
1445     * <tr>
1446     * <td>int</td>
1447     * <td>{@link #TIMES_CONTACTED}</td>
1448     * <td>read/write</td>
1449     * <td>The number of times the contact has been contacted. To have an effect
1450     * on the corresponding value of the aggregate contact, this field
1451     * should be set at the time the raw contact is inserted.
1452     * After that, this value is typically updated via
1453     * {@link ContactsContract.Contacts#markAsContacted}.</td>
1454     * </tr>
1455     * <tr>
1456     * <td>long</td>
1457     * <td>{@link #LAST_TIME_CONTACTED}</td>
1458     * <td>read/write</td>
1459     * <td>The timestamp of the last time the contact was contacted. To have an effect
1460     * on the corresponding value of the aggregate contact, this field
1461     * should be set at the time the raw contact is inserted.
1462     * After that, this value is typically updated via
1463     * {@link ContactsContract.Contacts#markAsContacted}.
1464     * </td>
1465     * </tr>
1466     * <tr>
1467     * <td>int</td>
1468     * <td>{@link #STARRED}</td>
1469     * <td>read/write</td>
1470     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
1471     * Changing this field immediately affects the corresponding aggregate contact:
1472     * if any raw contacts in that aggregate contact are starred, then the contact
1473     * itself is marked as starred.</td>
1474     * </tr>
1475     * <tr>
1476     * <td>String</td>
1477     * <td>{@link #CUSTOM_RINGTONE}</td>
1478     * <td>read/write</td>
1479     * <td>A custom ringtone associated with a raw contact. Typically this is the
1480     * URI returned by an activity launched with the
1481     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.
1482     * To have an effect on the corresponding value of the aggregate contact, this field
1483     * should be set at the time the raw contact is inserted. To set a custom
1484     * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE
1485     * Contacts.CUSTOM_RINGTONE}
1486     * instead.</td>
1487     * </tr>
1488     * <tr>
1489     * <td>int</td>
1490     * <td>{@link #SEND_TO_VOICEMAIL}</td>
1491     * <td>read/write</td>
1492     * <td>An indicator of whether calls from this raw contact should be forwarded
1493     * directly to voice mail ('1') or not ('0'). To have an effect
1494     * on the corresponding value of the aggregate contact, this field
1495     * should be set at the time the raw contact is inserted.</td>
1496     * </tr>
1497     * <tr>
1498     * <td>String</td>
1499     * <td>{@link #ACCOUNT_NAME}</td>
1500     * <td>read/write-once</td>
1501     * <td>The name of the account instance to which this row belongs, which when paired with
1502     * {@link #ACCOUNT_TYPE} identifies a specific account.
1503     * For example, this will be the Gmail address if it is a Google account.
1504     * It should be set at the time
1505     * the raw contact is inserted and never changed afterwards.</td>
1506     * </tr>
1507     * <tr>
1508     * <td>String</td>
1509     * <td>{@link #ACCOUNT_TYPE}</td>
1510     * <td>read/write-once</td>
1511     * <td>
1512     * <p>
1513     * The type of account to which this row belongs, which when paired with
1514     * {@link #ACCOUNT_NAME} identifies a specific account.
1515     * It should be set at the time
1516     * the raw contact is inserted and never changed afterwards.
1517     * </p>
1518     * <p>
1519     * To ensure uniqueness, new account types should be chosen according to the
1520     * Java package naming convention.  Thus a Google account is of type "com.google".
1521     * </p>
1522     * </td>
1523     * </tr>
1524     * <tr>
1525     * <td>String</td>
1526     * <td>{@link #SOURCE_ID}</td>
1527     * <td>read/write</td>
1528     * <td>String that uniquely identifies this row to its source account.
1529     * Typically it is set at the time the raw contact is inserted and never
1530     * changed afterwards. The one notable exception is a new raw contact: it
1531     * will have an account name and type, but no source id. This
1532     * indicates to the sync adapter that a new contact needs to be created
1533     * server-side and its ID stored in the corresponding SOURCE_ID field on
1534     * the phone.
1535     * </td>
1536     * </tr>
1537     * <tr>
1538     * <td>int</td>
1539     * <td>{@link #VERSION}</td>
1540     * <td>read-only</td>
1541     * <td>Version number that is updated whenever this row or its related data
1542     * changes. This field can be used for optimistic locking of a raw contact.
1543     * </td>
1544     * </tr>
1545     * <tr>
1546     * <td>int</td>
1547     * <td>{@link #DIRTY}</td>
1548     * <td>read/write</td>
1549     * <td>Flag indicating that {@link #VERSION} has changed, and this row needs
1550     * to be synchronized by its owning account.  The value is set to "1" automatically
1551     * whenever the raw contact changes, unless the URI has the
1552     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified.
1553     * The sync adapter should always supply this query parameter to prevent
1554     * unnecessary synchronization: user changes some data on the server,
1555     * the sync adapter updates the contact on the phone (without the
1556     * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag,
1557     * which triggers a sync to bring the changes to the server.
1558     * </td>
1559     * </tr>
1560     * <tr>
1561     * <td>String</td>
1562     * <td>{@link #SYNC1}</td>
1563     * <td>read/write</td>
1564     * <td>Generic column provided for arbitrary use by sync adapters.
1565     * The content provider
1566     * stores this information on behalf of the sync adapter but does not
1567     * interpret it in any way.
1568     * </td>
1569     * </tr>
1570     * <tr>
1571     * <td>String</td>
1572     * <td>{@link #SYNC2}</td>
1573     * <td>read/write</td>
1574     * <td>Generic column for use by sync adapters.
1575     * </td>
1576     * </tr>
1577     * <tr>
1578     * <td>String</td>
1579     * <td>{@link #SYNC3}</td>
1580     * <td>read/write</td>
1581     * <td>Generic column for use by sync adapters.
1582     * </td>
1583     * </tr>
1584     * <tr>
1585     * <td>String</td>
1586     * <td>{@link #SYNC4}</td>
1587     * <td>read/write</td>
1588     * <td>Generic column for use by sync adapters.
1589     * </td>
1590     * </tr>
1591     * </table>
1592     */
1593    public static final class RawContacts implements BaseColumns, RawContactsColumns,
1594            ContactOptionsColumns, ContactNameColumns, SyncColumns  {
1595        /**
1596         * This utility class cannot be instantiated
1597         */
1598        private RawContacts() {
1599        }
1600
1601        /**
1602         * The content:// style URI for this table, which requests a directory of
1603         * raw contact rows matching the selection criteria.
1604         */
1605        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
1606
1607        /**
1608         * The MIME type of the results from {@link #CONTENT_URI} when a specific
1609         * ID value is not provided, and multiple raw contacts may be returned.
1610         */
1611        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
1612
1613        /**
1614         * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI},
1615         * yielding a subdirectory of a single person.
1616         */
1617        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
1618
1619        /**
1620         * Aggregation mode: aggregate immediately after insert or update operation(s) are complete.
1621         */
1622        public static final int AGGREGATION_MODE_DEFAULT = 0;
1623
1624        /**
1625         * Do not use.
1626         *
1627         * TODO: deprecate in favor of {@link #AGGREGATION_MODE_DEFAULT}
1628         */
1629        public static final int AGGREGATION_MODE_IMMEDIATE = 1;
1630
1631        /**
1632         * <p>
1633         * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later.
1634         * Changes to the raw contact will update the associated aggregate contact but will not
1635         * result in any change in how the contact is aggregated. Similar to
1636         * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding
1637         * {@link Contacts} aggregate.
1638         * </p>
1639         * <p>
1640         * This can be used to postpone aggregation until after a series of updates, for better
1641         * performance and/or user experience.
1642         * </p>
1643         * <p>
1644         * Note that changing
1645         * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to
1646         * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any
1647         * subsequent
1648         * change to the raw contact's data will.
1649         * </p>
1650         */
1651        public static final int AGGREGATION_MODE_SUSPENDED = 2;
1652
1653        /**
1654         * <p>
1655         * Aggregation mode: never aggregate this raw contact.  The raw contact will not
1656         * have a corresponding {@link Contacts} aggregate and therefore will not be included in
1657         * {@link Contacts} query results.
1658         * </p>
1659         * <p>
1660         * For example, this mode can be used for a raw contact that is marked for deletion while
1661         * waiting for the deletion to occur on the server side.
1662         * </p>
1663         *
1664         * @see #AGGREGATION_MODE_SUSPENDED
1665         */
1666        public static final int AGGREGATION_MODE_DISABLED = 3;
1667
1668        /**
1669         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
1670         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
1671         * entry of the given {@link RawContacts} entry.
1672         */
1673        public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) {
1674            // TODO: use a lighter query by joining rawcontacts with contacts in provider
1675            final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY);
1676            final Cursor cursor = resolver.query(dataUri, new String[] {
1677                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
1678            }, null, null, null);
1679
1680            Uri lookupUri = null;
1681            try {
1682                if (cursor != null && cursor.moveToFirst()) {
1683                    final long contactId = cursor.getLong(0);
1684                    final String lookupKey = cursor.getString(1);
1685                    return Contacts.getLookupUri(contactId, lookupKey);
1686                }
1687            } finally {
1688                if (cursor != null) cursor.close();
1689            }
1690            return lookupUri;
1691        }
1692
1693        /**
1694         * A sub-directory of a single raw contact that contains all of its
1695         * {@link ContactsContract.Data} rows. To access this directory
1696         * append {@link Data#CONTENT_DIRECTORY} to the contact URI.
1697         *
1698         * TODO: deprecate in favor of {@link RawContacts.Entity}.
1699         */
1700        public static final class Data implements BaseColumns, DataColumns {
1701            /**
1702             * no public constructor since this is a utility class
1703             */
1704            private Data() {
1705            }
1706
1707            /**
1708             * The directory twig for this sub-table
1709             */
1710            public static final String CONTENT_DIRECTORY = "data";
1711        }
1712
1713        /**
1714         * <p>
1715         * A sub-directory of a single raw contact that contains all of its
1716         * {@link ContactsContract.Data} rows. To access this directory append
1717         * {@link #CONTENT_DIRECTORY} to the contact URI. See
1718         * {@link RawContactsEntity} for a stand-alone table containing the same
1719         * data.
1720         * </p>
1721         * <p>
1722         * Entity has two ID fields: {@link #_ID} for the raw contact
1723         * and {@link #DATA_ID} for the data rows.
1724         * Entity always contains at least one row, even if there are no
1725         * actual data rows. In this case the {@link #DATA_ID} field will be
1726         * null.
1727         * </p>
1728         * <p>
1729         * Entity reads all
1730         * data for a raw contact in one transaction, to guarantee
1731         * consistency.
1732         * </p>
1733         */
1734        public static final class Entity implements BaseColumns, DataColumns {
1735            /**
1736             * no public constructor since this is a utility class
1737             */
1738            private Entity() {
1739            }
1740
1741            /**
1742             * The directory twig for this sub-table
1743             */
1744            public static final String CONTENT_DIRECTORY = "entity";
1745
1746            /**
1747             * The ID of the data column. The value will be null if this raw contact has no
1748             * data rows.
1749             * <P>Type: INTEGER</P>
1750             */
1751            public static final String DATA_ID = "data_id";
1752        }
1753
1754        /**
1755         * TODO: javadoc
1756         * @param cursor
1757         * @return
1758         */
1759        public static EntityIterator newEntityIterator(Cursor cursor) {
1760            return new EntityIteratorImpl(cursor);
1761        }
1762
1763        private static class EntityIteratorImpl extends CursorEntityIterator {
1764            private static final String[] DATA_KEYS = new String[]{
1765                    Data.DATA1,
1766                    Data.DATA2,
1767                    Data.DATA3,
1768                    Data.DATA4,
1769                    Data.DATA5,
1770                    Data.DATA6,
1771                    Data.DATA7,
1772                    Data.DATA8,
1773                    Data.DATA9,
1774                    Data.DATA10,
1775                    Data.DATA11,
1776                    Data.DATA12,
1777                    Data.DATA13,
1778                    Data.DATA14,
1779                    Data.DATA15,
1780                    Data.SYNC1,
1781                    Data.SYNC2,
1782                    Data.SYNC3,
1783                    Data.SYNC4};
1784
1785            public EntityIteratorImpl(Cursor cursor) {
1786                super(cursor);
1787            }
1788
1789            @Override
1790            public android.content.Entity getEntityAndIncrementCursor(Cursor cursor)
1791                    throws RemoteException {
1792                final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID);
1793                final long rawContactId = cursor.getLong(columnRawContactId);
1794
1795                // we expect the cursor is already at the row we need to read from
1796                ContentValues cv = new ContentValues();
1797                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
1798                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
1799                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID);
1800                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
1801                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION);
1802                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID);
1803                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1);
1804                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2);
1805                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3);
1806                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4);
1807                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED);
1808                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID);
1809                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED);
1810                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED);
1811                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED);
1812                android.content.Entity contact = new android.content.Entity(cv);
1813
1814                // read data rows until the contact id changes
1815                do {
1816                    if (rawContactId != cursor.getLong(columnRawContactId)) {
1817                        break;
1818                    }
1819                    // add the data to to the contact
1820                    cv = new ContentValues();
1821                    cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID)));
1822                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1823                            Data.RES_PACKAGE);
1824                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE);
1825                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY);
1826                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
1827                            Data.IS_SUPER_PRIMARY);
1828                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION);
1829                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1830                            CommonDataKinds.GroupMembership.GROUP_SOURCE_ID);
1831                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1832                            Data.DATA_VERSION);
1833                    for (String key : DATA_KEYS) {
1834                        final int columnIndex = cursor.getColumnIndexOrThrow(key);
1835                        if (cursor.isNull(columnIndex)) {
1836                            // don't put anything
1837                        } else {
1838                            try {
1839                                cv.put(key, cursor.getString(columnIndex));
1840                            } catch (SQLiteException e) {
1841                                cv.put(key, cursor.getBlob(columnIndex));
1842                            }
1843                        }
1844                        // TODO: go back to this version of the code when bug
1845                        // http://b/issue?id=2306370 is fixed.
1846//                        if (cursor.isNull(columnIndex)) {
1847//                            // don't put anything
1848//                        } else if (cursor.isLong(columnIndex)) {
1849//                            values.put(key, cursor.getLong(columnIndex));
1850//                        } else if (cursor.isFloat(columnIndex)) {
1851//                            values.put(key, cursor.getFloat(columnIndex));
1852//                        } else if (cursor.isString(columnIndex)) {
1853//                            values.put(key, cursor.getString(columnIndex));
1854//                        } else if (cursor.isBlob(columnIndex)) {
1855//                            values.put(key, cursor.getBlob(columnIndex));
1856//                        }
1857                    }
1858                    contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv);
1859                } while (cursor.moveToNext());
1860
1861                return contact;
1862            }
1863
1864        }
1865    }
1866
1867    /**
1868     * Social status update columns.
1869     *
1870     * @see StatusUpdates
1871     * @see ContactsContract.Data
1872     */
1873    protected interface StatusColumns {
1874        /**
1875         * Contact's latest presence level.
1876         * <P>Type: INTEGER (one of the values below)</P>
1877         */
1878        public static final String PRESENCE = "mode";
1879
1880        /**
1881         * @deprecated use {@link #PRESENCE}
1882         */
1883        @Deprecated
1884        public static final String PRESENCE_STATUS = PRESENCE;
1885
1886        /**
1887         * An allowed value of {@link #PRESENCE}.
1888         */
1889        int OFFLINE = 0;
1890
1891        /**
1892         * An allowed value of {@link #PRESENCE}.
1893         */
1894        int INVISIBLE = 1;
1895
1896        /**
1897         * An allowed value of {@link #PRESENCE}.
1898         */
1899        int AWAY = 2;
1900
1901        /**
1902         * An allowed value of {@link #PRESENCE}.
1903         */
1904        int IDLE = 3;
1905
1906        /**
1907         * An allowed value of {@link #PRESENCE}.
1908         */
1909        int DO_NOT_DISTURB = 4;
1910
1911        /**
1912         * An allowed value of {@link #PRESENCE}.
1913         */
1914        int AVAILABLE = 5;
1915
1916        /**
1917         * Contact latest status update.
1918         * <p>Type: TEXT</p>
1919         */
1920        public static final String STATUS = "status";
1921
1922        /**
1923         * @deprecated use {@link #STATUS}
1924         */
1925        @Deprecated
1926        public static final String PRESENCE_CUSTOM_STATUS = STATUS;
1927
1928        /**
1929         * The absolute time in milliseconds when the latest status was inserted/updated.
1930         * <p>Type: NUMBER</p>
1931         */
1932        public static final String STATUS_TIMESTAMP = "status_ts";
1933
1934        /**
1935         * The package containing resources for this status: label and icon.
1936         * <p>Type: NUMBER</p>
1937         */
1938        public static final String STATUS_RES_PACKAGE = "status_res_package";
1939
1940        /**
1941         * The resource ID of the label describing the source of the status update, e.g. "Google
1942         * Talk".  This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
1943         * <p>Type: NUMBER</p>
1944         */
1945        public static final String STATUS_LABEL = "status_label";
1946
1947        /**
1948         * The resource ID of the icon for the source of the status update.
1949         * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
1950         * <p>Type: NUMBER</p>
1951         */
1952        public static final String STATUS_ICON = "status_icon";
1953    }
1954
1955    /**
1956     * Columns in the Data table.
1957     *
1958     * @see ContactsContract.Data
1959     */
1960    protected interface DataColumns {
1961        /**
1962         * The package name to use when creating {@link Resources} objects for
1963         * this data row. This value is only designed for use when building user
1964         * interfaces, and should not be used to infer the owner.
1965         *
1966         * @hide
1967         */
1968        public static final String RES_PACKAGE = "res_package";
1969
1970        /**
1971         * The MIME type of the item represented by this row.
1972         */
1973        public static final String MIMETYPE = "mimetype";
1974
1975        /**
1976         * A reference to the {@link RawContacts#_ID}
1977         * that this data belongs to.
1978         */
1979        public static final String RAW_CONTACT_ID = "raw_contact_id";
1980
1981        /**
1982         * Whether this is the primary entry of its kind for the raw contact it belongs to.
1983         * <P>Type: INTEGER (if set, non-0 means true)</P>
1984         */
1985        public static final String IS_PRIMARY = "is_primary";
1986
1987        /**
1988         * Whether this is the primary entry of its kind for the aggregate
1989         * contact it belongs to. Any data record that is "super primary" must
1990         * also be "primary".
1991         * <P>Type: INTEGER (if set, non-0 means true)</P>
1992         */
1993        public static final String IS_SUPER_PRIMARY = "is_super_primary";
1994
1995        /**
1996         * The version of this data record. This is a read-only value. The data column is
1997         * guaranteed to not change without the version going up. This value is monotonically
1998         * increasing.
1999         * <P>Type: INTEGER</P>
2000         */
2001        public static final String DATA_VERSION = "data_version";
2002
2003        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2004        public static final String DATA1 = "data1";
2005        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2006        public static final String DATA2 = "data2";
2007        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2008        public static final String DATA3 = "data3";
2009        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2010        public static final String DATA4 = "data4";
2011        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2012        public static final String DATA5 = "data5";
2013        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2014        public static final String DATA6 = "data6";
2015        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2016        public static final String DATA7 = "data7";
2017        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2018        public static final String DATA8 = "data8";
2019        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2020        public static final String DATA9 = "data9";
2021        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2022        public static final String DATA10 = "data10";
2023        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2024        public static final String DATA11 = "data11";
2025        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2026        public static final String DATA12 = "data12";
2027        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2028        public static final String DATA13 = "data13";
2029        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2030        public static final String DATA14 = "data14";
2031        /**
2032         * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention,
2033         * this field is used to store BLOBs (binary data).
2034         */
2035        public static final String DATA15 = "data15";
2036
2037        /** Generic column for use by sync adapters. */
2038        public static final String SYNC1 = "data_sync1";
2039        /** Generic column for use by sync adapters. */
2040        public static final String SYNC2 = "data_sync2";
2041        /** Generic column for use by sync adapters. */
2042        public static final String SYNC3 = "data_sync3";
2043        /** Generic column for use by sync adapters. */
2044        public static final String SYNC4 = "data_sync4";
2045    }
2046
2047    /**
2048     * Combines all columns returned by {@link ContactsContract.Data} table queries.
2049     *
2050     * @see ContactsContract.Data
2051     */
2052    protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns,
2053            RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns,
2054            ContactStatusColumns {
2055    }
2056
2057    /**
2058     * <p>
2059     * Constants for the data table, which contains data points tied to a raw
2060     * contact.  Each row of the data table is typically used to store a single
2061     * piece of contact
2062     * information (such as a phone number) and its
2063     * associated metadata (such as whether it is a work or home number).
2064     * </p>
2065     * <h3>Data kinds</h3>
2066     * <p>
2067     * Data is a generic table that can hold any kind of contact data.
2068     * The kind of data stored in a given row is specified by the row's
2069     * {@link #MIMETYPE} value, which determines the meaning of the
2070     * generic columns {@link #DATA1} through
2071     * {@link #DATA15}.
2072     * For example, if the data kind is
2073     * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column
2074     * {@link #DATA1} stores the
2075     * phone number, but if the data kind is
2076     * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1}
2077     * stores the email address.
2078     * Sync adapters and applications can introduce their own data kinds.
2079     * </p>
2080     * <p>
2081     * ContactsContract defines a small number of pre-defined data kinds, e.g.
2082     * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a
2083     * convenience, these classes define data kind specific aliases for DATA1 etc.
2084     * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as
2085     * {@link ContactsContract.Data Data.DATA1}.
2086     * </p>
2087     * <p>
2088     * {@link #DATA1} is an indexed column and should be used for the data element that is
2089     * expected to be most frequently used in query selections. For example, in the
2090     * case of a row representing email addresses {@link #DATA1} should probably
2091     * be used for the email address itself, while {@link #DATA2} etc can be
2092     * used for auxiliary information like type of email address.
2093     * <p>
2094     * <p>
2095     * By convention, {@link #DATA15} is used for storing BLOBs (binary data).
2096     * </p>
2097     * <p>
2098     * The sync adapter for a given account type must correctly handle every data type
2099     * used in the corresponding raw contacts.  Otherwise it could result in lost or
2100     * corrupted data.
2101     * </p>
2102     * <p>
2103     * Similarly, you should refrain from introducing new kinds of data for an other
2104     * party's account types. For example, if you add a data row for
2105     * "favorite song" to a raw contact owned by a Google account, it will not
2106     * get synced to the server, because the Google sync adapter does not know
2107     * how to handle this data kind. Thus new data kinds are typically
2108     * introduced along with new account types, i.e. new sync adapters.
2109     * </p>
2110     * <h3>Batch operations</h3>
2111     * <p>
2112     * Data rows can be inserted/updated/deleted using the traditional
2113     * {@link ContentResolver#insert}, {@link ContentResolver#update} and
2114     * {@link ContentResolver#delete} methods, however the newer mechanism based
2115     * on a batch of {@link ContentProviderOperation} will prove to be a better
2116     * choice in almost all cases. All operations in a batch are executed in a
2117     * single transaction, which ensures that the phone-side and server-side
2118     * state of a raw contact are always consistent. Also, the batch-based
2119     * approach is far more efficient: not only are the database operations
2120     * faster when executed in a single transaction, but also sending a batch of
2121     * commands to the content provider saves a lot of time on context switching
2122     * between your process and the process in which the content provider runs.
2123     * </p>
2124     * <p>
2125     * The flip side of using batched operations is that a large batch may lock
2126     * up the database for a long time preventing other applications from
2127     * accessing data and potentially causing ANRs ("Application Not Responding"
2128     * dialogs.)
2129     * </p>
2130     * <p>
2131     * To avoid such lockups of the database, make sure to insert "yield points"
2132     * in the batch. A yield point indicates to the content provider that before
2133     * executing the next operation it can commit the changes that have already
2134     * been made, yield to other requests, open another transaction and continue
2135     * processing operations. A yield point will not automatically commit the
2136     * transaction, but only if there is another request waiting on the
2137     * database. Normally a sync adapter should insert a yield point at the
2138     * beginning of each raw contact operation sequence in the batch. See
2139     * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}.
2140     * </p>
2141     * <h3>Operations</h3>
2142     * <dl>
2143     * <dt><b>Insert</b></dt>
2144     * <dd>
2145     * <p>
2146     * An individual data row can be inserted using the traditional
2147     * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows
2148     * should always be inserted as a batch.
2149     * </p>
2150     * <p>
2151     * An example of a traditional insert:
2152     * <pre>
2153     * ContentValues values = new ContentValues();
2154     * values.put(Data.RAW_CONTACT_ID, rawContactId);
2155     * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
2156     * values.put(Phone.NUMBER, "1-800-GOOG-411");
2157     * values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
2158     * values.put(Phone.LABEL, "free directory assistance");
2159     * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
2160     * </pre>
2161     * <p>
2162     * The same done using ContentProviderOperations:
2163     * <pre>
2164     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2165     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
2166     *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
2167     *          .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
2168     *          .withValue(Phone.NUMBER, "1-800-GOOG-411")
2169     *          .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
2170     *          .withValue(Phone.LABEL, "free directory assistance")
2171     *          .build());
2172     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2173     * </pre>
2174     * </p>
2175     * <dt><b>Update</b></dt>
2176     * <dd>
2177     * <p>
2178     * Just as with insert, update can be done incrementally or as a batch,
2179     * the batch mode being the preferred method:
2180     * <pre>
2181     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2182     * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
2183     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
2184     *          .withValue(Email.DATA, "somebody@android.com")
2185     *          .build());
2186     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2187     * </pre>
2188     * </p>
2189     * </dd>
2190     * <dt><b>Delete</b></dt>
2191     * <dd>
2192     * <p>
2193     * Just as with insert and update, deletion can be done either using the
2194     * {@link ContentResolver#delete} method or using a ContentProviderOperation:
2195     * <pre>
2196     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2197     * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
2198     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
2199     *          .build());
2200     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2201     * </pre>
2202     * </p>
2203     * </dd>
2204     * <dt><b>Query</b></dt>
2205     * <dd>
2206     * <p>
2207     * <dl>
2208     * <dt>Finding all Data of a given type for a given contact</dt>
2209     * <dd>
2210     * <pre>
2211     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
2212     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
2213     *          Data.CONTACT_ID + &quot;=?&quot; + " AND "
2214     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
2215     *          new String[] {String.valueOf(contactId)}, null);
2216     * </pre>
2217     * </p>
2218     * <p>
2219     * </dd>
2220     * <dt>Finding all Data of a given type for a given raw contact</dt>
2221     * <dd>
2222     * <pre>
2223     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
2224     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
2225     *          Data.RAW_CONTACT_ID + &quot;=?&quot; + " AND "
2226     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
2227     *          new String[] {String.valueOf(rawContactId)}, null);
2228     * </pre>
2229     * </dd>
2230     * <dt>Finding all Data for a given raw contact</dt>
2231     * <dd>
2232     * Most sync adapters will want to read all data rows for a raw contact
2233     * along with the raw contact itself.  For that you should use the
2234     * {@link RawContactsEntity}. See also {@link RawContacts}.
2235     * </dd>
2236     * </dl>
2237     * </p>
2238     * </dd>
2239     * </dl>
2240     * <h2>Columns</h2>
2241     * <p>
2242     * Many columns are available via a {@link Data#CONTENT_URI} query.  For best performance you
2243     * should explicitly specify a projection to only those columns that you need.
2244     * </p>
2245     * <table class="jd-sumtable">
2246     * <tr>
2247     * <th colspan='4'>Data</th>
2248     * </tr>
2249     * <tr>
2250     * <td style="width: 7em;">long</td>
2251     * <td style="width: 20em;">{@link #_ID}</td>
2252     * <td style="width: 5em;">read-only</td>
2253     * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words,
2254     * it would be a bad idea to delete and reinsert a data row. A sync adapter should
2255     * always do an update instead.</td>
2256     * </tr>
2257     * <tr>
2258     * <td>String</td>
2259     * <td>{@link #MIMETYPE}</td>
2260     * <td>read/write-once</td>
2261     * <td>
2262     * <p>The MIME type of the item represented by this row. Examples of common
2263     * MIME types are:
2264     * <ul>
2265     * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li>
2266     * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li>
2267     * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li>
2268     * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li>
2269     * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li>
2270     * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li>
2271     * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li>
2272     * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li>
2273     * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li>
2274     * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li>
2275     * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li>
2276     * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li>
2277     * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li>
2278     * </ul>
2279     * </p>
2280     * </td>
2281     * </tr>
2282     * <tr>
2283     * <td>long</td>
2284     * <td>{@link #RAW_CONTACT_ID}</td>
2285     * <td>read/write-once</td>
2286     * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td>
2287     * </tr>
2288     * <tr>
2289     * <td>int</td>
2290     * <td>{@link #IS_PRIMARY}</td>
2291     * <td>read/write</td>
2292     * <td>Whether this is the primary entry of its kind for the raw contact it belongs to.
2293     * "1" if true, "0" if false.
2294     * </td>
2295     * </tr>
2296     * <tr>
2297     * <td>int</td>
2298     * <td>{@link #IS_SUPER_PRIMARY}</td>
2299     * <td>read/write</td>
2300     * <td>Whether this is the primary entry of its kind for the aggregate
2301     * contact it belongs to. Any data record that is "super primary" must
2302     * also be "primary".  For example, the super-primary entry may be
2303     * interpreted as the default contact value of its kind (for example,
2304     * the default phone number to use for the contact).</td>
2305     * </tr>
2306     * <tr>
2307     * <td>int</td>
2308     * <td>{@link #DATA_VERSION}</td>
2309     * <td>read-only</td>
2310     * <td>The version of this data record. Whenever the data row changes
2311     * the version goes up. This value is monotonically increasing.</td>
2312     * </tr>
2313     * <tr>
2314     * <td>Any type</td>
2315     * <td>
2316     * {@link #DATA1}<br>
2317     * {@link #DATA2}<br>
2318     * {@link #DATA3}<br>
2319     * {@link #DATA4}<br>
2320     * {@link #DATA5}<br>
2321     * {@link #DATA6}<br>
2322     * {@link #DATA7}<br>
2323     * {@link #DATA8}<br>
2324     * {@link #DATA9}<br>
2325     * {@link #DATA10}<br>
2326     * {@link #DATA11}<br>
2327     * {@link #DATA12}<br>
2328     * {@link #DATA13}<br>
2329     * {@link #DATA14}<br>
2330     * {@link #DATA15}
2331     * </td>
2332     * <td>read/write</td>
2333     * <td>
2334     * <p>
2335     * Generic data columns.  The meaning of each column is determined by the
2336     * {@link #MIMETYPE}.  By convention, {@link #DATA15} is used for storing
2337     * BLOBs (binary data).
2338     * </p>
2339     * <p>
2340     * Data columns whose meaning is not explicitly defined for a given MIMETYPE
2341     * should not be used.  There is no guarantee that any sync adapter will
2342     * preserve them.  Sync adapters themselves should not use such columns either,
2343     * but should instead use {@link #SYNC1}-{@link #SYNC4}.
2344     * </p>
2345     * </td>
2346     * </tr>
2347     * <tr>
2348     * <td>Any type</td>
2349     * <td>
2350     * {@link #SYNC1}<br>
2351     * {@link #SYNC2}<br>
2352     * {@link #SYNC3}<br>
2353     * {@link #SYNC4}
2354     * </td>
2355     * <td>read/write</td>
2356     * <td>Generic columns for use by sync adapters. For example, a Photo row
2357     * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error)
2358     * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td>
2359     * </tr>
2360     * </table>
2361     *
2362     * <p>
2363     * Some columns from the most recent associated status update are also available
2364     * through an implicit join.
2365     * </p>
2366     * <table class="jd-sumtable">
2367     * <tr>
2368     * <th colspan='4'>Join with {@link StatusUpdates}</th>
2369     * </tr>
2370     * <tr>
2371     * <td style="width: 7em;">int</td>
2372     * <td style="width: 20em;">{@link #PRESENCE}</td>
2373     * <td style="width: 5em;">read-only</td>
2374     * <td>IM presence status linked to this data row. Compare with
2375     * {@link #CONTACT_PRESENCE}, which contains the contact's presence across
2376     * all IM rows. See {@link StatusUpdates} for individual status definitions.
2377     * The provider may choose not to store this value
2378     * in persistent storage. The expectation is that presence status will be
2379     * updated on a regular basic.
2380     * </td>
2381     * </tr>
2382     * <tr>
2383     * <td>String</td>
2384     * <td>{@link #STATUS}</td>
2385     * <td>read-only</td>
2386     * <td>Latest status update linked with this data row.</td>
2387     * </tr>
2388     * <tr>
2389     * <td>long</td>
2390     * <td>{@link #STATUS_TIMESTAMP}</td>
2391     * <td>read-only</td>
2392     * <td>The absolute time in milliseconds when the latest status was
2393     * inserted/updated for this data row.</td>
2394     * </tr>
2395     * <tr>
2396     * <td>String</td>
2397     * <td>{@link #STATUS_RES_PACKAGE}</td>
2398     * <td>read-only</td>
2399     * <td>The package containing resources for this status: label and icon.</td>
2400     * </tr>
2401     * <tr>
2402     * <td>long</td>
2403     * <td>{@link #STATUS_LABEL}</td>
2404     * <td>read-only</td>
2405     * <td>The resource ID of the label describing the source of status update linked
2406     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
2407     * </tr>
2408     * <tr>
2409     * <td>long</td>
2410     * <td>{@link #STATUS_ICON}</td>
2411     * <td>read-only</td>
2412     * <td>The resource ID of the icon for the source of the status update linked
2413     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
2414     * </tr>
2415     * </table>
2416     *
2417     * <p>
2418     * Some columns from the associated raw contact are also available through an
2419     * implicit join.  The other columns are excluded as uninteresting in this
2420     * context.
2421     * </p>
2422     *
2423     * <table class="jd-sumtable">
2424     * <tr>
2425     * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th>
2426     * </tr>
2427     * <tr>
2428     * <td style="width: 7em;">long</td>
2429     * <td style="width: 20em;">{@link #CONTACT_ID}</td>
2430     * <td style="width: 5em;">read-only</td>
2431     * <td>The id of the row in the {@link Contacts} table that this data belongs
2432     * to.</td>
2433     * </tr>
2434     * <tr>
2435     * <td>int</td>
2436     * <td>{@link #AGGREGATION_MODE}</td>
2437     * <td>read-only</td>
2438     * <td>See {@link RawContacts}.</td>
2439     * </tr>
2440     * <tr>
2441     * <td>int</td>
2442     * <td>{@link #DELETED}</td>
2443     * <td>read-only</td>
2444     * <td>See {@link RawContacts}.</td>
2445     * </tr>
2446     * </table>
2447     *
2448     * <p>
2449     * The ID column for the associated aggregated contact table
2450     * {@link ContactsContract.Contacts} is available
2451     * via the implicit join to the {@link RawContacts} table, see above.
2452     * The remaining columns from this table are also
2453     * available, through an implicit join.  This
2454     * facilitates lookup by
2455     * the value of a single data element, such as the email address.
2456     * </p>
2457     *
2458     * <table class="jd-sumtable">
2459     * <tr>
2460     * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th>
2461     * </tr>
2462     * <tr>
2463     * <td style="width: 7em;">String</td>
2464     * <td style="width: 20em;">{@link #LOOKUP_KEY}</td>
2465     * <td style="width: 5em;">read-only</td>
2466     * <td>See {@link ContactsContract.Contacts}</td>
2467     * </tr>
2468     * <tr>
2469     * <td>String</td>
2470     * <td>{@link #DISPLAY_NAME}</td>
2471     * <td>read-only</td>
2472     * <td>See {@link ContactsContract.Contacts}</td>
2473     * </tr>
2474     * <tr>
2475     * <td>long</td>
2476     * <td>{@link #PHOTO_ID}</td>
2477     * <td>read-only</td>
2478     * <td>See {@link ContactsContract.Contacts}.</td>
2479     * </tr>
2480     * <tr>
2481     * <td>int</td>
2482     * <td>{@link #IN_VISIBLE_GROUP}</td>
2483     * <td>read-only</td>
2484     * <td>See {@link ContactsContract.Contacts}.</td>
2485     * </tr>
2486     * <tr>
2487     * <td>int</td>
2488     * <td>{@link #HAS_PHONE_NUMBER}</td>
2489     * <td>read-only</td>
2490     * <td>See {@link ContactsContract.Contacts}.</td>
2491     * </tr>
2492     * <tr>
2493     * <td>int</td>
2494     * <td>{@link #TIMES_CONTACTED}</td>
2495     * <td>read-only</td>
2496     * <td>See {@link ContactsContract.Contacts}.</td>
2497     * </tr>
2498     * <tr>
2499     * <td>long</td>
2500     * <td>{@link #LAST_TIME_CONTACTED}</td>
2501     * <td>read-only</td>
2502     * <td>See {@link ContactsContract.Contacts}.</td>
2503     * </tr>
2504     * <tr>
2505     * <td>int</td>
2506     * <td>{@link #STARRED}</td>
2507     * <td>read-only</td>
2508     * <td>See {@link ContactsContract.Contacts}.</td>
2509     * </tr>
2510     * <tr>
2511     * <td>String</td>
2512     * <td>{@link #CUSTOM_RINGTONE}</td>
2513     * <td>read-only</td>
2514     * <td>See {@link ContactsContract.Contacts}.</td>
2515     * </tr>
2516     * <tr>
2517     * <td>int</td>
2518     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2519     * <td>read-only</td>
2520     * <td>See {@link ContactsContract.Contacts}.</td>
2521     * </tr>
2522     * <tr>
2523     * <td>int</td>
2524     * <td>{@link #CONTACT_PRESENCE}</td>
2525     * <td>read-only</td>
2526     * <td>See {@link ContactsContract.Contacts}.</td>
2527     * </tr>
2528     * <tr>
2529     * <td>String</td>
2530     * <td>{@link #CONTACT_STATUS}</td>
2531     * <td>read-only</td>
2532     * <td>See {@link ContactsContract.Contacts}.</td>
2533     * </tr>
2534     * <tr>
2535     * <td>long</td>
2536     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
2537     * <td>read-only</td>
2538     * <td>See {@link ContactsContract.Contacts}.</td>
2539     * </tr>
2540     * <tr>
2541     * <td>String</td>
2542     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
2543     * <td>read-only</td>
2544     * <td>See {@link ContactsContract.Contacts}.</td>
2545     * </tr>
2546     * <tr>
2547     * <td>long</td>
2548     * <td>{@link #CONTACT_STATUS_LABEL}</td>
2549     * <td>read-only</td>
2550     * <td>See {@link ContactsContract.Contacts}.</td>
2551     * </tr>
2552     * <tr>
2553     * <td>long</td>
2554     * <td>{@link #CONTACT_STATUS_ICON}</td>
2555     * <td>read-only</td>
2556     * <td>See {@link ContactsContract.Contacts}.</td>
2557     * </tr>
2558     * </table>
2559     */
2560    public final static class Data implements DataColumnsWithJoins {
2561        /**
2562         * This utility class cannot be instantiated
2563         */
2564        private Data() {}
2565
2566        /**
2567         * The content:// style URI for this table, which requests a directory
2568         * of data rows matching the selection criteria.
2569         */
2570        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
2571
2572        /**
2573         * The MIME type of the results from {@link #CONTENT_URI}.
2574         */
2575        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
2576
2577        /**
2578         * <p>
2579         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
2580         * Data.CONTENT_URI contains only exportable data.
2581         * </p>
2582         * <p>
2583         * This flag is useful (currently) only for vCard exporter in Contacts app, which
2584         * needs to exclude "un-exportable" data from available data to export, while
2585         * Contacts app itself has priviledge to access all data including "un-exportable"
2586         * ones and providers return all of them regardless of the callers' intention.
2587         * </p>
2588         * <p>
2589         * Type: INTEGER
2590         * </p>
2591         *
2592         * @hide Maybe available only in Eclair and not really ready for public use.
2593         * TODO: remove, or implement this feature completely. As of now (Eclair),
2594         * we only use this flag in queryEntities(), not query().
2595         */
2596        public static final String FOR_EXPORT_ONLY = "for_export_only";
2597
2598        /**
2599         * <p>
2600         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
2601         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
2602         * entry of the given {@link ContactsContract.Data} entry.
2603         * </p>
2604         * <p>
2605         * Returns the Uri for the contact in the first entry returned by
2606         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
2607         * for the provided {@code dataUri}.  If the query returns null or empty
2608         * results, silently returns null.
2609         * </p>
2610         */
2611        public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) {
2612            final Cursor cursor = resolver.query(dataUri, new String[] {
2613                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
2614            }, null, null, null);
2615
2616            Uri lookupUri = null;
2617            try {
2618                if (cursor != null && cursor.moveToFirst()) {
2619                    final long contactId = cursor.getLong(0);
2620                    final String lookupKey = cursor.getString(1);
2621                    return Contacts.getLookupUri(contactId, lookupKey);
2622                }
2623            } finally {
2624                if (cursor != null) cursor.close();
2625            }
2626            return lookupUri;
2627        }
2628    }
2629
2630    /**
2631     * <p>
2632     * Constants for the raw contacts entities table, which can be thought of as
2633     * an outer join of the raw_contacts table with the data table.  It is a strictly
2634     * read-only table.
2635     * </p>
2636     * <p>
2637     * If a raw contact has data rows, the RawContactsEntity cursor will contain
2638     * a one row for each data row. If the raw contact has no data rows, the
2639     * cursor will still contain one row with the raw contact-level information
2640     * and nulls for data columns.
2641     *
2642     * <pre>
2643     * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId);
2644     * Cursor c = getContentResolver().query(entityUri,
2645     *          new String[]{
2646     *              RawContactsEntity.SOURCE_ID,
2647     *              RawContactsEntity.DATA_ID,
2648     *              RawContactsEntity.MIMETYPE,
2649     *              RawContactsEntity.DATA1
2650     *          }, null, null, null);
2651     * try {
2652     *     while (c.moveToNext()) {
2653     *         String sourceId = c.getString(0);
2654     *         if (!c.isNull(1)) {
2655     *             String mimeType = c.getString(2);
2656     *             String data = c.getString(3);
2657     *             ...
2658     *         }
2659     *     }
2660     * } finally {
2661     *     c.close();
2662     * }
2663     * </pre>
2664     *
2665     * <h3>Columns</h3>
2666     * RawContactsEntity has a combination of RawContact and Data columns.
2667     *
2668     * <table class="jd-sumtable">
2669     * <tr>
2670     * <th colspan='4'>RawContacts</th>
2671     * </tr>
2672     * <tr>
2673     * <td style="width: 7em;">long</td>
2674     * <td style="width: 20em;">{@link #_ID}</td>
2675     * <td style="width: 5em;">read-only</td>
2676     * <td>Raw contact row ID. See {@link RawContacts}.</td>
2677     * </tr>
2678     * <tr>
2679     * <td>long</td>
2680     * <td>{@link #CONTACT_ID}</td>
2681     * <td>read-only</td>
2682     * <td>See {@link RawContacts}.</td>
2683     * </tr>
2684     * <tr>
2685     * <td>int</td>
2686     * <td>{@link #AGGREGATION_MODE}</td>
2687     * <td>read-only</td>
2688     * <td>See {@link RawContacts}.</td>
2689     * </tr>
2690     * <tr>
2691     * <td>int</td>
2692     * <td>{@link #DELETED}</td>
2693     * <td>read-only</td>
2694     * <td>See {@link RawContacts}.</td>
2695     * </tr>
2696     * </table>
2697     *
2698     * <table class="jd-sumtable">
2699     * <tr>
2700     * <th colspan='4'>Data</th>
2701     * </tr>
2702     * <tr>
2703     * <td style="width: 7em;">long</td>
2704     * <td style="width: 20em;">{@link #DATA_ID}</td>
2705     * <td style="width: 5em;">read-only</td>
2706     * <td>Data row ID. It will be null if the raw contact has no data rows.</td>
2707     * </tr>
2708     * <tr>
2709     * <td>String</td>
2710     * <td>{@link #MIMETYPE}</td>
2711     * <td>read-only</td>
2712     * <td>See {@link ContactsContract.Data}.</td>
2713     * </tr>
2714     * <tr>
2715     * <td>int</td>
2716     * <td>{@link #IS_PRIMARY}</td>
2717     * <td>read-only</td>
2718     * <td>See {@link ContactsContract.Data}.</td>
2719     * </tr>
2720     * <tr>
2721     * <td>int</td>
2722     * <td>{@link #IS_SUPER_PRIMARY}</td>
2723     * <td>read-only</td>
2724     * <td>See {@link ContactsContract.Data}.</td>
2725     * </tr>
2726     * <tr>
2727     * <td>int</td>
2728     * <td>{@link #DATA_VERSION}</td>
2729     * <td>read-only</td>
2730     * <td>See {@link ContactsContract.Data}.</td>
2731     * </tr>
2732     * <tr>
2733     * <td>Any type</td>
2734     * <td>
2735     * {@link #DATA1}<br>
2736     * {@link #DATA2}<br>
2737     * {@link #DATA3}<br>
2738     * {@link #DATA4}<br>
2739     * {@link #DATA5}<br>
2740     * {@link #DATA6}<br>
2741     * {@link #DATA7}<br>
2742     * {@link #DATA8}<br>
2743     * {@link #DATA9}<br>
2744     * {@link #DATA10}<br>
2745     * {@link #DATA11}<br>
2746     * {@link #DATA12}<br>
2747     * {@link #DATA13}<br>
2748     * {@link #DATA14}<br>
2749     * {@link #DATA15}
2750     * </td>
2751     * <td>read-only</td>
2752     * <td>See {@link ContactsContract.Data}.</td>
2753     * </tr>
2754     * <tr>
2755     * <td>Any type</td>
2756     * <td>
2757     * {@link #SYNC1}<br>
2758     * {@link #SYNC2}<br>
2759     * {@link #SYNC3}<br>
2760     * {@link #SYNC4}
2761     * </td>
2762     * <td>read-only</td>
2763     * <td>See {@link ContactsContract.Data}.</td>
2764     * </tr>
2765     * </table>
2766     */
2767    public final static class RawContactsEntity
2768            implements BaseColumns, DataColumns, RawContactsColumns {
2769        /**
2770         * This utility class cannot be instantiated
2771         */
2772        private RawContactsEntity() {}
2773
2774        /**
2775         * The content:// style URI for this table
2776         */
2777        public static final Uri CONTENT_URI =
2778                Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities");
2779
2780        /**
2781         * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities.
2782         */
2783        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity";
2784
2785        /**
2786         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
2787         * Data.CONTENT_URI contains only exportable data.
2788         *
2789         * This flag is useful (currently) only for vCard exporter in Contacts app, which
2790         * needs to exclude "un-exportable" data from available data to export, while
2791         * Contacts app itself has priviledge to access all data including "un-expotable"
2792         * ones and providers return all of them regardless of the callers' intention.
2793         * <P>Type: INTEGER</p>
2794         *
2795         * @hide Maybe available only in Eclair and not really ready for public use.
2796         * TODO: remove, or implement this feature completely. As of now (Eclair),
2797         * we only use this flag in queryEntities(), not query().
2798         */
2799        public static final String FOR_EXPORT_ONLY = "for_export_only";
2800
2801        /**
2802         * The ID of the data column. The value will be null if this raw contact has no data rows.
2803         * <P>Type: INTEGER</P>
2804         */
2805        public static final String DATA_ID = "data_id";
2806    }
2807
2808    /**
2809     * @see PhoneLookup
2810     */
2811    protected interface PhoneLookupColumns {
2812        /**
2813         * The phone number as the user entered it.
2814         * <P>Type: TEXT</P>
2815         */
2816        public static final String NUMBER = "number";
2817
2818        /**
2819         * The type of phone number, for example Home or Work.
2820         * <P>Type: INTEGER</P>
2821         */
2822        public static final String TYPE = "type";
2823
2824        /**
2825         * The user defined label for the phone number.
2826         * <P>Type: TEXT</P>
2827         */
2828        public static final String LABEL = "label";
2829    }
2830
2831    /**
2832     * A table that represents the result of looking up a phone number, for
2833     * example for caller ID. To perform a lookup you must append the number you
2834     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
2835     * optimized.
2836     * <pre>
2837     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
2838     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
2839     * </pre>
2840     *
2841     * <h3>Columns</h3>
2842     *
2843     * <table class="jd-sumtable">
2844     * <tr>
2845     * <th colspan='4'>PhoneLookup</th>
2846     * </tr>
2847     * <tr>
2848     * <td>long</td>
2849     * <td>{@link #_ID}</td>
2850     * <td>read-only</td>
2851     * <td>Data row ID.</td>
2852     * </tr>
2853     * <tr>
2854     * <td>String</td>
2855     * <td>{@link #NUMBER}</td>
2856     * <td>read-only</td>
2857     * <td>Phone number.</td>
2858     * </tr>
2859     * <tr>
2860     * <td>String</td>
2861     * <td>{@link #TYPE}</td>
2862     * <td>read-only</td>
2863     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
2864     * </tr>
2865     * <tr>
2866     * <td>String</td>
2867     * <td>{@link #LABEL}</td>
2868     * <td>read-only</td>
2869     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
2870     * </tr>
2871     * </table>
2872     * <p>
2873     * Columns from the Contacts table are also available through a join.
2874     * </p>
2875     * <table class="jd-sumtable">
2876     * <tr>
2877     * <th colspan='4'>Join with {@link Contacts}</th>
2878     * </tr>
2879     * <tr>
2880     * <td>String</td>
2881     * <td>{@link #LOOKUP_KEY}</td>
2882     * <td>read-only</td>
2883     * <td>See {@link ContactsContract.Contacts}</td>
2884     * </tr>
2885     * <tr>
2886     * <td>String</td>
2887     * <td>{@link #DISPLAY_NAME}</td>
2888     * <td>read-only</td>
2889     * <td>See {@link ContactsContract.Contacts}</td>
2890     * </tr>
2891     * <tr>
2892     * <td>long</td>
2893     * <td>{@link #PHOTO_ID}</td>
2894     * <td>read-only</td>
2895     * <td>See {@link ContactsContract.Contacts}.</td>
2896     * </tr>
2897     * <tr>
2898     * <td>int</td>
2899     * <td>{@link #IN_VISIBLE_GROUP}</td>
2900     * <td>read-only</td>
2901     * <td>See {@link ContactsContract.Contacts}.</td>
2902     * </tr>
2903     * <tr>
2904     * <td>int</td>
2905     * <td>{@link #HAS_PHONE_NUMBER}</td>
2906     * <td>read-only</td>
2907     * <td>See {@link ContactsContract.Contacts}.</td>
2908     * </tr>
2909     * <tr>
2910     * <td>int</td>
2911     * <td>{@link #TIMES_CONTACTED}</td>
2912     * <td>read-only</td>
2913     * <td>See {@link ContactsContract.Contacts}.</td>
2914     * </tr>
2915     * <tr>
2916     * <td>long</td>
2917     * <td>{@link #LAST_TIME_CONTACTED}</td>
2918     * <td>read-only</td>
2919     * <td>See {@link ContactsContract.Contacts}.</td>
2920     * </tr>
2921     * <tr>
2922     * <td>int</td>
2923     * <td>{@link #STARRED}</td>
2924     * <td>read-only</td>
2925     * <td>See {@link ContactsContract.Contacts}.</td>
2926     * </tr>
2927     * <tr>
2928     * <td>String</td>
2929     * <td>{@link #CUSTOM_RINGTONE}</td>
2930     * <td>read-only</td>
2931     * <td>See {@link ContactsContract.Contacts}.</td>
2932     * </tr>
2933     * <tr>
2934     * <td>int</td>
2935     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2936     * <td>read-only</td>
2937     * <td>See {@link ContactsContract.Contacts}.</td>
2938     * </tr>
2939     * </table>
2940     */
2941    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
2942            ContactsColumns, ContactOptionsColumns {
2943        /**
2944         * This utility class cannot be instantiated
2945         */
2946        private PhoneLookup() {}
2947
2948        /**
2949         * The content:// style URI for this table. Append the phone number you want to lookup
2950         * to this URI and query it to perform a lookup. For example:
2951         * <pre>
2952         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber));
2953         * </pre>
2954         */
2955        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
2956                "phone_lookup");
2957
2958        /**
2959         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
2960         *
2961         * @hide
2962         */
2963        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
2964    }
2965
2966    /**
2967     * Additional data mixed in with {@link StatusColumns} to link
2968     * back to specific {@link ContactsContract.Data#_ID} entries.
2969     *
2970     * @see StatusUpdates
2971     */
2972    protected interface PresenceColumns {
2973
2974        /**
2975         * Reference to the {@link Data#_ID} entry that owns this presence.
2976         * <P>Type: INTEGER</P>
2977         */
2978        public static final String DATA_ID = "presence_data_id";
2979
2980        /**
2981         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
2982         * <p>Type: NUMBER</p>
2983         */
2984        public static final String PROTOCOL = "protocol";
2985
2986        /**
2987         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
2988         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
2989         * omitted if {@link #PROTOCOL} value is not
2990         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
2991         *
2992         * <p>Type: NUMBER</p>
2993         */
2994        public static final String CUSTOM_PROTOCOL = "custom_protocol";
2995
2996        /**
2997         * The IM handle the presence item is for. The handle is scoped to
2998         * {@link #PROTOCOL}.
2999         * <P>Type: TEXT</P>
3000         */
3001        public static final String IM_HANDLE = "im_handle";
3002
3003        /**
3004         * The IM account for the local user that the presence data came from.
3005         * <P>Type: TEXT</P>
3006         */
3007        public static final String IM_ACCOUNT = "im_account";
3008    }
3009
3010    /**
3011     * <p>
3012     * A status update is linked to a {@link ContactsContract.Data} row and captures
3013     * the user's latest status update via the corresponding source, e.g.
3014     * "Having lunch" via "Google Talk".
3015     * </p>
3016     * <p>
3017     * There are two ways a status update can be inserted: by explicitly linking
3018     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
3019     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3020     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
3021     * either.
3022     * </p>
3023     * <p>
3024     * You cannot use {@link ContentResolver#update} to change a status, but
3025     * {@link ContentResolver#insert} will replace the latests status if it already
3026     * exists.
3027     * </p>
3028     * <p>
3029     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
3030     * for multiple contacts at once.
3031     * </p>
3032     *
3033     * <h3>Columns</h3>
3034     * <table class="jd-sumtable">
3035     * <tr>
3036     * <th colspan='4'>StatusUpdates</th>
3037     * </tr>
3038     * <tr>
3039     * <td>long</td>
3040     * <td>{@link #DATA_ID}</td>
3041     * <td>read/write</td>
3042     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
3043     * field is <i>not</i> specified, the provider will attempt to find a data row
3044     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3045     * {@link #IM_HANDLE} columns.
3046     * </td>
3047     * </tr>
3048     * <tr>
3049     * <td>long</td>
3050     * <td>{@link #PROTOCOL}</td>
3051     * <td>read/write</td>
3052     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
3053     * </tr>
3054     * <tr>
3055     * <td>String</td>
3056     * <td>{@link #CUSTOM_PROTOCOL}</td>
3057     * <td>read/write</td>
3058     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
3059     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
3060     * omitted if {@link #PROTOCOL} value is not
3061     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
3062     * </tr>
3063     * <tr>
3064     * <td>String</td>
3065     * <td>{@link #IM_HANDLE}</td>
3066     * <td>read/write</td>
3067     * <td> The IM handle the presence item is for. The handle is scoped to
3068     * {@link #PROTOCOL}.</td>
3069     * </tr>
3070     * <tr>
3071     * <td>String</td>
3072     * <td>{@link #IM_ACCOUNT}</td>
3073     * <td>read/write</td>
3074     * <td>The IM account for the local user that the presence data came from.</td>
3075     * </tr>
3076     * <tr>
3077     * <td>int</td>
3078     * <td>{@link #PRESENCE}</td>
3079     * <td>read/write</td>
3080     * <td>Contact IM presence status. The allowed values are:
3081     * <p>
3082     * <ul>
3083     * <li>{@link #OFFLINE}</li>
3084     * <li>{@link #INVISIBLE}</li>
3085     * <li>{@link #AWAY}</li>
3086     * <li>{@link #IDLE}</li>
3087     * <li>{@link #DO_NOT_DISTURB}</li>
3088     * <li>{@link #AVAILABLE}</li>
3089     * </ul>
3090     * </p>
3091     * <p>
3092     * Since presence status is inherently volatile, the content provider
3093     * may choose not to store this field in long-term storage.
3094     * </p>
3095     * </td>
3096     * </tr>
3097     * <tr>
3098     * <td>String</td>
3099     * <td>{@link #STATUS}</td>
3100     * <td>read/write</td>
3101     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
3102     * </tr>
3103     * <tr>
3104     * <td>long</td>
3105     * <td>{@link #STATUS_TIMESTAMP}</td>
3106     * <td>read/write</td>
3107     * <td>The absolute time in milliseconds when the status was
3108     * entered by the user. If this value is not provided, the provider will follow
3109     * this logic: if there was no prior status update, the value will be left as null.
3110     * If there was a prior status update, the provider will default this field
3111     * to the current time.</td>
3112     * </tr>
3113     * <tr>
3114     * <td>String</td>
3115     * <td>{@link #STATUS_RES_PACKAGE}</td>
3116     * <td>read/write</td>
3117     * <td> The package containing resources for this status: label and icon.</td>
3118     * </tr>
3119     * <tr>
3120     * <td>long</td>
3121     * <td>{@link #STATUS_LABEL}</td>
3122     * <td>read/write</td>
3123     * <td>The resource ID of the label describing the source of contact status,
3124     * e.g. "Google Talk". This resource is scoped by the
3125     * {@link #STATUS_RES_PACKAGE}.</td>
3126     * </tr>
3127     * <tr>
3128     * <td>long</td>
3129     * <td>{@link #STATUS_ICON}</td>
3130     * <td>read/write</td>
3131     * <td>The resource ID of the icon for the source of contact status. This
3132     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
3133     * </tr>
3134     * </table>
3135     */
3136    public static class StatusUpdates implements StatusColumns, PresenceColumns {
3137
3138        /**
3139         * This utility class cannot be instantiated
3140         */
3141        private StatusUpdates() {}
3142
3143        /**
3144         * The content:// style URI for this table
3145         */
3146        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
3147
3148        /**
3149         * Gets the resource ID for the proper presence icon.
3150         *
3151         * @param status the status to get the icon for
3152         * @return the resource ID for the proper presence icon
3153         */
3154        public static final int getPresenceIconResourceId(int status) {
3155            switch (status) {
3156                case AVAILABLE:
3157                    return android.R.drawable.presence_online;
3158                case IDLE:
3159                case AWAY:
3160                    return android.R.drawable.presence_away;
3161                case DO_NOT_DISTURB:
3162                    return android.R.drawable.presence_busy;
3163                case INVISIBLE:
3164                    return android.R.drawable.presence_invisible;
3165                case OFFLINE:
3166                default:
3167                    return android.R.drawable.presence_offline;
3168            }
3169        }
3170
3171        /**
3172         * Returns the precedence of the status code the higher number being the higher precedence.
3173         *
3174         * @param status The status code.
3175         * @return An integer representing the precedence, 0 being the lowest.
3176         */
3177        public static final int getPresencePrecedence(int status) {
3178            // Keep this function here incase we want to enforce a different precedence than the
3179            // natural order of the status constants.
3180            return status;
3181        }
3182
3183        /**
3184         * The MIME type of {@link #CONTENT_URI} providing a directory of
3185         * status update details.
3186         */
3187        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
3188
3189        /**
3190         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
3191         * status update detail.
3192         */
3193        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
3194    }
3195
3196    /**
3197     * @deprecated This old name was never meant to be made public. Do not use.
3198     */
3199    @Deprecated
3200    public static final class Presence extends StatusUpdates {
3201
3202    }
3203
3204    /**
3205     * Additional columns returned by the {@link Contacts#CONTENT_FILTER_URI} providing the
3206     * explanation of why the filter matched the contact.  Specifically, they contain the
3207     * data type and element that was used for matching.
3208     * <p>
3209     * This is temporary API, it will need to change when we move to FTS.
3210     *
3211     * @hide
3212     */
3213    public static class SearchSnippetColumns {
3214
3215        /**
3216         * The ID of the data row that was matched by the filter.
3217         *
3218         * @hide
3219         */
3220        public static final String SNIPPET_DATA_ID = "snippet_data_id";
3221
3222        /**
3223         * The type of data that was matched by the filter.
3224         *
3225         * @hide
3226         */
3227        public static final String SNIPPET_MIMETYPE = "snippet_mimetype";
3228
3229        /**
3230         * The {@link Data#DATA1} field of the data row that was matched by the filter.
3231         *
3232         * @hide
3233         */
3234        public static final String SNIPPET_DATA1 = "snippet_data1";
3235
3236        /**
3237         * The {@link Data#DATA2} field of the data row that was matched by the filter.
3238         *
3239         * @hide
3240         */
3241        public static final String SNIPPET_DATA2 = "snippet_data2";
3242
3243        /**
3244         * The {@link Data#DATA3} field of the data row that was matched by the filter.
3245         *
3246         * @hide
3247         */
3248        public static final String SNIPPET_DATA3 = "snippet_data3";
3249
3250        /**
3251         * The {@link Data#DATA4} field of the data row that was matched by the filter.
3252         *
3253         * @hide
3254         */
3255        public static final String SNIPPET_DATA4 = "snippet_data4";
3256
3257    }
3258
3259    /**
3260     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
3261     * table.
3262     */
3263    public static final class CommonDataKinds {
3264        /**
3265         * This utility class cannot be instantiated
3266         */
3267        private CommonDataKinds() {}
3268
3269        /**
3270         * The {@link Data#RES_PACKAGE} value for common data that should be
3271         * shown using a default style.
3272         *
3273         * @hide RES_PACKAGE is hidden
3274         */
3275        public static final String PACKAGE_COMMON = "common";
3276
3277        /**
3278         * The base types that all "Typed" data kinds support.
3279         */
3280        public interface BaseTypes {
3281            /**
3282             * A custom type. The custom label should be supplied by user.
3283             */
3284            public static int TYPE_CUSTOM = 0;
3285        }
3286
3287        /**
3288         * Columns common across the specific types.
3289         */
3290        protected interface CommonColumns extends BaseTypes {
3291            /**
3292             * The data for the contact method.
3293             * <P>Type: TEXT</P>
3294             */
3295            public static final String DATA = DataColumns.DATA1;
3296
3297            /**
3298             * The type of data, for example Home or Work.
3299             * <P>Type: INTEGER</P>
3300             */
3301            public static final String TYPE = DataColumns.DATA2;
3302
3303            /**
3304             * The user defined label for the the contact method.
3305             * <P>Type: TEXT</P>
3306             */
3307            public static final String LABEL = DataColumns.DATA3;
3308        }
3309
3310        /**
3311         * A data kind representing the contact's proper name. You can use all
3312         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
3313         *
3314         * <h2>Column aliases</h2>
3315         * <table class="jd-sumtable">
3316         * <tr>
3317         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3318         * </tr>
3319         * <tr>
3320         * <td>String</td>
3321         * <td>{@link #DISPLAY_NAME}</td>
3322         * <td>{@link #DATA1}</td>
3323         * <td></td>
3324         * </tr>
3325         * <tr>
3326         * <td>String</td>
3327         * <td>{@link #GIVEN_NAME}</td>
3328         * <td>{@link #DATA2}</td>
3329         * <td></td>
3330         * </tr>
3331         * <tr>
3332         * <td>String</td>
3333         * <td>{@link #FAMILY_NAME}</td>
3334         * <td>{@link #DATA3}</td>
3335         * <td></td>
3336         * </tr>
3337         * <tr>
3338         * <td>String</td>
3339         * <td>{@link #PREFIX}</td>
3340         * <td>{@link #DATA4}</td>
3341         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
3342         * </tr>
3343         * <tr>
3344         * <td>String</td>
3345         * <td>{@link #MIDDLE_NAME}</td>
3346         * <td>{@link #DATA5}</td>
3347         * <td></td>
3348         * </tr>
3349         * <tr>
3350         * <td>String</td>
3351         * <td>{@link #SUFFIX}</td>
3352         * <td>{@link #DATA6}</td>
3353         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
3354         * </tr>
3355         * <tr>
3356         * <td>String</td>
3357         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
3358         * <td>{@link #DATA7}</td>
3359         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
3360         * </tr>
3361         * <tr>
3362         * <td>String</td>
3363         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
3364         * <td>{@link #DATA8}</td>
3365         * <td></td>
3366         * </tr>
3367         * <tr>
3368         * <td>String</td>
3369         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
3370         * <td>{@link #DATA9}</td>
3371         * <td></td>
3372         * </tr>
3373         * </table>
3374         */
3375        public static final class StructuredName implements DataColumnsWithJoins {
3376            /**
3377             * This utility class cannot be instantiated
3378             */
3379            private StructuredName() {}
3380
3381            /** MIME type used when storing this in data table. */
3382            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
3383
3384            /**
3385             * The name that should be used to display the contact.
3386             * <i>Unstructured component of the name should be consistent with
3387             * its structured representation.</i>
3388             * <p>
3389             * Type: TEXT
3390             */
3391            public static final String DISPLAY_NAME = DATA1;
3392
3393            /**
3394             * The given name for the contact.
3395             * <P>Type: TEXT</P>
3396             */
3397            public static final String GIVEN_NAME = DATA2;
3398
3399            /**
3400             * The family name for the contact.
3401             * <P>Type: TEXT</P>
3402             */
3403            public static final String FAMILY_NAME = DATA3;
3404
3405            /**
3406             * The contact's honorific prefix, e.g. "Sir"
3407             * <P>Type: TEXT</P>
3408             */
3409            public static final String PREFIX = DATA4;
3410
3411            /**
3412             * The contact's middle name
3413             * <P>Type: TEXT</P>
3414             */
3415            public static final String MIDDLE_NAME = DATA5;
3416
3417            /**
3418             * The contact's honorific suffix, e.g. "Jr"
3419             */
3420            public static final String SUFFIX = DATA6;
3421
3422            /**
3423             * The phonetic version of the given name for the contact.
3424             * <P>Type: TEXT</P>
3425             */
3426            public static final String PHONETIC_GIVEN_NAME = DATA7;
3427
3428            /**
3429             * The phonetic version of the additional name for the contact.
3430             * <P>Type: TEXT</P>
3431             */
3432            public static final String PHONETIC_MIDDLE_NAME = DATA8;
3433
3434            /**
3435             * The phonetic version of the family name for the contact.
3436             * <P>Type: TEXT</P>
3437             */
3438            public static final String PHONETIC_FAMILY_NAME = DATA9;
3439
3440            /**
3441             * The style used for combining given/middle/family name into a full name.
3442             * See {@link ContactsContract.FullNameStyle}.
3443             *
3444             * @hide
3445             */
3446            public static final String FULL_NAME_STYLE = DATA10;
3447
3448            /**
3449             * The alphabet used for capturing the phonetic name.
3450             * See ContactsContract.PhoneticNameStyle.
3451             * @hide
3452             */
3453            public static final String PHONETIC_NAME_STYLE = DATA11;
3454        }
3455
3456        /**
3457         * <p>A data kind representing the contact's nickname. For example, for
3458         * Bob Parr ("Mr. Incredible"):
3459         * <pre>
3460         * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
3461         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3462         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3463         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
3464         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
3465         *          .build());
3466         *
3467         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3468         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3469         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
3470         *          .withValue(Nickname.NAME, "Mr. Incredible")
3471         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
3472         *          .withValue(Nickname.LABEL, "Superhero")
3473         *          .build());
3474         *
3475         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
3476         * </pre>
3477         * </p>
3478         * <p>
3479         * You can use all columns defined for {@link ContactsContract.Data} as well as the
3480         * following aliases.
3481         * </p>
3482         *
3483         * <h2>Column aliases</h2>
3484         * <table class="jd-sumtable">
3485         * <tr>
3486         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3487         * </tr>
3488         * <tr>
3489         * <td>String</td>
3490         * <td>{@link #NAME}</td>
3491         * <td>{@link #DATA1}</td>
3492         * <td></td>
3493         * </tr>
3494         * <tr>
3495         * <td>int</td>
3496         * <td>{@link #TYPE}</td>
3497         * <td>{@link #DATA2}</td>
3498         * <td>
3499         * Allowed values are:
3500         * <p>
3501         * <ul>
3502         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3503         * <li>{@link #TYPE_DEFAULT}</li>
3504         * <li>{@link #TYPE_OTHER_NAME}</li>
3505         * <li>{@link #TYPE_MAINDEN_NAME}</li>
3506         * <li>{@link #TYPE_SHORT_NAME}</li>
3507         * <li>{@link #TYPE_INITIALS}</li>
3508         * </ul>
3509         * </p>
3510         * </td>
3511         * </tr>
3512         * <tr>
3513         * <td>String</td>
3514         * <td>{@link #LABEL}</td>
3515         * <td>{@link #DATA3}</td>
3516         * <td></td>
3517         * </tr>
3518         * </table>
3519         */
3520        public static final class Nickname implements DataColumnsWithJoins, CommonColumns {
3521            /**
3522             * This utility class cannot be instantiated
3523             */
3524            private Nickname() {}
3525
3526            /** MIME type used when storing this in data table. */
3527            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
3528
3529            public static final int TYPE_DEFAULT = 1;
3530            public static final int TYPE_OTHER_NAME = 2;
3531            public static final int TYPE_MAINDEN_NAME = 3;
3532            public static final int TYPE_SHORT_NAME = 4;
3533            public static final int TYPE_INITIALS = 5;
3534
3535            /**
3536             * The name itself
3537             */
3538            public static final String NAME = DATA;
3539        }
3540
3541        /**
3542         * <p>
3543         * A data kind representing a telephone number.
3544         * </p>
3545         * <p>
3546         * You can use all columns defined for {@link ContactsContract.Data} as
3547         * well as the following aliases.
3548         * </p>
3549         * <h2>Column aliases</h2>
3550         * <table class="jd-sumtable">
3551         * <tr>
3552         * <th>Type</th>
3553         * <th>Alias</th><th colspan='2'>Data column</th>
3554         * </tr>
3555         * <tr>
3556         * <td>String</td>
3557         * <td>{@link #NUMBER}</td>
3558         * <td>{@link #DATA1}</td>
3559         * <td></td>
3560         * </tr>
3561         * <tr>
3562         * <td>int</td>
3563         * <td>{@link #TYPE}</td>
3564         * <td>{@link #DATA2}</td>
3565         * <td>Allowed values are:
3566         * <p>
3567         * <ul>
3568         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3569         * <li>{@link #TYPE_HOME}</li>
3570         * <li>{@link #TYPE_MOBILE}</li>
3571         * <li>{@link #TYPE_WORK}</li>
3572         * <li>{@link #TYPE_FAX_WORK}</li>
3573         * <li>{@link #TYPE_FAX_HOME}</li>
3574         * <li>{@link #TYPE_PAGER}</li>
3575         * <li>{@link #TYPE_OTHER}</li>
3576         * <li>{@link #TYPE_CALLBACK}</li>
3577         * <li>{@link #TYPE_CAR}</li>
3578         * <li>{@link #TYPE_COMPANY_MAIN}</li>
3579         * <li>{@link #TYPE_ISDN}</li>
3580         * <li>{@link #TYPE_MAIN}</li>
3581         * <li>{@link #TYPE_OTHER_FAX}</li>
3582         * <li>{@link #TYPE_RADIO}</li>
3583         * <li>{@link #TYPE_TELEX}</li>
3584         * <li>{@link #TYPE_TTY_TDD}</li>
3585         * <li>{@link #TYPE_WORK_MOBILE}</li>
3586         * <li>{@link #TYPE_WORK_PAGER}</li>
3587         * <li>{@link #TYPE_ASSISTANT}</li>
3588         * <li>{@link #TYPE_MMS}</li>
3589         * </ul>
3590         * </p>
3591         * </td>
3592         * </tr>
3593         * <tr>
3594         * <td>String</td>
3595         * <td>{@link #LABEL}</td>
3596         * <td>{@link #DATA3}</td>
3597         * <td></td>
3598         * </tr>
3599         * </table>
3600         */
3601        public static final class Phone implements DataColumnsWithJoins, CommonColumns {
3602            /**
3603             * This utility class cannot be instantiated
3604             */
3605            private Phone() {}
3606
3607            /** MIME type used when storing this in data table. */
3608            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
3609
3610            /**
3611             * The MIME type of {@link #CONTENT_URI} providing a directory of
3612             * phones.
3613             */
3614            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
3615
3616            /**
3617             * The content:// style URI for all data records of the
3618             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
3619             * associated raw contact and aggregate contact data.
3620             */
3621            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
3622                    "phones");
3623
3624            /**
3625             * The content:// style URL for phone lookup using a filter. The filter returns
3626             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
3627             * to display names as well as phone numbers. The filter argument should be passed
3628             * as an additional path segment after this URI.
3629             */
3630            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
3631                    "filter");
3632
3633            public static final int TYPE_HOME = 1;
3634            public static final int TYPE_MOBILE = 2;
3635            public static final int TYPE_WORK = 3;
3636            public static final int TYPE_FAX_WORK = 4;
3637            public static final int TYPE_FAX_HOME = 5;
3638            public static final int TYPE_PAGER = 6;
3639            public static final int TYPE_OTHER = 7;
3640            public static final int TYPE_CALLBACK = 8;
3641            public static final int TYPE_CAR = 9;
3642            public static final int TYPE_COMPANY_MAIN = 10;
3643            public static final int TYPE_ISDN = 11;
3644            public static final int TYPE_MAIN = 12;
3645            public static final int TYPE_OTHER_FAX = 13;
3646            public static final int TYPE_RADIO = 14;
3647            public static final int TYPE_TELEX = 15;
3648            public static final int TYPE_TTY_TDD = 16;
3649            public static final int TYPE_WORK_MOBILE = 17;
3650            public static final int TYPE_WORK_PAGER = 18;
3651            public static final int TYPE_ASSISTANT = 19;
3652            public static final int TYPE_MMS = 20;
3653
3654            /**
3655             * The phone number as the user entered it.
3656             * <P>Type: TEXT</P>
3657             */
3658            public static final String NUMBER = DATA;
3659
3660            /**
3661             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
3662             * @hide
3663             */
3664            @Deprecated
3665            public static final CharSequence getDisplayLabel(Context context, int type,
3666                    CharSequence label, CharSequence[] labelArray) {
3667                return getTypeLabel(context.getResources(), type, label);
3668            }
3669
3670            /**
3671             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
3672             * @hide
3673             */
3674            @Deprecated
3675            public static final CharSequence getDisplayLabel(Context context, int type,
3676                    CharSequence label) {
3677                return getTypeLabel(context.getResources(), type, label);
3678            }
3679
3680            /**
3681             * Return the string resource that best describes the given
3682             * {@link #TYPE}. Will always return a valid resource.
3683             */
3684            public static final int getTypeLabelResource(int type) {
3685                switch (type) {
3686                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
3687                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
3688                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
3689                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
3690                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
3691                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
3692                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
3693                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
3694                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
3695                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
3696                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
3697                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
3698                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
3699                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
3700                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
3701                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
3702                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
3703                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
3704                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
3705                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
3706                    default: return com.android.internal.R.string.phoneTypeCustom;
3707                }
3708            }
3709
3710            /**
3711             * Return a {@link CharSequence} that best describes the given type,
3712             * possibly substituting the given {@link #LABEL} value
3713             * for {@link #TYPE_CUSTOM}.
3714             */
3715            public static final CharSequence getTypeLabel(Resources res, int type,
3716                    CharSequence label) {
3717                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
3718                    return label;
3719                } else {
3720                    final int labelRes = getTypeLabelResource(type);
3721                    return res.getText(labelRes);
3722                }
3723            }
3724        }
3725
3726        /**
3727         * <p>
3728         * A data kind representing an email address.
3729         * </p>
3730         * <p>
3731         * You can use all columns defined for {@link ContactsContract.Data} as
3732         * well as the following aliases.
3733         * </p>
3734         * <h2>Column aliases</h2>
3735         * <table class="jd-sumtable">
3736         * <tr>
3737         * <th>Type</th>
3738         * <th>Alias</th><th colspan='2'>Data column</th>
3739         * </tr>
3740         * <tr>
3741         * <td>String</td>
3742         * <td>{@link #DATA}</td>
3743         * <td>{@link #DATA1}</td>
3744         * <td>Email address itself.</td>
3745         * </tr>
3746         * <tr>
3747         * <td>int</td>
3748         * <td>{@link #TYPE}</td>
3749         * <td>{@link #DATA2}</td>
3750         * <td>Allowed values are:
3751         * <p>
3752         * <ul>
3753         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3754         * <li>{@link #TYPE_HOME}</li>
3755         * <li>{@link #TYPE_WORK}</li>
3756         * <li>{@link #TYPE_OTHER}</li>
3757         * <li>{@link #TYPE_MOBILE}</li>
3758         * </ul>
3759         * </p>
3760         * </td>
3761         * </tr>
3762         * <tr>
3763         * <td>String</td>
3764         * <td>{@link #LABEL}</td>
3765         * <td>{@link #DATA3}</td>
3766         * <td></td>
3767         * </tr>
3768         * </table>
3769         */
3770        public static final class Email implements DataColumnsWithJoins, CommonColumns {
3771            /**
3772             * This utility class cannot be instantiated
3773             */
3774            private Email() {}
3775
3776            /** MIME type used when storing this in data table. */
3777            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
3778
3779            /**
3780             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
3781             */
3782            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
3783
3784            /**
3785             * The content:// style URI for all data records of the
3786             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
3787             * associated raw contact and aggregate contact data.
3788             */
3789            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
3790                    "emails");
3791
3792            /**
3793             * <p>
3794             * The content:// style URL for looking up data rows by email address. The
3795             * lookup argument, an email address, should be passed as an additional path segment
3796             * after this URI.
3797             * </p>
3798             * <p>Example:
3799             * <pre>
3800             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
3801             * Cursor c = getContentResolver().query(uri,
3802             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
3803             *          null, null, null);
3804             * </pre>
3805             * </p>
3806             */
3807            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
3808                    "lookup");
3809
3810            /**
3811             * <p>
3812             * The content:// style URL for email lookup using a filter. The filter returns
3813             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
3814             * to display names as well as email addresses. The filter argument should be passed
3815             * as an additional path segment after this URI.
3816             * </p>
3817             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
3818             * as well as "Bob Parr (incredible@android.com)".
3819             * <pre>
3820             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
3821             * Cursor c = getContentResolver().query(uri,
3822             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
3823             *          null, null, null);
3824             * </pre>
3825             * </p>
3826             */
3827            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
3828                    "filter");
3829
3830            /**
3831             * The email address.
3832             * <P>Type: TEXT</P>
3833             * @hide TODO: Unhide in a separate CL
3834             */
3835            public static final String ADDRESS = DATA1;
3836
3837            public static final int TYPE_HOME = 1;
3838            public static final int TYPE_WORK = 2;
3839            public static final int TYPE_OTHER = 3;
3840            public static final int TYPE_MOBILE = 4;
3841
3842            /**
3843             * The display name for the email address
3844             * <P>Type: TEXT</P>
3845             */
3846            public static final String DISPLAY_NAME = DATA4;
3847
3848            /**
3849             * Return the string resource that best describes the given
3850             * {@link #TYPE}. Will always return a valid resource.
3851             */
3852            public static final int getTypeLabelResource(int type) {
3853                switch (type) {
3854                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
3855                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
3856                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
3857                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
3858                    default: return com.android.internal.R.string.emailTypeCustom;
3859                }
3860            }
3861
3862            /**
3863             * Return a {@link CharSequence} that best describes the given type,
3864             * possibly substituting the given {@link #LABEL} value
3865             * for {@link #TYPE_CUSTOM}.
3866             */
3867            public static final CharSequence getTypeLabel(Resources res, int type,
3868                    CharSequence label) {
3869                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
3870                    return label;
3871                } else {
3872                    final int labelRes = getTypeLabelResource(type);
3873                    return res.getText(labelRes);
3874                }
3875            }
3876        }
3877
3878        /**
3879         * <p>
3880         * A data kind representing a postal addresses.
3881         * </p>
3882         * <p>
3883         * You can use all columns defined for {@link ContactsContract.Data} as
3884         * well as the following aliases.
3885         * </p>
3886         * <h2>Column aliases</h2>
3887         * <table class="jd-sumtable">
3888         * <tr>
3889         * <th>Type</th>
3890         * <th>Alias</th><th colspan='2'>Data column</th>
3891         * </tr>
3892         * <tr>
3893         * <td>String</td>
3894         * <td>{@link #FORMATTED_ADDRESS}</td>
3895         * <td>{@link #DATA1}</td>
3896         * <td></td>
3897         * </tr>
3898         * <tr>
3899         * <td>int</td>
3900         * <td>{@link #TYPE}</td>
3901         * <td>{@link #DATA2}</td>
3902         * <td>Allowed values are:
3903         * <p>
3904         * <ul>
3905         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3906         * <li>{@link #TYPE_HOME}</li>
3907         * <li>{@link #TYPE_WORK}</li>
3908         * <li>{@link #TYPE_OTHER}</li>
3909         * </ul>
3910         * </p>
3911         * </td>
3912         * </tr>
3913         * <tr>
3914         * <td>String</td>
3915         * <td>{@link #LABEL}</td>
3916         * <td>{@link #DATA3}</td>
3917         * <td></td>
3918         * </tr>
3919         * <tr>
3920         * <td>String</td>
3921         * <td>{@link #STREET}</td>
3922         * <td>{@link #DATA4}</td>
3923         * <td></td>
3924         * </tr>
3925         * <tr>
3926         * <td>String</td>
3927         * <td>{@link #POBOX}</td>
3928         * <td>{@link #DATA5}</td>
3929         * <td>Post Office Box number</td>
3930         * </tr>
3931         * <tr>
3932         * <td>String</td>
3933         * <td>{@link #NEIGHBORHOOD}</td>
3934         * <td>{@link #DATA6}</td>
3935         * <td></td>
3936         * </tr>
3937         * <tr>
3938         * <td>String</td>
3939         * <td>{@link #CITY}</td>
3940         * <td>{@link #DATA7}</td>
3941         * <td></td>
3942         * </tr>
3943         * <tr>
3944         * <td>String</td>
3945         * <td>{@link #REGION}</td>
3946         * <td>{@link #DATA8}</td>
3947         * <td></td>
3948         * </tr>
3949         * <tr>
3950         * <td>String</td>
3951         * <td>{@link #POSTCODE}</td>
3952         * <td>{@link #DATA9}</td>
3953         * <td></td>
3954         * </tr>
3955         * <tr>
3956         * <td>String</td>
3957         * <td>{@link #COUNTRY}</td>
3958         * <td>{@link #DATA10}</td>
3959         * <td></td>
3960         * </tr>
3961         * </table>
3962         */
3963        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns {
3964            /**
3965             * This utility class cannot be instantiated
3966             */
3967            private StructuredPostal() {
3968            }
3969
3970            /** MIME type used when storing this in data table. */
3971            public static final String CONTENT_ITEM_TYPE =
3972                    "vnd.android.cursor.item/postal-address_v2";
3973
3974            /**
3975             * The MIME type of {@link #CONTENT_URI} providing a directory of
3976             * postal addresses.
3977             */
3978            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
3979
3980            /**
3981             * The content:// style URI for all data records of the
3982             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
3983             */
3984            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
3985                    "postals");
3986
3987            public static final int TYPE_HOME = 1;
3988            public static final int TYPE_WORK = 2;
3989            public static final int TYPE_OTHER = 3;
3990
3991            /**
3992             * The full, unstructured postal address. <i>This field must be
3993             * consistent with any structured data.</i>
3994             * <p>
3995             * Type: TEXT
3996             */
3997            public static final String FORMATTED_ADDRESS = DATA;
3998
3999            /**
4000             * Can be street, avenue, road, etc. This element also includes the
4001             * house number and room/apartment/flat/floor number.
4002             * <p>
4003             * Type: TEXT
4004             */
4005            public static final String STREET = DATA4;
4006
4007            /**
4008             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
4009             * usually but not always mutually exclusive with street.
4010             * <p>
4011             * Type: TEXT
4012             */
4013            public static final String POBOX = DATA5;
4014
4015            /**
4016             * This is used to disambiguate a street address when a city
4017             * contains more than one street with the same name, or to specify a
4018             * small place whose mail is routed through a larger postal town. In
4019             * China it could be a county or a minor city.
4020             * <p>
4021             * Type: TEXT
4022             */
4023            public static final String NEIGHBORHOOD = DATA6;
4024
4025            /**
4026             * Can be city, village, town, borough, etc. This is the postal town
4027             * and not necessarily the place of residence or place of business.
4028             * <p>
4029             * Type: TEXT
4030             */
4031            public static final String CITY = DATA7;
4032
4033            /**
4034             * A state, province, county (in Ireland), Land (in Germany),
4035             * departement (in France), etc.
4036             * <p>
4037             * Type: TEXT
4038             */
4039            public static final String REGION = DATA8;
4040
4041            /**
4042             * Postal code. Usually country-wide, but sometimes specific to the
4043             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
4044             * <p>
4045             * Type: TEXT
4046             */
4047            public static final String POSTCODE = DATA9;
4048
4049            /**
4050             * The name or code of the country.
4051             * <p>
4052             * Type: TEXT
4053             */
4054            public static final String COUNTRY = DATA10;
4055
4056            /**
4057             * Return the string resource that best describes the given
4058             * {@link #TYPE}. Will always return a valid resource.
4059             */
4060            public static final int getTypeLabelResource(int type) {
4061                switch (type) {
4062                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
4063                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
4064                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
4065                    default: return com.android.internal.R.string.postalTypeCustom;
4066                }
4067            }
4068
4069            /**
4070             * Return a {@link CharSequence} that best describes the given type,
4071             * possibly substituting the given {@link #LABEL} value
4072             * for {@link #TYPE_CUSTOM}.
4073             */
4074            public static final CharSequence getTypeLabel(Resources res, int type,
4075                    CharSequence label) {
4076                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4077                    return label;
4078                } else {
4079                    final int labelRes = getTypeLabelResource(type);
4080                    return res.getText(labelRes);
4081                }
4082            }
4083        }
4084
4085        /**
4086         * <p>
4087         * A data kind representing an IM address
4088         * </p>
4089         * <p>
4090         * You can use all columns defined for {@link ContactsContract.Data} as
4091         * well as the following aliases.
4092         * </p>
4093         * <h2>Column aliases</h2>
4094         * <table class="jd-sumtable">
4095         * <tr>
4096         * <th>Type</th>
4097         * <th>Alias</th><th colspan='2'>Data column</th>
4098         * </tr>
4099         * <tr>
4100         * <td>String</td>
4101         * <td>{@link #DATA}</td>
4102         * <td>{@link #DATA1}</td>
4103         * <td></td>
4104         * </tr>
4105         * <tr>
4106         * <td>int</td>
4107         * <td>{@link #TYPE}</td>
4108         * <td>{@link #DATA2}</td>
4109         * <td>Allowed values are:
4110         * <p>
4111         * <ul>
4112         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4113         * <li>{@link #TYPE_HOME}</li>
4114         * <li>{@link #TYPE_WORK}</li>
4115         * <li>{@link #TYPE_OTHER}</li>
4116         * </ul>
4117         * </p>
4118         * </td>
4119         * </tr>
4120         * <tr>
4121         * <td>String</td>
4122         * <td>{@link #LABEL}</td>
4123         * <td>{@link #DATA3}</td>
4124         * <td></td>
4125         * </tr>
4126         * <tr>
4127         * <td>String</td>
4128         * <td>{@link #PROTOCOL}</td>
4129         * <td>{@link #DATA5}</td>
4130         * <td>
4131         * <p>
4132         * Allowed values:
4133         * <ul>
4134         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
4135         * as {@link #CUSTOM_PROTOCOL}.</li>
4136         * <li>{@link #PROTOCOL_AIM}</li>
4137         * <li>{@link #PROTOCOL_MSN}</li>
4138         * <li>{@link #PROTOCOL_YAHOO}</li>
4139         * <li>{@link #PROTOCOL_SKYPE}</li>
4140         * <li>{@link #PROTOCOL_QQ}</li>
4141         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
4142         * <li>{@link #PROTOCOL_ICQ}</li>
4143         * <li>{@link #PROTOCOL_JABBER}</li>
4144         * <li>{@link #PROTOCOL_NETMEETING}</li>
4145         * </ul>
4146         * </p>
4147         * </td>
4148         * </tr>
4149         * <tr>
4150         * <td>String</td>
4151         * <td>{@link #CUSTOM_PROTOCOL}</td>
4152         * <td>{@link #DATA6}</td>
4153         * <td></td>
4154         * </tr>
4155         * </table>
4156         */
4157        public static final class Im implements DataColumnsWithJoins, CommonColumns {
4158            /**
4159             * This utility class cannot be instantiated
4160             */
4161            private Im() {}
4162
4163            /** MIME type used when storing this in data table. */
4164            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
4165
4166            public static final int TYPE_HOME = 1;
4167            public static final int TYPE_WORK = 2;
4168            public static final int TYPE_OTHER = 3;
4169
4170            /**
4171             * This column should be populated with one of the defined
4172             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
4173             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
4174             * should contain the name of the custom protocol.
4175             */
4176            public static final String PROTOCOL = DATA5;
4177
4178            public static final String CUSTOM_PROTOCOL = DATA6;
4179
4180            /*
4181             * The predefined IM protocol types.
4182             */
4183            public static final int PROTOCOL_CUSTOM = -1;
4184            public static final int PROTOCOL_AIM = 0;
4185            public static final int PROTOCOL_MSN = 1;
4186            public static final int PROTOCOL_YAHOO = 2;
4187            public static final int PROTOCOL_SKYPE = 3;
4188            public static final int PROTOCOL_QQ = 4;
4189            public static final int PROTOCOL_GOOGLE_TALK = 5;
4190            public static final int PROTOCOL_ICQ = 6;
4191            public static final int PROTOCOL_JABBER = 7;
4192            public static final int PROTOCOL_NETMEETING = 8;
4193
4194            /**
4195             * Return the string resource that best describes the given
4196             * {@link #TYPE}. Will always return a valid resource.
4197             */
4198            public static final int getTypeLabelResource(int type) {
4199                switch (type) {
4200                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
4201                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
4202                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
4203                    default: return com.android.internal.R.string.imTypeCustom;
4204                }
4205            }
4206
4207            /**
4208             * Return a {@link CharSequence} that best describes the given type,
4209             * possibly substituting the given {@link #LABEL} value
4210             * for {@link #TYPE_CUSTOM}.
4211             */
4212            public static final CharSequence getTypeLabel(Resources res, int type,
4213                    CharSequence label) {
4214                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4215                    return label;
4216                } else {
4217                    final int labelRes = getTypeLabelResource(type);
4218                    return res.getText(labelRes);
4219                }
4220            }
4221
4222            /**
4223             * Return the string resource that best describes the given
4224             * {@link #PROTOCOL}. Will always return a valid resource.
4225             */
4226            public static final int getProtocolLabelResource(int type) {
4227                switch (type) {
4228                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
4229                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
4230                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
4231                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
4232                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
4233                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
4234                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
4235                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
4236                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
4237                    default: return com.android.internal.R.string.imProtocolCustom;
4238                }
4239            }
4240
4241            /**
4242             * Return a {@link CharSequence} that best describes the given
4243             * protocol, possibly substituting the given
4244             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
4245             */
4246            public static final CharSequence getProtocolLabel(Resources res, int type,
4247                    CharSequence label) {
4248                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
4249                    return label;
4250                } else {
4251                    final int labelRes = getProtocolLabelResource(type);
4252                    return res.getText(labelRes);
4253                }
4254            }
4255        }
4256
4257        /**
4258         * <p>
4259         * A data kind representing an organization.
4260         * </p>
4261         * <p>
4262         * You can use all columns defined for {@link ContactsContract.Data} as
4263         * well as the following aliases.
4264         * </p>
4265         * <h2>Column aliases</h2>
4266         * <table class="jd-sumtable">
4267         * <tr>
4268         * <th>Type</th>
4269         * <th>Alias</th><th colspan='2'>Data column</th>
4270         * </tr>
4271         * <tr>
4272         * <td>String</td>
4273         * <td>{@link #COMPANY}</td>
4274         * <td>{@link #DATA1}</td>
4275         * <td></td>
4276         * </tr>
4277         * <tr>
4278         * <td>int</td>
4279         * <td>{@link #TYPE}</td>
4280         * <td>{@link #DATA2}</td>
4281         * <td>Allowed values are:
4282         * <p>
4283         * <ul>
4284         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4285         * <li>{@link #TYPE_WORK}</li>
4286         * <li>{@link #TYPE_OTHER}</li>
4287         * </ul>
4288         * </p>
4289         * </td>
4290         * </tr>
4291         * <tr>
4292         * <td>String</td>
4293         * <td>{@link #LABEL}</td>
4294         * <td>{@link #DATA3}</td>
4295         * <td></td>
4296         * </tr>
4297         * <tr>
4298         * <td>String</td>
4299         * <td>{@link #TITLE}</td>
4300         * <td>{@link #DATA4}</td>
4301         * <td></td>
4302         * </tr>
4303         * <tr>
4304         * <td>String</td>
4305         * <td>{@link #DEPARTMENT}</td>
4306         * <td>{@link #DATA5}</td>
4307         * <td></td>
4308         * </tr>
4309         * <tr>
4310         * <td>String</td>
4311         * <td>{@link #JOB_DESCRIPTION}</td>
4312         * <td>{@link #DATA6}</td>
4313         * <td></td>
4314         * </tr>
4315         * <tr>
4316         * <td>String</td>
4317         * <td>{@link #SYMBOL}</td>
4318         * <td>{@link #DATA7}</td>
4319         * <td></td>
4320         * </tr>
4321         * <tr>
4322         * <td>String</td>
4323         * <td>{@link #PHONETIC_NAME}</td>
4324         * <td>{@link #DATA8}</td>
4325         * <td></td>
4326         * </tr>
4327         * <tr>
4328         * <td>String</td>
4329         * <td>{@link #OFFICE_LOCATION}</td>
4330         * <td>{@link #DATA9}</td>
4331         * <td></td>
4332         * </tr>
4333         * <tr>
4334         * <td>String</td>
4335         * <td>PHONETIC_NAME_STYLE</td>
4336         * <td>{@link #DATA10}</td>
4337         * <td></td>
4338         * </tr>
4339         * </table>
4340         */
4341        public static final class Organization implements DataColumnsWithJoins, CommonColumns {
4342            /**
4343             * This utility class cannot be instantiated
4344             */
4345            private Organization() {}
4346
4347            /** MIME type used when storing this in data table. */
4348            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
4349
4350            public static final int TYPE_WORK = 1;
4351            public static final int TYPE_OTHER = 2;
4352
4353            /**
4354             * The company as the user entered it.
4355             * <P>Type: TEXT</P>
4356             */
4357            public static final String COMPANY = DATA;
4358
4359            /**
4360             * The position title at this company as the user entered it.
4361             * <P>Type: TEXT</P>
4362             */
4363            public static final String TITLE = DATA4;
4364
4365            /**
4366             * The department at this company as the user entered it.
4367             * <P>Type: TEXT</P>
4368             */
4369            public static final String DEPARTMENT = DATA5;
4370
4371            /**
4372             * The job description at this company as the user entered it.
4373             * <P>Type: TEXT</P>
4374             */
4375            public static final String JOB_DESCRIPTION = DATA6;
4376
4377            /**
4378             * The symbol of this company as the user entered it.
4379             * <P>Type: TEXT</P>
4380             */
4381            public static final String SYMBOL = DATA7;
4382
4383            /**
4384             * The phonetic name of this company as the user entered it.
4385             * <P>Type: TEXT</P>
4386             */
4387            public static final String PHONETIC_NAME = DATA8;
4388
4389            /**
4390             * The office location of this organization.
4391             * <P>Type: TEXT</P>
4392             */
4393            public static final String OFFICE_LOCATION = DATA9;
4394
4395            /**
4396             * The alphabet used for capturing the phonetic name.
4397             * See {@link ContactsContract.PhoneticNameStyle}.
4398             * @hide
4399             */
4400            public static final String PHONETIC_NAME_STYLE = DATA10;
4401
4402            /**
4403             * Return the string resource that best describes the given
4404             * {@link #TYPE}. Will always return a valid resource.
4405             */
4406            public static final int getTypeLabelResource(int type) {
4407                switch (type) {
4408                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
4409                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
4410                    default: return com.android.internal.R.string.orgTypeCustom;
4411                }
4412            }
4413
4414            /**
4415             * Return a {@link CharSequence} that best describes the given type,
4416             * possibly substituting the given {@link #LABEL} value
4417             * for {@link #TYPE_CUSTOM}.
4418             */
4419            public static final CharSequence getTypeLabel(Resources res, int type,
4420                    CharSequence label) {
4421                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4422                    return label;
4423                } else {
4424                    final int labelRes = getTypeLabelResource(type);
4425                    return res.getText(labelRes);
4426                }
4427            }
4428        }
4429
4430        /**
4431         * <p>
4432         * A data kind representing a relation.
4433         * </p>
4434         * <p>
4435         * You can use all columns defined for {@link ContactsContract.Data} as
4436         * well as the following aliases.
4437         * </p>
4438         * <h2>Column aliases</h2>
4439         * <table class="jd-sumtable">
4440         * <tr>
4441         * <th>Type</th>
4442         * <th>Alias</th><th colspan='2'>Data column</th>
4443         * </tr>
4444         * <tr>
4445         * <td>String</td>
4446         * <td>{@link #NAME}</td>
4447         * <td>{@link #DATA1}</td>
4448         * <td></td>
4449         * </tr>
4450         * <tr>
4451         * <td>int</td>
4452         * <td>{@link #TYPE}</td>
4453         * <td>{@link #DATA2}</td>
4454         * <td>Allowed values are:
4455         * <p>
4456         * <ul>
4457         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4458         * <li>{@link #TYPE_ASSISTANT}</li>
4459         * <li>{@link #TYPE_BROTHER}</li>
4460         * <li>{@link #TYPE_CHILD}</li>
4461         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
4462         * <li>{@link #TYPE_FATHER}</li>
4463         * <li>{@link #TYPE_FRIEND}</li>
4464         * <li>{@link #TYPE_MANAGER}</li>
4465         * <li>{@link #TYPE_MOTHER}</li>
4466         * <li>{@link #TYPE_PARENT}</li>
4467         * <li>{@link #TYPE_PARTNER}</li>
4468         * <li>{@link #TYPE_REFERRED_BY}</li>
4469         * <li>{@link #TYPE_RELATIVE}</li>
4470         * <li>{@link #TYPE_SISTER}</li>
4471         * <li>{@link #TYPE_SPOUSE}</li>
4472         * </ul>
4473         * </p>
4474         * </td>
4475         * </tr>
4476         * <tr>
4477         * <td>String</td>
4478         * <td>{@link #LABEL}</td>
4479         * <td>{@link #DATA3}</td>
4480         * <td></td>
4481         * </tr>
4482         * </table>
4483         */
4484        public static final class Relation implements DataColumnsWithJoins, CommonColumns {
4485            /**
4486             * This utility class cannot be instantiated
4487             */
4488            private Relation() {}
4489
4490            /** MIME type used when storing this in data table. */
4491            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
4492
4493            public static final int TYPE_ASSISTANT = 1;
4494            public static final int TYPE_BROTHER = 2;
4495            public static final int TYPE_CHILD = 3;
4496            public static final int TYPE_DOMESTIC_PARTNER = 4;
4497            public static final int TYPE_FATHER = 5;
4498            public static final int TYPE_FRIEND = 6;
4499            public static final int TYPE_MANAGER = 7;
4500            public static final int TYPE_MOTHER = 8;
4501            public static final int TYPE_PARENT = 9;
4502            public static final int TYPE_PARTNER = 10;
4503            public static final int TYPE_REFERRED_BY = 11;
4504            public static final int TYPE_RELATIVE = 12;
4505            public static final int TYPE_SISTER = 13;
4506            public static final int TYPE_SPOUSE = 14;
4507
4508            /**
4509             * The name of the relative as the user entered it.
4510             * <P>Type: TEXT</P>
4511             */
4512            public static final String NAME = DATA;
4513        }
4514
4515        /**
4516         * <p>
4517         * A data kind representing an event.
4518         * </p>
4519         * <p>
4520         * You can use all columns defined for {@link ContactsContract.Data} as
4521         * well as the following aliases.
4522         * </p>
4523         * <h2>Column aliases</h2>
4524         * <table class="jd-sumtable">
4525         * <tr>
4526         * <th>Type</th>
4527         * <th>Alias</th><th colspan='2'>Data column</th>
4528         * </tr>
4529         * <tr>
4530         * <td>String</td>
4531         * <td>{@link #START_DATE}</td>
4532         * <td>{@link #DATA1}</td>
4533         * <td></td>
4534         * </tr>
4535         * <tr>
4536         * <td>int</td>
4537         * <td>{@link #TYPE}</td>
4538         * <td>{@link #DATA2}</td>
4539         * <td>Allowed values are:
4540         * <p>
4541         * <ul>
4542         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4543         * <li>{@link #TYPE_ANNIVERSARY}</li>
4544         * <li>{@link #TYPE_OTHER}</li>
4545         * <li>{@link #TYPE_BIRTHDAY}</li>
4546         * </ul>
4547         * </p>
4548         * </td>
4549         * </tr>
4550         * <tr>
4551         * <td>String</td>
4552         * <td>{@link #LABEL}</td>
4553         * <td>{@link #DATA3}</td>
4554         * <td></td>
4555         * </tr>
4556         * </table>
4557         */
4558        public static final class Event implements DataColumnsWithJoins, CommonColumns {
4559            /**
4560             * This utility class cannot be instantiated
4561             */
4562            private Event() {}
4563
4564            /** MIME type used when storing this in data table. */
4565            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
4566
4567            public static final int TYPE_ANNIVERSARY = 1;
4568            public static final int TYPE_OTHER = 2;
4569            public static final int TYPE_BIRTHDAY = 3;
4570
4571            /**
4572             * The event start date as the user entered it.
4573             * <P>Type: TEXT</P>
4574             */
4575            public static final String START_DATE = DATA;
4576
4577            /**
4578             * Return the string resource that best describes the given
4579             * {@link #TYPE}. Will always return a valid resource.
4580             */
4581            public static int getTypeResource(Integer type) {
4582                if (type == null) {
4583                    return com.android.internal.R.string.eventTypeOther;
4584                }
4585                switch (type) {
4586                    case TYPE_ANNIVERSARY:
4587                        return com.android.internal.R.string.eventTypeAnniversary;
4588                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
4589                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
4590                    default: return com.android.internal.R.string.eventTypeOther;
4591                }
4592            }
4593        }
4594
4595        /**
4596         * <p>
4597         * A data kind representing an photo for the contact.
4598         * </p>
4599         * <p>
4600         * Some sync adapters will choose to download photos in a separate
4601         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
4602         * through {@link ContactsContract.Data#SYNC4} to store temporary
4603         * data, e.g. the image URL or ID, state of download, server-side version
4604         * of the image.  It is allowed for the {@link #PHOTO} to be null.
4605         * </p>
4606         * <p>
4607         * You can use all columns defined for {@link ContactsContract.Data} as
4608         * well as the following aliases.
4609         * </p>
4610         * <h2>Column aliases</h2>
4611         * <table class="jd-sumtable">
4612         * <tr>
4613         * <th>Type</th>
4614         * <th>Alias</th><th colspan='2'>Data column</th>
4615         * </tr>
4616         * <tr>
4617         * <td>BLOB</td>
4618         * <td>{@link #PHOTO}</td>
4619         * <td>{@link #DATA15}</td>
4620         * <td>By convention, binary data is stored in DATA15.</td>
4621         * </tr>
4622         * </table>
4623         */
4624        public static final class Photo implements DataColumnsWithJoins {
4625            /**
4626             * This utility class cannot be instantiated
4627             */
4628            private Photo() {}
4629
4630            /** MIME type used when storing this in data table. */
4631            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
4632
4633            /**
4634             * Thumbnail photo of the raw contact. This is the raw bytes of an image
4635             * that could be inflated using {@link android.graphics.BitmapFactory}.
4636             * <p>
4637             * Type: BLOB
4638             */
4639            public static final String PHOTO = DATA15;
4640        }
4641
4642        /**
4643         * <p>
4644         * Notes about the contact.
4645         * </p>
4646         * <p>
4647         * You can use all columns defined for {@link ContactsContract.Data} as
4648         * well as the following aliases.
4649         * </p>
4650         * <h2>Column aliases</h2>
4651         * <table class="jd-sumtable">
4652         * <tr>
4653         * <th>Type</th>
4654         * <th>Alias</th><th colspan='2'>Data column</th>
4655         * </tr>
4656         * <tr>
4657         * <td>String</td>
4658         * <td>{@link #NOTE}</td>
4659         * <td>{@link #DATA1}</td>
4660         * <td></td>
4661         * </tr>
4662         * </table>
4663         */
4664        public static final class Note implements DataColumnsWithJoins {
4665            /**
4666             * This utility class cannot be instantiated
4667             */
4668            private Note() {}
4669
4670            /** MIME type used when storing this in data table. */
4671            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
4672
4673            /**
4674             * The note text.
4675             * <P>Type: TEXT</P>
4676             */
4677            public static final String NOTE = DATA1;
4678        }
4679
4680        /**
4681         * <p>
4682         * Group Membership.
4683         * </p>
4684         * <p>
4685         * You can use all columns defined for {@link ContactsContract.Data} as
4686         * well as the following aliases.
4687         * </p>
4688         * <h2>Column aliases</h2>
4689         * <table class="jd-sumtable">
4690         * <tr>
4691         * <th>Type</th>
4692         * <th>Alias</th><th colspan='2'>Data column</th>
4693         * </tr>
4694         * <tr>
4695         * <td>long</td>
4696         * <td>{@link #GROUP_ROW_ID}</td>
4697         * <td>{@link #DATA1}</td>
4698         * <td></td>
4699         * </tr>
4700         * <tr>
4701         * <td>String</td>
4702         * <td>{@link #GROUP_SOURCE_ID}</td>
4703         * <td>none</td>
4704         * <td>
4705         * <p>
4706         * The sourceid of the group that this group membership refers to.
4707         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
4708         * inserting a row.
4709         * </p>
4710         * <p>
4711         * If this field is specified, the provider will first try to
4712         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
4713         * is found, it will use the corresponding row id.  If the group is not
4714         * found, it will create one.
4715         * </td>
4716         * </tr>
4717         * </table>
4718         */
4719        public static final class GroupMembership implements DataColumnsWithJoins {
4720            /**
4721             * This utility class cannot be instantiated
4722             */
4723            private GroupMembership() {}
4724
4725            /** MIME type used when storing this in data table. */
4726            public static final String CONTENT_ITEM_TYPE =
4727                    "vnd.android.cursor.item/group_membership";
4728
4729            /**
4730             * The row id of the group that this group membership refers to. Exactly one of
4731             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
4732             * <P>Type: INTEGER</P>
4733             */
4734            public static final String GROUP_ROW_ID = DATA1;
4735
4736            /**
4737             * The sourceid of the group that this group membership refers to.  Exactly one of
4738             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
4739             * <P>Type: TEXT</P>
4740             */
4741            public static final String GROUP_SOURCE_ID = "group_sourceid";
4742        }
4743
4744        /**
4745         * <p>
4746         * A data kind representing a website related to the contact.
4747         * </p>
4748         * <p>
4749         * You can use all columns defined for {@link ContactsContract.Data} as
4750         * well as the following aliases.
4751         * </p>
4752         * <h2>Column aliases</h2>
4753         * <table class="jd-sumtable">
4754         * <tr>
4755         * <th>Type</th>
4756         * <th>Alias</th><th colspan='2'>Data column</th>
4757         * </tr>
4758         * <tr>
4759         * <td>String</td>
4760         * <td>{@link #URL}</td>
4761         * <td>{@link #DATA1}</td>
4762         * <td></td>
4763         * </tr>
4764         * <tr>
4765         * <td>int</td>
4766         * <td>{@link #TYPE}</td>
4767         * <td>{@link #DATA2}</td>
4768         * <td>Allowed values are:
4769         * <p>
4770         * <ul>
4771         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4772         * <li>{@link #TYPE_HOMEPAGE}</li>
4773         * <li>{@link #TYPE_BLOG}</li>
4774         * <li>{@link #TYPE_PROFILE}</li>
4775         * <li>{@link #TYPE_HOME}</li>
4776         * <li>{@link #TYPE_WORK}</li>
4777         * <li>{@link #TYPE_FTP}</li>
4778         * <li>{@link #TYPE_OTHER}</li>
4779         * </ul>
4780         * </p>
4781         * </td>
4782         * </tr>
4783         * <tr>
4784         * <td>String</td>
4785         * <td>{@link #LABEL}</td>
4786         * <td>{@link #DATA3}</td>
4787         * <td></td>
4788         * </tr>
4789         * </table>
4790         */
4791        public static final class Website implements DataColumnsWithJoins, CommonColumns {
4792            /**
4793             * This utility class cannot be instantiated
4794             */
4795            private Website() {}
4796
4797            /** MIME type used when storing this in data table. */
4798            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
4799
4800            public static final int TYPE_HOMEPAGE = 1;
4801            public static final int TYPE_BLOG = 2;
4802            public static final int TYPE_PROFILE = 3;
4803            public static final int TYPE_HOME = 4;
4804            public static final int TYPE_WORK = 5;
4805            public static final int TYPE_FTP = 6;
4806            public static final int TYPE_OTHER = 7;
4807
4808            /**
4809             * The website URL string.
4810             * <P>Type: TEXT</P>
4811             */
4812            public static final String URL = DATA;
4813        }
4814    }
4815
4816    /**
4817     * @see Groups
4818     */
4819    protected interface GroupsColumns {
4820        /**
4821         * The display title of this group.
4822         * <p>
4823         * Type: TEXT
4824         */
4825        public static final String TITLE = "title";
4826
4827        /**
4828         * The package name to use when creating {@link Resources} objects for
4829         * this group. This value is only designed for use when building user
4830         * interfaces, and should not be used to infer the owner.
4831         *
4832         * @hide
4833         */
4834        public static final String RES_PACKAGE = "res_package";
4835
4836        /**
4837         * The display title of this group to load as a resource from
4838         * {@link #RES_PACKAGE}, which may be localized.
4839         * <P>Type: TEXT</P>
4840         *
4841         * @hide
4842         */
4843        public static final String TITLE_RES = "title_res";
4844
4845        /**
4846         * Notes about the group.
4847         * <p>
4848         * Type: TEXT
4849         */
4850        public static final String NOTES = "notes";
4851
4852        /**
4853         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
4854         * to the sync adapter, null otherwise.
4855         * <P>Type: TEXT</P>
4856         */
4857        public static final String SYSTEM_ID = "system_id";
4858
4859        /**
4860         * The total number of {@link Contacts} that have
4861         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
4862         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
4863         * <p>
4864         * Type: INTEGER
4865         */
4866        public static final String SUMMARY_COUNT = "summ_count";
4867
4868        /**
4869         * The total number of {@link Contacts} that have both
4870         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
4871         * Read-only value that is only present when querying
4872         * {@link Groups#CONTENT_SUMMARY_URI}.
4873         * <p>
4874         * Type: INTEGER
4875         */
4876        public static final String SUMMARY_WITH_PHONES = "summ_phones";
4877
4878        /**
4879         * Flag indicating if the contacts belonging to this group should be
4880         * visible in any user interface.
4881         * <p>
4882         * Type: INTEGER (boolean)
4883         */
4884        public static final String GROUP_VISIBLE = "group_visible";
4885
4886        /**
4887         * The "deleted" flag: "0" by default, "1" if the row has been marked
4888         * for deletion. When {@link android.content.ContentResolver#delete} is
4889         * called on a group, it is marked for deletion. The sync adaptor
4890         * deletes the group on the server and then calls ContactResolver.delete
4891         * once more, this time setting the the
4892         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
4893         * finalize the data removal.
4894         * <P>Type: INTEGER</P>
4895         */
4896        public static final String DELETED = "deleted";
4897
4898        /**
4899         * Whether this group should be synced if the SYNC_EVERYTHING settings
4900         * is false for this group's account.
4901         * <p>
4902         * Type: INTEGER (boolean)
4903         */
4904        public static final String SHOULD_SYNC = "should_sync";
4905
4906        /**
4907         * Any newly created contacts will automatically be added to groups that have this
4908         * flag set to true.
4909         * <p>
4910         * Type: INTEGER (boolean)
4911         */
4912        public static final String AUTO_ADD = "auto_add";
4913
4914        /**
4915         * When a contacts is marked as a favorites it will be automatically added
4916         * to the groups that have this flag set, and when it is removed from favorites
4917         * it will be removed from these groups.
4918         * <p>
4919         * Type: INTEGER (boolean)
4920         */
4921        public static final String FAVORITES = "favorites";
4922    }
4923
4924    /**
4925     * Constants for the groups table. Only per-account groups are supported.
4926     * <h2>Columns</h2>
4927     * <table class="jd-sumtable">
4928     * <tr>
4929     * <th colspan='4'>Groups</th>
4930     * </tr>
4931     * <tr>
4932     * <td>long</td>
4933     * <td>{@link #_ID}</td>
4934     * <td>read-only</td>
4935     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
4936     * In other words, it would be a really bad idea to delete and reinsert a
4937     * group. A sync adapter should always do an update instead.</td>
4938     * </tr>
4939     * <tr>
4940     * <td>String</td>
4941     * <td>{@link #TITLE}</td>
4942     * <td>read/write</td>
4943     * <td>The display title of this group.</td>
4944     * </tr>
4945     * <tr>
4946     * <td>String</td>
4947     * <td>{@link #NOTES}</td>
4948     * <td>read/write</td>
4949     * <td>Notes about the group.</td>
4950     * </tr>
4951     * <tr>
4952     * <td>String</td>
4953     * <td>{@link #SYSTEM_ID}</td>
4954     * <td>read/write</td>
4955     * <td>The ID of this group if it is a System Group, i.e. a group that has a
4956     * special meaning to the sync adapter, null otherwise.</td>
4957     * </tr>
4958     * <tr>
4959     * <td>int</td>
4960     * <td>{@link #SUMMARY_COUNT}</td>
4961     * <td>read-only</td>
4962     * <td>The total number of {@link Contacts} that have
4963     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
4964     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
4965     * </tr>
4966     * <tr>
4967     * <td>int</td>
4968     * <td>{@link #SUMMARY_WITH_PHONES}</td>
4969     * <td>read-only</td>
4970     * <td>The total number of {@link Contacts} that have both
4971     * {@link CommonDataKinds.GroupMembership} in this group, and also have
4972     * phone numbers. Read-only value that is only present when querying
4973     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
4974     * </tr>
4975     * <tr>
4976     * <td>int</td>
4977     * <td>{@link #GROUP_VISIBLE}</td>
4978     * <td>read-only</td>
4979     * <td>Flag indicating if the contacts belonging to this group should be
4980     * visible in any user interface. Allowed values: 0 and 1.</td>
4981     * </tr>
4982     * <tr>
4983     * <td>int</td>
4984     * <td>{@link #DELETED}</td>
4985     * <td>read/write</td>
4986     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
4987     * for deletion. When {@link android.content.ContentResolver#delete} is
4988     * called on a group, it is marked for deletion. The sync adaptor deletes
4989     * the group on the server and then calls ContactResolver.delete once more,
4990     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
4991     * query parameter to finalize the data removal.</td>
4992     * </tr>
4993     * <tr>
4994     * <td>int</td>
4995     * <td>{@link #SHOULD_SYNC}</td>
4996     * <td>read/write</td>
4997     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
4998     * is false for this group's account.</td>
4999     * </tr>
5000     * </table>
5001     */
5002    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
5003        /**
5004         * This utility class cannot be instantiated
5005         */
5006        private Groups() {
5007        }
5008
5009        /**
5010         * The content:// style URI for this table
5011         */
5012        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
5013
5014        /**
5015         * The content:// style URI for this table joined with details data from
5016         * {@link ContactsContract.Data}.
5017         */
5018        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
5019                "groups_summary");
5020
5021        /**
5022         * The MIME type of a directory of groups.
5023         */
5024        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
5025
5026        /**
5027         * The MIME type of a single group.
5028         */
5029        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
5030
5031        public static EntityIterator newEntityIterator(Cursor cursor) {
5032            return new EntityIteratorImpl(cursor);
5033        }
5034
5035        private static class EntityIteratorImpl extends CursorEntityIterator {
5036            public EntityIteratorImpl(Cursor cursor) {
5037                super(cursor);
5038            }
5039
5040            @Override
5041            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
5042                // we expect the cursor is already at the row we need to read from
5043                final ContentValues values = new ContentValues();
5044                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
5045                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
5046                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
5047                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
5048                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
5049                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
5050                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
5051                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
5052                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
5053                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
5054                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
5055                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
5056                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
5057                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
5058                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
5059                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
5060                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
5061                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
5062                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
5063                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
5064                cursor.moveToNext();
5065                return new Entity(values);
5066            }
5067        }
5068    }
5069
5070    /**
5071     * <p>
5072     * Constants for the contact aggregation exceptions table, which contains
5073     * aggregation rules overriding those used by automatic aggregation. This
5074     * type only supports query and update. Neither insert nor delete are
5075     * supported.
5076     * </p>
5077     * <h2>Columns</h2>
5078     * <table class="jd-sumtable">
5079     * <tr>
5080     * <th colspan='4'>AggregationExceptions</th>
5081     * </tr>
5082     * <tr>
5083     * <td>int</td>
5084     * <td>{@link #TYPE}</td>
5085     * <td>read/write</td>
5086     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
5087     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
5088     * </tr>
5089     * <tr>
5090     * <td>long</td>
5091     * <td>{@link #RAW_CONTACT_ID1}</td>
5092     * <td>read/write</td>
5093     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
5094     * the rule applies to.</td>
5095     * </tr>
5096     * <tr>
5097     * <td>long</td>
5098     * <td>{@link #RAW_CONTACT_ID2}</td>
5099     * <td>read/write</td>
5100     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
5101     * that the rule applies to.</td>
5102     * </tr>
5103     * </table>
5104     */
5105    public static final class AggregationExceptions implements BaseColumns {
5106        /**
5107         * This utility class cannot be instantiated
5108         */
5109        private AggregationExceptions() {}
5110
5111        /**
5112         * The content:// style URI for this table
5113         */
5114        public static final Uri CONTENT_URI =
5115                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
5116
5117        /**
5118         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
5119         */
5120        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
5121
5122        /**
5123         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
5124         */
5125        public static final String CONTENT_ITEM_TYPE =
5126                "vnd.android.cursor.item/aggregation_exception";
5127
5128        /**
5129         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
5130         * {@link #TYPE_AUTOMATIC}.
5131         *
5132         * <P>Type: INTEGER</P>
5133         */
5134        public static final String TYPE = "type";
5135
5136        /**
5137         * Allows the provider to automatically decide whether the specified raw contacts should
5138         * be included in the same aggregate contact or not.
5139         */
5140        public static final int TYPE_AUTOMATIC = 0;
5141
5142        /**
5143         * Makes sure that the specified raw contacts are included in the same
5144         * aggregate contact.
5145         */
5146        public static final int TYPE_KEEP_TOGETHER = 1;
5147
5148        /**
5149         * Makes sure that the specified raw contacts are NOT included in the same
5150         * aggregate contact.
5151         */
5152        public static final int TYPE_KEEP_SEPARATE = 2;
5153
5154        /**
5155         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
5156         */
5157        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
5158
5159        /**
5160         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
5161         * applies to.
5162         */
5163        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
5164    }
5165
5166    /**
5167     * @see Settings
5168     */
5169    protected interface SettingsColumns {
5170        /**
5171         * The name of the account instance to which this row belongs.
5172         * <P>Type: TEXT</P>
5173         */
5174        public static final String ACCOUNT_NAME = "account_name";
5175
5176        /**
5177         * The type of account to which this row belongs, which when paired with
5178         * {@link #ACCOUNT_NAME} identifies a specific account.
5179         * <P>Type: TEXT</P>
5180         */
5181        public static final String ACCOUNT_TYPE = "account_type";
5182
5183        /**
5184         * Depending on the mode defined by the sync-adapter, this flag controls
5185         * the top-level sync behavior for this data source.
5186         * <p>
5187         * Type: INTEGER (boolean)
5188         */
5189        public static final String SHOULD_SYNC = "should_sync";
5190
5191        /**
5192         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
5193         * entries should be visible in any user interface.
5194         * <p>
5195         * Type: INTEGER (boolean)
5196         */
5197        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
5198
5199        /**
5200         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5201         * {@link Groups#SHOULD_SYNC} under this account have been marked as
5202         * unsynced.
5203         */
5204        public static final String ANY_UNSYNCED = "any_unsynced";
5205
5206        /**
5207         * Read-only count of {@link Contacts} from a specific source that have
5208         * no {@link CommonDataKinds.GroupMembership} entries.
5209         * <p>
5210         * Type: INTEGER
5211         */
5212        public static final String UNGROUPED_COUNT = "summ_count";
5213
5214        /**
5215         * Read-only count of {@link Contacts} from a specific source that have
5216         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
5217         * <p>
5218         * Type: INTEGER
5219         */
5220        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
5221    }
5222
5223    /**
5224     * <p>
5225     * Contacts-specific settings for various {@link Account}'s.
5226     * </p>
5227     * <h2>Columns</h2>
5228     * <table class="jd-sumtable">
5229     * <tr>
5230     * <th colspan='4'>Settings</th>
5231     * </tr>
5232     * <tr>
5233     * <td>String</td>
5234     * <td>{@link #ACCOUNT_NAME}</td>
5235     * <td>read/write-once</td>
5236     * <td>The name of the account instance to which this row belongs.</td>
5237     * </tr>
5238     * <tr>
5239     * <td>String</td>
5240     * <td>{@link #ACCOUNT_TYPE}</td>
5241     * <td>read/write-once</td>
5242     * <td>The type of account to which this row belongs, which when paired with
5243     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
5244     * </tr>
5245     * <tr>
5246     * <td>int</td>
5247     * <td>{@link #SHOULD_SYNC}</td>
5248     * <td>read/write</td>
5249     * <td>Depending on the mode defined by the sync-adapter, this flag controls
5250     * the top-level sync behavior for this data source.</td>
5251     * </tr>
5252     * <tr>
5253     * <td>int</td>
5254     * <td>{@link #UNGROUPED_VISIBLE}</td>
5255     * <td>read/write</td>
5256     * <td>Flag indicating if contacts without any
5257     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
5258     * user interface.</td>
5259     * </tr>
5260     * <tr>
5261     * <td>int</td>
5262     * <td>{@link #ANY_UNSYNCED}</td>
5263     * <td>read-only</td>
5264     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5265     * {@link Groups#SHOULD_SYNC} under this account have been marked as
5266     * unsynced.</td>
5267     * </tr>
5268     * <tr>
5269     * <td>int</td>
5270     * <td>{@link #UNGROUPED_COUNT}</td>
5271     * <td>read-only</td>
5272     * <td>Read-only count of {@link Contacts} from a specific source that have
5273     * no {@link CommonDataKinds.GroupMembership} entries.</td>
5274     * </tr>
5275     * <tr>
5276     * <td>int</td>
5277     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
5278     * <td>read-only</td>
5279     * <td>Read-only count of {@link Contacts} from a specific source that have
5280     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
5281     * numbers.</td>
5282     * </tr>
5283     * </table>
5284     */
5285    public static final class Settings implements SettingsColumns {
5286        /**
5287         * This utility class cannot be instantiated
5288         */
5289        private Settings() {
5290        }
5291
5292        /**
5293         * The content:// style URI for this table
5294         */
5295        public static final Uri CONTENT_URI =
5296                Uri.withAppendedPath(AUTHORITY_URI, "settings");
5297
5298        /**
5299         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5300         * settings.
5301         */
5302        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
5303
5304        /**
5305         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
5306         */
5307        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
5308    }
5309
5310    /**
5311     * Private API for inquiring about the general status of the provider.
5312     *
5313     * @hide
5314     */
5315    public static final class ProviderStatus {
5316
5317        /**
5318         * Not instantiable.
5319         */
5320        private ProviderStatus() {
5321        }
5322
5323        /**
5324         * The content:// style URI for this table.  Requests to this URI can be
5325         * performed on the UI thread because they are always unblocking.
5326         *
5327         * @hide
5328         */
5329        public static final Uri CONTENT_URI =
5330                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
5331
5332        /**
5333         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5334         * settings.
5335         *
5336         * @hide
5337         */
5338        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
5339
5340        /**
5341         * An integer representing the current status of the provider.
5342         *
5343         * @hide
5344         */
5345        public static final String STATUS = "status";
5346
5347        /**
5348         * Default status of the provider.
5349         *
5350         * @hide
5351         */
5352        public static final int STATUS_NORMAL = 0;
5353
5354        /**
5355         * The status used when the provider is in the process of upgrading.  Contacts
5356         * are temporarily unaccessible.
5357         *
5358         * @hide
5359         */
5360        public static final int STATUS_UPGRADING = 1;
5361
5362        /**
5363         * The status used if the provider was in the process of upgrading but ran
5364         * out of storage. The DATA1 column will contain the estimated amount of
5365         * storage required (in bytes). Update status to STATUS_NORMAL to force
5366         * the provider to retry the upgrade.
5367         *
5368         * @hide
5369         */
5370        public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2;
5371
5372        /**
5373         * The status used during a locale change.
5374         *
5375         * @hide
5376         */
5377        public static final int STATUS_CHANGING_LOCALE = 3;
5378
5379        /**
5380         * Additional data associated with the status.
5381         *
5382         * @hide
5383         */
5384        public static final String DATA1 = "data1";
5385    }
5386
5387    /**
5388     * Helper methods to display QuickContact dialogs that allow users to pivot on
5389     * a specific {@link Contacts} entry.
5390     */
5391    public static final class QuickContact {
5392        /**
5393         * Action used to trigger person pivot dialog.
5394         * @hide
5395         */
5396        public static final String ACTION_QUICK_CONTACT =
5397                "com.android.contacts.action.QUICK_CONTACT";
5398
5399        /**
5400         * Extra used to specify pivot dialog location in screen coordinates.
5401         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
5402         * @hide
5403         */
5404        @Deprecated
5405        public static final String EXTRA_TARGET_RECT = "target_rect";
5406
5407        /**
5408         * Extra used to specify size of pivot dialog.
5409         * @hide
5410         */
5411        public static final String EXTRA_MODE = "mode";
5412
5413        /**
5414         * Extra used to indicate a list of specific MIME-types to exclude and
5415         * not display. Stored as a {@link String} array.
5416         * @hide
5417         */
5418        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
5419
5420        /**
5421         * Small QuickContact mode, usually presented with minimal actions.
5422         */
5423        public static final int MODE_SMALL = 1;
5424
5425        /**
5426         * Medium QuickContact mode, includes actions and light summary describing
5427         * the {@link Contacts} entry being shown. This may include social
5428         * status and presence details.
5429         */
5430        public static final int MODE_MEDIUM = 2;
5431
5432        /**
5433         * Large QuickContact mode, includes actions and larger, card-like summary
5434         * of the {@link Contacts} entry being shown. This may include detailed
5435         * information, such as a photo.
5436         */
5437        public static final int MODE_LARGE = 3;
5438
5439        /**
5440         * Trigger a dialog that lists the various methods of interacting with
5441         * the requested {@link Contacts} entry. This may be based on available
5442         * {@link ContactsContract.Data} rows under that contact, and may also
5443         * include social status and presence details.
5444         *
5445         * @param context The parent {@link Context} that may be used as the
5446         *            parent for this dialog.
5447         * @param target Specific {@link View} from your layout that this dialog
5448         *            should be centered around. In particular, if the dialog
5449         *            has a "callout" arrow, it will be pointed and centered
5450         *            around this {@link View}.
5451         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
5452         *            {@link Uri} that describes a specific contact to feature
5453         *            in this dialog.
5454         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
5455         *            {@link #MODE_LARGE}, indicating the desired dialog size,
5456         *            when supported.
5457         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
5458         *            to exclude when showing this dialog. For example, when
5459         *            already viewing the contact details card, this can be used
5460         *            to omit the details entry from the dialog.
5461         */
5462        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
5463                String[] excludeMimes) {
5464            // Find location and bounds of target view, adjusting based on the
5465            // assumed local density.
5466            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
5467            final int[] pos = new int[2];
5468            target.getLocationOnScreen(pos);
5469
5470            final Rect rect = new Rect();
5471            rect.left = (int) (pos[0] * appScale + 0.5f);
5472            rect.top = (int) (pos[1] * appScale + 0.5f);
5473            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
5474            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
5475
5476            // Trigger with obtained rectangle
5477            showQuickContact(context, rect, lookupUri, mode, excludeMimes);
5478        }
5479
5480        /**
5481         * Trigger a dialog that lists the various methods of interacting with
5482         * the requested {@link Contacts} entry. This may be based on available
5483         * {@link ContactsContract.Data} rows under that contact, and may also
5484         * include social status and presence details.
5485         *
5486         * @param context The parent {@link Context} that may be used as the
5487         *            parent for this dialog.
5488         * @param target Specific {@link Rect} that this dialog should be
5489         *            centered around, in screen coordinates. In particular, if
5490         *            the dialog has a "callout" arrow, it will be pointed and
5491         *            centered around this {@link Rect}. If you are running at a
5492         *            non-native density, you need to manually adjust using
5493         *            {@link DisplayMetrics#density} before calling.
5494         * @param lookupUri A
5495         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
5496         *            {@link Uri} that describes a specific contact to feature
5497         *            in this dialog.
5498         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
5499         *            {@link #MODE_LARGE}, indicating the desired dialog size,
5500         *            when supported.
5501         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
5502         *            to exclude when showing this dialog. For example, when
5503         *            already viewing the contact details card, this can be used
5504         *            to omit the details entry from the dialog.
5505         */
5506        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
5507                String[] excludeMimes) {
5508            // Launch pivot dialog through intent for now
5509            final Intent intent = new Intent(ACTION_QUICK_CONTACT);
5510            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
5511                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
5512
5513            intent.setData(lookupUri);
5514            intent.setSourceBounds(target);
5515            intent.putExtra(EXTRA_MODE, mode);
5516            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
5517            context.startActivity(intent);
5518        }
5519    }
5520
5521    /**
5522     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
5523     * that involve contacts.
5524     */
5525    public static final class Intents {
5526        /**
5527         * This is the intent that is fired when a search suggestion is clicked on.
5528         */
5529        public static final String SEARCH_SUGGESTION_CLICKED =
5530                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
5531
5532        /**
5533         * This is the intent that is fired when a search suggestion for dialing a number
5534         * is clicked on.
5535         */
5536        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
5537                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
5538
5539        /**
5540         * This is the intent that is fired when a search suggestion for creating a contact
5541         * is clicked on.
5542         */
5543        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
5544                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
5545
5546        /**
5547         * Starts an Activity that lets the user pick a contact to attach an image to.
5548         * After picking the contact it launches the image cropper in face detection mode.
5549         */
5550        public static final String ATTACH_IMAGE =
5551                "com.android.contacts.action.ATTACH_IMAGE";
5552
5553        /**
5554         * Takes as input a data URI with a mailto: or tel: scheme. If a single
5555         * contact exists with the given data it will be shown. If no contact
5556         * exists, a dialog will ask the user if they want to create a new
5557         * contact with the provided details filled in. If multiple contacts
5558         * share the data the user will be prompted to pick which contact they
5559         * want to view.
5560         * <p>
5561         * For <code>mailto:</code> URIs, the scheme specific portion must be a
5562         * raw email address, such as one built using
5563         * {@link Uri#fromParts(String, String, String)}.
5564         * <p>
5565         * For <code>tel:</code> URIs, the scheme specific portion is compared
5566         * to existing numbers using the standard caller ID lookup algorithm.
5567         * The number must be properly encoded, for example using
5568         * {@link Uri#fromParts(String, String, String)}.
5569         * <p>
5570         * Any extras from the {@link Insert} class will be passed along to the
5571         * create activity if there are no contacts to show.
5572         * <p>
5573         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
5574         * prompting the user when the contact doesn't exist.
5575         */
5576        public static final String SHOW_OR_CREATE_CONTACT =
5577                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
5578
5579        /**
5580         * Starts an Activity that lets the user select the multiple phones from a
5581         * list of phone numbers which come from the contacts or
5582         * {@link #EXTRA_PHONE_URIS}.
5583         * <p>
5584         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
5585         * could belong to the contacts or not, and will be selected by default.
5586         * <p>
5587         * The user's selection will be returned from
5588         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
5589         * if the resultCode is
5590         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
5591         * numbers are in the Intent's
5592         * {@link #EXTRA_PHONE_URIS}; otherwise, the
5593         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
5594         * left the Activity without changing the selection.
5595         *
5596         * @hide
5597         */
5598        public static final String ACTION_GET_MULTIPLE_PHONES =
5599                "com.android.contacts.action.GET_MULTIPLE_PHONES";
5600
5601        /**
5602         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
5603         * contact if no matching contact found. Otherwise, default behavior is
5604         * to prompt user with dialog before creating.
5605         * <p>
5606         * Type: BOOLEAN
5607         */
5608        public static final String EXTRA_FORCE_CREATE =
5609                "com.android.contacts.action.FORCE_CREATE";
5610
5611        /**
5612         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
5613         * description to be shown when prompting user about creating a new
5614         * contact.
5615         * <p>
5616         * Type: STRING
5617         */
5618        public static final String EXTRA_CREATE_DESCRIPTION =
5619            "com.android.contacts.action.CREATE_DESCRIPTION";
5620
5621        /**
5622         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
5623         * <p>
5624         * The phone numbers want to be picked by default should be passed in as
5625         * input value. These phone numbers could belong to the contacts or not.
5626         * <p>
5627         * The phone numbers which were picked by the user are returned as output
5628         * value.
5629         * <p>
5630         * Type: array of URIs, the tel URI is used for the phone numbers which don't
5631         * belong to any contact, the content URI is used for phone id in contacts.
5632         *
5633         * @hide
5634         */
5635        public static final String EXTRA_PHONE_URIS =
5636            "com.android.contacts.extra.PHONE_URIS";
5637
5638        /**
5639         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
5640         * dialog location using screen coordinates. When not specified, the
5641         * dialog will be centered.
5642         *
5643         * @hide
5644         */
5645        @Deprecated
5646        public static final String EXTRA_TARGET_RECT = "target_rect";
5647
5648        /**
5649         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
5650         * desired dialog style, usually a variation on size. One of
5651         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
5652         *
5653         * @hide
5654         */
5655        @Deprecated
5656        public static final String EXTRA_MODE = "mode";
5657
5658        /**
5659         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
5660         *
5661         * @hide
5662         */
5663        @Deprecated
5664        public static final int MODE_SMALL = 1;
5665
5666        /**
5667         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
5668         *
5669         * @hide
5670         */
5671        @Deprecated
5672        public static final int MODE_MEDIUM = 2;
5673
5674        /**
5675         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
5676         *
5677         * @hide
5678         */
5679        @Deprecated
5680        public static final int MODE_LARGE = 3;
5681
5682        /**
5683         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
5684         * a list of specific MIME-types to exclude and not display. Stored as a
5685         * {@link String} array.
5686         *
5687         * @hide
5688         */
5689        @Deprecated
5690        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
5691
5692        /**
5693         * Intents related to the Contacts app UI.
5694         *
5695         * @hide
5696         */
5697        public static final class UI {
5698            /**
5699             * The action for the default contacts list tab.
5700             */
5701            public static final String LIST_DEFAULT =
5702                    "com.android.contacts.action.LIST_DEFAULT";
5703
5704            /**
5705             * The action for the contacts list tab.
5706             */
5707            public static final String LIST_GROUP_ACTION =
5708                    "com.android.contacts.action.LIST_GROUP";
5709
5710            /**
5711             * When in LIST_GROUP_ACTION mode, this is the group to display.
5712             */
5713            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
5714
5715            /**
5716             * The action for the all contacts list tab.
5717             */
5718            public static final String LIST_ALL_CONTACTS_ACTION =
5719                    "com.android.contacts.action.LIST_ALL_CONTACTS";
5720
5721            /**
5722             * The action for the contacts with phone numbers list tab.
5723             */
5724            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
5725                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
5726
5727            /**
5728             * The action for the starred contacts list tab.
5729             */
5730            public static final String LIST_STARRED_ACTION =
5731                    "com.android.contacts.action.LIST_STARRED";
5732
5733            /**
5734             * The action for the frequent contacts list tab.
5735             */
5736            public static final String LIST_FREQUENT_ACTION =
5737                    "com.android.contacts.action.LIST_FREQUENT";
5738
5739            /**
5740             * The action for the "strequent" contacts list tab. It first lists the starred
5741             * contacts in alphabetical order and then the frequent contacts in descending
5742             * order of the number of times they have been contacted.
5743             */
5744            public static final String LIST_STREQUENT_ACTION =
5745                    "com.android.contacts.action.LIST_STREQUENT";
5746
5747            /**
5748             * A key for to be used as an intent extra to set the activity
5749             * title to a custom String value.
5750             */
5751            public static final String TITLE_EXTRA_KEY =
5752                    "com.android.contacts.extra.TITLE_EXTRA";
5753
5754            /**
5755             * Activity Action: Display a filtered list of contacts
5756             * <p>
5757             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
5758             * filtering
5759             * <p>
5760             * Output: Nothing.
5761             */
5762            public static final String FILTER_CONTACTS_ACTION =
5763                    "com.android.contacts.action.FILTER_CONTACTS";
5764
5765            /**
5766             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
5767             * intents to supply the text on which to filter.
5768             */
5769            public static final String FILTER_TEXT_EXTRA_KEY =
5770                    "com.android.contacts.extra.FILTER_TEXT";
5771        }
5772
5773        /**
5774         * Convenience class that contains string constants used
5775         * to create contact {@link android.content.Intent Intents}.
5776         */
5777        public static final class Insert {
5778            /** The action code to use when adding a contact */
5779            public static final String ACTION = Intent.ACTION_INSERT;
5780
5781            /**
5782             * If present, forces a bypass of quick insert mode.
5783             */
5784            public static final String FULL_MODE = "full_mode";
5785
5786            /**
5787             * The extra field for the contact name.
5788             * <P>Type: String</P>
5789             */
5790            public static final String NAME = "name";
5791
5792            // TODO add structured name values here.
5793
5794            /**
5795             * The extra field for the contact phonetic name.
5796             * <P>Type: String</P>
5797             */
5798            public static final String PHONETIC_NAME = "phonetic_name";
5799
5800            /**
5801             * The extra field for the contact company.
5802             * <P>Type: String</P>
5803             */
5804            public static final String COMPANY = "company";
5805
5806            /**
5807             * The extra field for the contact job title.
5808             * <P>Type: String</P>
5809             */
5810            public static final String JOB_TITLE = "job_title";
5811
5812            /**
5813             * The extra field for the contact notes.
5814             * <P>Type: String</P>
5815             */
5816            public static final String NOTES = "notes";
5817
5818            /**
5819             * The extra field for the contact phone number.
5820             * <P>Type: String</P>
5821             */
5822            public static final String PHONE = "phone";
5823
5824            /**
5825             * The extra field for the contact phone number type.
5826             * <P>Type: Either an integer value from
5827             * {@link CommonDataKinds.Phone},
5828             *  or a string specifying a custom label.</P>
5829             */
5830            public static final String PHONE_TYPE = "phone_type";
5831
5832            /**
5833             * The extra field for the phone isprimary flag.
5834             * <P>Type: boolean</P>
5835             */
5836            public static final String PHONE_ISPRIMARY = "phone_isprimary";
5837
5838            /**
5839             * The extra field for an optional second contact phone number.
5840             * <P>Type: String</P>
5841             */
5842            public static final String SECONDARY_PHONE = "secondary_phone";
5843
5844            /**
5845             * The extra field for an optional second contact phone number type.
5846             * <P>Type: Either an integer value from
5847             * {@link CommonDataKinds.Phone},
5848             *  or a string specifying a custom label.</P>
5849             */
5850            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
5851
5852            /**
5853             * The extra field for an optional third contact phone number.
5854             * <P>Type: String</P>
5855             */
5856            public static final String TERTIARY_PHONE = "tertiary_phone";
5857
5858            /**
5859             * The extra field for an optional third contact phone number type.
5860             * <P>Type: Either an integer value from
5861             * {@link CommonDataKinds.Phone},
5862             *  or a string specifying a custom label.</P>
5863             */
5864            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
5865
5866            /**
5867             * The extra field for the contact email address.
5868             * <P>Type: String</P>
5869             */
5870            public static final String EMAIL = "email";
5871
5872            /**
5873             * The extra field for the contact email type.
5874             * <P>Type: Either an integer value from
5875             * {@link CommonDataKinds.Email}
5876             *  or a string specifying a custom label.</P>
5877             */
5878            public static final String EMAIL_TYPE = "email_type";
5879
5880            /**
5881             * The extra field for the email isprimary flag.
5882             * <P>Type: boolean</P>
5883             */
5884            public static final String EMAIL_ISPRIMARY = "email_isprimary";
5885
5886            /**
5887             * The extra field for an optional second contact email address.
5888             * <P>Type: String</P>
5889             */
5890            public static final String SECONDARY_EMAIL = "secondary_email";
5891
5892            /**
5893             * The extra field for an optional second contact email type.
5894             * <P>Type: Either an integer value from
5895             * {@link CommonDataKinds.Email}
5896             *  or a string specifying a custom label.</P>
5897             */
5898            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
5899
5900            /**
5901             * The extra field for an optional third contact email address.
5902             * <P>Type: String</P>
5903             */
5904            public static final String TERTIARY_EMAIL = "tertiary_email";
5905
5906            /**
5907             * The extra field for an optional third contact email type.
5908             * <P>Type: Either an integer value from
5909             * {@link CommonDataKinds.Email}
5910             *  or a string specifying a custom label.</P>
5911             */
5912            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
5913
5914            /**
5915             * The extra field for the contact postal address.
5916             * <P>Type: String</P>
5917             */
5918            public static final String POSTAL = "postal";
5919
5920            /**
5921             * The extra field for the contact postal address type.
5922             * <P>Type: Either an integer value from
5923             * {@link CommonDataKinds.StructuredPostal}
5924             *  or a string specifying a custom label.</P>
5925             */
5926            public static final String POSTAL_TYPE = "postal_type";
5927
5928            /**
5929             * The extra field for the postal isprimary flag.
5930             * <P>Type: boolean</P>
5931             */
5932            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
5933
5934            /**
5935             * The extra field for an IM handle.
5936             * <P>Type: String</P>
5937             */
5938            public static final String IM_HANDLE = "im_handle";
5939
5940            /**
5941             * The extra field for the IM protocol
5942             */
5943            public static final String IM_PROTOCOL = "im_protocol";
5944
5945            /**
5946             * The extra field for the IM isprimary flag.
5947             * <P>Type: boolean</P>
5948             */
5949            public static final String IM_ISPRIMARY = "im_isprimary";
5950        }
5951    }
5952}
5953