Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d8dfeb5e authored by Fred Quintana's avatar Fred Quintana
Browse files

- 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
parent a41d3856
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -28851,6 +28851,21 @@
<parameter name="previousResult" type="int">
</parameter>
</method>
<method name="withValue"
 return="android.content.ContentProviderOperation.Builder"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="key" type="java.lang.String">
</parameter>
<parameter name="value" type="java.lang.Object">
</parameter>
</method>
<method name="withValueBackReference"
 return="android.content.ContentProviderOperation.Builder"
 abstract="false"
+49 −2
Original line number Diff line number Diff line
@@ -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,7 +438,52 @@ 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;
        }
        
+85 −33
Original line number Diff line number Diff line
@@ -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,7 +730,6 @@ public final class ContactsContract {
             */
            public static final String RINGTONE_URI = "data2";
        }
    }

        /**
         * Constants for the contact aggregation exceptions table, which contains
@@ -750,4 +774,32 @@ public final class ContactsContract {
             */
            public static final String CONTACT_ID2 = "contact_id2";
        }

        /**
         * Group Membership.
         */
        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";
        }
    }
}