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/os | |
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/os')
-rw-r--r-- | core/java/android/os/Bundle.java | 64 | ||||
-rw-r--r-- | core/java/android/os/Parcel.java | 52 |
2 files changed, 116 insertions, 0 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( |