From ac4d3b8537514fc7432e9ae954046871c81cd082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Tue, 13 Dec 2016 00:27:43 -0800 Subject: [PATCH] [android] Cleaned up documentation; fixed build --- .../mapboxsdk/annotations/MultiPoint.java | 15 --------- .../mapbox/mapboxsdk/annotations/Polygon.java | 32 ++++++++++++++++++- .../mapboxsdk/annotations/PolygonOptions.java | 19 ++++++++--- .../activity/annotation/PolygonActivity.java | 2 +- platform/android/src/jni.cpp | 4 +-- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java index 9803c50d0e8..2bd3c82786c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java @@ -11,13 +11,11 @@ public abstract class MultiPoint extends Annotation { private List points; - private List> holes; private float alpha = 1.0f; protected MultiPoint() { super(); points = new ArrayList<>(); - holes = new ArrayList<>(); } /** @@ -29,15 +27,6 @@ public List getPoints() { return new ArrayList<>(points); } - /* - * Returns a copy of the holes. - * - * @return holes - as a copy - */ - public List> getHoles() { - return new ArrayList<>(holes); - } - /** * Sets the points of this polyline. This method will take a copy of the points, so further * mutations to points will have no effect on this polyline. @@ -59,10 +48,6 @@ public void addPoint(LatLng point) { update(); } - void addHole(List hole) { - holes.add(hole); - } - /** * Value between 0 and 1 defining the polyline alpha. * diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java index 7b9de86bc4c..94dbb55bb4c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polygon.java @@ -2,18 +2,48 @@ import android.graphics.Color; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapboxMap; +import java.util.ArrayList; +import java.util.List; + /** * Polygon is a geometry annotation that's a closed loop of coordinates. */ public final class Polygon extends MultiPoint { + private List> holes; private int fillColor = Color.BLACK; // default fillColor is black private int strokeColor = Color.BLACK; // default strokeColor is black Polygon() { super(); + holes = new ArrayList<>(); + } + + /** + * Returns a copy of the holes. + * + * @return A {@link List} of holes. + */ + public List> getHoles() { + return new ArrayList<>(holes); + } + + /** + * Sets the holes of this polygon. This method will take a copy of the holes, so further + * mutations to holes will have no effect on this polygon. + * + * @param points A {@link List} {@link List}s of {@link LatLng} points making up the holes. + */ + public void setHoles(List> holes) { + this.holes = new ArrayList<>(holes); + update(); + } + + void addHole(List hole) { + holes.add(hole); } /** @@ -26,7 +56,7 @@ public int getFillColor() { } /** - * Get the color fo the stroke of the polygon. + * Get the color for the stroke of the polygon. * * @return The color of the stroke. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java index 46ad1f03a4d..6ed95990ebc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolygonOptions.java @@ -108,6 +108,12 @@ public PolygonOptions addAll(Iterable points) { return this; } + /** + * Adds a hole to the outline of the polygon being built. + * + * @param points {@link Iterable} list made up of {@link LatLng} points defining the hole + * @return This {@link PolygonOptions} object with the given hole added to the outline. + */ public PolygonOptions addHole(Iterable points) { List hole = new ArrayList(); for (LatLng point : points) { @@ -193,17 +199,20 @@ public List getPoints() { return polygon.getPoints(); } + /** + * Gets the holes set for this {@link PolygonOptions} object. + */ public List> getHoles() { return polygon.getHoles(); } /** * Compares this {@link PolygonOptions} object with another {@link PolygonOptions} and - * determines if their color, alpha, stroke color, and vertices match. + * determines if their color, alpha, stroke color, vertices, and holes match. * * @param o Another {@link PolygonOptions} to compare with this object. - * @return True if color, alpha, stroke color, and vertices match this {@link PolygonOptions} - * object. Else, false. + * @return True if color, alpha, stroke color, vertices, and holes match this + * {@link PolygonOptions} object. Else, false. */ @Override public boolean equals(Object o) { @@ -225,10 +234,10 @@ public boolean equals(Object o) { if (getStrokeColor() != polygon.getStrokeColor()) { return false; } - if (getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null) { + if (getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null) { return false; } - return !(getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null); + return !(getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null); } /** diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java index 5cd19d1fea3..451152a38c2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/annotation/PolygonActivity.java @@ -179,7 +179,7 @@ static final class Config { } }; - static final List> STAR_SHAPE_HOLES = new ArrayList>() { + static final List> STAR_SHAPE_HOLES = new ArrayList>() { { add(new ArrayList() { { diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 830c3e43964..3949f4ecc41 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -767,8 +767,8 @@ jni::jarray* nativeAddPolygons(JNIEnv *env, jni::jobject* obj, jlong nati NullCheck(*env, jarrayHoles); std::size_t size = jni::GetArrayLength(*env, *jarrayHoles); - for (std::size_t i = 0; i < size; i++) { - jni::jobject* hole = reinterpret_cast(jni::GetObjectArrayElement(*env, *jarrayHoles, i)); + for (std::size_t j = 0; j < size; j++) { + jni::jobject* hole = jni::GetObjectArrayElement(*env, *jarrayHoles, j); NullCheck(*env, hole); geometry.push_back(toGeometry>(env, hole)); jni::DeleteLocalRef(*env, hole);