diff options
author | Fred Quintana <fredq@google.com> | 2009-05-22 14:23:31 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-06-01 16:17:03 -0700 |
commit | 03d9490758c9318cee6d14d3cc5007556dce92d0 (patch) | |
tree | 58d56d848d0a1f0638157f0ba70afc9b75119601 /core/java/android/content/Entity.java | |
parent | b0d031ad132dac585d1f21d46ebebcc4d13f40c7 (diff) | |
download | frameworks_base-03d9490758c9318cee6d14d3cc5007556dce92d0.zip frameworks_base-03d9490758c9318cee6d14d3cc5007556dce92d0.tar.gz frameworks_base-03d9490758c9318cee6d14d3cc5007556dce92d0.tar.bz2 |
- create a new generic ISyncAdapter implementation, SyncAdapterNew
- change the applyBatch to take an ArrayList rather than an []
- change Entity to be a final flass that contains ContentValues
- remove the ability to update/insert Entities by a ContentProviderOperation
Diffstat (limited to 'core/java/android/content/Entity.java')
-rw-r--r-- | core/java/android/content/Entity.java | 80 |
1 files changed, 79 insertions, 1 deletions
diff --git a/core/java/android/content/Entity.java b/core/java/android/content/Entity.java index 31ea2cd..325dce5 100644 --- a/core/java/android/content/Entity.java +++ b/core/java/android/content/Entity.java @@ -17,10 +17,88 @@ package android.content; import android.os.Parcelable; +import android.os.Parcel; +import android.net.Uri; +import android.util.Log; + +import java.util.ArrayList; /** * Objects that pass through the ContentProvider and ContentResolver's methods that deal with * Entities must implement this abstract base class and thus themselves be Parcelable. */ -public abstract class Entity implements Parcelable { +public final class Entity implements Parcelable { + final private ContentValues mValues; + final private ArrayList<NamedContentValues> mSubValues; + + public Entity(ContentValues values) { + mValues = values; + mSubValues = new ArrayList<NamedContentValues>(); + } + + public ContentValues getEntityValues() { + return mValues; + } + + public ArrayList<NamedContentValues> getSubValues() { + return mSubValues; + } + + public void addSubValue(Uri uri, ContentValues values) { + mSubValues.add(new Entity.NamedContentValues(uri, values)); + } + + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + mValues.writeToParcel(dest, 0); + dest.writeInt(mSubValues.size()); + for (NamedContentValues value : mSubValues) { + value.uri.writeToParcel(dest, 0); + value.values.writeToParcel(dest, 0); + } + } + + private Entity(Parcel source) { + mValues = ContentValues.CREATOR.createFromParcel(source); + final int numValues = source.readInt(); + mSubValues = new ArrayList<NamedContentValues>(numValues); + for (int i = 0; i < numValues; i++) { + final Uri uri = Uri.CREATOR.createFromParcel(source); + final ContentValues values = ContentValues.CREATOR.createFromParcel(source); + mSubValues.add(new NamedContentValues(uri, values)); + } + } + + public static final Creator<Entity> CREATOR = new Creator<Entity>() { + public Entity createFromParcel(Parcel source) { + return new Entity(source); + } + + public Entity[] newArray(int size) { + return new Entity[size]; + } + }; + + public static class NamedContentValues { + public final Uri uri; + public final ContentValues values; + + public NamedContentValues(Uri uri, ContentValues values) { + this.uri = uri; + this.values = values; + } + } + + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("Entity: ").append(getEntityValues()); + for (Entity.NamedContentValues namedValue : getSubValues()) { + sb.append("\n ").append(namedValue.uri); + sb.append("\n -> ").append(namedValue.values); + } + return sb.toString(); + } } |