Skip to content

Commit

Permalink
Java Annotation API cleaner mapbox#1716
Browse files Browse the repository at this point in the history
  • Loading branch information
hallahan committed Jul 16, 2015
1 parent d4407b7 commit 9e3f607
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public abstract class Annotation {

/**
* The annotation id
* <p/>
*
* Internal C++ id is stored as unsigned int.
*/
protected Long id; // null unless added to a MapView
Expand All @@ -19,6 +19,10 @@ public abstract class Annotation {

public Annotation() {}

public float getAlpha() {
return alpha;
}

public long getId() {
return id;
}
Expand All @@ -32,6 +36,10 @@ public void remove() {
mapView.removeAnnotation(this);
}

public void setAlpha(float alpha) {
this.alpha = alpha;
}

public void setId(Long id) {
this.id = id;
}
Expand All @@ -44,4 +52,13 @@ public void setVisible(boolean visible) {
this.visible = visible;
}

// TODO: Implement getZIndex of Google Maps Android API
// public float getZIndex() {
//
// }

// TODO: Implement setZIndex of Google Maps Android API
// public void setZIndex(float zIndex) {
//
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mapbox.mapboxgl.annotations;

public abstract class AnnotationOptions {

protected Annotation annotation;

public AnnotationOptions() {}

public AnnotationOptions alpha(float alpha) {
annotation.alpha = alpha;
return this;
}

public float getAlpha() {
return annotation.alpha;
}

public boolean isVisible() {
return annotation.visible;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import com.mapbox.mapboxgl.geometry.LatLng;

public class CircleOptions {
public class CircleOptions extends AnnotationOptions {

private Circle circle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

public class Marker extends Annotation {

/**
* Member fields are without access qualifiers
* so that they can be directly set by MarkerOptions
* from within the module.
*/
float anchorU;
float anchorV;
boolean draggable;
Expand All @@ -36,6 +31,14 @@ public float getAlpha() {
return alpha;
}

public float getAnchorU() {
return anchorU;
}

public float getAnchorV() {
return anchorV;
}

/**
* NOTE: Google Maps Android API uses String for IDs.
*
Expand Down Expand Up @@ -63,9 +66,6 @@ public String getTitle() {
return title;
}

// Method in Google Maps Android API
// public int hashCode()

public void hideInfoWindow() {
//TODO hideInfoWindow
infoWindowShown = false;
Expand All @@ -83,8 +83,9 @@ public boolean isInfoWindowShown () {
return infoWindowShown;
}

void setAlpha(float alpha) {
this.alpha = alpha;
void setAnchor(float u, float v) {
this.anchorU = u;
this.anchorV = v;
}

void setDraggable(boolean draggable) {
Expand All @@ -95,11 +96,6 @@ void setFlat(boolean flat) {
this.flat = flat;
}

// TODO: Implement this method of Google Maps Android API
// void setIcon(BitmapDescriptor icon) {
//
// }

void setInfoWindowAnchor(float u, float v) {
infoWindowAnchorU = u;
infoWindowAnchorV = v;
Expand All @@ -124,4 +120,13 @@ void setTitle(String title) {
void showInfoWindow() {
infoWindowShown = true;
}


// TODO Method in Google Maps Android API
// public int hashCode()

// TODO: Implement this method of Google Maps Android API
// void setIcon(BitmapDescriptor icon) {
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,34 @@

import com.mapbox.mapboxgl.geometry.LatLng;

/**
* Created by Nicholas Hallahan on 7/13/15.
* nick@theoutpost.io
*/
public class MarkerOptions {

private Marker marker;
public class MarkerOptions extends AnnotationOptions {

public MarkerOptions() {
marker = new Marker();
}

public MarkerOptions alpha(float alpha) {
marker.alpha = alpha;
return this;
annotation = new Marker();
}

public MarkerOptions anchor(float u, float v) {
marker.anchorU = u;
marker.anchorV = v;
((Marker)annotation).anchorU = u;
((Marker)annotation).anchorV = v;
return this;
}

public MarkerOptions draggable(boolean draggable) {
marker.draggable = draggable;
((Marker)annotation).draggable = draggable;
return this;
}

public MarkerOptions flat(boolean flat) {
marker.flat = flat;
((Marker)annotation).flat = flat;
return this;
}

public float getAlpha() {
return marker.alpha;
}

public float getAnchorU() {
return marker.anchorU;
return ((Marker)annotation).anchorU;
}

public float getAnchorV() {
return marker.anchorV;
return ((Marker)annotation).anchorV;
}

// TODO: Implement this method of Google Maps Android API
Expand All @@ -53,81 +38,82 @@ public float getAnchorV() {
// }

public float getInfoWindowAnchorU() {
return marker.infoWindowAnchorU;
return ((Marker)annotation).infoWindowAnchorU;
}

public float getInfoWindowAnchorV() {
return marker.infoWindowAnchorV;
return ((Marker)annotation).infoWindowAnchorV;
}

public Marker getMarker() {
return marker;
return (Marker)annotation;
}

public LatLng getPosition() {
return marker.position;
return ((Marker)annotation).position;
}

public float getRotation() {
return marker.rotation;
return ((Marker)annotation).rotation;
}

public String getSnippet() {
return marker.snippet;
return ((Marker)annotation).snippet;
}

public String getTitle() {
return marker.title;
return ((Marker)annotation).title;
}

// TODO: Implement this method of Google Maps Android API
// public MarkerOptions icon(BitmapDescriptor icon) {
//
// }

public MarkerOptions infoWindowAnchor(float u, float v) {
marker.infoWindowAnchorU = u;
marker.infoWindowAnchorV = v;
((Marker)annotation).infoWindowAnchorU = u;
((Marker)annotation).infoWindowAnchorV = v;
return this;
}

public boolean isDraggable() {
return marker.draggable;
return ((Marker)annotation).draggable;
}

public boolean isFlat() {
return marker.flat;
return ((Marker)annotation).flat;
}

public boolean isVisible() {
return marker.visible;
return ((Marker)annotation).visible;
}

public MarkerOptions position(LatLng position) {
marker.position = position;
((Marker)annotation).position = position;
return this;
}

public MarkerOptions rotation(float rotation) {
marker.rotation = rotation;
((Marker)annotation).rotation = rotation;
return this;
}

public MarkerOptions snippet(String snippet) {
marker.snippet = snippet;
((Marker)annotation).snippet = snippet;
return this;
}

public MarkerOptions title(String title) {
marker.title = title;
((Marker)annotation).title = title;
return this;
}

public MarkerOptions visible(boolean visible) {
marker.visible = visible;
annotation.visible = visible;
return this;
}


// TODO: Implement this method of Google Maps Android API
// public MarkerOptions icon(BitmapDescriptor icon) {
//
// }

// TODO: Implement this method of Google Maps Android API
// public void writeToParcel (Parcel out, int flags)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@ public MultiPoint() {
points = new ArrayList<>();
}

/**
* Returns a copy of the points.
*
* @return points - as a copy
*/
public List<LatLng> getPoints() {
return points;
return new ArrayList<>(points);
}

/**
* 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.
*
* @param points
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>(points);
}

// TODO: Implement getZIndex of Google Maps Android API
// public float getZIndex() {
//
// }

// TODO: Implement hashCode of Google Maps Android API
// public int hashCode() {
Expand All @@ -33,18 +45,9 @@ public List<LatLng> getPoints() {
//
// }

/**
* 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.
*
* @param points
*/
void setPoints(List<LatLng> points) {
this.points = new ArrayList<>();
for (LatLng latLng : points) {
this.points.add(latLng);
}
}
// TODO: Implement setGeodesic of Google Maps Android API
// public void setGeodesic(boolean geodesic) {
//
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mapbox.mapboxgl.annotations;

import com.mapbox.mapboxgl.geometry.LatLng;

import java.util.List;

public abstract class MultiPointOptions extends AnnotationOptions {

public MultiPointOptions() {}

public List<LatLng> getPoints() {
// the getter gives us a copy, which is the safe thing to do...
return ((MultiPoint)annotation).getPoints();
}
}
Loading

0 comments on commit 9e3f607

Please sign in to comment.