Some more API

This commit is contained in:
mar-v-in 2015-01-09 19:24:02 +01:00
parent 6649591d11
commit 93666176e7
6 changed files with 123 additions and 64 deletions

View File

@ -211,8 +211,8 @@ public class CircleOptions implements SafeParcelable {
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel out, int flags) {
SafeParcelUtil.writeObject(this, dest, flags); SafeParcelUtil.writeObject(this, out, flags);
} }
/** /**

View File

@ -335,8 +335,8 @@ public class GroundOverlayOptions implements SafeParcelable {
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel out, int flags) {
SafeParcelUtil.writeObject(this, dest, flags); SafeParcelUtil.writeObject(this, out, flags);
} }
/** /**

View File

@ -21,16 +21,47 @@ import org.microg.safeparcel.SafeParcelUtil;
import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParcelable;
import org.microg.safeparcel.SafeParceled; import org.microg.safeparcel.SafeParceled;
public class LatLng implements SafeParcelable { /**
* An immutable class representing a pair of latitude and longitude coordinates, stored as degrees.
*/
public final class LatLng implements SafeParcelable {
@SafeParceled(1) @SafeParceled(1)
private int versionCode; private final int versionCode;
/**
* Latitude, in degrees. This value is in the range [-90, 90].
*/
@SafeParceled(2) @SafeParceled(2)
public double latitude; public final double latitude;
/**
* Longitude, in degrees. This value is in the range [-180, 180).
*/
@SafeParceled(3) @SafeParceled(3)
public double longitude; public final double longitude;
public LatLng(int versionCode, double latitude, double longitude) { /**
this.versionCode = versionCode; * This constructor is dirty setting the final fields to make the compiler happy.
* In fact, those are replaced by their real values later using SafeParcelUtil.
*/
private LatLng() {
versionCode = -1;
latitude = longitude = 0;
}
private LatLng(Parcel in) {
this();
SafeParcelUtil.readObject(this, in);
}
/**
* Constructs a LatLng with the given latitude and longitude, measured in degrees.
*
* @param latitude The point's latitude. This will be clamped to between -90 degrees and
* +90 degrees inclusive.
* @param longitude The point's longitude. This will be normalized to be within -180 degrees
* inclusive and +180 degrees exclusive.
*/
public LatLng(double latitude, double longitude) {
this.versionCode = 1;
this.latitude = Math.max(-90, Math.min(90, latitude)); this.latitude = Math.max(-90, Math.min(90, latitude));
if ((-180 <= longitude) && (longitude < 180)) { if ((-180 <= longitude) && (longitude < 180)) {
this.longitude = longitude; this.longitude = longitude;
@ -39,12 +70,28 @@ public class LatLng implements SafeParcelable {
} }
} }
private LatLng(Parcel in) { /**
SafeParcelUtil.readObject(this, in); * Tests if this LatLng is equal to another.
} * <p/>
* Two points are considered equal if and only if their latitudes are bitwise equal and their
* longitudes are bitwise equal. This means that two {@link LatLng}s that are very near, in
* terms of geometric distance, might not be considered {@code .equal()}.
*/
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
public LatLng(double latitude, double longitude) { LatLng latLng = (LatLng) o;
this(1, latitude, longitude);
if (Double.compare(latLng.latitude, latitude) != 0)
return false;
if (Double.compare(latLng.longitude, longitude) != 0)
return false;
return true;
} }
@Override @Override
@ -66,8 +113,8 @@ public class LatLng implements SafeParcelable {
} }
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel out, int flags) {
SafeParcelUtil.writeObject(this, dest, flags); SafeParcelUtil.writeObject(this, out, flags);
} }
public static Creator<LatLng> CREATOR = new Creator<LatLng>() { public static Creator<LatLng> CREATOR = new Creator<LatLng>() {

View File

@ -21,28 +21,43 @@ import org.microg.safeparcel.SafeParcelUtil;
import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParcelable;
import org.microg.safeparcel.SafeParceled; import org.microg.safeparcel.SafeParceled;
public class LatLngBounds implements SafeParcelable { /**
* An immutable class representing a latitude/longitude aligned rectangle.
*/
public final class LatLngBounds implements SafeParcelable {
@SafeParceled(1) @SafeParceled(1)
private int versionCode; private final int versionCode;
/**
* Southwest corner of the bound.
*/
@SafeParceled(2) @SafeParceled(2)
public LatLng southWest; public final LatLng southwest;
/**
* Northeast corner of the bound.
*/
@SafeParceled(3) @SafeParceled(3)
public LatLng northEast; public final LatLng northeast;
public LatLngBounds(int versionCode, LatLng southWest, LatLng northEast) { /**
this.versionCode = versionCode; * This constructor is dirty setting the final fields to make the compiler happy.
this.southWest = southWest; * In fact, those are replaced by their real values later using SafeParcelUtil.
this.northEast = northEast; */
} private LatLngBounds() {
this.versionCode = -1;
public LatLngBounds(LatLng southWest, LatLng northEast) { southwest = northeast = null;
this(1, southWest, northEast);
} }
private LatLngBounds(Parcel in) { private LatLngBounds(Parcel in) {
this();
SafeParcelUtil.readObject(this, in); SafeParcelUtil.readObject(this, in);
} }
public LatLngBounds(LatLng southwest, LatLng northeast) throws IllegalArgumentException {
this.versionCode = 1;
this.southwest = southwest;
this.northeast = northeast;
}
@Override @Override
public int describeContents() { public int describeContents() {
return 0; return 0;

View File

@ -17,50 +17,47 @@
package com.google.android.gms.maps.model; package com.google.android.gms.maps.model;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import org.microg.safeparcel.SafeParcelUtil; import org.microg.safeparcel.SafeParcelUtil;
import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParcelable;
import org.microg.safeparcel.SafeParceled; import org.microg.safeparcel.SafeParceled;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class PolylineOptions implements SafeParcelable { public class PolylineOptions implements SafeParcelable {
@SafeParceled(1) @SafeParceled(1)
private int versionCode; private int versionCode;
// TODO // TODO
private List<LatLng> points; private List<LatLng> points;
private float width; private float width;
private int color; private int color;
private float zIndex; private float zIndex;
private boolean visible; private boolean visible;
private boolean geodesic; private boolean geodesic;
public PolylineOptions() {
}
public PolylineOptions() { private PolylineOptions(Parcel in) {
} SafeParcelUtil.readObject(this, in);
}
private PolylineOptions(Parcel in) { @Override
SafeParcelUtil.readObject(this, in); public int describeContents() {
} return 0;
}
@Override @Override
public int describeContents() { public void writeToParcel(Parcel dest, int flags) {
return 0; SafeParcelUtil.writeObject(this, dest, flags);
} }
@Override public static Creator<PolylineOptions> CREATOR = new Creator<PolylineOptions>() {
public void writeToParcel(Parcel dest, int flags) { public PolylineOptions createFromParcel(Parcel source) {
SafeParcelUtil.writeObject(this, dest, flags); return new PolylineOptions(source);
} }
public static Creator<PolylineOptions> CREATOR = new Creator<PolylineOptions>() { public PolylineOptions[] newArray(int size) {
public PolylineOptions createFromParcel(Parcel source) { return new PolylineOptions[size];
return new PolylineOptions(source); }
} };
public PolylineOptions[] newArray(int size) {
return new PolylineOptions[size];
}
};
} }

View File

@ -55,8 +55,8 @@ public class VisibleRegion implements SafeParcelable {
* orientated top view * orientated top view
*/ */
public VisibleRegion(LatLngBounds bounds) { public VisibleRegion(LatLngBounds bounds) {
this(bounds.southWest, new LatLng(bounds.southWest.latitude, bounds.northEast.longitude), this(bounds.southwest, new LatLng(bounds.southwest.latitude, bounds.northeast.longitude),
new LatLng(bounds.northEast.latitude, bounds.southWest.longitude), bounds.northEast, new LatLng(bounds.northeast.latitude, bounds.southwest.longitude), bounds.northeast,
bounds); bounds);
} }