diff options
author | Romain Guy <romainguy@android.com> | 2009-08-11 12:10:08 -0700 |
---|---|---|
committer | Romain Guy <romainguy@android.com> | 2009-08-11 12:10:08 -0700 |
commit | 09ddc08b0d9c849e22f778666f383b7ceefbd9c8 (patch) | |
tree | 0cc207986d0e73614924e0faaefa49d79101805b /core/java/android/appwidget | |
parent | b474b451048728e0a565f1b065b76b4c35cefc66 (diff) | |
download | frameworks_base-09ddc08b0d9c849e22f778666f383b7ceefbd9c8.zip frameworks_base-09ddc08b0d9c849e22f778666f383b7ceefbd9c8.tar.gz frameworks_base-09ddc08b0d9c849e22f778666f383b7ceefbd9c8.tar.bz2 |
Fixes #2021442. Prevent app widgets from clobbering Home's view ids.
Diffstat (limited to 'core/java/android/appwidget')
-rw-r--r-- | core/java/android/appwidget/AppWidgetHostView.java | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/core/java/android/appwidget/AppWidgetHostView.java b/core/java/android/appwidget/AppWidgetHostView.java index 9799ac4..cced338 100644 --- a/core/java/android/appwidget/AppWidgetHostView.java +++ b/core/java/android/appwidget/AppWidgetHostView.java @@ -24,16 +24,17 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.SystemClock; +import android.os.Parcelable; +import android.os.Parcel; import android.util.AttributeSet; import android.util.Log; +import android.util.SparseArray; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.RemoteViews; import android.widget.TextView; -import android.widget.FrameLayout.LayoutParams; /** * Provides the glue to show AppWidget views. This class offers automatic animation @@ -108,6 +109,24 @@ public class AppWidgetHostView extends FrameLayout { return mInfo; } + @Override + protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { + final ParcelableSparseArray jail = new ParcelableSparseArray(); + super.dispatchSaveInstanceState(jail); + container.put(generateId(), jail); + } + + private int generateId() { + final int id = getId(); + return id == View.NO_ID ? mAppWidgetId : id; + } + + @Override + protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { + final ParcelableSparseArray jail = (ParcelableSparseArray) container.get(generateId()); + super.dispatchRestoreInstanceState(jail); + } + /** {@inheritDoc} */ @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { @@ -339,4 +358,36 @@ public class AppWidgetHostView extends FrameLayout { tv.setBackgroundColor(Color.argb(127, 0, 0, 0)); return tv; } + + private static class ParcelableSparseArray extends SparseArray<Parcelable> implements Parcelable { + public int describeContents() { + return 0; + } + + public void writeToParcel(Parcel dest, int flags) { + final int count = size(); + dest.writeInt(count); + for (int i = 0; i < count; i++) { + dest.writeInt(keyAt(i)); + dest.writeParcelable(valueAt(i), 0); + } + } + + public static final Parcelable.Creator<ParcelableSparseArray> CREATOR = + new Parcelable.Creator<ParcelableSparseArray>() { + public ParcelableSparseArray createFromParcel(Parcel source) { + final ParcelableSparseArray array = new ParcelableSparseArray(); + final ClassLoader loader = array.getClass().getClassLoader(); + final int count = source.readInt(); + for (int i = 0; i < count; i++) { + array.put(source.readInt(), source.readParcelable(loader)); + } + return array; + } + + public ParcelableSparseArray[] newArray(int size) { + return new ParcelableSparseArray[size]; + } + }; + } } |