Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Manually write and read camera's padding array to parcel #15788

Merged
merged 1 commit into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ public CameraPosition createFromParcel(Parcel in) {
LatLng target = in.readParcelable(LatLng.class.getClassLoader());
double tilt = in.readDouble();
double zoom = in.readDouble();
double[] padding = new double[4];
in.readDoubleArray(padding);

double[] padding = null;
int paddingSize = in.readInt();
if (paddingSize > 0) {
padding = new double[paddingSize];
for (int i = 0; i < paddingSize; i++) {
padding[i] = in.readDouble();
}
}

return new CameraPosition(target, zoom, tilt, bearing, padding);
}

Expand Down Expand Up @@ -139,7 +147,16 @@ public void writeToParcel(Parcel out, int flags) {
out.writeParcelable(target, flags);
out.writeDouble(tilt);
out.writeDouble(zoom);
out.writeDoubleArray(padding);

if (padding != null) {
int length = padding.length;
out.writeInt(length);
for (double v : padding) {
out.writeDouble(v);
}
} else {
out.writeInt(-1);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,15 @@ public void testParcelable() {
CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
}

@Test
public void testParcelableNulls() {
CameraPosition cameraPosition1 = new CameraPosition(null, 3, 4, 5, null);
Parcel parcel = Parcel.obtain();
cameraPosition1.writeToParcel(parcel, 0);
parcel.setDataPosition(0);

CameraPosition cameraPosition2 = CameraPosition.CREATOR.createFromParcel(parcel);
assertEquals("Parcel should match original object", cameraPosition1, cameraPosition2);
}
}