Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] Cleaned up documentation; fixed build
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 27, 2017
1 parent fb8d421 commit ac4d3b8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
public abstract class MultiPoint extends Annotation {

private List<LatLng> points;
private List<List<LatLng>> holes;
private float alpha = 1.0f;

protected MultiPoint() {
super();
points = new ArrayList<>();
holes = new ArrayList<>();
}

/**
Expand All @@ -29,15 +27,6 @@ public List<LatLng> getPoints() {
return new ArrayList<>(points);
}

/*
* Returns a copy of the holes.
*
* @return holes - as a copy
*/
public List<List<LatLng>> 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.
Expand All @@ -59,10 +48,6 @@ public void addPoint(LatLng point) {
update();
}

void addHole(List<LatLng> hole) {
holes.add(hole);
}

/**
* Value between 0 and 1 defining the polyline alpha.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<LatLng>> 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<List<LatLng>> 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<? extends List<LatLng>> holes) {
this.holes = new ArrayList<>(holes);
update();
}

void addHole(List<LatLng> hole) {
holes.add(hole);
}

/**
Expand All @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ public PolygonOptions addAll(Iterable<LatLng> 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<LatLng> points) {
List<LatLng> hole = new ArrayList<LatLng>();
for (LatLng point : points) {
Expand Down Expand Up @@ -193,17 +199,20 @@ public List<LatLng> getPoints() {
return polygon.getPoints();
}

/**
* Gets the holes set for this {@link PolygonOptions} object.
*/
public List<List<LatLng>> 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) {
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static final class Config {
}
};

static final List<List<LatLng>> STAR_SHAPE_HOLES = new ArrayList<ArrayList<LatLng>>() {
static final List<? extends List<LatLng>> STAR_SHAPE_HOLES = new ArrayList<ArrayList<LatLng>>() {
{
add(new ArrayList<LatLng>() {
{
Expand Down
4 changes: 2 additions & 2 deletions platform/android/src/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ jni::jarray<jlong>* 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::jobject*>(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<mbgl::LinearRing<double>>(env, hole));
jni::DeleteLocalRef(*env, hole);
Expand Down

0 comments on commit ac4d3b8

Please sign in to comment.