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

Commit

Permalink
[android] Tidy up annotations API
Browse files Browse the repository at this point in the history
Make unimplemented properties package private.
Make annotations object properties immutable.
Make InfoWindow and Circle classes package private.
Remove no longer needed casts from Options classes.
Added a few missing get/add methods to annotations classes for consistency.
Mininal version of #2546 suitable for v2.1.0 release.
  • Loading branch information
Leith Bade committed Oct 20, 2015
1 parent fd5f061 commit c0e1b54
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ public abstract class Annotation implements Comparable<Annotation> {
*
* Internal C++ id is stored as unsigned int.
*/
protected long id = -1; // -1 unless added to a MapView
protected MapView mapView;
private long id = -1; // -1 unless added to a MapView
private MapView mapView;

float alpha = 1.0f;
boolean visible = true;
private float alpha = 1.0f;
private boolean visible = true;

public Annotation() {}
protected Annotation() {}

public float getAlpha() {
return alpha;
}

/**
* Do not use this method. Used internally by the SDK.
*/
public long getId() {
return id;
}

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

Expand All @@ -34,19 +37,29 @@ public void remove() {
mapView.removeAnnotation(this);
}

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

/**
* Do not use this method. Used internally by the SDK.
*/
public void setId(long id) {
this.id = id;
}

/**
* Do not use this method. Used internally by the SDK.
*/
public void setMapView(MapView mapView) {
this.mapView = mapView;
}

public void setVisible(boolean visible) {
protected MapView getMapView() {
return mapView;
}

void setVisible(boolean visible) {
this.visible = visible;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* https://github.com/mapbox/mapbox-gl-native/issues/1882
* https://github.com/mapbox/mapbox-gl-native/issues/1726
*/
public class Circle extends Annotation {
class Circle extends Annotation {

LatLng center;
int fillColor = Color.BLACK;
double radius;
int strokeColor = Color.BLACK;
float strokeWidth = 10; // Google Maps API defaults to 10
private LatLng center;
private int fillColor = Color.BLACK;
private double radius;
private int strokeColor = Color.BLACK;
private float strokeWidth = 10; // Google Maps API defaults to 10

public LatLng getCenter() {
return center;
Expand All @@ -44,23 +44,23 @@ public float getStrokeWidth() {
return strokeWidth;
}

public void setCenter(LatLng center) {
void setCenter(LatLng center) {
this.center = center;
}

public void setFillColor(int color) {
void setFillColor(int color) {
fillColor = color;
}

public void setRadius(double radius) {
void setRadius(double radius) {
this.radius = radius;
}

public void setStrokeColor (int color) {
void setStrokeColor (int color) {
strokeColor = color;
}

public void setStrokeWidth (float width) {
void setStrokeWidth (float width) {
strokeWidth = width;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,73 @@
* https://github.com/mapbox/mapbox-gl-native/issues/1882
* https://github.com/mapbox/mapbox-gl-native/issues/1726
*/
public class CircleOptions {
class CircleOptions {

private Circle circle;

public CircleOptions() {
circle = new Circle();
}
public CircleOptions center(LatLng center) {
circle.center = center;
circle.setCenter(center);;
return this;
}

public CircleOptions fillColor(int color) {
circle.fillColor = color;
circle.setFillColor(color);
return this;
}

public LatLng getCenter() {
return circle.center;
return circle.getCenter();
}

public int getFillColor() {
return circle.fillColor;
return circle.getFillColor();
}

public double getRadius() {
return circle.radius;
return circle.getRadius();
}

public int getStrokeColor () {
return circle.strokeColor;
return circle.getStrokeColor();
}

public float getStrokeWidth() {
return circle.strokeWidth;
return circle.getStrokeWidth();
}

public CircleOptions radius (double radius) {
circle.radius = radius;
public CircleOptions radius(double radius) {
circle.setRadius(radius);
return this;
}

public CircleOptions strokeColor(int color) {
circle.strokeColor = color;
circle.setStrokeColor(color);
return this;
}

public CircleOptions strokeWidth (float width) {
circle.strokeWidth = width;
circle.setStrokeWidth(width);
return this;
}

public CircleOptions alpha(float alpha) {
circle.alpha = alpha;
circle.setAlpha(alpha);
return this;
}

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

public boolean isVisible() {
return circle.visible;
private CircleOptions visible(boolean visible) {
circle.setVisible(visible);
return this;
}

private boolean isVisible() {
return circle.isVisible();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* A tooltip view
*/
public final class InfoWindow {
final class InfoWindow {

private Marker boundMarker;
private MapView mMapView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import android.util.AttributeSet;
import android.view.View;

public final class InfoWindowTipView extends View {
final class InfoWindowTipView extends View {

private Paint mPaint;
private Path mPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.mapbox.mapboxsdk.R;

public class InfoWindowView extends RelativeLayout{
class InfoWindowView extends RelativeLayout{

private InfoWindowTipView mTipView;

Expand Down
Loading

0 comments on commit c0e1b54

Please sign in to comment.