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