From 87be52b358406874efd0c3386ae1a3c0102278b3 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 | 14 -------- .../mapbox/mapboxsdk/annotations/Polygon.java | 32 ++++++++++++++++++- .../mapboxsdk/annotations/PolygonOptions.java | 22 +++++++++---- .../activity/annotation/PolygonActivity.java | 10 +++--- platform/android/src/jni.cpp | 4 +-- 5 files changed, 54 insertions(+), 28 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 b8482a48a30..78d21db2e91 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,14 +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. @@ -58,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 a06938e3cb0..6fe17476f31 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 627d7b1663a..3fe27f2d0ea 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 @@ -107,7 +107,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) { @@ -115,7 +120,7 @@ public PolygonOptions addHole(Iterable points) { } polygon.addHole(hole); - + return this; } @@ -193,17 +198,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) { @@ -215,8 +223,8 @@ public boolean equals(Object o) { if (Float.compare(polygon.getAlpha(), getAlpha()) != 0) return false; if (getFillColor() != polygon.getFillColor()) return false; if (getStrokeColor() != polygon.getStrokeColor()) return false; - if (getHoles() != null ? !getHoles().equals(polygon.getHoles()) : polygon.getHoles() != null) return false; - return !(getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null); + if (getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null) return false; + 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 f6a5619e450..f8051ebce98 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 @@ -152,7 +152,7 @@ public boolean onOptionsItemSelected(MenuItem item) { double lat = 0; double lon = 0; int points = 0; - for (LatLng latLng : polygon) { + for (LatLng latLng : polygon.getPoints()) { points++; lat += latLng.getLatitude(); lon += latLng.getLongitude(); @@ -188,9 +188,11 @@ public boolean onOptionsItemSelected(MenuItem item) { hole3.add(new LatLng(lat, lon - 0.005)); hole3.add(new LatLng(lat, lon)); - polygon.addHole(hole1) - .addHole(hole2) - .addHole(hole3); + List> holes = new ArrayList<>(); + holes.add(hole1); + holes.add(hole2); + holes.add(hole3); + polygon.setHoles(holes); return true; diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 825fc74b5a1..df41e258fe4 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 = reinterpret_cast(jni::GetObjectArrayElement(*env, *jarrayHoles, j)); NullCheck(*env, hole); geometry.push_back(toGeometry>(env, hole)); jni::DeleteLocalRef(*env, hole);