From 7a66ec6c5e442f892e6b4ea5669dac8f25772719 Mon Sep 17 00:00:00 2001 From: Pablo Guardiola Date: Wed, 12 Apr 2017 17:45:33 +0200 Subject: refactor signature from Hole to List (#8722) --- .../com/mapbox/mapboxsdk/annotations/Hole.java | 53 ---------------------- .../com/mapbox/mapboxsdk/annotations/Polygon.java | 15 +++--- .../mapboxsdk/annotations/PolygonOptions.java | 28 ++++++------ .../activity/annotation/PolygonActivity.java | 13 +++--- 4 files changed, 28 insertions(+), 81 deletions(-) delete mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Hole.java diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Hole.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Hole.java deleted file mode 100644 index cabe16cc5c..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Hole.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - - -import android.os.Parcel; -import android.os.Parcelable; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -import java.util.ArrayList; -import java.util.List; - -/** - * Encapsulates a {@link List} of {@link LatLng} points defining a hole - */ -public class Hole extends ArrayList implements Parcelable { - - public Hole() { - super(); - } - - /** - * Creates a Hole. - * - * @param holePoints {@link List} list of {@link LatLng} points defining a hole - */ - public Hole(List holePoints) { - super(holePoints); - } - - protected Hole(Parcel in) { - in.readTypedList(this, LatLng.CREATOR); - } - - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(Parcel parcel, int i) { - parcel.writeTypedList(this); - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public Hole createFromParcel(Parcel in) { - return new Hole(in); - } - - public Hole[] newArray(int size) { - return new Hole[size]; - } - }; -} 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 9245d9cdc8..dd2c37762a 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,6 +2,7 @@ package com.mapbox.mapboxsdk.annotations; import android.graphics.Color; +import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.maps.MapboxMap; import java.util.ArrayList; @@ -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 holes; + private List> holes; Polygon() { super(); @@ -42,9 +43,9 @@ public final class Polygon extends BasePointCollection { /** * 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 getHoles() { + public List> getHoles() { return new ArrayList<>(holes); } @@ -72,9 +73,9 @@ public final class Polygon extends BasePointCollection { * 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 holes) { + public void setHoles(List> holes) { this.holes = new ArrayList<>(holes); update(); } @@ -82,9 +83,9 @@ public final class Polygon extends BasePointCollection { /** * 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 hole) { holes.add(hole); update(); } 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 7405ebfb4a..eaad25133e 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 @@ -27,11 +27,11 @@ public final class PolygonOptions implements Parcelable { private PolygonOptions(Parcel in) { polygon = new Polygon(); - ArrayList pointsList = new ArrayList<>(); + List pointsList = new ArrayList<>(); in.readList(pointsList, LatLng.class.getClassLoader()); addAll(pointsList); - ArrayList holes = new ArrayList<>(); - in.readTypedList(holes, Hole.CREATOR); + List> holes = new ArrayList<>(); + in.readList(holes, LatLng.class.getClassLoader()); addAllHoles(holes); alpha(in.readFloat()); fillColor(in.readInt()); @@ -59,7 +59,7 @@ public final class PolygonOptions implements Parcelable { @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()); @@ -115,10 +115,10 @@ public final class PolygonOptions implements Parcelable { /** * 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 hole) { polygon.addHole(hole); return this; } @@ -126,11 +126,11 @@ public final class PolygonOptions implements Parcelable { /** * 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... holes) { + for (List hole : holes) { addHole(hole); } return this; @@ -139,11 +139,11 @@ public final class PolygonOptions implements Parcelable { /** * 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 holes) { - for (Hole hole : holes) { + public PolygonOptions addAllHoles(Iterable> holes) { + for (List hole : holes) { addHole(hole); } return this; @@ -231,9 +231,9 @@ public final class PolygonOptions implements Parcelable { /** * 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 getHoles() { + public List> getHoles() { return polygon.getHoles(); } 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 429509e1d2..b51d717f33 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 @@ -6,7 +6,6 @@ import android.support.v7.app.AppCompatActivity; 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; @@ -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) { @@ -146,7 +145,7 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall return true; case R.id.action_id_holes: holes = !holes; - polygon.setHoles(holes ? STAR_SHAPE_HOLES : Collections.emptyList()); + polygon.setHoles(holes ? STAR_SHAPE_HOLES : Collections.>emptyList()); return true; default: return super.onOptionsItemSelected(item); @@ -188,9 +187,9 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall static final List BROKEN_SHAPE_POINTS = STAR_SHAPE_POINTS.subList(0, STAR_SHAPE_POINTS.size() - 3); - static final List STAR_SHAPE_HOLES = new ArrayList() { + static final List> STAR_SHAPE_HOLES = new ArrayList>() { { - add(new Hole(new ArrayList() { + add(new ArrayList<>(new ArrayList() { { add(new LatLng(45.521743, -122.669091)); add(new LatLng(45.530483, -122.676833)); @@ -198,7 +197,7 @@ public class PolygonActivity extends AppCompatActivity implements OnMapReadyCall add(new LatLng(45.521743, -122.669091)); } })); - add(new Hole(new ArrayList() { + add(new ArrayList<>(new ArrayList() { { add(new LatLng(45.529743, -122.662791)); add(new LatLng(45.525543, -122.662791)); -- cgit v1.2.1