diff options
author | Fred Quintana <fredq@google.com> | 2009-06-04 10:28:49 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-06-04 12:23:54 -0700 |
commit | d8dfeb5ee82d679f491cd20e776907a69fb4f27c (patch) | |
tree | d9bdc91053e247e2c9c7b8513b8b4ecf5cf4ec4c /core/java | |
parent | a41d3856fafff0e92cc85586c7d2a414036f85ac (diff) | |
download | frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.zip frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.tar.gz frameworks_base-d8dfeb5ee82d679f491cd20e776907a69fb4f27c.tar.bz2 |
- make it easier to add content values to the ContentProviderOperation
- add the group membership common kind as well as some IM utilities to the ContactsContract
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/content/ContentProviderOperation.java | 51 | ||||
-rw-r--r-- | core/java/android/provider/ContactsContract.java | 118 |
2 files changed, 134 insertions, 35 deletions
diff --git a/core/java/android/content/ContentProviderOperation.java b/core/java/android/content/ContentProviderOperation.java index 07be017..001af16 100644 --- a/core/java/android/content/ContentProviderOperation.java +++ b/core/java/android/content/ContentProviderOperation.java @@ -20,6 +20,7 @@ import android.net.Uri; import android.database.Cursor; import android.os.Parcelable; import android.os.Parcel; +import android.os.Debug; import java.util.Map; import java.util.HashMap; @@ -428,7 +429,8 @@ public class ContentProviderOperation implements Parcelable { /** * The ContentValues to use. This may be null. These values may be overwritten by - * the corresponding value specified by {@link #withValueBackReferences(ContentValues)}. + * the corresponding value specified by {@link #withValueBackReference} or by + * future calls to {@link #withValues} or {@link #withValue}. * This can only be used with builders of type insert or update. * @return this builder, to allow for chaining. */ @@ -436,11 +438,56 @@ public class ContentProviderOperation implements Parcelable { if (mType != TYPE_INSERT && mType != TYPE_UPDATE) { throw new IllegalArgumentException("only inserts and updates can have values"); } - mValues = values; + if (mValues == null) { + mValues = new ContentValues(); + } + mValues.putAll(values); return this; } /** + * A value to insert or update. This value may be overwritten by + * the corresponding value specified by {@link #withValueBackReference}. + * This can only be used with builders of type insert or update. + * @param key the name of this value + * @param value the value itself. the type must be acceptable for insertion by + * {@link ContentValues#put} + * @return this builder, to allow for chaining. + */ + public Builder withValue(String key, Object value) { + if (mType != TYPE_INSERT && mType != TYPE_UPDATE) { + throw new IllegalArgumentException("only inserts and updates can have values"); + } + if (mValues == null) { + mValues = new ContentValues(); + } + if (value == null) { + mValues.putNull(key); + } else if (value instanceof String) { + mValues.put(key, (String) value); + } else if (value instanceof Byte) { + mValues.put(key, (Byte) value); + } else if (value instanceof Short) { + mValues.put(key, (Short) value); + } else if (value instanceof Integer) { + mValues.put(key, (Integer) value); + } else if (value instanceof Long) { + mValues.put(key, (Long) value); + } else if (value instanceof Float) { + mValues.put(key, (Float) value); + } else if (value instanceof Double) { + mValues.put(key, (Double) value); + } else if (value instanceof Boolean) { + mValues.put(key, (Boolean) value); + } else if (value instanceof byte[]) { + mValues.put(key, (byte[]) value); + } else { + throw new IllegalArgumentException("bad value type: " + value.getClass().getName()); + } + return this; + } + + /** * The selection and arguments to use. An occurrence of '?' in the selection will be * replaced with the corresponding occurence of the selection argument. Any of the * selection arguments may be overwritten by a selection argument back reference as diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java index 60187d1..2bbf5f9 100644 --- a/core/java/android/provider/ContactsContract.java +++ b/core/java/android/provider/ContactsContract.java @@ -610,6 +610,31 @@ public final class ContactsContract { public static final int PROTOCOL_GOOGLE_TALK = 5; public static final int PROTOCOL_ICQ = 6; public static final int PROTOCOL_JABBER = 7; + + public static String encodePredefinedImProtocol(int protocol) { + return "pre:" + protocol; + } + + public static String encodeCustomImProtocol(String protocolString) { + return "custom:" + protocolString; + } + + public static Object decodeImProtocol(String encodedString) { + if (encodedString == null) { + return null; + } + + if (encodedString.startsWith("pre:")) { + return Integer.parseInt(encodedString.substring(4)); + } + + if (encodedString.startsWith("custom:")) { + return encodedString.substring(7); + } + + throw new IllegalArgumentException( + "the value is not a valid encoded protocol, " + encodedString); + } } /** @@ -705,49 +730,76 @@ public final class ContactsContract { */ public static final String RINGTONE_URI = "data2"; } - } - /** - * Constants for the contact aggregation exceptions table, which contains - * aggregation rules overriding those used by automatic aggregation. - */ - public static final class AggregationExceptions { /** - * This utility class cannot be instantiated + * Constants for the contact aggregation exceptions table, which contains + * aggregation rules overriding those used by automatic aggregation. */ - private AggregationExceptions() {} + public static final class AggregationExceptions { + /** + * This utility class cannot be instantiated + */ + private AggregationExceptions() {} - /** - * The content:// style URI for this table - */ - public static final Uri CONTENT_URI = - Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions"); + /** + * The content:// style URI for this table + */ + public static final Uri CONTENT_URI = + Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions"); - /** - * The MIME type of {@link #CONTENT_URI} providing a directory of data. - */ - public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception"; + /** + * The MIME type of {@link #CONTENT_URI} providing a directory of data. + */ + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception"; - /** - * The type of exception: {@link #TYPE_NEVER_MATCH} or {@link #TYPE_ALWAYS_MATCH}. - * - * <P>Type: INTEGER</P> - */ - public static final String TYPE = "type"; + /** + * The type of exception: {@link #TYPE_NEVER_MATCH} or {@link #TYPE_ALWAYS_MATCH}. + * + * <P>Type: INTEGER</P> + */ + public static final String TYPE = "type"; - public static final int TYPE_NEVER_MATCH = 0; - public static final int TYPE_ALWAYS_MATCH = 1; + public static final int TYPE_NEVER_MATCH = 0; + public static final int TYPE_ALWAYS_MATCH = 1; - /** - * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of one of - * the contacts that the rule applies to. - */ - public static final String CONTACT_ID1 = "contact_id1"; + /** + * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of one of + * the contacts that the rule applies to. + */ + public static final String CONTACT_ID1 = "contact_id1"; + + /** + * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of the other + * contact that the rule applies to. + */ + public static final String CONTACT_ID2 = "contact_id2"; + } /** - * A reference to the {@link android.provider.ContactsContract.Contacts#_ID} of the other - * contact that the rule applies to. + * Group Membership. */ - public static final String CONTACT_ID2 = "contact_id2"; + public static final class GroupMembership implements BaseCommonColumns { + private GroupMembership() {} + + /** Mime-type used when storing this in data table. */ + public static final String CONTENT_ITEM_TYPE = + "vnd.android.cursor.item/group_membership"; + + /** + * The row id of the group that this group membership refers to. Either this or the + * GROUP_SOURCE_ID must be set. If they are both set then they must refer to the same + * group. + * <P>Type: INTEGER</P> + */ + public static final String GROUP_ROW_ID = "data1"; + + /** + * The source id of the group that this membership refers to. Either this or the + * GROUP_ROW_ID must be set. If they are both set then they must refer to the same + * group. + * <P>Type: STRING</P> + */ + public static final String GROUP_SOURCE_ID = "data2"; + } } } |