diff options
-rw-r--r-- | api/current.txt | 18 | ||||
-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 |
5 files changed, 128 insertions, 72 deletions
diff --git a/api/current.txt b/api/current.txt index 5e14236..c04b18d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -21577,6 +21577,8 @@ package android.os { method public short getShort(java.lang.String); method public short getShort(java.lang.String, short); method public short[] getShortArray(java.lang.String); + method public android.util.Size getSize(java.lang.String); + method public android.util.SizeF getSizeF(java.lang.String); method public android.util.SparseArray<T> getSparseParcelableArray(java.lang.String); method public java.util.ArrayList<java.lang.String> getStringArrayList(java.lang.String); method public boolean hasFileDescriptors(); @@ -21601,6 +21603,8 @@ package android.os { method public void putSerializable(java.lang.String, java.io.Serializable); method public void putShort(java.lang.String, short); method public void putShortArray(java.lang.String, short[]); + method public void putSize(java.lang.String, android.util.Size); + method public void putSizeF(java.lang.String, android.util.SizeF); method public void putSparseParcelableArray(java.lang.String, android.util.SparseArray<? extends android.os.Parcelable>); method public void putStringArrayList(java.lang.String, java.util.ArrayList<java.lang.String>); method public void readFromParcel(android.os.Parcel); @@ -22052,6 +22056,8 @@ package android.os { method public final android.os.PersistableBundle readPersistableBundle(); method public final android.os.PersistableBundle readPersistableBundle(java.lang.ClassLoader); method public final java.io.Serializable readSerializable(); + method public final android.util.Size readSize(); + method public final android.util.SizeF readSizeF(); method public final android.util.SparseArray readSparseArray(java.lang.ClassLoader); method public final android.util.SparseBooleanArray readSparseBooleanArray(); method public final java.lang.String readString(); @@ -22093,6 +22099,8 @@ package android.os { method public final void writeParcelableArray(T[], int); method public final void writePersistableBundle(android.os.PersistableBundle); method public final void writeSerializable(java.io.Serializable); + method public final void writeSize(android.util.Size); + method public final void writeSizeF(android.util.SizeF); method public final void writeSparseArray(android.util.SparseArray<java.lang.Object>); method public final void writeSparseBooleanArray(android.util.SparseBooleanArray); method public final void writeString(java.lang.String); @@ -32132,23 +32140,17 @@ package android.util { field public static final android.util.Rational ZERO; } - public final class Size implements android.os.Parcelable { + public final class Size { ctor public Size(int, int); - method public int describeContents(); method public int getHeight(); method public int getWidth(); method public static android.util.Size parseSize(java.lang.String) throws java.lang.NumberFormatException; - method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; } - public final class SizeF implements android.os.Parcelable { + public final class SizeF { ctor public SizeF(float, float); - method public int describeContents(); method public float getHeight(); method public float getWidth(); - method public void writeToParcel(android.os.Parcel, int); - field public static final android.os.Parcelable.Creator CREATOR; } public class SparseArray implements java.lang.Cloneable { 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; } |