Merge "Add support for reading and writing double array values"
This commit is contained in:
@@ -58,12 +58,12 @@ import java.util.Set;
|
|||||||
* appropriate to place any Parcel data in to persistent storage: changes
|
* appropriate to place any Parcel data in to persistent storage: changes
|
||||||
* in the underlying implementation of any of the data in the Parcel can
|
* in the underlying implementation of any of the data in the Parcel can
|
||||||
* render older data unreadable.</p>
|
* render older data unreadable.</p>
|
||||||
*
|
*
|
||||||
* <p>The bulk of the Parcel API revolves around reading and writing data
|
* <p>The bulk of the Parcel API revolves around reading and writing data
|
||||||
* of various types. There are six major classes of such functions available.</p>
|
* of various types. There are six major classes of such functions available.</p>
|
||||||
*
|
*
|
||||||
* <h3>Primitives</h3>
|
* <h3>Primitives</h3>
|
||||||
*
|
*
|
||||||
* <p>The most basic data functions are for writing and reading primitive
|
* <p>The most basic data functions are for writing and reading primitive
|
||||||
* data types: {@link #writeByte}, {@link #readByte}, {@link #writeDouble},
|
* data types: {@link #writeByte}, {@link #readByte}, {@link #writeDouble},
|
||||||
* {@link #readDouble}, {@link #writeFloat}, {@link #readFloat}, {@link #writeInt},
|
* {@link #readDouble}, {@link #writeFloat}, {@link #readFloat}, {@link #writeInt},
|
||||||
@@ -71,15 +71,15 @@ import java.util.Set;
|
|||||||
* {@link #writeString}, {@link #readString}. Most other
|
* {@link #writeString}, {@link #readString}. Most other
|
||||||
* data operations are built on top of these. The given data is written and
|
* data operations are built on top of these. The given data is written and
|
||||||
* read using the endianess of the host CPU.</p>
|
* read using the endianess of the host CPU.</p>
|
||||||
*
|
*
|
||||||
* <h3>Primitive Arrays</h3>
|
* <h3>Primitive Arrays</h3>
|
||||||
*
|
*
|
||||||
* <p>There are a variety of methods for reading and writing raw arrays
|
* <p>There are a variety of methods for reading and writing raw arrays
|
||||||
* of primitive objects, which generally result in writing a 4-byte length
|
* of primitive objects, which generally result in writing a 4-byte length
|
||||||
* followed by the primitive data items. The methods for reading can either
|
* followed by the primitive data items. The methods for reading can either
|
||||||
* read the data into an existing array, or create and return a new array.
|
* read the data into an existing array, or create and return a new array.
|
||||||
* These available types are:</p>
|
* These available types are:</p>
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li> {@link #writeBooleanArray(boolean[])},
|
* <li> {@link #writeBooleanArray(boolean[])},
|
||||||
* {@link #readBooleanArray(boolean[])}, {@link #createBooleanArray()}
|
* {@link #readBooleanArray(boolean[])}, {@link #createBooleanArray()}
|
||||||
@@ -101,9 +101,9 @@ import java.util.Set;
|
|||||||
* <li> {@link #writeSparseBooleanArray(SparseBooleanArray)},
|
* <li> {@link #writeSparseBooleanArray(SparseBooleanArray)},
|
||||||
* {@link #readSparseBooleanArray()}.
|
* {@link #readSparseBooleanArray()}.
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <h3>Parcelables</h3>
|
* <h3>Parcelables</h3>
|
||||||
*
|
*
|
||||||
* <p>The {@link Parcelable} protocol provides an extremely efficient (but
|
* <p>The {@link Parcelable} protocol provides an extremely efficient (but
|
||||||
* low-level) protocol for objects to write and read themselves from Parcels.
|
* low-level) protocol for objects to write and read themselves from Parcels.
|
||||||
* You can use the direct methods {@link #writeParcelable(Parcelable, int)}
|
* You can use the direct methods {@link #writeParcelable(Parcelable, int)}
|
||||||
@@ -113,7 +113,7 @@ import java.util.Set;
|
|||||||
* methods write both the class type and its data to the Parcel, allowing
|
* methods write both the class type and its data to the Parcel, allowing
|
||||||
* that class to be reconstructed from the appropriate class loader when
|
* that class to be reconstructed from the appropriate class loader when
|
||||||
* later reading.</p>
|
* later reading.</p>
|
||||||
*
|
*
|
||||||
* <p>There are also some methods that provide a more efficient way to work
|
* <p>There are also some methods that provide a more efficient way to work
|
||||||
* with Parcelables: {@link #writeTypedObject}, {@link #writeTypedArray},
|
* with Parcelables: {@link #writeTypedObject}, {@link #writeTypedArray},
|
||||||
* {@link #writeTypedList}, {@link #readTypedObject},
|
* {@link #writeTypedList}, {@link #readTypedObject},
|
||||||
@@ -126,9 +126,9 @@ import java.util.Set;
|
|||||||
* call {@link Parcelable#writeToParcel Parcelable.writeToParcel} and
|
* call {@link Parcelable#writeToParcel Parcelable.writeToParcel} and
|
||||||
* {@link Parcelable.Creator#createFromParcel Parcelable.Creator.createFromParcel}
|
* {@link Parcelable.Creator#createFromParcel Parcelable.Creator.createFromParcel}
|
||||||
* yourself.)</p>
|
* yourself.)</p>
|
||||||
*
|
*
|
||||||
* <h3>Bundles</h3>
|
* <h3>Bundles</h3>
|
||||||
*
|
*
|
||||||
* <p>A special type-safe container, called {@link Bundle}, is available
|
* <p>A special type-safe container, called {@link Bundle}, is available
|
||||||
* for key/value maps of heterogeneous values. This has many optimizations
|
* for key/value maps of heterogeneous values. This has many optimizations
|
||||||
* for improved performance when reading and writing data, and its type-safe
|
* for improved performance when reading and writing data, and its type-safe
|
||||||
@@ -136,16 +136,16 @@ import java.util.Set;
|
|||||||
* data contents into a Parcel. The methods to use are
|
* data contents into a Parcel. The methods to use are
|
||||||
* {@link #writeBundle(Bundle)}, {@link #readBundle()}, and
|
* {@link #writeBundle(Bundle)}, {@link #readBundle()}, and
|
||||||
* {@link #readBundle(ClassLoader)}.
|
* {@link #readBundle(ClassLoader)}.
|
||||||
*
|
*
|
||||||
* <h3>Active Objects</h3>
|
* <h3>Active Objects</h3>
|
||||||
*
|
*
|
||||||
* <p>An unusual feature of Parcel is the ability to read and write active
|
* <p>An unusual feature of Parcel is the ability to read and write active
|
||||||
* objects. For these objects the actual contents of the object is not
|
* objects. For these objects the actual contents of the object is not
|
||||||
* written, rather a special token referencing the object is written. When
|
* written, rather a special token referencing the object is written. When
|
||||||
* reading the object back from the Parcel, you do not get a new instance of
|
* reading the object back from the Parcel, you do not get a new instance of
|
||||||
* the object, but rather a handle that operates on the exact same object that
|
* the object, but rather a handle that operates on the exact same object that
|
||||||
* was originally written. There are two forms of active objects available.</p>
|
* was originally written. There are two forms of active objects available.</p>
|
||||||
*
|
*
|
||||||
* <p>{@link Binder} objects are a core facility of Android's general cross-process
|
* <p>{@link Binder} objects are a core facility of Android's general cross-process
|
||||||
* communication system. The {@link IBinder} interface describes an abstract
|
* communication system. The {@link IBinder} interface describes an abstract
|
||||||
* protocol with a Binder object. Any such interface can be written in to
|
* protocol with a Binder object. Any such interface can be written in to
|
||||||
@@ -158,7 +158,7 @@ import java.util.Set;
|
|||||||
* {@link #createBinderArray()},
|
* {@link #createBinderArray()},
|
||||||
* {@link #writeBinderList(List)}, {@link #readBinderList(List)},
|
* {@link #writeBinderList(List)}, {@link #readBinderList(List)},
|
||||||
* {@link #createBinderArrayList()}.</p>
|
* {@link #createBinderArrayList()}.</p>
|
||||||
*
|
*
|
||||||
* <p>FileDescriptor objects, representing raw Linux file descriptor identifiers,
|
* <p>FileDescriptor objects, representing raw Linux file descriptor identifiers,
|
||||||
* can be written and {@link ParcelFileDescriptor} objects returned to operate
|
* can be written and {@link ParcelFileDescriptor} objects returned to operate
|
||||||
* on the original file descriptor. The returned file descriptor is a dup
|
* on the original file descriptor. The returned file descriptor is a dup
|
||||||
@@ -166,9 +166,9 @@ import java.util.Set;
|
|||||||
* operating on the same underlying file stream, with the same position, etc.
|
* operating on the same underlying file stream, with the same position, etc.
|
||||||
* The methods to use are {@link #writeFileDescriptor(FileDescriptor)},
|
* The methods to use are {@link #writeFileDescriptor(FileDescriptor)},
|
||||||
* {@link #readFileDescriptor()}.
|
* {@link #readFileDescriptor()}.
|
||||||
*
|
*
|
||||||
* <h3>Untyped Containers</h3>
|
* <h3>Untyped Containers</h3>
|
||||||
*
|
*
|
||||||
* <p>A final class of methods are for writing and reading standard Java
|
* <p>A final class of methods are for writing and reading standard Java
|
||||||
* containers of arbitrary types. These all revolve around the
|
* containers of arbitrary types. These all revolve around the
|
||||||
* {@link #writeValue(Object)} and {@link #readValue(ClassLoader)} methods
|
* {@link #writeValue(Object)} and {@link #readValue(ClassLoader)} methods
|
||||||
@@ -229,6 +229,7 @@ public final class Parcel {
|
|||||||
private static final int VAL_PERSISTABLEBUNDLE = 25;
|
private static final int VAL_PERSISTABLEBUNDLE = 25;
|
||||||
private static final int VAL_SIZE = 26;
|
private static final int VAL_SIZE = 26;
|
||||||
private static final int VAL_SIZEF = 27;
|
private static final int VAL_SIZEF = 27;
|
||||||
|
private static final int VAL_DOUBLEARRAY = 28;
|
||||||
|
|
||||||
// The initial int32 in a Binder call's reply Parcel header:
|
// The initial int32 in a Binder call's reply Parcel header:
|
||||||
private static final int EX_SECURITY = -1;
|
private static final int EX_SECURITY = -1;
|
||||||
@@ -642,7 +643,7 @@ public final class Parcel {
|
|||||||
* growing dataCapacity() if needed. The Map keys must be String objects.
|
* growing dataCapacity() if needed. The Map keys must be String objects.
|
||||||
* The Map values are written using {@link #writeValue} and must follow
|
* The Map values are written using {@link #writeValue} and must follow
|
||||||
* the specification there.
|
* the specification there.
|
||||||
*
|
*
|
||||||
* <p>It is strongly recommended to use {@link #writeBundle} instead of
|
* <p>It is strongly recommended to use {@link #writeBundle} instead of
|
||||||
* this method, since the Bundle class provides a type-safe API that
|
* this method, since the Bundle class provides a type-safe API that
|
||||||
* allows you to avoid mysterious type errors at the point of marshalling.
|
* allows you to avoid mysterious type errors at the point of marshalling.
|
||||||
@@ -1408,6 +1409,9 @@ public final class Parcel {
|
|||||||
} else if (v instanceof SizeF) {
|
} else if (v instanceof SizeF) {
|
||||||
writeInt(VAL_SIZEF);
|
writeInt(VAL_SIZEF);
|
||||||
writeSizeF((SizeF) v);
|
writeSizeF((SizeF) v);
|
||||||
|
} else if (v instanceof double[]) {
|
||||||
|
writeInt(VAL_DOUBLEARRAY);
|
||||||
|
writeDoubleArray((double[]) v);
|
||||||
} else {
|
} else {
|
||||||
Class<?> clazz = v.getClass();
|
Class<?> clazz = v.getClass();
|
||||||
if (clazz.isArray() && clazz.getComponentType() == Object.class) {
|
if (clazz.isArray() && clazz.getComponentType() == Object.class) {
|
||||||
@@ -1483,7 +1487,7 @@ public final class Parcel {
|
|||||||
* exception will be re-thrown by this function as a RuntimeException
|
* exception will be re-thrown by this function as a RuntimeException
|
||||||
* (to be caught by the system's last-resort exception handling when
|
* (to be caught by the system's last-resort exception handling when
|
||||||
* dispatching a transaction).
|
* dispatching a transaction).
|
||||||
*
|
*
|
||||||
* <p>The supported exception types are:
|
* <p>The supported exception types are:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>{@link BadParcelableException}
|
* <li>{@link BadParcelableException}
|
||||||
@@ -1493,7 +1497,7 @@ public final class Parcel {
|
|||||||
* <li>{@link SecurityException}
|
* <li>{@link SecurityException}
|
||||||
* <li>{@link NetworkOnMainThreadException}
|
* <li>{@link NetworkOnMainThreadException}
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param e The Exception to be written.
|
* @param e The Exception to be written.
|
||||||
*
|
*
|
||||||
* @see #writeNoException
|
* @see #writeNoException
|
||||||
@@ -1814,7 +1818,7 @@ public final class Parcel {
|
|||||||
if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
|
if (Bundle.DEBUG) Log.d(TAG, "null bundle: length=" + length);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Bundle bundle = new Bundle(this, length);
|
final Bundle bundle = new Bundle(this, length);
|
||||||
if (loader != null) {
|
if (loader != null) {
|
||||||
bundle.setClassLoader(loader);
|
bundle.setClassLoader(loader);
|
||||||
@@ -2325,7 +2329,7 @@ public final class Parcel {
|
|||||||
return readArrayList(loader);
|
return readArrayList(loader);
|
||||||
|
|
||||||
case VAL_BOOLEANARRAY:
|
case VAL_BOOLEANARRAY:
|
||||||
return createBooleanArray();
|
return createBooleanArray();
|
||||||
|
|
||||||
case VAL_BYTEARRAY:
|
case VAL_BYTEARRAY:
|
||||||
return createByteArray();
|
return createByteArray();
|
||||||
@@ -2375,6 +2379,9 @@ public final class Parcel {
|
|||||||
case VAL_SIZEF:
|
case VAL_SIZEF:
|
||||||
return readSizeF();
|
return readSizeF();
|
||||||
|
|
||||||
|
case VAL_DOUBLEARRAY:
|
||||||
|
return createDoubleArray();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
int off = dataPosition() - 4;
|
int off = dataPosition() - 4;
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
|
|||||||
Reference in New Issue
Block a user