diff --git a/src/com/google/android/gms/maps/model/BitmapDescriptor.java b/src/com/google/android/gms/maps/model/BitmapDescriptor.java new file mode 100644 index 00000000..800c1745 --- /dev/null +++ b/src/com/google/android/gms/maps/model/BitmapDescriptor.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014 μg Project Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.android.gms.maps.model; + +import com.google.android.gms.dynamic.IObjectWrapper; + +/** + * Defines an image. For a marker, it can be used to set the image of the marker icon. For a ground + * overlay, it can be used to set the image to place on the surface of the earth. + */ +public class BitmapDescriptor { + private final IObjectWrapper remoteObject; + + public BitmapDescriptor(IObjectWrapper remoteObject) { + this.remoteObject = remoteObject; + } + + public IObjectWrapper getRemoteObject() { + return remoteObject; + } +} diff --git a/src/com/google/android/gms/maps/model/CameraPosition.java b/src/com/google/android/gms/maps/model/CameraPosition.java index 109dfddb..ea00da74 100644 --- a/src/com/google/android/gms/maps/model/CameraPosition.java +++ b/src/com/google/android/gms/maps/model/CameraPosition.java @@ -16,31 +16,78 @@ package com.google.android.gms.maps.model; +import android.content.Context; import android.os.Parcel; +import android.util.AttributeSet; import org.microg.safeparcel.SafeParcelUtil; import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; import java.util.Arrays; -public class CameraPosition implements SafeParcelable { +/** + * An immutable class that aggregates all camera position parameters. + */ +public final class CameraPosition implements SafeParcelable { @SafeParceled(1) - private int versionCode; + private final int versionCode; + /** + * The location that the camera is pointing at. + */ @SafeParceled(2) - public LatLng target; + public final LatLng target; + /** + * Zoom level near the center of the screen. + * See {@link Builder#zoom(float)} for the definition of the camera's zoom level. + */ @SafeParceled(3) - public float zoom; + public final float zoom; + /** + * The angle, in degrees, of the camera angle from the nadir (directly facing the Earth). + * See {@link Builder#tilt(float)} for details of restrictions on the range of values. + */ @SafeParceled(4) - public float tilt; + public final float tilt; + /** + * Direction that the camera is pointing in, in degrees clockwise from north. + */ @SafeParceled(5) - public float bearing; + public final float bearing; - private CameraPosition(Parcel in) { - SafeParcelUtil.readObject(this, in); + /** + * 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 CameraPosition() { + target = null; + versionCode = -1; + zoom = tilt = bearing = 0; } - public CameraPosition(int versionCode, LatLng target, float zoom, float tilt, float bearing) { - this.versionCode = versionCode; + private CameraPosition(Parcel in) { + this(); + SafeParcelUtil.readObject(this, in); + if (target == null) + throw new NullPointerException("Target must not be null"); + } + + /** + * Constructs a CameraPosition. + * + * @param target The target location to align with the center of the screen. + * @param zoom Zoom level at target. See {@link #zoom} for details of restrictions. + * @param tilt The camera angle, in degrees, from the nadir (directly down). See + * {@link #tilt} for details of restrictions. + * @param bearing Direction that the camera is pointing in, in degrees clockwise from north. + * This value will be normalized to be within 0 degrees inclusive and 360 + * degrees exclusive. + * @throws NullPointerException if {@code target} is {@code null} + * @throws IllegalArgumentException if {@code tilt} is outside range of {@code 0} to {@code 90} + * degrees inclusive + */ + public CameraPosition(LatLng target, float zoom, float tilt, float bearing) + throws NullPointerException, IllegalArgumentException { + versionCode = 1; if (target == null) { throw new NullPointerException("null camera target"); } @@ -56,17 +103,27 @@ public class CameraPosition implements SafeParcelable { this.bearing = bearing % 360; } - public CameraPosition(LatLng target, float zoom, float tilt, float bearing) { - this(1, target, zoom, tilt, bearing); + /** + * Creates a builder for a camera position. + */ + public static Builder builder() { + return new Builder(); } - public static CameraPosition create(LatLng latLng) { - return new CameraPosition(latLng, 0, 0, 0); + /** + * Creates a builder for a camera position, initialized to a given position. + */ + public static Builder builder(CameraPosition camera) { + return new Builder(camera); } - @Override - public int hashCode() { - return Arrays.hashCode(new Object[] { target, zoom, tilt, bearing }); + /** + * Creates a CameraPostion from the attribute set + * + * @throws UnsupportedOperationException + */ + public static CameraPosition createFromAttributes(Context context, AttributeSet attrs) { + return null; // TODO } @Override @@ -75,8 +132,53 @@ public class CameraPosition implements SafeParcelable { } @Override - public void writeToParcel(Parcel dest, int flags) { - SafeParcelUtil.writeObject(this, dest, flags); + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + CameraPosition that = (CameraPosition) o; + + if (Float.compare(that.bearing, bearing) != 0) + return false; + if (Float.compare(that.tilt, tilt) != 0) + return false; + if (Float.compare(that.zoom, zoom) != 0) + return false; + if (!target.equals(that.target)) + return false; + + return true; + } + + /** + * Constructs a CameraPosition pointed for a particular target and zoom level. The resultant + * bearing is North, and the viewing angle is perpendicular to the Earth's surface. i.e., + * directly facing the Earth's surface, with the top of the screen pointing North. + * + * @param target The target location to align with the center of the screen. + * @param zoom Zoom level at target. See {@link Builder#zoom(float)} for details on the range + * the value will be clamped to. The larger the value the more zoomed in the + * camera is. + */ + public static final CameraPosition fromLatLngZoom(LatLng target, float zoom) { + return builder().target(target).zoom(zoom).build(); + } + + @Override + public int hashCode() { + return Arrays.hashCode(new Object[] { target, zoom, tilt, bearing }); + } + + @Override + public String toString() { + return super.toString(); // TODO + } + + @Override + public void writeToParcel(Parcel out, int flags) { + SafeParcelUtil.writeObject(this, out, flags); } public static Creator CREATOR = new Creator() { @@ -88,4 +190,81 @@ public class CameraPosition implements SafeParcelable { return new CameraPosition[size]; } }; + + /** + * Builds camera position. + */ + public static final class Builder { + private LatLng target; + private float zoom; + private float tilt; + private float bearing; + + public Builder() { + } + + public Builder(CameraPosition previous) { + target = previous.target; + zoom = previous.zoom; + tilt = previous.tilt; + bearing = previous.bearing; + } + + /** + * Sets the direction that the camera is pointing in, in degrees clockwise from north. + */ + public Builder bearing(float bearing) { + this.bearing = bearing; + return this; + } + + /** + * Builds a {@link CameraPosition}. + */ + public CameraPosition build() { + return null; + } + + /** + * Sets the location that the camera is pointing at. + */ + public Builder target(LatLng target) { + this.target = target; + return this; + } + + /** + * Sets the angle, in degrees, of the camera from the nadir (directly facing the Earth). + * When changing the camera position for a map, this value is restricted depending on the + * zoom level of the camera. The restrictions are as follows: + * + * The minimum is always 0 (directly down). If you specify a value outside this range and try to move the camera to this camera position it will be clamped to these bounds. + */ + public Builder tilt(float tilt) { + this.tilt = tilt; + return this; + } + + /** + * Sets the zoom level of the camera. Zoom level is defined such that at zoom level 0, the + * whole world is approximately 256dp wide (assuming that the camera is not tilted). + * Increasing the zoom level by 1 doubles the width of the world on the screen. Hence at + * zoom level N, the width of the world is approximately 256 * 2 N dp, i.e., at zoom level + * 2, the whole world is approximately 1024dp wide. + *

+ * When changing the camera position for a map, the zoom level of the camera is restricted + * to a certain range depending on various factors including location, map type and map + * size. Note that the camera zoom need not be an integer value. + */ + public Builder zoom(float zoom) { + this.zoom = zoom; + return this; + } + } } diff --git a/src/com/google/android/gms/maps/model/CircleOptions.java b/src/com/google/android/gms/maps/model/CircleOptions.java index 1b6d982d..e0224674 100644 --- a/src/com/google/android/gms/maps/model/CircleOptions.java +++ b/src/com/google/android/gms/maps/model/CircleOptions.java @@ -16,38 +16,36 @@ package com.google.android.gms.maps.model; +import android.graphics.Color; import android.os.Parcel; import org.microg.safeparcel.SafeParcelUtil; import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; +/** + * Defines options for a Circle. + */ public class CircleOptions implements SafeParcelable { - public static Creator CREATOR = new Creator() { - public CircleOptions createFromParcel(Parcel source) { - return new CircleOptions(source); - } - - public CircleOptions[] newArray(int size) { - return new CircleOptions[size]; - } - }; @SafeParceled(1) private int versionCode; @SafeParceled(2) private LatLng center; @SafeParceled(3) - private double radius; + private double radius = 0; @SafeParceled(4) - private float strokeWidth; + private float strokeWidth = 10; @SafeParceled(5) - private int strokeColor; + private int strokeColor = Color.BLACK; @SafeParceled(6) - private int fillColor; + private int fillColor = Color.TRANSPARENT; @SafeParceled(7) - private float zIndex; + private float zIndex = 0; @SafeParceled(8) - private boolean visisble; + private boolean visible = true; + /** + * Creates circle options. + */ public CircleOptions() { } @@ -60,8 +58,185 @@ public class CircleOptions implements SafeParcelable { return 0; } + /** + * Sets the center using a {@link LatLng}. + *

+ * The center must not be {@code null}. + *

+ * This method is mandatory because there is no default center. + * + * @param center The geographic center as a {@link LatLng}. + * @return this {@link CircleOptions} object + */ + public CircleOptions center(LatLng center) { + this.center = center; + return this; + } + + /** + * Sets the fill color. + *

+ * The fill color is the color inside the circle, in the integer format specified by + * {@link Color}. If TRANSPARENT is used then no fill is drawn. + *

+ * By default the fill color is transparent ({@code 0x00000000}). + * + * @param color color in the {@link Color} format + * @return this {@link CircleOptions} object + */ + public CircleOptions fillColor(int color) { + this.fillColor = color; + return this; + } + + /** + * Returns the center as a {@link LatLng}. + * + * @return The geographic center as a {@link LatLng}. + */ + public LatLng getCenter() { + return center; + } + + /** + * Returns the fill color. + * + * @return The color in the {@link Color} format. + */ + public int getFillColor() { + return fillColor; + } + + /** + * Returns the circle's radius, in meters. + * + * @return The radius in meters. + */ + public double getRadius() { + return radius; + } + + /** + * Returns the stroke color. + * + * @return The color in the {@link Color} format. + */ + public int getStrokeColor() { + return strokeColor; + } + + /** + * Returns the stroke width. + * + * @return The width in screen pixels. + */ + public float getStrokeWidth() { + return strokeWidth; + } + + /** + * Returns the zIndex. + * + * @return The zIndex value. + */ + public float getZIndex() { + return zIndex; + } + + /** + * Checks whether the circle is visible. + * + * @return {code true} if the circle is visible; {@code false} if it is invisible. + */ + public boolean isVisible() { + return visible; + } + + /** + * Sets the radius in meters. + *

+ * The radius must be zero or greater. The default radius is zero. + * + * @param radius radius in meters + * @return this {@link CircleOptions} object + */ + public CircleOptions radius(double radius) { + this.radius = radius; + return this; + } + + /** + * Sets the stroke color. + *

+ * The stroke color is the color of this circle's outline, in the integer format specified by + * {@link Color}. If TRANSPARENT is used then no outline is drawn. + *

+ * By default the stroke color is black ({@code 0xff000000}). + * + * @param color color in the {@link Color} format + * @return this {@link CircleOptions} object + */ + public CircleOptions strokeColor(int color) { + this.strokeColor = color; + return this; + } + + /** + * Sets the stroke width. + *

+ * The stroke width is the width (in screen pixels) of the circle's outline. It must be zero or + * greater. If it is zero then no outline is drawn. + *

+ * The default width is 10 pixels. + * + * @param width width in screen pixels + * @return this {@link CircleOptions} object + */ + public CircleOptions strokeWidth(float width) { + this.strokeWidth = width; + return this; + } + + /** + * Sets the visibility. + *

+ * If this circle is not visible then it is not drawn, but all other state is preserved. + * + * @param visible {@code false} to make this circle invisible + * @return this {@link CircleOptions} object + */ + public CircleOptions visible(boolean visible) { + this.visible = visible; + return this; + } + @Override public void writeToParcel(Parcel dest, int flags) { SafeParcelUtil.writeObject(this, dest, flags); } + + /** + * Sets the zIndex. + *

+ * Overlays (such as circles) with higher zIndices are drawn above those with lower indices. + *

+ * By default the zIndex is {@code 0.0}. + * + * @param zIndex zIndex value + * @return this {@link CircleOptions} object + */ + public CircleOptions zIndex(float zIndex) { + this.zIndex = zIndex; + return this; + } + + public static Creator CREATOR = new Creator() { + public CircleOptions createFromParcel(Parcel source) { + return new CircleOptions(source); + } + + public CircleOptions[] newArray(int size) { + return new CircleOptions[size]; + } + }; } diff --git a/src/com/google/android/gms/maps/model/GroundOverlayOptions.java b/src/com/google/android/gms/maps/model/GroundOverlayOptions.java index dd758cfe..856ec8ae 100644 --- a/src/com/google/android/gms/maps/model/GroundOverlayOptions.java +++ b/src/com/google/android/gms/maps/model/GroundOverlayOptions.java @@ -18,15 +18,25 @@ package com.google.android.gms.maps.model; import android.os.IBinder; import android.os.Parcel; +import com.google.android.gms.dynamic.ObjectWrapper; import org.microg.safeparcel.SafeParcelUtil; import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; +/** + * Defines options for a ground overlay. + */ public class GroundOverlayOptions implements SafeParcelable { + /** + * Flag for when no dimension is specified for the height. + */ + public static final float NO_DIMENSION = -1; + @SafeParceled(1) private int versionCode; @SafeParceled(2) - private IBinder wrappedImage; + private IBinder image; + private BitmapDescriptor imageDescriptor; @SafeParceled(3) private LatLng location; @SafeParceled(4) @@ -42,18 +52,56 @@ public class GroundOverlayOptions implements SafeParcelable { @SafeParceled(9) private boolean visible; @SafeParceled(10) - private float transparency; + private float transparency = 0; @SafeParceled(11) private float anchorU; @SafeParceled(12) private float anchorV; + /** + * Creates a new set of ground overlay options. + */ public GroundOverlayOptions() { } private GroundOverlayOptions(Parcel in) { SafeParcelUtil.readObject(this, in); - // wrappedImage = new BitmapDescriptor(IObjectWrapper.Stub.asInterface(SafeReader.readBinder(in, position))); + } + + /** + * Specifies the anchor to be at a particular point in the image. + *

+ * The anchor specifies the point in the image that aligns with the ground overlay's location. + *

+ * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) + * is the top-left corner of the image, and (1, 1) is the bottom-right corner. + * + * @param u u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1]) + * @param v v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1]) + * @return this {@link GroundOverlayOptions} object with a new anchor set. + */ + public GroundOverlayOptions anchor(float u, float v) { + this.anchorU = u; + this.anchorV = v; + return this; + } + + /** + * Specifies the bearing of the ground overlay in degrees clockwise from north. The rotation is + * performed about the anchor point. If not specified, the default is 0 (i.e., up on the image + * points north). + *

+ * If a ground overlay with position set using {@link #positionFromBounds(LatLngBounds)} is + * rotated, its size will preserved and it will no longer be guaranteed to fit inside the + * bounds. + * + * @param bearing the bearing in degrees clockwise from north. Values outside the range + * [0, 360) will be normalized. + * @return this {@link GroundOverlayOptions} object with a new bearing set. + */ + public GroundOverlayOptions bearing(float bearing) { + this.bearing = bearing; + return this; } @Override @@ -61,10 +109,245 @@ public class GroundOverlayOptions implements SafeParcelable { return 0; } + /** + * Horizontal distance, normalized to [0, 1], of the anchor from the left edge. + * + * @return the u value of the anchor. + */ + public float getAnchorU() { + return anchorU; + } + + /** + * Vertical distance, normalized to [0, 1], of the anchor from the top edge. + * + * @return the v value of the anchor. + */ + public float getAnchorV() { + return anchorV; + } + + /** + * Gets the bearing set for this options object. + * + * @return the bearing of the ground overlay. + */ + public float getBearing() { + return bearing; + } + + /** + * Gets the bounds set for this options object. + * + * @return the bounds of the ground overlay. This will be {@code null} if the position was set + * using {@link #position(LatLng, float)} or {@link #position(LatLng, float, float)} + */ + public LatLngBounds getBounds() { + return bounds; + } + + /** + * Gets the height set for this options object. + * + * @return the height of the ground overlay. + */ + public float getHeight() { + return height; + } + + /** + * Gets the image set for this options object. + * + * @return the image of the ground overlay. + */ + public BitmapDescriptor getImage() { + if (imageDescriptor == null && image != null) { + imageDescriptor = new BitmapDescriptor(ObjectWrapper.asInterface(image)); + } + return imageDescriptor; + } + + /** + * Gets the location set for this options object. + * + * @return the location to place the anchor of the ground overlay. This will be {@code null} + * if the position was set using {@link #positionFromBounds(LatLngBounds)}. + */ + public LatLng getLocation() { + return location; + } + + /** + * Gets the transparency set for this options object. + * + * @return the transparency of the ground overlay. + */ + public float getTransparency() { + return transparency; + } + + /** + * Gets the width set for this options object. + * + * @return the width of the ground overlay. + */ + public float getWidth() { + return width; + } + + /** + * Gets the zIndex set for this options object. + * + * @return the zIndex of the ground overlay. + */ + public float getZIndex() { + return zIndex; + } + + /** + * Specifies the image for this ground overlay. + *

+ * To load an image as a texture (which is used to draw the image on a map), it must be + * converted into an image with sides that are powers of two. This is so that a mipmap can be + * created in order to render the texture at various zoom levels - see + * Mipmap (Wikipedia) for details. Hence, to + * conserve memory by avoiding this conversion, it is advised that the dimensions of the image + * are powers of two. + * + * @param image the {@link BitmapDescriptor} to use for this ground overlay + * @return this {@link GroundOverlayOptions} object with a new image set. + */ + public GroundOverlayOptions image(BitmapDescriptor image) { + this.imageDescriptor = image; + this.image = imageDescriptor.getRemoteObject().asBinder(); + return this; + } + + /** + * Gets the visibility setting for this options object. + * + * @return {@code true} if the ground overlay is to be visible; {@code false} if it is not. + */ + public boolean isVisible() { + return visible; + } + + /** + * Specifies the position for this ground overlay using an anchor point (a {@link LatLng}), + * width and height (both in meters). When rendered, the image will be scaled to fit the + * dimensions specified (i.e., its proportions will not necessarily be preserved). + * + * @param location the location on the map {@code LatLng} to which the anchor point in the + * given image will remain fixed. The anchor will remain fixed to the position + * on the ground when transformations are applied (e.g., setDimensions, + * setBearing, etc.). + * @param width the width of the overlay (in meters) + * @param height the height of the overlay (in meters) + * @return this {@link GroundOverlayOptions} object with a new position set. + * @throws IllegalArgumentException if anchor is null + * @throws IllegalArgumentException if width or height are negative + * @throws IllegalStateException if the position was already set using + * {@link #positionFromBounds(LatLngBounds)} + */ + public GroundOverlayOptions position(LatLng location, float width, float height) + throws IllegalArgumentException, IllegalStateException { + if (location == null) + throw new IllegalArgumentException("location must not be null"); + if (width < 0 || height < 0) + throw new IllegalArgumentException("Width and height must not be negative"); + if (bounds != null) + throw new IllegalStateException("Position already set using positionFromBounds"); + this.location = location; + this.width = width; + this.height = height; + return this; + } + + /** + * Specifies the position for this ground overlay using an anchor point (a {@link LatLng}) and + * the width (in meters). When rendered, the image will retain its proportions from the bitmap, + * i.e., the height will be calculated to preserve the original proportions of the image. + * + * @param location the location on the map {@link LatLng} to which the anchor point in the + * given image will remain fixed. The anchor will remain fixed to the position + * on the ground when transformations are applied (e.g., setDimensions, + * setBearing, etc.). + * @param width the width of the overlay (in meters). The height will be determined + * automatically based on the image proportions. + * @return this {@link GroundOverlayOptions} object with a new position set. + * @throws IllegalArgumentException if anchor is null + * @throws IllegalArgumentException if width is negative + * @throws IllegalStateException if the position was already set using + * {@link #positionFromBounds(LatLngBounds)} + */ + public GroundOverlayOptions position(LatLng location, float width) + throws IllegalArgumentException, IllegalStateException { + if (location == null) + throw new IllegalArgumentException("location must not be null"); + if (width < 0 || height < 0) + throw new IllegalArgumentException("Width must not be negative"); + if (bounds != null) + throw new IllegalStateException("Position already set using positionFromBounds"); + this.location = location; + this.width = width; + return this; + } + + /** + * Specifies the position for this ground overlay. When rendered, the image will be scaled to + * fit the bounds (i.e., its proportions will not necessarily be preserved). + * + * @param bounds a {@link LatLngBounds} in which to place the ground overlay + * @return this {@link GroundOverlayOptions} object with a new position set. + * @throws IllegalStateException if the position was already set using + * {@link #position(LatLng, float)} or + * {@link #position(LatLng, float, float)} + */ + public GroundOverlayOptions positionFromBounds(LatLngBounds bounds) + throws IllegalStateException { + this.bounds = bounds; + return this; + } + + /** + * Specifies the transparency of the ground overlay. The default transparency is {code 0} + * (opaque). + * + * @param transparency a float in the range {@code [0..1]} where {@code 0} means that the + * ground overlay is opaque and {code 1} means that the ground overlay is + * transparent + * @return this {@link GroundOverlayOptions} object with a new visibility setting. + * @throws IllegalArgumentException if the transparency is outside the range [0..1]. + */ + public GroundOverlayOptions transparency(float transparency) throws IllegalArgumentException { + this.transparency = transparency; + return this; + } + + /** + * Specifies the visibility for the ground overlay. The default visibility is {@code true}. + * + * @return this {@link GroundOverlayOptions} object with a new visibility setting. + */ + public GroundOverlayOptions visible(boolean visible) { + this.visible = visible; + return this; + } + @Override public void writeToParcel(Parcel dest, int flags) { SafeParcelUtil.writeObject(this, dest, flags); - // SafeParcelWriter.write(dest, 2, wrappedImage.getRemoteObject().asBinder(), false); + } + + /** + * Specifies the ground overlay's zIndex, i.e., the order in which it will be drawn. See the + * documentation at the top of this class for more information about zIndex. + * + * @return this {@link GroundOverlayOptions} object with a new zIndex set. + */ + public GroundOverlayOptions zIndex(float zIndex) { + this.zIndex = zIndex; + return this; } public static Creator CREATOR = new Creator() { diff --git a/src/com/google/android/gms/maps/model/LatLng.java b/src/com/google/android/gms/maps/model/LatLng.java index 1d4d1ddd..225828a6 100644 --- a/src/com/google/android/gms/maps/model/LatLng.java +++ b/src/com/google/android/gms/maps/model/LatLng.java @@ -22,21 +22,12 @@ import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; public class LatLng implements SafeParcelable { - public static Creator CREATOR = new Creator() { - public LatLng createFromParcel(Parcel source) { - return new LatLng(source); - } - - public LatLng[] newArray(int size) { - return new LatLng[size]; - } - }; + @SafeParceled(1) + private int versionCode; @SafeParceled(2) public double latitude; @SafeParceled(3) public double longitude; - @SafeParceled(1) - private int versionCode; public LatLng(int versionCode, double latitude, double longitude) { this.versionCode = versionCode; @@ -78,4 +69,14 @@ public class LatLng implements SafeParcelable { public void writeToParcel(Parcel dest, int flags) { SafeParcelUtil.writeObject(this, dest, flags); } + + public static Creator CREATOR = new Creator() { + public LatLng createFromParcel(Parcel source) { + return new LatLng(source); + } + + public LatLng[] newArray(int size) { + return new LatLng[size]; + } + }; } diff --git a/src/com/google/android/gms/maps/model/LatLngBounds.java b/src/com/google/android/gms/maps/model/LatLngBounds.java index 42da1d3f..371facb4 100644 --- a/src/com/google/android/gms/maps/model/LatLngBounds.java +++ b/src/com/google/android/gms/maps/model/LatLngBounds.java @@ -22,15 +22,6 @@ import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; public class LatLngBounds implements SafeParcelable { - public static Creator CREATOR = new Creator() { - public LatLngBounds createFromParcel(Parcel source) { - return new LatLngBounds(source); - } - - public LatLngBounds[] newArray(int size) { - return new LatLngBounds[size]; - } - }; @SafeParceled(1) private int versionCode; @SafeParceled(2) @@ -61,4 +52,14 @@ public class LatLngBounds implements SafeParcelable { public void writeToParcel(Parcel dest, int flags) { SafeParcelUtil.writeObject(this, dest, flags); } + + public static Creator CREATOR = new Creator() { + public LatLngBounds createFromParcel(Parcel source) { + return new LatLngBounds(source); + } + + public LatLngBounds[] newArray(int size) { + return new LatLngBounds[size]; + } + }; } diff --git a/src/com/google/android/gms/maps/model/MarkerOptions.java b/src/com/google/android/gms/maps/model/MarkerOptions.java index 4162f0c0..4da6246b 100644 --- a/src/com/google/android/gms/maps/model/MarkerOptions.java +++ b/src/com/google/android/gms/maps/model/MarkerOptions.java @@ -18,6 +18,7 @@ package com.google.android.gms.maps.model; import android.os.IBinder; import android.os.Parcel; +import com.google.android.gms.dynamic.ObjectWrapper; import org.microg.safeparcel.SafeParcelUtil; import org.microg.safeparcel.SafeParcelable; import org.microg.safeparcel.SafeParceled; @@ -32,8 +33,15 @@ public class MarkerOptions implements SafeParcelable { private String title; @SafeParceled(4) private String snippet; + /** + * This is a IBinder to the remote BitmapDescriptor created using BitmapDescriptorFactory + */ @SafeParceled(5) private IBinder icon; + /** + * The real BitmapDescriptor. Not transferred through Parcel. + */ + private BitmapDescriptor iconDescriptor; @SafeParceled(6) private float anchorU = 0.5F; @SafeParceled(7) @@ -53,73 +61,285 @@ public class MarkerOptions implements SafeParcelable { @SafeParceled(14) private float alpha = 1F; - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - } - + /** + * Creates a new set of marker options. + */ public MarkerOptions() { } private MarkerOptions(Parcel in) { SafeParcelUtil.readObject(this, in); - // this.icon = icon == null ? null : new BitmapDescriptor(ObjectWrapper.asInterface(icon)); } - public LatLng getPosition() { - return position; + @Override + public int describeContents() { + return 0; } - public String getTitle() { - return title; + /** + * Sets the alpha (opacity) of the marker. This is a value from 0 to 1, where 0 means the + * marker is completely transparent and 1 means the marker is completely opaque. + * + * @return the object for which the method was called, with the new alpha set. + */ + public MarkerOptions alpha(float alpha) { + this.alpha = alpha; + return this; } - public String getSnippet() { - return snippet; + /** + * Specifies the anchor to be at a particular point in the marker image. + *

+ * The anchor specifies the point in the icon image that is anchored to the marker's position + * on the Earth's surface. + *

+ * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) + * is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring + * point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, + * obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point + * (0.7, 0.6) resolves to the grid point at (3, 1). + * + * @param u u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1]) + * @param v v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1]) + * @return the object for which the method was called, with the new anchor set. + */ + public MarkerOptions anchor(float u, float v) { + this.anchorU = u; + this.anchorV = v; + return this; } - public IBinder getIcon() { - return icon; + /** + * Sets the draggability for the marker. + * + * @return the object for which the method was called, with the new draggable state set. + */ + public MarkerOptions draggable(boolean draggable) { + this.draggable = draggable; + return this; } + /** + * Sets whether this marker should be flat against the map true or a billboard facing the + * camera false. If the marker is flat against the map, it will remain stuck to the map as the + * camera rotates and tilts but will still remain the same size as the camera zooms, unlike a + * GroundOverlay. If the marker is a billboard, it will always be drawn facing the camera + * and will rotate and tilt with the camera. The default value is false. + * + * @return the object for which the method was called, with the new flat state set. + */ + public MarkerOptions flat(boolean flat) { + this.flat = flat; + return this; + } + + /** + * Gets the alpha set for this MarkerOptions object. + * + * @return the alpha of the marker in the range [0, 1]. + */ + public float getAlpha() { + return alpha; + } + + /** + * Horizontal distance, normalized to [0, 1], of the anchor from the left edge. + * + * @return the u value of the anchor. + */ public float getAnchorU() { return anchorU; } + /** + * Vertical distance, normalized to [0, 1], of the anchor from the top edge. + * + * @return the v value of the anchor. + */ public float getAnchorV() { return anchorV; } - public boolean isDraggable() { - return draggable; - } - - public boolean isVisible() { - return visible; - } - - public boolean isFlat() { - return flat; - } - - public float getRotation() { - return rotation; + /** + * Gets the custom icon set for this MarkerOptions object. + * + * @return An {@link BitmapDescriptor} representing the custom icon, or {@code null} if no + * custom icon is set. + */ + public BitmapDescriptor getIcon() { + if (iconDescriptor == null && icon != null) { + iconDescriptor = new BitmapDescriptor(ObjectWrapper.asInterface(icon)); + } + return iconDescriptor; } + /** + * Horizontal distance, normalized to [0, 1], of the info window anchor from the left edge. + * + * @return the u value of the info window anchor. + */ public float getInfoWindowAnchorU() { return infoWindowAnchorU; } + /** + * Vertical distance, normalized to [0, 1], of the info window anchor from the top edge. + * + * @return the v value of the info window anchor. + */ public float getInfoWindowAnchorV() { return infoWindowAnchorV; } - public float getAlpha() { - return alpha; + /** + * Returns the position set for this MarkerOptions object. + * + * @return A {@link LatLng} object specifying the marker's current position. + */ + public LatLng getPosition() { + return position; + } + + /** + * Gets the rotation set for this MarkerOptions object. + * + * @return the rotation of the marker in degrees clockwise from the default position. + */ + public float getRotation() { + return rotation; + } + + /** + * Gets the snippet set for this MarkerOptions object. + * + * @return A string containing the marker's snippet. + */ + public String getSnippet() { + return snippet; + } + + /** + * Gets the title set for this MarkerOptions object. + * + * @return A string containing the marker's title. + */ + public String getTitle() { + return title; + } + + /** + * Sets the icon for the marker. + * + * @param icon if null, the default marker is used. + * @return the object for which the method was called, with the new icon set. + */ + public MarkerOptions icon(BitmapDescriptor icon) { + this.iconDescriptor = icon; + this.icon = icon == null ? null : icon.getRemoteObject().asBinder(); + return this; + } + + /** + * Specifies the anchor point of the info window on the marker image. This is specified in the + * same coordinate system as the anchor. See {@link MarkerOptions#anchor(float, float)} for + * more details. The default is the top middle of the image. + * + * @param u u-coordinate of the info window anchor, as a ratio of the image width (in the range [0, 1]) + * @param v v-coordinate of the info window anchor, as a ratio of the image height (in the range [0, 1]) + * @return the object for which the method was called, with the new info window anchor set. + */ + public MarkerOptions infoWindowAnchor(float u, float v) { + this.infoWindowAnchorU = u; + this.infoWindowAnchorV = v; + return this; + } + + /** + * Gets the draggability setting for this MarkerOptions object. + * + * @return {@code true} if the marker is draggable; otherwise, returns {@code false}. + */ + public boolean isDraggable() { + return draggable; + } + + /** + * Gets the flat setting for this MarkerOptions object. + * + * @return {@code true} if the marker is flat against the map; {@code false} if the marker + * should face the camera. + */ + public boolean isFlat() { + return flat; + } + + /** + * Gets the visibility setting for this MarkerOptions object. + * + * @return {@code true} if the marker is visible; otherwise, returns {@code false}. + */ + public boolean isVisible() { + return visible; + } + + /** + * Sets the location for the marker. + * + * @return the object for which the method was called, with the new position set. + */ + public MarkerOptions position(LatLng position) { + this.position = position; + return this; + } + + /** + * Sets the rotation of the marker in degrees clockwise about the marker's anchor point. The + * axis of rotation is perpendicular to the marker. A rotation of 0 corresponds to the default + * position of the marker. When the marker is flat on the map, the default position is North + * aligned and the rotation is such that the marker always remains flat on the map. When the + * marker is a billboard, the default position is pointing up and the rotation is such that + * the marker is always facing the camera. The default value is 0. + * + * @return the object for which the method was called, with the new rotation set. + */ + public MarkerOptions rotation(float rotation) { + this.rotation = rotation; + return this; + } + + /** + * Sets the snippet for the marker. + * + * @return the object for which the method was called, with the new snippet set. + */ + public MarkerOptions snippet(String snippet) { + this.snippet = snippet; + return this; + } + + /** + * Sets the title for the marker. + * + * @return the object for which the method was called, with the new title set. + */ + public MarkerOptions title(String title) { + this.title = title; + return this; + } + + /** + * Sets the visibility for the marker. + * + * @return the object for which the method was called, with the new visibility state set. + */ + public MarkerOptions visible(boolean visible) { + this.visible = visible; + return this; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + SafeParcelUtil.writeObject(this, dest, flags); } public static Creator CREATOR = new Creator() { diff --git a/src/com/google/android/gms/maps/model/VisibleRegion.java b/src/com/google/android/gms/maps/model/VisibleRegion.java index 21f9cd13..76f2342c 100644 --- a/src/com/google/android/gms/maps/model/VisibleRegion.java +++ b/src/com/google/android/gms/maps/model/VisibleRegion.java @@ -50,6 +50,16 @@ public class VisibleRegion implements SafeParcelable { this(1, nearLeft, nearRight, farLeft, farRight, bounds); } + /** + * This is assuming that the visible region matches the bounds, which means that it's a north + * 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, + bounds); + } + public VisibleRegion(Parcel in) { SafeParcelUtil.readObject(this, in); } diff --git a/src/com/google/android/gms/maps/model/package-info.java b/src/com/google/android/gms/maps/model/package-info.java new file mode 100644 index 00000000..de5998b2 --- /dev/null +++ b/src/com/google/android/gms/maps/model/package-info.java @@ -0,0 +1,4 @@ +/** + * Contains the Google Maps Android API model classes. + */ +package com.google.android.gms.maps.model; diff --git a/src/org/microg/gms/maps/Constants.java b/src/org/microg/gms/maps/Constants.java new file mode 100644 index 00000000..89745851 --- /dev/null +++ b/src/org/microg/gms/maps/Constants.java @@ -0,0 +1,28 @@ +package org.microg.gms.maps; + +public class Constants { + /** + * No base map tiles. + */ + public static final int MAP_TYPE_NONE = 0; + + /** + * Basic maps. + */ + public static final int MAP_TYPE_NORMAL = 1; + + /** + * Satellite maps with no labels. + */ + public static final int MAP_TYPE_SATELLITE = 2; + + /** + * Terrain maps. + */ + public static final int MAP_TYPE_TERRAIN = 3; + + /** + * Satellite maps with a transparent layer of major streets. + */ + public static final int MAP_TYPE_HYBRID = 4; +}