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
public void writeToParcel(Parcel dest, int flags) {
SafeParcelUtil.writeObject(this, dest, flags);
public void writeToParcel(Parcel out, int flags) {
SafeParcelUtil.writeObject(this, out, flags);
}
/**

View File

@ -335,8 +335,8 @@ public class GroundOverlayOptions implements SafeParcelable {
}
@Override
public void writeToParcel(Parcel dest, int flags) {
SafeParcelUtil.writeObject(this, dest, flags);
public void writeToParcel(Parcel out, int 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.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)
private int versionCode;
private final int versionCode;
/**
* Latitude, in degrees. This value is in the range [-90, 90].
*/
@SafeParceled(2)
public double latitude;
public final double latitude;
/**
* Longitude, in degrees. This value is in the range [-180, 180).
*/
@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));
if ((-180 <= longitude) && (longitude < 180)) {
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) {
this(1, latitude, longitude);
LatLng latLng = (LatLng) o;
if (Double.compare(latLng.latitude, latitude) != 0)
return false;
if (Double.compare(latLng.longitude, longitude) != 0)
return false;
return true;
}
@Override
@ -66,8 +113,8 @@ public class LatLng implements SafeParcelable {
}
@Override
public void writeToParcel(Parcel dest, int flags) {
SafeParcelUtil.writeObject(this, dest, flags);
public void writeToParcel(Parcel out, int flags) {
SafeParcelUtil.writeObject(this, out, flags);
}
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.SafeParceled;
public class LatLngBounds implements SafeParcelable {
/**
* An immutable class representing a latitude/longitude aligned rectangle.
*/
public final class LatLngBounds implements SafeParcelable {
@SafeParceled(1)
private int versionCode;
private final int versionCode;
/**
* Southwest corner of the bound.
*/
@SafeParceled(2)
public LatLng southWest;
public final LatLng southwest;
/**
* Northeast corner of the bound.
*/
@SafeParceled(3)
public LatLng northEast;
public final LatLng northeast;
public LatLngBounds(int versionCode, LatLng southWest, LatLng northEast) {
this.versionCode = versionCode;
this.southWest = southWest;
this.northEast = northEast;
}
public LatLngBounds(LatLng southWest, LatLng northEast) {
this(1, southWest, northEast);
/**
* 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 LatLngBounds() {
this.versionCode = -1;
southwest = northeast = null;
}
private LatLngBounds(Parcel in) {
this();
SafeParcelUtil.readObject(this, in);
}
public LatLngBounds(LatLng southwest, LatLng northeast) throws IllegalArgumentException {
this.versionCode = 1;
this.southwest = southwest;
this.northeast = northeast;
}
@Override
public int describeContents() {
return 0;

View File

@ -17,12 +17,10 @@
package com.google.android.gms.maps.model;
import android.os.Parcel;
import android.os.Parcelable;
import org.microg.safeparcel.SafeParcelUtil;
import org.microg.safeparcel.SafeParcelable;
import org.microg.safeparcel.SafeParceled;
import java.util.ArrayList;
import java.util.List;
public class PolylineOptions implements SafeParcelable {
@ -36,7 +34,6 @@ public class PolylineOptions implements SafeParcelable {
private boolean visible;
private boolean geodesic;
public PolylineOptions() {
}

View File

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