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

[android] Polygon holes signature refactor #8722

Merged
merged 1 commit into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor signature from Hole to List<LatLng>
  • Loading branch information
Guardiola31337 committed Apr 12, 2017
commit b6c914e7b24d4535050be18e7ef0b46e458c6a78

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Color;

import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapboxMap;

import java.util.ArrayList;
Expand All @@ -14,7 +15,7 @@ public final class Polygon extends BasePointCollection {

private int fillColor = Color.BLACK; // default fillColor is black
private int strokeColor = Color.BLACK; // default strokeColor is black
private List<Hole> holes;
private List<List<LatLng>> holes;

Polygon() {
super();
Expand Down Expand Up @@ -42,9 +43,9 @@ public int getStrokeColor() {
/**
* Returns a copy of the holes.
*
* @return A {@link List} of holes.
* @return A {@link List} of {@link List} of {@link LatLng} points making up the holes.
*/
public List<Hole> getHoles() {
public List<List<LatLng>> getHoles() {
return new ArrayList<>(holes);
}

Expand Down Expand Up @@ -72,19 +73,19 @@ public void setStrokeColor(int color) {
* 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 holes A {@link List} of {@link Hole} points making up the holes.
* @param holes A {@link List} of {@link List} of {@link LatLng} points making up the holes.
*/
public void setHoles(List<? extends Hole> holes) {
public void setHoles(List<? extends List<LatLng>> holes) {
this.holes = new ArrayList<>(holes);
update();
}

/**
* Add a hole to the polygon.
*
* @param hole A {@link Hole} hole to be added.
* @param hole A {@link List} of {@link List} of {@link LatLng} points making up the hole to be added.
*/
void addHole(Hole hole) {
void addHole(List<LatLng> hole) {
holes.add(hole);
update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public PolygonOptions[] newArray(int size) {

private PolygonOptions(Parcel in) {
polygon = new Polygon();
ArrayList<LatLng> pointsList = new ArrayList<>();
List<LatLng> pointsList = new ArrayList<>();
in.readList(pointsList, LatLng.class.getClassLoader());
addAll(pointsList);
ArrayList<Hole> holes = new ArrayList<>();
in.readTypedList(holes, Hole.CREATOR);
List<List<LatLng>> holes = new ArrayList<>();
in.readList(holes, LatLng.class.getClassLoader());
addAllHoles(holes);
alpha(in.readFloat());
fillColor(in.readInt());
Expand Down Expand Up @@ -59,7 +59,7 @@ public int describeContents() {
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeList(getPoints());
out.writeTypedList(getHoles());
out.writeList(getHoles());
out.writeFloat(getAlpha());
out.writeInt(getFillColor());
out.writeInt(getStrokeColor());
Expand Down Expand Up @@ -115,22 +115,22 @@ public PolygonOptions addAll(Iterable<LatLng> points) {
/**
* Adds a hole to the outline of the polygon being built.
*
* @param hole {@link Hole} list made up of {@link LatLng} points defining the hole
* @param hole {@link List} 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(Hole hole) {
public PolygonOptions addHole(List<LatLng> hole) {
polygon.addHole(hole);
return this;
}

/**
* Adds holes to the outline of the polygon being built.
*
* @param holes {@link Hole} holes to be added to polygon geometry.
* @param holes {@link List} list made up of {@link LatLng} holes to be added to polygon geometry
* @return This {@link PolygonOptions} object with the given holes added to the outline.
*/
public PolygonOptions addHole(Hole... holes) {
for (Hole hole : holes) {
public PolygonOptions addHole(List<LatLng>... holes) {
for (List<LatLng> hole : holes) {
addHole(hole);
}
return this;
Expand All @@ -139,11 +139,11 @@ public PolygonOptions addHole(Hole... holes) {
/**
* Adds holes to the outline of the polygon being built.
*
* @param holes {@link Iterable} list made up of {@link Hole} holes defining the hole geometry
* @param holes {@link Iterable} list made up of {@link List} list of {@link LatLng} holes defining the hole geometry
* @return This {@link PolygonOptions} object with the given holes added to the outline.
*/
public PolygonOptions addAllHoles(Iterable<Hole> holes) {
for (Hole hole : holes) {
public PolygonOptions addAllHoles(Iterable<List<LatLng>> holes) {
for (List<LatLng> hole : holes) {
addHole(hole);
}
return this;
Expand Down Expand Up @@ -231,9 +231,9 @@ public List<LatLng> getPoints() {
/**
* Gets the holes set for this {@link PolygonOptions} object.
*
* @return The list made up of {@link List} of {@link LatLng} points defining the holes.
* @return The list made up of {@link List} of {@link List} of {@link LatLng} points defining the holes.
*/
public List<Hole> getHoles() {
public List<List<LatLng>> getHoles() {
return polygon.getHoles();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.view.Menu;
import android.view.MenuItem;

import com.mapbox.mapboxsdk.annotations.Hole;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
import com.mapbox.mapboxsdk.camera.CameraPosition;
Expand Down Expand Up @@ -46,8 +45,8 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall
private boolean fullAlpha = true;
private boolean visible = true;
private boolean color = true;
private boolean allPoints;
private boolean holes;
private boolean allPoints = true;
private boolean holes = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -146,7 +145,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.action_id_holes:
holes = !holes;
polygon.setHoles(holes ? STAR_SHAPE_HOLES : Collections.<Hole>emptyList());
polygon.setHoles(holes ? STAR_SHAPE_HOLES : Collections.<List<LatLng>>emptyList());
return true;
default:
return super.onOptionsItemSelected(item);
Expand Down Expand Up @@ -188,17 +187,17 @@ static final class Config {
static final List<LatLng> BROKEN_SHAPE_POINTS =
STAR_SHAPE_POINTS.subList(0, STAR_SHAPE_POINTS.size() - 3);

static final List<? extends Hole> STAR_SHAPE_HOLES = new ArrayList<Hole>() {
static final List<? extends List<LatLng>> STAR_SHAPE_HOLES = new ArrayList<List<LatLng>>() {
{
add(new Hole(new ArrayList<LatLng>() {
add(new ArrayList<>(new ArrayList<LatLng>() {
{
add(new LatLng(45.521743, -122.669091));
add(new LatLng(45.530483, -122.676833));
add(new LatLng(45.520483, -122.676833));
add(new LatLng(45.521743, -122.669091));
}
}));
add(new Hole(new ArrayList<LatLng>() {
add(new ArrayList<>(new ArrayList<LatLng>() {
{
add(new LatLng(45.529743, -122.662791));
add(new LatLng(45.525543, -122.662791));
Expand Down