diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-09-05 16:45:59 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-05 16:46:00 +0000 |
commit | d3cc74cac29c0534762228accf72ea8c6f5bebde (patch) | |
tree | 65bdcb2eb7b7008e9d47a5df33bae72d47716250 /core/java/android | |
parent | 08e76661bc0ce62dd215aae16ed17394f53fce3f (diff) | |
parent | 5ef33984d0cc50bf4654b0d8e9557ac34d44fddd (diff) | |
download | frameworks_base-d3cc74cac29c0534762228accf72ea8c6f5bebde.zip frameworks_base-d3cc74cac29c0534762228accf72ea8c6f5bebde.tar.gz frameworks_base-d3cc74cac29c0534762228accf72ea8c6f5bebde.tar.bz2 |
Merge "Move Size parceling to Bundle." into lmp-dev
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/os/Bundle.java | 64 | ||||
-rw-r--r-- | core/java/android/os/Parcel.java | 52 | ||||
-rw-r--r-- | core/java/android/util/Size.java | 33 | ||||
-rw-r--r-- | core/java/android/util/SizeF.java | 33 |
4 files changed, 118 insertions, 64 deletions
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java index 3252d19..a9aa570 100644 --- a/core/java/android/os/Bundle.java +++ b/core/java/android/os/Bundle.java @@ -17,6 +17,8 @@ package android.os; import android.util.ArrayMap; +import android.util.Size; +import android.util.SizeF; import android.util.SparseArray; import java.io.Serializable; @@ -335,6 +337,30 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable { } /** + * Inserts a Size value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a Size object, or null + */ + public void putSize(String key, Size value) { + unparcel(); + mMap.put(key, value); + } + + /** + * Inserts a SizeF value into the mapping of this Bundle, replacing + * any existing value for the given key. Either key or value may be null. + * + * @param key a String, or null + * @param value a SizeF object, or null + */ + public void putSizeF(String key, SizeF value) { + unparcel(); + mMap.put(key, value); + } + + /** * Inserts an array of Parcelable values into the mapping of this Bundle, * replacing any existing value for the given key. Either key or value may * be null. @@ -712,6 +738,44 @@ public final class Bundle extends BaseBundle implements Cloneable, Parcelable { * value is explicitly associated with the key. * * @param key a String, or null + * @return a Size value, or null + */ + public Size getSize(String key) { + unparcel(); + final Object o = mMap.get(key); + try { + return (Size) o; + } catch (ClassCastException e) { + typeWarning(key, o, "Size", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null + * @return a Size value, or null + */ + public SizeF getSizeF(String key) { + unparcel(); + final Object o = mMap.get(key); + try { + return (SizeF) o; + } catch (ClassCastException e) { + typeWarning(key, o, "SizeF", e); + return null; + } + } + + /** + * Returns the value associated with the given key, or null if + * no mapping of the desired type exists for the given key or a null + * value is explicitly associated with the key. + * + * @param key a String, or null * @return a Bundle value, or null */ public Bundle getBundle(String key) { diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 645d510..d1ad0ad 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -19,6 +19,8 @@ package android.os; import android.text.TextUtils; import android.util.ArrayMap; import android.util.Log; +import android.util.Size; +import android.util.SizeF; import android.util.SparseArray; import android.util.SparseBooleanArray; @@ -224,6 +226,8 @@ public final class Parcel { private static final int VAL_BOOLEANARRAY = 23; private static final int VAL_CHARSEQUENCEARRAY = 24; private static final int VAL_PERSISTABLEBUNDLE = 25; + private static final int VAL_SIZE = 26; + private static final int VAL_SIZEF = 27; // The initial int32 in a Binder call's reply Parcel header: private static final int EX_SECURITY = -1; @@ -672,6 +676,24 @@ public final class Parcel { } /** + * Flatten a Size into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. + */ + public final void writeSize(Size val) { + writeInt(val.getWidth()); + writeInt(val.getHeight()); + } + + /** + * Flatten a SizeF into the parcel at the current dataPosition(), + * growing dataCapacity() if needed. + */ + public final void writeSizeF(SizeF val) { + writeFloat(val.getWidth()); + writeFloat(val.getHeight()); + } + + /** * Flatten a List into the parcel at the current dataPosition(), growing * dataCapacity() if needed. The List values are written using * {@link #writeValue} and must follow the specification there. @@ -1293,6 +1315,12 @@ public final class Parcel { } else if (v instanceof PersistableBundle) { writeInt(VAL_PERSISTABLEBUNDLE); writePersistableBundle((PersistableBundle) v); + } else if (v instanceof Size) { + writeInt(VAL_SIZE); + writeSize((Size) v); + } else if (v instanceof SizeF) { + writeInt(VAL_SIZEF); + writeSizeF((SizeF) v); } else { Class<?> clazz = v.getClass(); if (clazz.isArray() && clazz.getComponentType() == Object.class) { @@ -1699,6 +1727,24 @@ public final class Parcel { } /** + * Read a Size from the parcel at the current dataPosition(). + */ + public final Size readSize() { + final int width = readInt(); + final int height = readInt(); + return new Size(width, height); + } + + /** + * Read a SizeF from the parcel at the current dataPosition(). + */ + public final SizeF readSizeF() { + final float width = readFloat(); + final float height = readFloat(); + return new SizeF(width, height); + } + + /** * Read and return a byte[] object from the parcel. */ public final byte[] createByteArray() { @@ -2160,6 +2206,12 @@ public final class Parcel { case VAL_PERSISTABLEBUNDLE: return readPersistableBundle(loader); + case VAL_SIZE: + return readSize(); + + case VAL_SIZEF: + return readSizeF(); + default: int off = dataPosition() - 4; throw new RuntimeException( diff --git a/core/java/android/util/Size.java b/core/java/android/util/Size.java index 6424344..62df564 100644 --- a/core/java/android/util/Size.java +++ b/core/java/android/util/Size.java @@ -18,13 +18,10 @@ package android.util; import static com.android.internal.util.Preconditions.checkNotNull; -import android.os.Parcel; -import android.os.Parcelable; - /** * Immutable class for describing width and height dimensions in pixels. */ -public final class Size implements Parcelable { +public final class Size { /** * Create a new immutable Size instance. * @@ -36,11 +33,6 @@ public final class Size implements Parcelable { mHeight = height; } - private Size(Parcel in) { - mWidth = in.readInt(); - mHeight = in.readInt(); - } - /** * Get the width of the size (in pixels). * @return width @@ -155,29 +147,6 @@ public final class Size implements Parcelable { return mHeight ^ ((mWidth << (Integer.SIZE / 2)) | (mWidth >>> (Integer.SIZE / 2))); } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeInt(mWidth); - out.writeInt(mHeight); - } - - public static final Parcelable.Creator<Size> CREATOR = new Parcelable.Creator<Size>() { - @Override - public Size createFromParcel(Parcel in) { - return new Size(in); - } - - @Override - public Size[] newArray(int size) { - return new Size[size]; - } - }; - private final int mWidth; private final int mHeight; } diff --git a/core/java/android/util/SizeF.java b/core/java/android/util/SizeF.java index 88bb439..ac4f187 100644 --- a/core/java/android/util/SizeF.java +++ b/core/java/android/util/SizeF.java @@ -18,9 +18,6 @@ package android.util; import static com.android.internal.util.Preconditions.checkArgumentFinite; -import android.os.Parcel; -import android.os.Parcelable; - /** * Immutable class for describing width and height dimensions in some arbitrary * unit. @@ -28,7 +25,7 @@ import android.os.Parcelable; * Width and height are finite values stored as a floating point representation. * </p> */ -public final class SizeF implements Parcelable { +public final class SizeF { /** * Create a new immutable SizeF instance. * @@ -46,11 +43,6 @@ public final class SizeF implements Parcelable { mHeight = checkArgumentFinite(height, "height"); } - private SizeF(Parcel in) { - mWidth = in.readFloat(); - mHeight = in.readFloat(); - } - /** * Get the width of the size (as an arbitrary unit). * @return width @@ -111,29 +103,6 @@ public final class SizeF implements Parcelable { return Float.floatToIntBits(mWidth) ^ Float.floatToIntBits(mHeight); } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeFloat(mWidth); - out.writeFloat(mHeight); - } - - public static final Parcelable.Creator<SizeF> CREATOR = new Parcelable.Creator<SizeF>() { - @Override - public SizeF createFromParcel(Parcel in) { - return new SizeF(in); - } - - @Override - public SizeF[] newArray(int size) { - return new SizeF[size]; - } - }; - private final float mWidth; private final float mHeight; } |