下面列出了怎么用android.os.ParcelFormatException的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public KeymasterArgument createFromParcel(Parcel in) {
final int pos = in.dataPosition();
final int tag = in.readInt();
switch (KeymasterDefs.getTagType(tag)) {
case KeymasterDefs.KM_ENUM:
case KeymasterDefs.KM_ENUM_REP:
case KeymasterDefs.KM_UINT:
case KeymasterDefs.KM_UINT_REP:
return new KeymasterIntArgument(tag, in);
case KeymasterDefs.KM_ULONG:
case KeymasterDefs.KM_ULONG_REP:
return new KeymasterLongArgument(tag, in);
case KeymasterDefs.KM_DATE:
return new KeymasterDateArgument(tag, in);
case KeymasterDefs.KM_BYTES:
case KeymasterDefs.KM_BIGNUM:
return new KeymasterBlobArgument(tag, in);
case KeymasterDefs.KM_BOOL:
return new KeymasterBooleanArgument(tag, in);
default:
throw new ParcelFormatException("Bad tag: " + tag + " at " + pos);
}
}
public NetworkEvent createFromParcel(Parcel in) {
final int initialPosition = in.dataPosition();
final int parcelToken = in.readInt();
// we need to move back to the position from before we read parcelToken
in.setDataPosition(initialPosition);
switch (parcelToken) {
case PARCEL_TOKEN_DNS_EVENT:
return DnsEvent.CREATOR.createFromParcel(in);
case PARCEL_TOKEN_CONNECT_EVENT:
return ConnectEvent.CREATOR.createFromParcel(in);
default:
throw new ParcelFormatException("Unexpected NetworkEvent token in parcel: "
+ parcelToken);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.x);
dest.writeFloat(this.getY());
if (getData() != null) {
if (getData() instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.getData(), flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.x);
dest.writeFloat(this.getY());
if (getData() != null) {
if (getData() instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.getData(), flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.x);
dest.writeFloat(this.getY());
if (getData() != null) {
if (getData() instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.getData(), flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.mVal);
dest.writeInt(this.mXIndex);
if (mData != null) {
if (mData instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.mData, flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.mVal);
dest.writeInt(this.mXIndex);
if (mData != null) {
if (mData instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.mData, flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeFloat(this.mVal);
dest.writeInt(this.mXIndex);
if (mData != null) {
if (mData instanceof Parcelable) {
dest.writeInt(1);
dest.writeParcelable((Parcelable) this.mData, flags);
} else {
throw new ParcelFormatException("Cannot parcel an Entry with non-parcelable data");
}
} else {
dest.writeInt(0);
}
}