diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations')
18 files changed, 3009 insertions, 2961 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java index 40b330b8c2..831c1db5a3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java @@ -15,123 +15,127 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; */ public abstract class Annotation implements Comparable<Annotation> { - /** - * <p> - * The annotation id - * </p> - * Internal C++ id is stored as unsigned int. - */ - private long id = -1; // -1 unless added to a MapView - protected MapboxMap mapboxMap; - protected MapView mapView; + /** + * <p> + * The annotation id + * </p> + * Internal C++ id is stored as unsigned int. + */ + private long id = -1; // -1 unless added to a MapView + protected MapboxMap mapboxMap; + protected MapView mapView; - protected Annotation() { - } + protected Annotation() { + } - /** - * <p> - * Gets the annotation's unique ID. - * </p> - * This ID is unique for a MapView instance and is suitable for associating your own extra - * data with. - * - * @return the assigned id. - */ - public long getId() { - return id; - } + /** + * <p> + * Gets the annotation's unique ID. + * </p> + * This ID is unique for a MapView instance and is suitable for associating your own extra + * data with. + * + * @return the assigned id. + */ + public long getId() { + return id; + } - /** - * Do not use this method, used internally by the SDK. - */ - public void remove() { - if (mapboxMap == null) { - return; - } - mapboxMap.removeAnnotation(this); + /** + * Do not use this method, used internally by the SDK. + */ + public void remove() { + if (mapboxMap == null) { + return; } + mapboxMap.removeAnnotation(this); + } - /** - * Do not use this method, used internally by the SDK. - * - * @param id the assigned id - */ - public void setId(long id) { - this.id = id; - } + /** + * Do not use this method, used internally by the SDK. + * + * @param id the assigned id + */ + public void setId(long id) { + this.id = id; + } - /** - * Do not use this method, used internally by the SDK. - * - * @param mapboxMap the hosting mapbox map - */ - public void setMapboxMap(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; - } + /** + * Do not use this method, used internally by the SDK. + * + * @param mapboxMap the hosting mapbox map + */ + public void setMapboxMap(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + } - /** - * Gets the hosting mapbox map. - * - * @return the MapboxMap - */ - protected MapboxMap getMapboxMap() { - return mapboxMap; - } + /** + * Gets the hosting mapbox map. + * + * @return the MapboxMap + */ + protected MapboxMap getMapboxMap() { + return mapboxMap; + } - /** - * Do not use this method, used internally by the SDK. - * - * @param mapView the hosting map view - */ - public void setMapView(MapView mapView) { - this.mapView = mapView; - } + /** + * Do not use this method, used internally by the SDK. + * + * @param mapView the hosting map view + */ + public void setMapView(MapView mapView) { + this.mapView = mapView; + } - /** - * Gets the hosting map view. - * - * @return The MapView - */ - protected MapView getMapView() { - return mapView; - } + /** + * Gets the hosting map view. + * + * @return The MapView + */ + protected MapView getMapView() { + return mapView; + } - @Override - public int compareTo(@NonNull Annotation annotation) { - if (id < annotation.getId()) { - return 1; - } else if (id > annotation.getId()) { - return -1; - } - return 0; + @Override + public int compareTo(@NonNull Annotation annotation) { + if (id < annotation.getId()) { + return 1; + } else if (id > annotation.getId()) { + return -1; } + return 0; + } - /** - * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and - * determines if their color, alpha, width, and vertices match. - * - * @param o Another {@link PolylineOptions} to compare with this object. - * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object. - * Else, false. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || !(o instanceof Annotation)) return false; - Annotation that = (Annotation) o; - return id == that.getId(); + /** + * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and + * determines if their color, alpha, width, and vertices match. + * + * @param object Another {@link PolylineOptions} to compare with this object. + * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object. + * Else, false. + */ + @Override + public boolean equals(Object object) { + if (this == object) { + return true; } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - return (int) (getId() ^ (getId() >>> 32)); + if (object == null || !(object instanceof Annotation)) { + return false; } + Annotation that = (Annotation) object; + return id == that.getId(); + } + + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + return (int) (getId() ^ (getId() >>> 32)); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java index 4e56531a7f..82868e2888 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerOptions.java @@ -6,7 +6,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng; /** * Abstract builder class for composing custom Marker objects. - * + * <p> * Extending this class requires implementing Parceable interface. * * @param <U> Type of the marker to be composed @@ -14,107 +14,107 @@ import com.mapbox.mapboxsdk.geometry.LatLng; */ public abstract class BaseMarkerOptions<U extends Marker, T extends BaseMarkerOptions<U, T>> implements Parcelable { - protected LatLng position; - protected String snippet; - protected String title; - protected Icon icon; + protected LatLng position; + protected String snippet; + protected String title; + protected Icon icon; - /** - * Set the geographical location of the Marker. - * - * @param position the location to position the {@link Marker}. - * @return the object for which the method was called. - */ - public T position(LatLng position) { - this.position = position; - return getThis(); - } + /** + * Set the geographical location of the Marker. + * + * @param position the location to position the {@link Marker}. + * @return the object for which the method was called. + */ + public T position(LatLng position) { + this.position = position; + return getThis(); + } - /** - * Set the snippet of the Marker. - * - * @param snippet the snippet of the {@link Marker}. - * @return the object for which the method was called. - */ - public T snippet(String snippet) { - this.snippet = snippet; - return getThis(); - } + /** + * Set the snippet of the Marker. + * + * @param snippet the snippet of the {@link Marker}. + * @return the object for which the method was called. + */ + public T snippet(String snippet) { + this.snippet = snippet; + return getThis(); + } - /** - * Set the title of the Marker. - * - * @param title the title of the {@link Marker}. - * @return the object for which the method was called. - */ - public T title(String title) { - this.title = title; - return getThis(); - } + /** + * Set the title of the Marker. + * + * @param title the title of the {@link Marker}. + * @return the object for which the method was called. + */ + public T title(String title) { + this.title = title; + return getThis(); + } - /** - * Set the icon of the Marker. - * - * @param icon the icon of the {@link Marker}. - * @return the object for which the method was called. - */ - public T icon(Icon icon) { - this.icon = icon; - return getThis(); - } + /** + * Set the icon of the Marker. + * + * @param icon the icon of the {@link Marker}. + * @return the object for which the method was called. + */ + public T icon(Icon icon) { + this.icon = icon; + return getThis(); + } - /** - * Set the icon of the Marker. - * - * @param icon the icon of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setIcon(Icon icon) { - return icon(icon); - } + /** + * Set the icon of the Marker. + * + * @param icon the icon of the {@link Marker}. + * @return the object for which the method was called. + */ + public T setIcon(Icon icon) { + return icon(icon); + } - /** - * Set the geographical location of the Marker. - * - * @param position the location to position the {@link Marker}. - * @return the object for which the method was called. - */ - public T setPosition(LatLng position) { - return position(position); - } + /** + * Set the geographical location of the Marker. + * + * @param position the location to position the {@link Marker}. + * @return the object for which the method was called. + */ + public T setPosition(LatLng position) { + return position(position); + } - /** - * Set the snippet of the Marker. - * - * @param snippet the snippet of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setSnippet(String snippet) { - return snippet(snippet); - } + /** + * Set the snippet of the Marker. + * + * @param snippet the snippet of the {@link Marker}. + * @return the object for which the method was called. + */ + public T setSnippet(String snippet) { + return snippet(snippet); + } - /** - * Set the title of the Marker. - * - * @param title the title of the {@link Marker}. - * @return the object for which the method was called. - */ - public T setTitle(String title) { - return title(title); - } + /** + * Set the title of the Marker. + * + * @param title the title of the {@link Marker}. + * @return the object for which the method was called. + */ + public T setTitle(String title) { + return title(title); + } - /** - * Get the instance of the object for which this method was called. - * - * @return the object for which the this method was called. - */ - public abstract T getThis(); + /** + * Get the instance of the object for which this method was called. + * + * @return the object for which the this method was called. + */ + public abstract T getThis(); - /** - * Get the Marker. - * - * @return the Marker created from this builder. - */ - public abstract U getMarker(); + /** + * Get the Marker. + * + * @return the Marker created from this builder. + */ + public abstract U getMarker(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java index e93f2c801d..ddedf3debf 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java @@ -15,267 +15,268 @@ import com.mapbox.mapboxsdk.geometry.LatLng; * @param <U> Type of the marker view to be composed. * @param <T> Type of the builder to be used for composing. */ -public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends BaseMarkerViewOptions<U, T>> implements Parcelable { +public abstract class BaseMarkerViewOptions<U extends MarkerView, T extends BaseMarkerViewOptions<U, T>> + implements Parcelable { - protected LatLng position; - protected String snippet; - protected String title; - protected Icon icon; - protected boolean flat; - protected float anchorU = 0.5f; - protected float anchorV = 1f; - protected float infoWindowAnchorU = 0.5f; - protected float infoWindowAnchorV = 0.0f; - protected float rotation; - protected boolean visible = true; - protected boolean selected; - protected float alpha = 1.0f; + protected LatLng position; + protected String snippet; + protected String title; + protected Icon icon; + protected boolean flat; + protected float anchorU = 0.5f; + protected float anchorV = 1f; + protected float infoWindowAnchorU = 0.5f; + protected float infoWindowAnchorV = 0.0f; + protected float rotation; + protected boolean visible = true; + protected boolean selected; + protected float alpha = 1.0f; - /** - * Default constructor - */ - public BaseMarkerViewOptions() { - } + /** + * Default constructor + */ + public BaseMarkerViewOptions() { + } - /** - * Set the geographical location of the MarkerView. - * - * @param position the location to position the {@link MarkerView}. - * @return the object for which the method was called. - */ - public T position(@NonNull LatLng position) { - this.position = position; - return getThis(); - } + /** + * Set the geographical location of the MarkerView. + * + * @param position the location to position the {@link MarkerView}. + * @return the object for which the method was called. + */ + public T position(@NonNull LatLng position) { + this.position = position; + return getThis(); + } - /** - * Set the snippet of the MarkerView. - * - * @param snippet the snippet of the {@link MarkerView}. - * @return the object for which the method was called. - */ - public T snippet(String snippet) { - this.snippet = snippet; - return getThis(); - } + /** + * Set the snippet of the MarkerView. + * + * @param snippet the snippet of the {@link MarkerView}. + * @return the object for which the method was called. + */ + public T snippet(String snippet) { + this.snippet = snippet; + return getThis(); + } - /** - * Set the title of the MarkerView. - * - * @param title the title of the {@link MarkerView}. - * @return the object for which the method was called. - */ - public T title(String title) { - this.title = title; - return getThis(); - } + /** + * Set the title of the MarkerView. + * + * @param title the title of the {@link MarkerView}. + * @return the object for which the method was called. + */ + public T title(String title) { + this.title = title; + return getThis(); + } - /** - * Set the icon of the MarkerView. - * - * @param icon the icon of the {@link MarkerView}. - * @return the object for which the method was called. - */ - public T icon(Icon icon) { - this.icon = icon; - return getThis(); - } + /** + * Set the icon of the MarkerView. + * + * @param icon the icon of the {@link MarkerView}. + * @return the object for which the method was called. + */ + public T icon(Icon icon) { + this.icon = icon; + return getThis(); + } - /** - * Set the flat state of the MarkerView. - * - * @param flat the flat state of the {@link MarkerView}. - * @return the object for which the method was called. - */ - public T flat(boolean flat) { - this.flat = flat; - return getThis(); - } + /** + * Set the flat state of the MarkerView. + * + * @param flat the flat state of the {@link MarkerView}. + * @return the object for which the method was called. + */ + public T flat(boolean flat) { + this.flat = flat; + return getThis(); + } - /** - * Set the anchor of the {@link MarkerView}. - * - * @param u the u-value. - * @param v the v-value. - * @return the object for which the method was called. - */ - public T anchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { - this.anchorU = u; - this.anchorV = v; - return getThis(); - } + /** + * Set the anchor of the {@link MarkerView}. + * + * @param u the u-value. + * @param v the v-value. + * @return the object for which the method was called. + */ + public T anchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { + this.anchorU = u; + this.anchorV = v; + return getThis(); + } - /** - * Set the InfoWindow anchor of the {@link MarkerView}. - * - * @param u the u-value. - * @param v the v-values. - * @return the object for which the method was called. - */ - public T infoWindowAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { - this.infoWindowAnchorU = u; - this.infoWindowAnchorV = v; - return getThis(); - } + /** + * Set the InfoWindow anchor of the {@link MarkerView}. + * + * @param u the u-value. + * @param v the v-values. + * @return the object for which the method was called. + */ + public T infoWindowAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { + this.infoWindowAnchorU = u; + this.infoWindowAnchorV = v; + return getThis(); + } - /** - * Set the rotation of the {@link MarkerView}. - * - * @param rotation the rotation value. - * @return the object for which the method was called. - */ - public T rotation(float rotation) { - this.rotation = rotation; - while (this.rotation > 360) { - this.rotation -= 360; - } - while (this.rotation < 0) { - this.rotation += 360; - } - return getThis(); + /** + * Set the rotation of the {@link MarkerView}. + * + * @param rotation the rotation value. + * @return the object for which the method was called. + */ + public T rotation(float rotation) { + this.rotation = rotation; + while (this.rotation > 360) { + this.rotation -= 360; } - - /** - * Set the visibility state of the {@link MarkerView}. - * - * @param visible the visible state. - * @return the object for which the method was called. - */ - public T visible(boolean visible) { - this.visible = visible; - return getThis(); + while (this.rotation < 0) { + this.rotation += 360; } + return getThis(); + } - /** - * Set the alpha of the {@link MarkerView}. - * - * @param alpha the alpha value. - * @return the object for which the method was called. - */ - public T alpha(float alpha) { - this.alpha = alpha; - return getThis(); - } + /** + * Set the visibility state of the {@link MarkerView}. + * + * @param visible the visible state. + * @return the object for which the method was called. + */ + public T visible(boolean visible) { + this.visible = visible; + return getThis(); + } - /** - * Get the geographical location of the {@link MarkerView}. - * - * @return the geographical location. - */ - public LatLng getPosition() { - return position; - } + /** + * Set the alpha of the {@link MarkerView}. + * + * @param alpha the alpha value. + * @return the object for which the method was called. + */ + public T alpha(float alpha) { + this.alpha = alpha; + return getThis(); + } - /** - * Get the snippet of the {@link MarkerView}. - * - * @return the snippet. - */ - public String getSnippet() { - return snippet; - } + /** + * Get the geographical location of the {@link MarkerView}. + * + * @return the geographical location. + */ + public LatLng getPosition() { + return position; + } - /** - * Get the title of the {@link MarkerView}. - * - * @return the title. - */ - public String getTitle() { - return title; - } + /** + * Get the snippet of the {@link MarkerView}. + * + * @return the snippet. + */ + public String getSnippet() { + return snippet; + } - /** - * Get the icon of the {@link MarkerView}. - * - * @return the icon. - */ - public Icon getIcon() { - return icon; - } + /** + * Get the title of the {@link MarkerView}. + * + * @return the title. + */ + public String getTitle() { + return title; + } - /** - * Get the flat state of the {@link MarkerView}. - * - * @return the flat state. - */ - public boolean isFlat() { - return flat; - } + /** + * Get the icon of the {@link MarkerView}. + * + * @return the icon. + */ + public Icon getIcon() { + return icon; + } - /** - * Get the u-value of the {@link MarkerView} anchor. - * - * @return the u-value. - */ - public float getAnchorU() { - return anchorU; - } + /** + * Get the flat state of the {@link MarkerView}. + * + * @return the flat state. + */ + public boolean isFlat() { + return flat; + } - /** - * Get the v-value of the {@link MarkerView} anchor. - * - * @return the v-value. - */ - public float getAnchorV() { - return anchorV; - } + /** + * Get the u-value of the {@link MarkerView} anchor. + * + * @return the u-value. + */ + public float getAnchorU() { + return anchorU; + } - /** - * Get the u-value of the MarkerView InfoWindow anchor. - * - * @return the u-value. - */ - public float getInfoWindowAnchorU() { - return infoWindowAnchorU; - } + /** + * Get the v-value of the {@link MarkerView} anchor. + * + * @return the v-value. + */ + public float getAnchorV() { + return anchorV; + } - /** - * Get the v-value of the MarkerView InfoWindow anchor. - * - * @return the v-value. - */ - public float getInfoWindowAnchorV() { - return infoWindowAnchorV; - } + /** + * Get the u-value of the MarkerView InfoWindow anchor. + * + * @return the u-value. + */ + public float getInfoWindowAnchorU() { + return infoWindowAnchorU; + } - /** - * Get the rotation of the MarkerView. - * - * @return the rotation value. - */ - public float getRotation() { - return rotation; - } + /** + * Get the v-value of the MarkerView InfoWindow anchor. + * + * @return the v-value. + */ + public float getInfoWindowAnchorV() { + return infoWindowAnchorV; + } - /** - * Get the visibility state of the MarkerView. - * - * @return the visibility state. - */ - public boolean isVisible() { - return visible; - } + /** + * Get the rotation of the MarkerView. + * + * @return the rotation value. + */ + public float getRotation() { + return rotation; + } - /** - * Get the alpha of the MarkerView. - * - * @return the alpha value. - */ - public float getAlpha() { - return alpha; - } + /** + * Get the visibility state of the MarkerView. + * + * @return the visibility state. + */ + public boolean isVisible() { + return visible; + } + + /** + * Get the alpha of the MarkerView. + * + * @return the alpha value. + */ + public float getAlpha() { + return alpha; + } - /** - * Get the instance of the object for which this method was called. - * - * @return the object for which the this method was called. - */ - public abstract T getThis(); + /** + * Get the instance of the object for which this method was called. + * + * @return the object for which the this method was called. + */ + public abstract T getThis(); - /** - * Get the MarkerView. - * - * @return the MarkerView created from this builder. - */ - public abstract U getMarker(); + /** + * Get the MarkerView. + * + * @return the MarkerView created from this builder. + */ + public abstract U getMarker(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java index ae7cf6eb8c..b1a05ec436 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java @@ -10,67 +10,73 @@ import com.mapbox.mapboxsdk.maps.MapView; * @see Marker */ public class Icon { - private Bitmap mBitmap; - private String mId; + private Bitmap mBitmap; + private String mId; - Icon(String id, Bitmap bitmap) { - mId = id; - mBitmap = bitmap; - } + Icon(String id, Bitmap bitmap) { + mId = id; + mBitmap = bitmap; + } - /** - * {@link String} identifier for this {@link Icon}. - * - * @return {@link String} identifier for this {@link Icon}. - */ - public String getId() { - return mId; - } + /** + * {@link String} identifier for this {@link Icon}. + * + * @return {@link String} identifier for this {@link Icon}. + */ + public String getId() { + return mId; + } - /** - * Get the {@link Bitmap} being used for this {@link Icon}. - * - * @return The {@link Bitmap} being used for the {@link Icon}. - */ - public Bitmap getBitmap() { - return mBitmap; - } + /** + * Get the {@link Bitmap} being used for this {@link Icon}. + * + * @return The {@link Bitmap} being used for the {@link Icon}. + */ + public Bitmap getBitmap() { + return mBitmap; + } - /** - * Compares this {@link Icon} object with another {@link Icon} and determines if they match. - * - * @param o Another {@link Icon} to compare with this object. - * @return True if the {@link Icon} being passed in matches this {@link Icon} object. Else, - * false. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + /** + * Compares this {@link Icon} object with another {@link Icon} and determines if they match. + * + * @param object Another {@link Icon} to compare with this object. + * @return True if the {@link Icon} being passed in matches this {@link Icon} object. Else, + * false. + */ + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + if (object == null || getClass() != object.getClass()) { + return false; + } - Icon icon = (Icon) o; + Icon icon = (Icon) object; - if (!mBitmap.equals(icon.mBitmap)) return false; - return mId.equals(icon.mId); + if (!mBitmap.equals(icon.mBitmap)) { + return false; } + return mId.equals(icon.mId); + } - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 0; - if (mBitmap != null) { - result = mBitmap.hashCode(); - } - if (mId != null) { - result = 31 * result + mId.hashCode(); - } - return result; + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + int result = 0; + if (mBitmap != null) { + result = mBitmap.hashCode(); + } + if (mId != null) { + result = 31 * result + mId.hashCode(); } + return result; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java index 9427501bb8..052d5592e4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java @@ -29,205 +29,207 @@ import java.io.InputStream; */ public final class IconFactory { - private static final String ICON_ID_PREFIX = "com.mapbox.icons.icon_"; - public static final Bitmap ICON_MARKERVIEW_BITMAP = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8); - public static final String ICON_MARKERVIEW_ID = ICON_ID_PREFIX + "marker_view"; - - private Context mContext; - private static IconFactory sInstance; - private Icon mDefaultMarker; - private Icon mDefaultMarkerView; - private BitmapFactory.Options mOptions; - - private int mNextId = 0; - - public static synchronized IconFactory getInstance(@NonNull Context context) { - if (sInstance == null) { - sInstance = new IconFactory(context.getApplicationContext()); - } - return sInstance; - } + private static final String ICON_ID_PREFIX = "com.mapbox.icons.icon_"; + public static final Bitmap ICON_MARKERVIEW_BITMAP = Bitmap.createBitmap(1, 1, Bitmap.Config.ALPHA_8); + public static final String ICON_MARKERVIEW_ID = ICON_ID_PREFIX + "marker_view"; - private IconFactory(@NonNull Context context) { - mContext = context; - DisplayMetrics realMetrics = null; - DisplayMetrics metrics = new DisplayMetrics(); - WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - realMetrics = new DisplayMetrics(); - wm.getDefaultDisplay().getRealMetrics(realMetrics); - } - wm.getDefaultDisplay().getMetrics(metrics); - - mOptions = new BitmapFactory.Options(); - mOptions.inScaled = true; - mOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT; - mOptions.inTargetDensity = metrics.densityDpi; - if (realMetrics != null) { - mOptions.inScreenDensity = realMetrics.densityDpi; - } - } + private Context mContext; + private static IconFactory sInstance; + private Icon mDefaultMarker; + private Icon mDefaultMarkerView; + private BitmapFactory.Options mOptions; - /** - * Creates an {@link Icon} from a given Bitmap image. - * - * @param bitmap image used for creating the Icon. - * @return The {@link Icon} using the given Bitmap image. - */ - public Icon fromBitmap(@NonNull Bitmap bitmap) { - if (mNextId < 0) { - throw new TooManyIconsException(); - } - String id = ICON_ID_PREFIX + ++mNextId; - return new Icon(id, bitmap); - } + private int mNextId = 0; - /** - * Create an {@link Icon} from a given {@link Drawable}. - * - * @param drawable A {@link Drawable} object used for creating the {@link Icon}. - * @return {@link Icon} with the provided {@link Drawable}. - */ - public Icon fromDrawable(@NonNull Drawable drawable) { - int width = drawable.getIntrinsicWidth(); - int height = drawable.getIntrinsicHeight(); - return fromDrawable(drawable, width, height); + public static synchronized IconFactory getInstance(@NonNull Context context) { + if (sInstance == null) { + sInstance = new IconFactory(context.getApplicationContext()); } - - /** - * Create an {@link Icon} from a given {@link Drawable}. - * - * @param drawable A {@link Drawable} object used for creating the {@link Icon}. - * @param width An integer greater then zero defining the {@link Icon} width. - * @param height An integer greater then zero defining the {@link Icon} height. - * @return {@link Icon} with the provided {@link Drawable}. - */ - public Icon fromDrawable(@NonNull Drawable drawable, int width, int height) { - if ((width < 0) || (height < 0)) { - return null; - } - - Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(bitmap); - Rect temp = drawable.getBounds(); - Rect bounds = new Rect(0, 0, width, height); - drawable.setBounds(bounds); - drawable.draw(canvas); - drawable.setBounds(temp); - return fromBitmap(bitmap); + return sInstance; + } + + private IconFactory(@NonNull Context context) { + mContext = context; + DisplayMetrics realMetrics = null; + DisplayMetrics metrics = new DisplayMetrics(); + WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + realMetrics = new DisplayMetrics(); + wm.getDefaultDisplay().getRealMetrics(realMetrics); } - - /** - * Create an {@link Icon} using the resource ID of a Bitmap image. - * - * @param resourceId The resource ID of a Bitmap image. - * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. - */ - public Icon fromResource(@DrawableRes int resourceId) { - Drawable drawable = ContextCompat.getDrawable(mContext, resourceId); - Bitmap bitmap; - if (drawable instanceof BitmapDrawable) { - BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; - bitmap = bitmapDrawable.getBitmap(); - } else { - if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { - bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); - } else { - bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); - } - - Canvas canvas = new Canvas(bitmap); - drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - drawable.draw(canvas); - } - return fromBitmap(bitmap); + wm.getDefaultDisplay().getMetrics(metrics); + + mOptions = new BitmapFactory.Options(); + mOptions.inScaled = true; + mOptions.inDensity = DisplayMetrics.DENSITY_DEFAULT; + mOptions.inTargetDensity = metrics.densityDpi; + if (realMetrics != null) { + mOptions.inScreenDensity = realMetrics.densityDpi; } - - /** - * Provides an {@link Icon} using the default marker icon used for {@link Marker}. - * - * @return An {@link Icon} with the default {@link Marker} icon. - */ - public Icon defaultMarker() { - if (mDefaultMarker == null) { - mDefaultMarker = fromResource(R.drawable.mapbox_marker_icon_default); - } - return mDefaultMarker; + } + + /** + * Creates an {@link Icon} from a given Bitmap image. + * + * @param bitmap image used for creating the Icon. + * @return The {@link Icon} using the given Bitmap image. + */ + public Icon fromBitmap(@NonNull Bitmap bitmap) { + if (mNextId < 0) { + throw new TooManyIconsException(); } - - /** - * Provides an {@link Icon} using the default marker icon used for {@link MarkerView}. - * - * @return An {@link Icon} with the default {@link MarkerView} icon. - */ - public Icon defaultMarkerView() { - if (mDefaultMarkerView == null) { - mDefaultMarkerView = fromResource(R.drawable.mapbox_markerview_icon_default); - } - return mDefaultMarkerView; + String id = ICON_ID_PREFIX + ++mNextId; + return new Icon(id, bitmap); + } + + /** + * Create an {@link Icon} from a given {@link Drawable}. + * + * @param drawable A {@link Drawable} object used for creating the {@link Icon}. + * @return {@link Icon} with the provided {@link Drawable}. + */ + public Icon fromDrawable(@NonNull Drawable drawable) { + int width = drawable.getIntrinsicWidth(); + int height = drawable.getIntrinsicHeight(); + return fromDrawable(drawable, width, height); + } + + /** + * Create an {@link Icon} from a given {@link Drawable}. + * + * @param drawable A {@link Drawable} object used for creating the {@link Icon}. + * @param width An integer greater then zero defining the {@link Icon} width. + * @param height An integer greater then zero defining the {@link Icon} height. + * @return {@link Icon} with the provided {@link Drawable}. + */ + public Icon fromDrawable(@NonNull Drawable drawable, int width, int height) { + if ((width < 0) || (height < 0)) { + return null; } - private Icon fromInputStream(@NonNull InputStream is) { - Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions); - return fromBitmap(bitmap); + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + Rect temp = drawable.getBounds(); + Rect bounds = new Rect(0, 0, width, height); + drawable.setBounds(bounds); + drawable.draw(canvas); + drawable.setBounds(temp); + return fromBitmap(bitmap); + } + + /** + * Create an {@link Icon} using the resource ID of a Bitmap image. + * + * @param resourceId The resource ID of a Bitmap image. + * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. + */ + public Icon fromResource(@DrawableRes int resourceId) { + Drawable drawable = ContextCompat.getDrawable(mContext, resourceId); + Bitmap bitmap; + if (drawable instanceof BitmapDrawable) { + BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; + bitmap = bitmapDrawable.getBitmap(); + } else { + if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) { + bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); + } else { + bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), + Bitmap.Config.ARGB_8888); + } + + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); } - - /** - * Creates an {@link Icon} using the name of a Bitmap image in the assets directory. - * - * @param assetName The name of a Bitmap image in the assets directory. - * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. - */ - public Icon fromAsset(@NonNull String assetName) { - InputStream is; - try { - is = mContext.getAssets().open(assetName); - } catch (IOException e) { - return null; - } - return fromInputStream(is); + return fromBitmap(bitmap); + } + + /** + * Provides an {@link Icon} using the default marker icon used for {@link Marker}. + * + * @return An {@link Icon} with the default {@link Marker} icon. + */ + public Icon defaultMarker() { + if (mDefaultMarker == null) { + mDefaultMarker = fromResource(R.drawable.mapbox_marker_icon_default); } - - /** - * Creates an {@link Icon} using the absolute file path of a Bitmap image. - * - * @param absolutePath The absolute path of the Bitmap image. - * @return The {@link Icon} that was loaded from the absolute path or {@code null} if failed to - * load. - */ - public Icon fromPath(@NonNull String absolutePath) { - Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, mOptions); - return fromBitmap(bitmap); + return mDefaultMarker; + } + + /** + * Provides an {@link Icon} using the default marker icon used for {@link MarkerView}. + * + * @return An {@link Icon} with the default {@link MarkerView} icon. + */ + public Icon defaultMarkerView() { + if (mDefaultMarkerView == null) { + mDefaultMarkerView = fromResource(R.drawable.mapbox_markerview_icon_default); } - - /** - * Create an {@link Icon} using the name of a Bitmap image file located in the internal storage. - * In particular, this calls {@link Context#openFileInput(String)}. - * - * @param fileName The name of the Bitmap image file. - * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. - * @see <a href="https://developer.android.com/guide/topics/data/data-storage.html#filesInternal">Using the Internal Storage</a> - */ - public Icon fromFile(@NonNull String fileName) { - FileInputStream is; - try { - is = mContext.openFileInput(fileName); - } catch (FileNotFoundException e) { - return null; - } - return fromInputStream(is); + return mDefaultMarkerView; + } + + private Icon fromInputStream(@NonNull InputStream is) { + Bitmap bitmap = BitmapFactory.decodeStream(is, null, mOptions); + return fromBitmap(bitmap); + } + + /** + * Creates an {@link Icon} using the name of a Bitmap image in the assets directory. + * + * @param assetName The name of a Bitmap image in the assets directory. + * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. + */ + public Icon fromAsset(@NonNull String assetName) { + InputStream is; + try { + is = mContext.getAssets().open(assetName); + } catch (IOException ioException) { + return null; } - - /** - * Create an {@link Icon} using a previously created icon identifier along with a provided - * Bitmap. - * - * @param iconId The {@link Icon} identifier you'd like to recreate. - * @param bitmap a Bitmap used to replace the current one. - * @return The {@link Icon} using the new Bitmap. - */ - public static Icon recreate(@NonNull String iconId, @NonNull Bitmap bitmap) { - return new Icon(iconId, bitmap); + return fromInputStream(is); + } + + /** + * Creates an {@link Icon} using the absolute file path of a Bitmap image. + * + * @param absolutePath The absolute path of the Bitmap image. + * @return The {@link Icon} that was loaded from the absolute path or {@code null} if failed to + * load. + */ + public Icon fromPath(@NonNull String absolutePath) { + Bitmap bitmap = BitmapFactory.decodeFile(absolutePath, mOptions); + return fromBitmap(bitmap); + } + + /** + * Create an {@link Icon} using the name of a Bitmap image file located in the internal storage. + * In particular, this calls {@link Context#openFileInput(String)}. + * + * @param fileName The name of the Bitmap image file. + * @return The {@link Icon} that was loaded from the asset or {@code null} if failed to load. + * @see <a href="https://developer.android.com/guide/topics/data/data-storage.html#filesInternal"> + * Using the Internal Storage</a> + */ + public Icon fromFile(@NonNull String fileName) { + FileInputStream is; + try { + is = mContext.openFileInput(fileName); + } catch (FileNotFoundException fileNotFoundException) { + return null; } + return fromInputStream(is); + } + + /** + * Create an {@link Icon} using a previously created icon identifier along with a provided + * Bitmap. + * + * @param iconId The {@link Icon} identifier you'd like to recreate. + * @param bitmap a Bitmap used to replace the current one. + * @return The {@link Icon} using the new Bitmap. + */ + public static Icon recreate(@NonNull String iconId, @NonNull Bitmap bitmap) { + return new Icon(iconId, bitmap); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java index b33d489da2..34d2c31139 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindow.java @@ -31,270 +31,271 @@ import java.lang.ref.WeakReference; */ public class InfoWindow { - private WeakReference<Marker> mBoundMarker; - private WeakReference<MapboxMap> mMapboxMap; - protected WeakReference<View> mView; - - private float mMarkerHeightOffset; - private float mMarkerWidthOffset; - private float mViewWidthOffset; - private PointF mCoordinates; - private boolean mIsVisible; - - @LayoutRes - private int mLayoutRes; - - InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) { - mLayoutRes = layoutResId; - View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false); - initialize(view, mapboxMap); - } + private WeakReference<Marker> boundMarker; + private WeakReference<MapboxMap> mapboxMap; + protected WeakReference<View> view; + + private float markerHeightOffset; + private float markerWidthOffset; + private float viewWidthOffset; + private PointF coordinates; + private boolean isVisible; + + @LayoutRes + private int layoutRes; + + InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) { + layoutRes = layoutResId; + View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false); + initialize(view, mapboxMap); + } + + InfoWindow(View view, MapboxMap mapboxMap) { + initialize(view, mapboxMap); + } + + private void initialize(View view, MapboxMap mapboxMap) { + this.mapboxMap = new WeakReference<>(mapboxMap); + isVisible = false; + this.view = new WeakReference<>(view); + + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get(); + if (mapboxMap != null) { + MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap.getOnInfoWindowClickListener(); + boolean handledDefaultClick = false; + if (onInfoWindowClickListener != null) { + handledDefaultClick = onInfoWindowClickListener.onInfoWindowClick(getBoundMarker()); + } + + if (!handledDefaultClick) { + // default behavior: close it when clicking on the tooltip: + close(); + } + } + } + }); + + view.setOnLongClickListener(new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + MapboxMap mapboxMap = InfoWindow.this.mapboxMap.get(); + if (mapboxMap != null) { + MapboxMap.OnInfoWindowLongClickListener listener = mapboxMap.getOnInfoWindowLongClickListener(); + if (listener != null) { + listener.onInfoWindowLongClick(getBoundMarker()); + } + } + return true; + } + }); + } + + + /** + * Open the info window at the specified position. + * + * @param boundMarker The marker on which is hooked the view. + * @param position to place the window on the map. + * @param offsetX The offset of the view to the position, in pixels. This allows to offset + * the view from the object position. + * @param offsetY The offset of the view to the position, in pixels. This allows to offset + * the view from the object position. + * @return this {@link InfoWindow}. + */ + InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offsetX, int offsetY) { + setBoundMarker(boundMarker); + + MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, + MapView.LayoutParams.WRAP_CONTENT); + + MapboxMap mapboxMap = this.mapboxMap.get(); + View view = this.view.get(); + if (view != null && mapboxMap != null) { + view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + + // Calculate y-offset for update method + markerHeightOffset = -view.getMeasuredHeight() + offsetY; + markerWidthOffset = -offsetX; + + // Calculate default Android x,y coordinate + coordinates = mapboxMap.getProjection().toScreenLocation(position); + float x = coordinates.x - (view.getMeasuredWidth() / 2) + offsetX; + float y = coordinates.y - view.getMeasuredHeight() + offsetY; + + if (view instanceof InfoWindowView) { + // only apply repositioning/margin for InfoWindowView + Resources resources = mapView.getContext().getResources(); + + // get right/left popup window + float rightSideInfowWindow = x + view.getMeasuredWidth(); + float leftSideInfoWindow = x; + + // get right/left map view + final float mapRight = mapView.getRight(); + final float mapLeft = mapView.getLeft(); + + float marginHorizontal = resources.getDimension(R.dimen.mapbox_infowindow_margin); + float tipViewOffset = resources.getDimension(R.dimen.mapbox_infowindow_tipview_width) / 2; + float tipViewMarginLeft = view.getMeasuredWidth() / 2 - tipViewOffset; + + boolean outOfBoundsLeft = false; + boolean outOfBoundsRight = false; + + // only optimise margins if view is inside current viewport + if (coordinates.x >= 0 && coordinates.x <= mapView.getWidth() + && coordinates.y >= 0 && coordinates.y <= mapView.getHeight()) { + + // if out of bounds right + if (rightSideInfowWindow > mapRight) { + outOfBoundsRight = true; + x -= rightSideInfowWindow - mapRight; + tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset; + rightSideInfowWindow = x + view.getMeasuredWidth(); + } + + // fit screen left + if (leftSideInfoWindow < mapLeft) { + outOfBoundsLeft = true; + x += mapLeft - leftSideInfoWindow; + tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset; + leftSideInfoWindow = x; + } + + // Add margin right + if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { + x -= marginHorizontal - (mapRight - rightSideInfowWindow); + tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; + leftSideInfoWindow = x; + } + + // Add margin left + if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { + x += marginHorizontal - (leftSideInfoWindow - mapLeft); + tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; + } + } - InfoWindow(View view, MapboxMap mapboxMap) { - initialize(view, mapboxMap); - } + // Adjust tipView + InfoWindowView infoWindowView = (InfoWindowView) view; + infoWindowView.setTipViewMarginLeft((int) tipViewMarginLeft); + } - private void initialize(View view, MapboxMap mapboxMap) { - mMapboxMap = new WeakReference<>(mapboxMap); - mIsVisible = false; - mView = new WeakReference<>(view); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MapboxMap mapboxMap = mMapboxMap.get(); - if (mapboxMap != null) { - MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = mapboxMap.getOnInfoWindowClickListener(); - boolean handledDefaultClick = false; - if (onInfoWindowClickListener != null) { - handledDefaultClick = onInfoWindowClickListener.onInfoWindowClick(getBoundMarker()); - } - - if (!handledDefaultClick) { - // default behavior: close it when clicking on the tooltip: - close(); - } - } - } - }); - - view.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View v) { - MapboxMap mapboxMap = mMapboxMap.get(); - if (mapboxMap != null) { - MapboxMap.OnInfoWindowLongClickListener listener = mapboxMap.getOnInfoWindowLongClickListener(); - if (listener != null) { - listener.onInfoWindowLongClick(getBoundMarker()); - } - } - return true; - } - }); - } + // set anchor popupwindowview + view.setX(x); + view.setY(y); + // Calculate x-offset for update method + viewWidthOffset = x - coordinates.x - offsetX; - /** - * Open the info window at the specified position. - * - * @param boundMarker The marker on which is hooked the view. - * @param position to place the window on the map. - * @param offsetX The offset of the view to the position, in pixels. This allows to offset - * the view from the object position. - * @param offsetY The offset of the view to the position, in pixels. This allows to offset - * the view from the object position. - * @return this {@link InfoWindow}. - */ - InfoWindow open(MapView mapView, Marker boundMarker, LatLng position, int offsetX, int offsetY) { - setBoundMarker(boundMarker); - - MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT); - - MapboxMap mapboxMap = mMapboxMap.get(); - View view = mView.get(); - if (view != null && mapboxMap != null) { - view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - - // Calculate y-offset for update method - mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY; - mMarkerWidthOffset = -offsetX; - - // Calculate default Android x,y coordinate - mCoordinates = mapboxMap.getProjection().toScreenLocation(position); - float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX; - float y = mCoordinates.y - view.getMeasuredHeight() + offsetY; - - if (view instanceof InfoWindowView) { - // only apply repositioning/margin for InfoWindowView - Resources resources = mapView.getContext().getResources(); - - // get right/left popup window - float rightSideInfowWindow = x + view.getMeasuredWidth(); - float leftSideInfoWindow = x; - - // get right/left map view - final float mapRight = mapView.getRight(); - final float mapLeft = mapView.getLeft(); - - float marginHorizontal = resources.getDimension(R.dimen.mapbox_infowindow_margin); - float tipViewOffset = resources.getDimension(R.dimen.mapbox_infowindow_tipview_width) / 2; - float tipViewMarginLeft = view.getMeasuredWidth() / 2 - tipViewOffset; - - boolean outOfBoundsLeft = false; - boolean outOfBoundsRight = false; - - // only optimise margins if view is inside current viewport - if (mCoordinates.x >= 0 && mCoordinates.x <= mapView.getWidth() - && mCoordinates.y >= 0 && mCoordinates.y <= mapView.getHeight()) { - - // if out of bounds right - if (rightSideInfowWindow > mapRight) { - outOfBoundsRight = true; - x -= rightSideInfowWindow - mapRight; - tipViewMarginLeft += rightSideInfowWindow - mapRight + tipViewOffset; - rightSideInfowWindow = x + view.getMeasuredWidth(); - } - - // fit screen left - if (leftSideInfoWindow < mapLeft) { - outOfBoundsLeft = true; - x += mapLeft - leftSideInfoWindow; - tipViewMarginLeft -= mapLeft - leftSideInfoWindow + tipViewOffset; - leftSideInfoWindow = x; - } - - // Add margin right - if (outOfBoundsRight && mapRight - rightSideInfowWindow < marginHorizontal) { - x -= marginHorizontal - (mapRight - rightSideInfowWindow); - tipViewMarginLeft += marginHorizontal - (mapRight - rightSideInfowWindow) - tipViewOffset; - leftSideInfoWindow = x; - } - - // Add margin left - if (outOfBoundsLeft && leftSideInfoWindow - mapLeft < marginHorizontal) { - x += marginHorizontal - (leftSideInfoWindow - mapLeft); - tipViewMarginLeft -= (marginHorizontal - (leftSideInfoWindow - mapLeft)) - tipViewOffset; - } - } - - // Adjust tipView - InfoWindowView infoWindowView = (InfoWindowView) view; - infoWindowView.setTipViewMarginLeft((int) tipViewMarginLeft); - } - - // set anchor popupwindowview - view.setX(x); - view.setY(y); - - // Calculate x-offset for update method - mViewWidthOffset = x - mCoordinates.x - offsetX; - - close(); //if it was already opened - mapView.addView(view, lp); - mIsVisible = true; - } - return this; + close(); //if it was already opened + mapView.addView(view, lp); + isVisible = true; } - - /** - * Close this {@link InfoWindow} if it is visible, otherwise calling this will do nothing. - * - * @return This {@link InfoWindow} - */ - InfoWindow close() { - MapboxMap mapboxMap = mMapboxMap.get(); - if (mIsVisible && mapboxMap != null) { - mIsVisible = false; - View view = mView.get(); - if (view != null && view.getParent() != null) { - ((ViewGroup) view.getParent()).removeView(view); - } - - Marker marker = getBoundMarker(); - MapboxMap.OnInfoWindowCloseListener listener = mapboxMap.getOnInfoWindowCloseListener(); - if (listener != null) { - listener.onInfoWindowClose(marker); - } - - setBoundMarker(null); - } - return this; + return this; + } + + /** + * Close this {@link InfoWindow} if it is visible, otherwise calling this will do nothing. + * + * @return This {@link InfoWindow} + */ + InfoWindow close() { + MapboxMap mapboxMap = this.mapboxMap.get(); + if (isVisible && mapboxMap != null) { + isVisible = false; + View view = this.view.get(); + if (view != null && view.getParent() != null) { + ((ViewGroup) view.getParent()).removeView(view); + } + + Marker marker = getBoundMarker(); + MapboxMap.OnInfoWindowCloseListener listener = mapboxMap.getOnInfoWindowCloseListener(); + if (listener != null) { + listener.onInfoWindowClose(marker); + } + + setBoundMarker(null); } - - /** - * Constructs the view that is displayed when the InfoWindow opens. This retrieves data from - * overlayItem and shows it in the tooltip. - * - * @param overlayItem the tapped overlay item - */ - void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) { - View view = mView.get(); - if (view == null) { - view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false); - initialize(view, mapboxMap); - } - mMapboxMap = new WeakReference<>(mapboxMap); - String title = overlayItem.getTitle(); - TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title)); - if (!TextUtils.isEmpty(title)) { - titleTextView.setText(title); - titleTextView.setVisibility(View.VISIBLE); - } else { - titleTextView.setVisibility(View.GONE); - } - - String snippet = overlayItem.getSnippet(); - TextView snippetTextView = ((TextView) view.findViewById(R.id.infowindow_description)); - if (!TextUtils.isEmpty(snippet)) { - snippetTextView.setText(snippet); - snippetTextView.setVisibility(View.VISIBLE); - } else { - snippetTextView.setVisibility(View.GONE); - } + return this; + } + + /** + * Constructs the view that is displayed when the InfoWindow opens. This retrieves data from + * overlayItem and shows it in the tooltip. + * + * @param overlayItem the tapped overlay item + */ + void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) { + View view = this.view.get(); + if (view == null) { + view = LayoutInflater.from(mapView.getContext()).inflate(layoutRes, mapView, false); + initialize(view, mapboxMap); } - - InfoWindow setBoundMarker(Marker boundMarker) { - mBoundMarker = new WeakReference<>(boundMarker); - return this; + this.mapboxMap = new WeakReference<>(mapboxMap); + String title = overlayItem.getTitle(); + TextView titleTextView = ((TextView) view.findViewById(R.id.infowindow_title)); + if (!TextUtils.isEmpty(title)) { + titleTextView.setText(title); + titleTextView.setVisibility(View.VISIBLE); + } else { + titleTextView.setVisibility(View.GONE); } - Marker getBoundMarker() { - if (mBoundMarker == null) { - return null; - } - return mBoundMarker.get(); + String snippet = overlayItem.getSnippet(); + TextView snippetTextView = ((TextView) view.findViewById(R.id.infowindow_description)); + if (!TextUtils.isEmpty(snippet)) { + snippetTextView.setText(snippet); + snippetTextView.setVisibility(View.VISIBLE); + } else { + snippetTextView.setVisibility(View.GONE); } + } - /** - * Will result in getting this {@link InfoWindow} and updating the view being displayed. - */ - public void update() { - MapboxMap mapboxMap = mMapboxMap.get(); - Marker marker = mBoundMarker.get(); - View view = mView.get(); - if (mapboxMap != null && marker != null && view != null) { - mCoordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - - if (view instanceof InfoWindowView) { - view.setX(mCoordinates.x + mViewWidthOffset - mMarkerWidthOffset); - } else { - view.setX(mCoordinates.x - (view.getMeasuredWidth() / 2) - mMarkerWidthOffset); - } - view.setY(mCoordinates.y + mMarkerHeightOffset); - } - } + InfoWindow setBoundMarker(Marker boundMarker) { + this.boundMarker = new WeakReference<>(boundMarker); + return this; + } - /** - * Retrieve this {@link InfoWindow}'s current view being used. - * - * @return This {@link InfoWindow}'s current View. - */ - public View getView() { - return mView != null ? mView.get() : null; + Marker getBoundMarker() { + if (boundMarker == null) { + return null; } - - boolean isVisible() { - return mIsVisible; + return boundMarker.get(); + } + + /** + * Will result in getting this {@link InfoWindow} and updating the view being displayed. + */ + public void update() { + MapboxMap mapboxMap = this.mapboxMap.get(); + Marker marker = boundMarker.get(); + View view = this.view.get(); + if (mapboxMap != null && marker != null && view != null) { + coordinates = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); + + if (view instanceof InfoWindowView) { + view.setX(coordinates.x + viewWidthOffset - markerWidthOffset); + } else { + view.setX(coordinates.x - (view.getMeasuredWidth() / 2) - markerWidthOffset); + } + view.setY(coordinates.y + markerHeightOffset); } + } + + /** + * Retrieve this {@link InfoWindow}'s current view being used. + * + * @return This {@link InfoWindow}'s current View. + */ + public View getView() { + return view != null ? view.get() : null; + } + + boolean isVisible() { + return isVisible; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowTipView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowTipView.java index 41c7fc9e97..abcebfec83 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowTipView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowTipView.java @@ -12,51 +12,51 @@ import com.mapbox.mapboxsdk.R; final class InfoWindowTipView extends View { - private Paint mPaint; - private Path mPath; - private int mLineWidth; - - public InfoWindowTipView(Context context, AttributeSet attrs) { - super(context, attrs); - - mPath = new Path(); - mLineWidth = (int) context.getResources().getDimension(R.dimen.mapbox_infowindow_line_width); - mPaint = new Paint(); - mPaint.setColor(Color.WHITE); - mPaint.setAntiAlias(true); - mPaint.setStrokeWidth(0.0f); - mPaint.setStyle(Paint.Style.FILL); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - int height = getMeasuredHeight(); - int width = getMeasuredWidth(); - - mPath.rewind(); - - this.mPaint.setColor(Color.WHITE); - this.mPaint.setAntiAlias(true); - this.mPaint.setStrokeWidth(0.0f); - this.mPaint.setStyle(Paint.Style.FILL); - - mPath.moveTo(0, 0); - mPath.lineTo(width, 0); - mPath.lineTo((width / 2), height); - mPath.lineTo(0, 0); - canvas.drawPath(mPath, this.mPaint); - - mPath.rewind(); - - this.mPaint.setColor(Color.parseColor("#C2C2C2")); - this.mPaint.setAntiAlias(true); - this.mPaint.setStrokeWidth(mLineWidth); - this.mPaint.setStyle(Paint.Style.STROKE); - - mPath.moveTo(0, 0); - mPath.lineTo(width / 2, height); - mPath.lineTo(width, 0); - canvas.drawPath(mPath, this.mPaint); - } + private Paint mPaint; + private Path mPath; + private int mLineWidth; + + public InfoWindowTipView(Context context, AttributeSet attrs) { + super(context, attrs); + + mPath = new Path(); + mLineWidth = (int) context.getResources().getDimension(R.dimen.mapbox_infowindow_line_width); + mPaint = new Paint(); + mPaint.setColor(Color.WHITE); + mPaint.setAntiAlias(true); + mPaint.setStrokeWidth(0.0f); + mPaint.setStyle(Paint.Style.FILL); + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + int height = getMeasuredHeight(); + int width = getMeasuredWidth(); + + mPath.rewind(); + + this.mPaint.setColor(Color.WHITE); + this.mPaint.setAntiAlias(true); + this.mPaint.setStrokeWidth(0.0f); + this.mPaint.setStyle(Paint.Style.FILL); + + mPath.moveTo(0, 0); + mPath.lineTo(width, 0); + mPath.lineTo((width / 2), height); + mPath.lineTo(0, 0); + canvas.drawPath(mPath, this.mPaint); + + mPath.rewind(); + + this.mPaint.setColor(Color.parseColor("#C2C2C2")); + this.mPaint.setAntiAlias(true); + this.mPaint.setStrokeWidth(mLineWidth); + this.mPaint.setStyle(Paint.Style.STROKE); + + mPath.moveTo(0, 0); + mPath.lineTo(width / 2, height); + mPath.lineTo(width, 0); + canvas.drawPath(mPath, this.mPaint); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowView.java index 7595073aa2..d1a59aae4e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/InfoWindowView.java @@ -9,30 +9,30 @@ import com.mapbox.mapboxsdk.R; class InfoWindowView extends RelativeLayout { - private InfoWindowTipView mTipView; - - public InfoWindowView(Context context) { - this(context, null); - } - - public InfoWindowView(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public InfoWindowView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initialize(context); - } - - private void initialize(Context context) { - LayoutInflater.from(context).inflate(R.layout.mapbox_infowindow_content, this); - mTipView = (InfoWindowTipView) findViewById(R.id.infowindow_tipview); - } - - void setTipViewMarginLeft(int marginLeft) { - RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mTipView.getLayoutParams(); - layoutParams.leftMargin = marginLeft; - // This is a bit of a hack but prevents an occasional gap between the InfoWindow - layoutParams.topMargin = (int) getResources().getDimension(R.dimen.mapbox_infowindow_offset); - } + private InfoWindowTipView mTipView; + + public InfoWindowView(Context context) { + this(context, null); + } + + public InfoWindowView(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public InfoWindowView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + initialize(context); + } + + private void initialize(Context context) { + LayoutInflater.from(context).inflate(R.layout.mapbox_infowindow_content, this); + mTipView = (InfoWindowTipView) findViewById(R.id.infowindow_tipview); + } + + void setTipViewMarginLeft(int marginLeft) { + RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mTipView.getLayoutParams(); + layoutParams.leftMargin = marginLeft; + // This is a bit of a hack but prevents an occasional gap between the InfoWindow + layoutParams.topMargin = (int) getResources().getDimension(R.dimen.mapbox_infowindow_offset); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java index c4d1090194..edf118205b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Marker.java @@ -27,249 +27,249 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; */ public class Marker extends Annotation { - private LatLng position; - private String snippet; - private Icon icon; - private String title; + private LatLng position; + private String snippet; + private Icon icon; + private String title; - private InfoWindow infoWindow; - private boolean infoWindowShown; + private InfoWindow infoWindow; + private boolean infoWindowShown; - private int topOffsetPixels; - private int rightOffsetPixels; + private int topOffsetPixels; + private int rightOffsetPixels; - /** - * Constructor - */ - Marker() { - super(); - } + /** + * Constructor + */ + Marker() { + super(); + } - /** - * Creates a instance of {@link Marker} using the builder of Marker. - * - * @param baseMarkerOptions The builder used to construct the Marker. - */ - public Marker(BaseMarkerOptions baseMarkerOptions) { - position = baseMarkerOptions.position; - snippet = baseMarkerOptions.snippet; - icon = baseMarkerOptions.icon; - title = baseMarkerOptions.title; - } + /** + * Creates a instance of {@link Marker} using the builder of Marker. + * + * @param baseMarkerOptions The builder used to construct the Marker. + */ + public Marker(BaseMarkerOptions baseMarkerOptions) { + position = baseMarkerOptions.position; + snippet = baseMarkerOptions.snippet; + icon = baseMarkerOptions.icon; + title = baseMarkerOptions.title; + } - Marker(BaseMarkerViewOptions baseMarkerViewOptions) { - position = baseMarkerViewOptions.position; - snippet = baseMarkerViewOptions.snippet; - icon = baseMarkerViewOptions.icon; - title = baseMarkerViewOptions.title; - } + Marker(BaseMarkerViewOptions baseMarkerViewOptions) { + position = baseMarkerViewOptions.position; + snippet = baseMarkerViewOptions.snippet; + icon = baseMarkerViewOptions.icon; + title = baseMarkerViewOptions.title; + } - Marker(LatLng position, Icon icon, String title, String snippet) { - this.position = position; - this.icon = icon; - this.title = title; - this.snippet = snippet; - } + Marker(LatLng position, Icon icon, String title, String snippet) { + this.position = position; + this.icon = icon; + this.title = title; + this.snippet = snippet; + } - /** - * Returns the position of the marker. - * - * @return A {@link LatLng} object specifying the marker's current position. - */ - public LatLng getPosition() { - return position; - } + /** + * Returns the position of the marker. + * + * @return A {@link LatLng} object specifying the marker's current position. + */ + public LatLng getPosition() { + return position; + } - /** - * Gets the snippet of the marker. - * - * @return A string containing the marker's snippet. - */ - public String getSnippet() { - return snippet; - } + /** + * Gets the snippet of the marker. + * + * @return A string containing the marker's snippet. + */ + public String getSnippet() { + return snippet; + } - /** - * Gets the snippet of the marker. - * - * @return A string containing the marker's snippet. - */ - public String getTitle() { - return title; - } + /** + * Gets the snippet of the marker. + * + * @return A string containing the marker's snippet. + */ + public String getTitle() { + return title; + } - /** - * Do not use this method, used internally by the SDK. - */ - public void hideInfoWindow() { - if (infoWindow != null) { - infoWindow.close(); - } - infoWindowShown = false; + /** + * Do not use this method, used internally by the SDK. + */ + public void hideInfoWindow() { + if (infoWindow != null) { + infoWindow.close(); } + infoWindowShown = false; + } - /** - * Do not use this method, used internally by the SDK. - * - * @return true if the infoWindow is shown - */ - public boolean isInfoWindowShown() { - return infoWindowShown; - } + /** + * Do not use this method, used internally by the SDK. + * + * @return true if the infoWindow is shown + */ + public boolean isInfoWindowShown() { + return infoWindowShown; + } - /** - * Sets the location of the marker. - * - * @param position A {@link LatLng} defining the marker position. - */ - public void setPosition(LatLng position) { - this.position = position; - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } + /** + * Sets the location of the marker. + * + * @param position A {@link LatLng} defining the marker position. + */ + public void setPosition(LatLng position) { + this.position = position; + MapboxMap map = getMapboxMap(); + if (map != null) { + map.updateMarker(this); } + } - /** - * Sets the snippet of the marker. - * - * @param snippet A String used in the marker info window. If {@code null}, the snippet is - * cleared. - */ - public void setSnippet(String snippet) { - this.snippet = snippet; - refreshInfoWindowContent(); - } + /** + * Sets the snippet of the marker. + * + * @param snippet A String used in the marker info window. If {@code null}, the snippet is + * cleared. + */ + public void setSnippet(String snippet) { + this.snippet = snippet; + refreshInfoWindowContent(); + } - /** - * Sets the icon of the marker. - * - * @param icon The {@link Icon} to be used as Marker image - */ - public void setIcon(@Nullable Icon icon) { - this.icon = icon; - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } + /** + * Sets the icon of the marker. + * + * @param icon The {@link Icon} to be used as Marker image + */ + public void setIcon(@Nullable Icon icon) { + this.icon = icon; + MapboxMap map = getMapboxMap(); + if (map != null) { + map.updateMarker(this); } + } - /** - * Gets the {@link Icon} currently used for the marker. If no Icon was set for the marker, the - * default icon will be returned. - * - * @return The {@link Icon} the marker is using. - */ - public Icon getIcon() { - return icon; - } + /** + * Gets the {@link Icon} currently used for the marker. If no Icon was set for the marker, the + * default icon will be returned. + * + * @return The {@link Icon} the marker is using. + */ + public Icon getIcon() { + return icon; + } - /** - * Sets the title of the marker. - * - * @param title A String used in the marker info window. If {@code null}, the title is - * cleared. - */ - public void setTitle(String title) { - this.title = title; - refreshInfoWindowContent(); - } + /** + * Sets the title of the marker. + * + * @param title A String used in the marker info window. If {@code null}, the title is + * cleared. + */ + public void setTitle(String title) { + this.title = title; + refreshInfoWindowContent(); + } - /** - * Gets the {@link InfoWindow} the marker is using. If the marker hasn't had an info window - * defined, this will return {@code null}. - * - * @return - */ - @Nullable - public InfoWindow getInfoWindow() { - return infoWindow; - } + /** + * Gets the {@link InfoWindow} the marker is using. If the marker hasn't had an info window + * defined, this will return {@code null}. + * + * @return The info window the marker is using. + */ + @Nullable + public InfoWindow getInfoWindow() { + return infoWindow; + } - /** - * Update only for default Marker's InfoWindow content for Title and Snippet - */ - private void refreshInfoWindowContent() { - if (isInfoWindowShown() && mapView != null && mapboxMap != null && mapboxMap.getInfoWindowAdapter() == null) { - InfoWindow infoWindow = getInfoWindow(mapView); - if (mapView.getContext() != null) { - infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); - } - MapboxMap map = getMapboxMap(); - if (map != null) { - map.updateMarker(this); - } - infoWindow.update(); - } + /** + * Update only for default Marker's InfoWindow content for Title and Snippet + */ + private void refreshInfoWindowContent() { + if (isInfoWindowShown() && mapView != null && mapboxMap != null && mapboxMap.getInfoWindowAdapter() == null) { + InfoWindow infoWindow = getInfoWindow(mapView); + if (mapView.getContext() != null) { + infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); + } + MapboxMap map = getMapboxMap(); + if (map != null) { + map.updateMarker(this); + } + infoWindow.update(); } + } - /** - * Do not use this method, used internally by the SDK. Use {@link MapboxMap#selectMarker(Marker)} - * if you want to programmatically display the markers info window. - * - * @param mapboxMap The hosting mapbox map. - * @param mapView The hosting map view. - * @return The info window that was shown. - */ - public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) { - setMapboxMap(mapboxMap); - setMapView(mapView); - MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter(); - if (infoWindowAdapter != null) { - // end developer is using a custom InfoWindowAdapter - View content = infoWindowAdapter.getInfoWindow(this); - if (content != null) { - infoWindow = new InfoWindow(content, mapboxMap); - showInfoWindow(infoWindow, mapView); - return infoWindow; - } - } - - InfoWindow infoWindow = getInfoWindow(mapView); - if (mapView.getContext() != null) { - infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); - } - return showInfoWindow(infoWindow, mapView); + /** + * Do not use this method, used internally by the SDK. Use {@link MapboxMap#selectMarker(Marker)} + * if you want to programmatically display the markers info window. + * + * @param mapboxMap The hosting mapbox map. + * @param mapView The hosting map view. + * @return The info window that was shown. + */ + public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) { + setMapboxMap(mapboxMap); + setMapView(mapView); + MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter(); + if (infoWindowAdapter != null) { + // end developer is using a custom InfoWindowAdapter + View content = infoWindowAdapter.getInfoWindow(this); + if (content != null) { + infoWindow = new InfoWindow(content, mapboxMap); + showInfoWindow(infoWindow, mapView); + return infoWindow; + } } - private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) { - iw.open(mapView, this, getPosition(), rightOffsetPixels, topOffsetPixels); - infoWindowShown = true; - return iw; + InfoWindow infoWindow = getInfoWindow(mapView); + if (mapView.getContext() != null) { + infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); } + return showInfoWindow(infoWindow, mapView); + } - private InfoWindow getInfoWindow(@NonNull MapView mapView) { - if (infoWindow == null && mapView.getContext() != null) { - infoWindow = new InfoWindow(mapView, R.layout.mapbox_infowindow_view, getMapboxMap()); - } - return infoWindow; - } + private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) { + iw.open(mapView, this, getPosition(), rightOffsetPixels, topOffsetPixels); + infoWindowShown = true; + return iw; + } - /** - * Do not use this method, used internally by the SDK. - * - * @param topOffsetPixels the top offset pixels. - */ - public void setTopOffsetPixels(int topOffsetPixels) { - this.topOffsetPixels = topOffsetPixels; + private InfoWindow getInfoWindow(@NonNull MapView mapView) { + if (infoWindow == null && mapView.getContext() != null) { + infoWindow = new InfoWindow(mapView, R.layout.mapbox_infowindow_view, getMapboxMap()); } + return infoWindow; + } - /** - * Do not use this method, used internally by the SDK. - * - * @param rightOffsetPixels the right offset pixels. - */ - public void setRightOffsetPixels(int rightOffsetPixels) { - this.rightOffsetPixels = rightOffsetPixels; - } + /** + * Do not use this method, used internally by the SDK. + * + * @param topOffsetPixels the top offset pixels. + */ + public void setTopOffsetPixels(int topOffsetPixels) { + this.topOffsetPixels = topOffsetPixels; + } - /** - * Returns a String with the marker position. - * - * @return A String with the marker position. - */ - @Override - public String toString() { - return "Marker [position[" + getPosition() + "]]"; - } + /** + * Do not use this method, used internally by the SDK. + * + * @param rightOffsetPixels the right offset pixels. + */ + public void setRightOffsetPixels(int rightOffsetPixels) { + this.rightOffsetPixels = rightOffsetPixels; + } + + /** + * Returns a String with the marker position. + * + * @return A String with the marker position. + */ + @Override + public String toString() { + return "Marker [position[" + getPosition() + "]]"; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java index 282da6407e..49d4867801 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerOptions.java @@ -21,161 +21,168 @@ import com.mapbox.mapboxsdk.geometry.LatLng; */ public final class MarkerOptions extends BaseMarkerOptions<Marker, MarkerOptions> implements Parcelable { - /** - * Defines options for a Marker. - */ - public MarkerOptions() { + /** + * Defines options for a Marker. + */ + public MarkerOptions() { + } + + protected MarkerOptions(Parcel in) { + position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); + snippet(in.readString()); + title(in.readString()); + if (in.readByte() != 0) { + // this means we have an icon + String iconId = in.readString(); + Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); + Icon icon = new Icon(iconId, iconBitmap); + icon(icon); } - - protected MarkerOptions(Parcel in) { - position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); - snippet(in.readString()); - title(in.readString()); - if (in.readByte() != 0) { - // this means we have an icon - String iconId = in.readString(); - Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); - Icon icon = new Icon(iconId, iconBitmap); - icon(icon); - } + } + + @Override + public MarkerOptions getThis() { + return this; + } + + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + * + * @return integer 0. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Flatten this object in to a Parcel. + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. May be 0 or + * {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(getPosition(), flags); + out.writeString(getSnippet()); + out.writeString(getTitle()); + Icon icon = getIcon(); + out.writeByte((byte) (icon != null ? 1 : 0)); + if (icon != null) { + out.writeString(getIcon().getId()); + out.writeParcelable(getIcon().getBitmap(), flags); } - - @Override - public MarkerOptions getThis() { - return this; + } + + /** + * Do not use this method. Used internally by the SDK. + * + * @return Marker The build marker + */ + public Marker getMarker() { + if (position == null) { + throw new InvalidMarkerPositionException(); } - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } + return new Marker(position, icon, title, snippet); + } + + /** + * Returns the position set for this {@link MarkerOptions} object. + * + * @return A {@link LatLng} object specifying the marker's current position. + */ + public LatLng getPosition() { + return position; + } + + /** + * Gets the snippet set for this {@link MarkerOptions} object. + * + * @return A string containing the marker's snippet. + */ + public String getSnippet() { + return snippet; + } + + /** + * Gets the title set for this {@link MarkerOptions} object. + * + * @return A string containing the marker's title. + */ + public String getTitle() { + return title; + } + + /** + * Gets the custom icon set for this {@link MarkerOptions} object. + * + * @return A {@link Icon} object that the marker is using. If the icon wasn't set, default icon + * will return. + */ + public Icon getIcon() { + return icon; + } + + public static final Parcelable.Creator<MarkerOptions> CREATOR = + new Parcelable.Creator<MarkerOptions>() { + public MarkerOptions createFromParcel(Parcel in) { + return new MarkerOptions(in); + } + + public MarkerOptions[] newArray(int size) { + return new MarkerOptions[size]; + } + }; - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(getPosition(), flags); - out.writeString(getSnippet()); - out.writeString(getTitle()); - Icon icon = getIcon(); - out.writeByte((byte) (icon != null ? 1 : 0)); - if (icon != null) { - out.writeString(getIcon().getId()); - out.writeParcelable(getIcon().getBitmap(), flags); - } + /** + * Compares this {@link MarkerOptions} object with another {@link MarkerOptions} and + * determines if their properties match. + * + * @param o Another {@link MarkerOptions} to compare with this object. + * @return True if marker properties match this {@link MarkerOptions} object. + * Else, false. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return Marker The build marker - */ - public Marker getMarker() { - if (position == null) { - throw new InvalidMarkerPositionException(); - } - - return new Marker(position, icon, title, snippet); + if (o == null || getClass() != o.getClass()) { + return false; } - /** - * Returns the position set for this {@link MarkerOptions} object. - * - * @return A {@link LatLng} object specifying the marker's current position. - */ - public LatLng getPosition() { - return position; - } + MarkerOptions marker = (MarkerOptions) o; - /** - * Gets the snippet set for this {@link MarkerOptions} object. - * - * @return A string containing the marker's snippet. - */ - public String getSnippet() { - return snippet; + if (getPosition() != null ? !getPosition().equals(marker.getPosition()) : marker.getPosition() != null) { + return false; } - - /** - * Gets the title set for this {@link MarkerOptions} object. - * - * @return A string containing the marker's title. - */ - public String getTitle() { - return title; + if (getSnippet() != null ? !getSnippet().equals(marker.getSnippet()) : marker.getSnippet() != null) { + return false; } - - /** - * Gets the custom icon set for this {@link MarkerOptions} object. - * - * @return A {@link Icon} object that the marker is using. If the icon wasn't set, default icon - * will return. - */ - public Icon getIcon() { - return icon; - } - - public static final Parcelable.Creator<MarkerOptions> CREATOR - = new Parcelable.Creator<MarkerOptions>() { - public MarkerOptions createFromParcel(Parcel in) { - return new MarkerOptions(in); - } - - public MarkerOptions[] newArray(int size) { - return new MarkerOptions[size]; - } - }; - - /** - * Compares this {@link MarkerOptions} object with another {@link MarkerOptions} and - * determines if their properties match. - * - * @param o Another {@link MarkerOptions} to compare with this object. - * @return True if marker properties match this {@link MarkerOptions} object. - * Else, false. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - MarkerOptions marker = (MarkerOptions) o; - - if (getPosition() != null ? !getPosition().equals(marker.getPosition()) : marker.getPosition() != null) - return false; - if (getSnippet() != null ? !getSnippet().equals(marker.getSnippet()) : marker.getSnippet() != null) - return false; - if (getIcon() != null ? !getIcon().equals(marker.getIcon()) : marker.getIcon() != null) - return false; - return !(getTitle() != null ? !getTitle().equals(marker.getTitle()) : marker.getTitle() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getPosition() != null ? getPosition().hashCode() : 0); - result = 31 * result + (getSnippet() != null ? getSnippet().hashCode() : 0); - result = 31 * result + (getIcon() != null ? getIcon().hashCode() : 0); - result = 31 * result + (getTitle() != null ? getTitle().hashCode() : 0); - return result; + if (getIcon() != null ? !getIcon().equals(marker.getIcon()) : marker.getIcon() != null) { + return false; } + return !(getTitle() != null ? !getTitle().equals(marker.getTitle()) : marker.getTitle() != null); + } + + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getPosition() != null ? getPosition().hashCode() : 0); + result = 31 * result + (getSnippet() != null ? getSnippet().hashCode() : 0); + result = 31 * result + (getIcon() != null ? getIcon().hashCode() : 0); + result = 31 * result + (getTitle() != null ? getTitle().hashCode() : 0); + return result; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java index a32186b52e..c1b643eb4c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java @@ -26,382 +26,384 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; */ public class MarkerView extends Marker { - private MarkerViewManager markerViewManager; - - private float width; - private float height; - - private float anchorU; - private float anchorV; - - private float offsetX = MapboxConstants.UNMEASURED; - private float offsetY = MapboxConstants.UNMEASURED; - - private float infoWindowAnchorU; - private float infoWindowAnchorV; - - private boolean flat; - private boolean visible = true; - - private float tiltValue; - private float rotation; - private float alpha = 1; - - private Icon markerViewIcon; - - private boolean selected; - - - /** - * Publicly hidden default constructor - */ - MarkerView() { - } - - /** - * Creates a instance of MarkerView using the builder of MarkerView - * - * @param baseMarkerViewOptions the builder used to construct the MarkerView - */ - public MarkerView(BaseMarkerViewOptions baseMarkerViewOptions) { - super(baseMarkerViewOptions); - this.alpha = baseMarkerViewOptions.getAlpha(); - this.anchorU = baseMarkerViewOptions.getAnchorU(); - this.anchorV = baseMarkerViewOptions.getAnchorV(); - this.infoWindowAnchorU = baseMarkerViewOptions.getInfoWindowAnchorU(); - this.infoWindowAnchorV = baseMarkerViewOptions.getInfoWindowAnchorV(); - this.flat = baseMarkerViewOptions.isFlat(); - this.rotation = baseMarkerViewOptions.getRotation(); - this.selected = baseMarkerViewOptions.selected; - } - - float getWidth() { - return width; - } - - void setWidth(float width) { - this.width = width; - } - - float getHeight() { - return height; - } - - void setHeight(float height) { - this.height = height; - } - - /** - * Specifies the anchor being set on a particular point of the MarkerView. - * <p> - * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) - * is the top-left corner of the image, and (1, 1) is the bottom-right corner. - * </p> - * - * @param u u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1]). - * @param v v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1]). - */ - public void setAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { - this.anchorU = u; - this.anchorV = v; - setOffset(-1, -1); - } - - /** - * Get the horizontal distance, normalized to [0, 1], of the anchor from the left edge. - * - * @return The u-value of the anchor. - */ - public float getAnchorU() { - return anchorU; - } - - /** - * Get the vertical distance, normalized to [0, 1], of the anchor from the top edge. - * - * @return the v-value of the anchor. - */ - public float getAnchorV() { - return anchorV; - } - - /** - * Internal method to set the calculated offset. - * <p> - * These are calculated based on the View bounds and the provided anchor. - * </p> - * - * @param x the x-value of the offset. - * @param y the y-value of the offset. - */ - void setOffset(float x, float y) { - offsetX = x; - offsetY = y; - } - - /** - * Internal method to get the horizontal calculated offset. - * - * @return the calculated horizontal offset. - */ - float getOffsetX() { - return offsetX; - } - - /** - * Internal method to get the vertical calculated offset. - * - * @return the calculated vertical offset. - */ - float getOffsetY() { - return offsetY; - } - - /** - * Specifies the anchor point of the info window on the View of the MarkerView. - * <p> - * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) - * is the top-left corner of the image, and (1, 1) is the bottom-right corner. - * </p> - * <p> - * The default is the top middle of the View. - * </p> - * - * @param u u-coordinate of the info window anchor, as a ratio of the image width (in the range [0, 1]). - * @param v v-coordinate of the info window anchor, as a ratio of the image height (in the range [0, 1]). - * @see #setAnchor(float, float) for more details. - */ - public void setInfoWindowAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { - this.infoWindowAnchorU = u; - this.infoWindowAnchorV = v; - } - - /** - * Get the horizontal distance, normalized to [0, 1], of the info window anchor from the left edge. - * - * @return the u value of the InfoWindow anchor. - */ - public float getInfoWindowAnchorU() { - return infoWindowAnchorU; - } - - /** - * Get the vertical distance, normalized to [0, 1], of the info window anchor from the top edge. - * - * @return the v value of the InfoWindow anchor. - */ - public float getInfoWindowAnchorV() { - return infoWindowAnchorV; - } - - /** - * Get the flat state of a MarkerView. - * - * @return true if the MarkerView is flat; false if the MarkerView is billboard. - */ - public boolean isFlat() { - return flat; - } - - /** - * Sets whether this MarkerView should be flat against the map (true) or a billboard facing the - * camera (false). - * - * @param flat the flat state of the MarkerView. - */ - public void setFlat(boolean flat) { - this.flat = flat; - } - - /** - * Internal method to get the current tilted value of a MarkerView. - * - * @return the tilted value. - */ - float getTilt() { - return tiltValue; - } - - /** - * Internal method to set the current titled value of a MarkerView. - * - * @param tiltValue the tilted value to set. - */ - void setTilt(@FloatRange(from = 0.0, to = MapboxConstants.MAXIMUM_TILT) float tiltValue) { - this.tiltValue = tiltValue; - } - - /** - * Set the visible state of a MarkerView. - * - * @param visible true will make the MarkerView visible, false will hide the MarkerView. - */ - public void setVisible(boolean visible) { - this.visible = visible; - if (markerViewManager != null) { - markerViewManager.animateVisible(this, visible); - } - } - - /** - * Returns the visible state of the MarkerView. - * - * @return the visible state. - */ - public boolean isVisible() { - return visible; - } - - /** - * Set the rotation value of the MarkerView in degrees. - * <p> - * Input will be limited to 0 - 360 degrees. - * </p> - * <p> - * This will result in animating the rotation of the MarkerView using an rotation animator - * from current value to the provided parameter value. - * </p> - * - * @param rotation the rotation value to animate to. - */ - public void setRotation(float rotation) { - // limit to 0 - 360 degrees - float newRotation = rotation; - while (newRotation > 360) { - newRotation -= 360; - } - while (newRotation < 0) { - newRotation += 360; - } - - this.rotation = newRotation; - if (markerViewManager != null) { - markerViewManager.animateRotationBy(this, newRotation); - } - } - - /** - * Get the rotation value of the MarkerView. - * - * @return the rotation value. - */ - public float getRotation() { - return rotation; - } - - /** - * Get the alpha value of the MarkerView. - * - * @return the alpha value. - */ - public float getAlpha() { - return alpha; - } - - /** - * Set the alpha value of the MarkerView. - * <p> - * This will result in animating the alpha of the MarkerView using an alpha animator - * from current value to the provided parameter value. - * </p> - * - * @param alpha the alpha value to animate to. - */ - public void setAlpha(@FloatRange(from = 0.0, to = 255.0) float alpha) { - this.alpha = alpha; - if (markerViewManager != null) { - markerViewManager.animateAlpha(this, alpha); - } - } - - /** - * Set the icon of the MarkerView. - * - * @param icon the {@link Icon} to be used as Marker image. - */ - @Override - public void setIcon(@Nullable Icon icon) { - if (icon != null) { - markerViewIcon = IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, icon.getBitmap()); - } - Icon transparentIcon = IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, - IconFactory.ICON_MARKERVIEW_BITMAP); - if (markerViewManager != null) { - markerViewManager.updateIcon(this); - } - super.setIcon(transparentIcon); - } - - /** - * Sets the location of the marker. - * - * @param position A {@link LatLng} defining the marker position. - */ - @Override - public void setPosition(LatLng position) { - super.setPosition(position); - if (markerViewManager != null) { - markerViewManager.update(); - } - } - - /** - * Determine if the {@link MarkerView} is selected or not. - * - * @return True if the MarkerView's selected, else false. - */ - public boolean isSelected() { - return selected; - } - - /** - * For internal use only, use {@link MapboxMap#selectMarker(Marker)} instead. - */ - void setSelected(boolean selected) { - this.selected = selected; - } - - /** - * Get the icon of the MarkerView. - * - * @return the icon use as Marker image. - */ - @Override - public Icon getIcon() { - return markerViewIcon; - } - - /** - * Set the MapboxMap associated tot the MapView containing the MarkerView. - * <p> - * This method is used to instantiate the MarkerView and provide an instance of {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter} - * </p> - * <p> - * This method is used to notify that a MarkerView is no longer active by setting a null value. - * </p> - * - * @param mapboxMap the MapboxMap instances. - */ - @Override - public void setMapboxMap(MapboxMap mapboxMap) { - super.setMapboxMap(mapboxMap); - if (mapboxMap != null) { - if (isFlat()) { - // initial tilt value if MapboxMap is started with a tilt attribute - tiltValue = (float) mapboxMap.getCameraPosition().tilt; - } - - markerViewManager = mapboxMap.getMarkerViewManager(); - } - } - - /** - * Get the String representation of a MarkerView. - * - * @return the String representation. - */ - @Override - public String toString() { - return "MarkerView [position[" + getPosition() + "]]"; - } + private MarkerViewManager markerViewManager; + + private float width; + private float height; + + private float anchorU; + private float anchorV; + + private float offsetX = MapboxConstants.UNMEASURED; + private float offsetY = MapboxConstants.UNMEASURED; + + private float infoWindowAnchorU; + private float infoWindowAnchorV; + + private boolean flat; + private boolean visible = true; + + private float tiltValue; + private float rotation; + private float alpha = 1; + + private Icon markerViewIcon; + + private boolean selected; + + + /** + * Publicly hidden default constructor + */ + MarkerView() { + } + + /** + * Creates a instance of MarkerView using the builder of MarkerView + * + * @param baseMarkerViewOptions the builder used to construct the MarkerView + */ + public MarkerView(BaseMarkerViewOptions baseMarkerViewOptions) { + super(baseMarkerViewOptions); + this.alpha = baseMarkerViewOptions.getAlpha(); + this.anchorU = baseMarkerViewOptions.getAnchorU(); + this.anchorV = baseMarkerViewOptions.getAnchorV(); + this.infoWindowAnchorU = baseMarkerViewOptions.getInfoWindowAnchorU(); + this.infoWindowAnchorV = baseMarkerViewOptions.getInfoWindowAnchorV(); + this.flat = baseMarkerViewOptions.isFlat(); + this.rotation = baseMarkerViewOptions.getRotation(); + this.selected = baseMarkerViewOptions.selected; + } + + float getWidth() { + return width; + } + + void setWidth(float width) { + this.width = width; + } + + float getHeight() { + return height; + } + + void setHeight(float height) { + this.height = height; + } + + /** + * Specifies the anchor being set on a particular point of the MarkerView. + * <p> + * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) + * is the top-left corner of the image, and (1, 1) is the bottom-right corner. + * </p> + * + * @param u u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1]). + * @param v v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1]). + */ + public void setAnchor(@FloatRange(from = 0.0, to = 1.0) float u, @FloatRange(from = 0.0, to = 1.0) float v) { + this.anchorU = u; + this.anchorV = v; + setOffset(-1, -1); + } + + /** + * Get the horizontal distance, normalized to [0, 1], of the anchor from the left edge. + * + * @return The u-value of the anchor. + */ + public float getAnchorU() { + return anchorU; + } + + /** + * Get the vertical distance, normalized to [0, 1], of the anchor from the top edge. + * + * @return the v-value of the anchor. + */ + public float getAnchorV() { + return anchorV; + } + + /** + * Internal method to set the calculated offset. + * <p> + * These are calculated based on the View bounds and the provided anchor. + * </p> + * + * @param x the x-value of the offset. + * @param y the y-value of the offset. + */ + void setOffset(float x, float y) { + offsetX = x; + offsetY = y; + } + + /** + * Internal method to get the horizontal calculated offset. + * + * @return the calculated horizontal offset. + */ + float getOffsetX() { + return offsetX; + } + + /** + * Internal method to get the vertical calculated offset. + * + * @return the calculated vertical offset. + */ + float getOffsetY() { + return offsetY; + } + + /** + * Specifies the anchor point of the info window on the View of the MarkerView. + * <p> + * The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) + * is the top-left corner of the image, and (1, 1) is the bottom-right corner. + * </p> + * <p> + * The default is the top middle of the View. + * </p> + * + * @param u u-coordinate of the info window anchor, as a ratio of the image width (in the range [0, 1]). + * @param v v-coordinate of the info window anchor, as a ratio of the image height (in the range [0, 1]). + * @see #setAnchor(float, float) for more details. + */ + public void setInfoWindowAnchor(@FloatRange(from = 0.0, to = 1.0) float u, + @FloatRange(from = 0.0, to = 1.0) float v) { + this.infoWindowAnchorU = u; + this.infoWindowAnchorV = v; + } + + /** + * Get the horizontal distance, normalized to [0, 1], of the info window anchor from the left edge. + * + * @return the u value of the InfoWindow anchor. + */ + public float getInfoWindowAnchorU() { + return infoWindowAnchorU; + } + + /** + * Get the vertical distance, normalized to [0, 1], of the info window anchor from the top edge. + * + * @return the v value of the InfoWindow anchor. + */ + public float getInfoWindowAnchorV() { + return infoWindowAnchorV; + } + + /** + * Get the flat state of a MarkerView. + * + * @return true if the MarkerView is flat; false if the MarkerView is billboard. + */ + public boolean isFlat() { + return flat; + } + + /** + * Sets whether this MarkerView should be flat against the map (true) or a billboard facing the + * camera (false). + * + * @param flat the flat state of the MarkerView. + */ + public void setFlat(boolean flat) { + this.flat = flat; + } + + /** + * Internal method to get the current tilted value of a MarkerView. + * + * @return the tilted value. + */ + float getTilt() { + return tiltValue; + } + + /** + * Internal method to set the current titled value of a MarkerView. + * + * @param tiltValue the tilted value to set. + */ + void setTilt(@FloatRange(from = 0.0, to = MapboxConstants.MAXIMUM_TILT) float tiltValue) { + this.tiltValue = tiltValue; + } + + /** + * Set the visible state of a MarkerView. + * + * @param visible true will make the MarkerView visible, false will hide the MarkerView. + */ + public void setVisible(boolean visible) { + this.visible = visible; + if (markerViewManager != null) { + markerViewManager.animateVisible(this, visible); + } + } + + /** + * Returns the visible state of the MarkerView. + * + * @return the visible state. + */ + public boolean isVisible() { + return visible; + } + + /** + * Set the rotation value of the MarkerView in degrees. + * <p> + * Input will be limited to 0 - 360 degrees. + * </p> + * <p> + * This will result in animating the rotation of the MarkerView using an rotation animator + * from current value to the provided parameter value. + * </p> + * + * @param rotation the rotation value to animate to. + */ + public void setRotation(float rotation) { + // limit to 0 - 360 degrees + float newRotation = rotation; + while (newRotation > 360) { + newRotation -= 360; + } + while (newRotation < 0) { + newRotation += 360; + } + + this.rotation = newRotation; + if (markerViewManager != null) { + markerViewManager.animateRotationBy(this, newRotation); + } + } + + /** + * Get the rotation value of the MarkerView. + * + * @return the rotation value. + */ + public float getRotation() { + return rotation; + } + + /** + * Get the alpha value of the MarkerView. + * + * @return the alpha value. + */ + public float getAlpha() { + return alpha; + } + + /** + * Set the alpha value of the MarkerView. + * <p> + * This will result in animating the alpha of the MarkerView using an alpha animator + * from current value to the provided parameter value. + * </p> + * + * @param alpha the alpha value to animate to. + */ + public void setAlpha(@FloatRange(from = 0.0, to = 255.0) float alpha) { + this.alpha = alpha; + if (markerViewManager != null) { + markerViewManager.animateAlpha(this, alpha); + } + } + + /** + * Set the icon of the MarkerView. + * + * @param icon the {@link Icon} to be used as Marker image. + */ + @Override + public void setIcon(@Nullable Icon icon) { + if (icon != null) { + markerViewIcon = IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, icon.getBitmap()); + } + Icon transparentIcon = IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, + IconFactory.ICON_MARKERVIEW_BITMAP); + if (markerViewManager != null) { + markerViewManager.updateIcon(this); + } + super.setIcon(transparentIcon); + } + + /** + * Sets the location of the marker. + * + * @param position A {@link LatLng} defining the marker position. + */ + @Override + public void setPosition(LatLng position) { + super.setPosition(position); + if (markerViewManager != null) { + markerViewManager.update(); + } + } + + /** + * Determine if the {@link MarkerView} is selected or not. + * + * @return True if the MarkerView's selected, else false. + */ + public boolean isSelected() { + return selected; + } + + /** + * For internal use only, use {@link MapboxMap#selectMarker(Marker)} instead. + */ + void setSelected(boolean selected) { + this.selected = selected; + } + + /** + * Get the icon of the MarkerView. + * + * @return the icon use as Marker image. + */ + @Override + public Icon getIcon() { + return markerViewIcon; + } + + /** + * Set the MapboxMap associated tot the MapView containing the MarkerView. + * <p> + * This method is used to instantiate the MarkerView and provide an instance of + * {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter} + * </p> + * <p> + * This method is used to notify that a MarkerView is no longer active by setting a null value. + * </p> + * + * @param mapboxMap the MapboxMap instances. + */ + @Override + public void setMapboxMap(MapboxMap mapboxMap) { + super.setMapboxMap(mapboxMap); + if (mapboxMap != null) { + if (isFlat()) { + // initial tilt value if MapboxMap is started with a tilt attribute + tiltValue = (float) mapboxMap.getCameraPosition().tilt; + } + + markerViewManager = mapboxMap.getMarkerViewManager(); + } + } + + /** + * Get the String representation of a MarkerView. + * + * @return the String representation. + */ + @Override + public String toString() { + return "MarkerView [position[" + getPosition() + "]]"; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java index 8989bb22d7..d953bfca0c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java @@ -32,609 +32,610 @@ import java.util.Map; */ public class MarkerViewManager implements MapView.OnMapChangedListener { - private final ViewGroup markerViewContainer; - private final Map<MarkerView, View> markerViewMap = new HashMap<>(); - private final LongSparseArray<OnMarkerViewAddedListener> markerViewAddedListenerMap = new LongSparseArray<>(); - private final List<MapboxMap.MarkerViewAdapter> markerViewAdapters = new ArrayList<>(); - - // TODO refactor MapboxMap out for Projection and Transform - // Requires removing MapboxMap from Annotations by using Peer model from #6912 - private MapboxMap mapboxMap; - - private long viewMarkerBoundsUpdateTime; - private MapboxMap.OnMarkerViewClickListener onMarkerViewClickListener; - private boolean isWaitingForRenderInvoke; - - /** - * Creates an instance of MarkerViewManager. - * - * @param container the ViewGroup associated with the MarkerViewManager - */ - public MarkerViewManager(@NonNull ViewGroup container) { - this.markerViewContainer = container; - this.markerViewAdapters.add(new ImageMarkerViewAdapter(container.getContext())); + private final ViewGroup markerViewContainer; + private final Map<MarkerView, View> markerViewMap = new HashMap<>(); + private final LongSparseArray<OnMarkerViewAddedListener> markerViewAddedListenerMap = new LongSparseArray<>(); + private final List<MapboxMap.MarkerViewAdapter> markerViewAdapters = new ArrayList<>(); + + // TODO refactor MapboxMap out for Projection and Transform + // Requires removing MapboxMap from Annotations by using Peer model from #6912 + private MapboxMap mapboxMap; + + private long viewMarkerBoundsUpdateTime; + private MapboxMap.OnMarkerViewClickListener onMarkerViewClickListener; + private boolean isWaitingForRenderInvoke; + + /** + * Creates an instance of MarkerViewManager. + * + * @param container the ViewGroup associated with the MarkerViewManager + */ + public MarkerViewManager(@NonNull ViewGroup container) { + this.markerViewContainer = container; + this.markerViewAdapters.add(new ImageMarkerViewAdapter(container.getContext())); + } + + // TODO refactor MapboxMap out for Projection and Transform + // Requires removing MapboxMap from Annotations by using Peer model from #6912 + public void bind(MapboxMap mapboxMap) { + this.mapboxMap = mapboxMap; + } + + + @Override + public void onMapChanged(@MapView.MapChange int change) { + if (isWaitingForRenderInvoke && change == MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) { + isWaitingForRenderInvoke = false; + invalidateViewMarkersInVisibleRegion(); } - - // TODO refactor MapboxMap out for Projection and Transform - // Requires removing MapboxMap from Annotations by using Peer model from #6912 - public void bind(MapboxMap mapboxMap) { - this.mapboxMap = mapboxMap; + } + + public void setWaitingForRenderInvoke(boolean waitingForRenderInvoke) { + isWaitingForRenderInvoke = waitingForRenderInvoke; + } + + /** + * Animate a MarkerView to a given rotation. + * <p> + * The {@link MarkerView} will be rotated from its current rotation to the given rotation. + * </p> + * + * @param marker the MarkerView to rotate. + * @param rotation the rotation value. + */ + public void animateRotation(@NonNull MarkerView marker, float rotation) { + View convertView = markerViewMap.get(marker); + if (convertView != null) { + AnimatorUtils.rotate(convertView, rotation); } - - - @Override - public void onMapChanged(@MapView.MapChange int change) { - if (isWaitingForRenderInvoke && change == MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) { - isWaitingForRenderInvoke = false; - invalidateViewMarkersInVisibleRegion(); - } + } + + /** + * Animate a MarkerView with a given rotation. + * + * @param marker the MarkerView to rotate by. + * @param rotation the rotation by value, limited to 0 - 360 degrees. + */ + public void animateRotationBy(@NonNull MarkerView marker, float rotation) { + View convertView = markerViewMap.get(marker); + if (convertView != null) { + convertView.animate().cancel(); + // calculate new direction + float diff = rotation - convertView.getRotation(); + if (diff > 180.0f) { + diff -= 360.0f; + } else if (diff < -180.0f) { + diff += 360.f; + } + AnimatorUtils.rotateBy(convertView, diff); } - - public void setWaitingForRenderInvoke(boolean waitingForRenderInvoke) { - isWaitingForRenderInvoke = waitingForRenderInvoke; + } + + /** + * Animate a MarkerView to a given alpha value. + * <p> + * The {@link MarkerView} will be transformed from its current alpha value to the given value. + * </p> + * + * @param marker the MarkerView to change its alpha value. + * @param alpha the alpha value. + */ + public void animateAlpha(@NonNull MarkerView marker, float alpha) { + View convertView = markerViewMap.get(marker); + if (convertView != null) { + AnimatorUtils.alpha(convertView, alpha); } - - /** - * Animate a MarkerView to a given rotation. - * <p> - * The {@link MarkerView} will be rotated from its current rotation to the given rotation. - * </p> - * - * @param marker the MarkerView to rotate. - * @param rotation the rotation value. - */ - public void animateRotation(@NonNull MarkerView marker, float rotation) { - View convertView = markerViewMap.get(marker); - if (convertView != null) { - AnimatorUtils.rotate(convertView, rotation); - } + } + + /** + * Animate a MarkerVIew to be visible or invisible + * <p> + * The {@link MarkerView} will be made {@link View#VISIBLE} or {@link View#GONE}. + * </p> + * + * @param marker the MarkerView to change its visibility + * @param visible the flag indicating if MarkerView is visible + */ + public void animateVisible(@NonNull MarkerView marker, boolean visible) { + View convertView = markerViewMap.get(marker); + if (convertView != null) { + convertView.setVisibility(visible ? View.VISIBLE : View.GONE); } - - /** - * Animate a MarkerView with a given rotation. - * - * @param marker the MarkerView to rotate by. - * @param rotation the rotation by value, limited to 0 - 360 degrees. - */ - public void animateRotationBy(@NonNull MarkerView marker, float rotation) { - View convertView = markerViewMap.get(marker); - if (convertView != null) { - convertView.animate().cancel(); - // calculate new direction - float diff = rotation - convertView.getRotation(); - if (diff > 180.0f) { - diff -= 360.0f; - } else if (diff < -180.0f) { - diff += 360.f; + } + + /** + * Updates the position of MarkerViews currently found in the viewport. + * <p> + * The collection of {@link MarkerView} will be iterated and each item position will be updated. + * If an item is View state is not visible and its related flag is set to visible, the + * {@link MarkerView} will be animated to visible using alpha animation. + * </p> + */ + public void update() { + for (final MarkerView marker : markerViewMap.keySet()) { + final View convertView = markerViewMap.get(marker); + if (convertView != null) { + PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); + if (marker.getOffsetX() == MapboxConstants.UNMEASURED) { + // ensure view is measured first + if (marker.getWidth() == 0) { + convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); + if (convertView.getMeasuredWidth() != 0) { + marker.setWidth(convertView.getMeasuredWidth()); + marker.setHeight(convertView.getMeasuredHeight()); } - AnimatorUtils.rotateBy(convertView, diff); + } + } + if (marker.getWidth() != 0) { + int x = (int) (marker.getAnchorU() * marker.getWidth()); + int y = (int) (marker.getAnchorV() * marker.getHeight()); + marker.setOffset(x, y); } - } - /** - * Animate a MarkerView to a given alpha value. - * <p> - * The {@link MarkerView} will be transformed from its current alpha value to the given value. - * </p> - * - * @param marker the MarkerView to change its alpha value. - * @param alpha the alpha value. - */ - public void animateAlpha(@NonNull MarkerView marker, float alpha) { - View convertView = markerViewMap.get(marker); - if (convertView != null) { - AnimatorUtils.alpha(convertView, alpha); + convertView.setX(point.x - marker.getOffsetX()); + convertView.setY(point.y - marker.getOffsetY()); + + // animate visibility + if (marker.isVisible() && convertView.getVisibility() == View.GONE) { + animateVisible(marker, true); } + } } - - /** - * Animate a MarkerVIew to be visible or invisible - * <p> - * The {@link MarkerView} will be made {@link View#VISIBLE} or {@link View#GONE}. - * </p> - * - * @param marker the MarkerView to change its visibility - * @param visible the flag indicating if MarkerView is visible - */ - public void animateVisible(@NonNull MarkerView marker, boolean visible) { - View convertView = markerViewMap.get(marker); + } + + /** + * Set tilt on every non flat MarkerView currently shown in the Viewport. + * + * @param tilt the tilt value. + */ + public void setTilt(float tilt) { + View convertView; + for (MarkerView markerView : markerViewMap.keySet()) { + if (markerView.isFlat()) { + convertView = markerViewMap.get(markerView); if (convertView != null) { - convertView.setVisibility(visible ? View.VISIBLE : View.GONE); + markerView.setTilt(tilt); + convertView.setRotationX(tilt); } + } } - - /** - * Updates the position of MarkerViews currently found in the viewport. - * <p> - * The collection of {@link MarkerView} will be iterated and each item position will be updated. - * If an item is View state is not visible and its related flag is set to visible, the - * {@link MarkerView} will be animated to visible using alpha animation. - * </p> - */ - public void update() { - for (final MarkerView marker : markerViewMap.keySet()) { - final View convertView = markerViewMap.get(marker); - if (convertView != null) { - PointF point = mapboxMap.getProjection().toScreenLocation(marker.getPosition()); - if (marker.getOffsetX() == MapboxConstants.UNMEASURED) { - // ensure view is measured first - if (marker.getWidth() == 0) { - convertView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - if (convertView.getMeasuredWidth() != 0) { - marker.setWidth(convertView.getMeasuredWidth()); - marker.setHeight(convertView.getMeasuredHeight()); - } - } - } - if (marker.getWidth() != 0) { - int x = (int) (marker.getAnchorU() * marker.getWidth()); - int y = (int) (marker.getAnchorV() * marker.getHeight()); - marker.setOffset(x, y); - } - - convertView.setX(point.x - marker.getOffsetX()); - convertView.setY(point.y - marker.getOffsetY()); - - // animate visibility - if (marker.isVisible() && convertView.getVisibility() == View.GONE) { - animateVisible(marker, true); - } - } - } + } + + /** + * Update and invalidate the MarkerView icon. + * + * @param markerView the marker view to updates. + */ + public void updateIcon(@NonNull MarkerView markerView) { + View convertView = markerViewMap.get(markerView); + if (convertView != null && convertView instanceof ImageView) { + ((ImageView) convertView).setImageBitmap(markerView.getIcon().getBitmap()); } - - /** - * Set tilt on every non flat MarkerView currently shown in the Viewport. - * - * @param tilt the tilt value. - */ - public void setTilt(float tilt) { - View convertView; - for (MarkerView markerView : markerViewMap.keySet()) { - if (markerView.isFlat()) { - convertView = markerViewMap.get(markerView); - if (convertView != null) { - markerView.setTilt(tilt); - convertView.setRotationX(tilt); - } - } + } + + /** + * Animate a MarkerView to a deselected state. + * <p> + * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onDeselect(MarkerView, View)} + * will be called to execute an animation. + * </p> + * + * @param marker the MarkerView to deselect. + */ + public void deselect(@NonNull MarkerView marker) { + deselect(marker, true); + } + + /** + * Animate a MarkerView to a deselected state. + * <p> + * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onDeselect(MarkerView, View)} + * will be called to execute an animation. + * </p> + * + * @param marker the MarkerView to deselect. + * @param callbackToMap indicates if deselect marker must be called on MapboxMap. + */ + public void deselect(@NonNull MarkerView marker, boolean callbackToMap) { + final View convertView = markerViewMap.get(marker); + if (convertView != null) { + for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + adapter.onDeselect(marker, convertView); } + } } - - /** - * Update and invalidate the MarkerView icon. - * - * @param markerView the marker view to updates. - */ - public void updateIcon(@NonNull MarkerView markerView) { - View convertView = markerViewMap.get(markerView); - if (convertView != null && convertView instanceof ImageView) { - ((ImageView) convertView).setImageBitmap(markerView.getIcon().getBitmap()); - } + if (callbackToMap) { + mapboxMap.deselectMarker(marker); } - - /** - * Animate a MarkerView to a deselected state. - * <p> - * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onDeselect(MarkerView, View)} - * will be called to execute an animation. - * </p> - * - * @param marker the MarkerView to deselect. - */ - public void deselect(@NonNull MarkerView marker) { - deselect(marker, true); + marker.setSelected(false); + } + + /** + * Animate a MarkerView to a selected state. + * + * @param marker the MarkerView object to select. + */ + public void select(@NonNull MarkerView marker) { + select(marker, true); + } + + /** + * Animate a MarkerView to a selected state. + * + * @param marker the MarkerView object to select. + * @param callbackToMap indicates if select marker must be called on {@link MapboxMap}. + */ + public void select(@NonNull MarkerView marker, boolean callbackToMap) { + final View convertView = markerViewMap.get(marker); + for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + select(marker, convertView, adapter, callbackToMap); + } } - - /** - * Animate a MarkerView to a deselected state. - * <p> - * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onDeselect(MarkerView, View)} - * will be called to execute an animation. - * </p> - * - * @param marker the MarkerView to deselect. - * @param callbackToMap indicates if deselect marker must be called on MapboxMap. - */ - public void deselect(@NonNull MarkerView marker, boolean callbackToMap) { - final View convertView = markerViewMap.get(marker); - if (convertView != null) { - for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - adapter.onDeselect(marker, convertView); - } - } - } + } + + /** + * Animate a MarkerView to a selected state. + * <p> + * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onSelect(MarkerView, View, boolean)} + * will be called to execute an animation. + * </p> + * + * @param marker the MarkerView object to select. + * @param convertView the View presentation of the MarkerView. + * @param adapter the adapter used to adapt the marker to the convertView. + */ + public void select(@NonNull MarkerView marker, View convertView, MapboxMap.MarkerViewAdapter adapter) { + select(marker, convertView, adapter, true); + } + + + /** + * Animate a MarkerView to a selected state. + * <p> + * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onSelect(MarkerView, View, boolean)} + * will be called to execute an animation. + * </p> + * + * @param marker the MarkerView object to select. + * @param convertView the View presentation of the MarkerView. + * @param adapter the adapter used to adapt the marker to the convertView. + * @param callbackToMap indicates if select marker must be called on MapboxMap. + */ + public void select(@NonNull MarkerView marker, View convertView, MapboxMap.MarkerViewAdapter adapter, + boolean callbackToMap) { + if (convertView != null) { + if (adapter.onSelect(marker, convertView, false)) { if (callbackToMap) { - mapboxMap.deselectMarker(marker); + mapboxMap.selectMarker(marker); } - marker.setSelected(false); + } + marker.setSelected(true); + convertView.bringToFront(); } - - /** - * Animate a MarkerView to a selected state. - * - * @param marker the MarkerView object to select. - */ - public void select(@NonNull MarkerView marker) { - select(marker, true); + } + + /** + * Get view representation from a MarkerView. If marker is not found in current viewport, + * {@code null} is returned. + * + * @param marker the marker to get the view. + * @return the Android SDK View object. + */ + @Nullable + public View getView(MarkerView marker) { + return markerViewMap.get(marker); + } + + /** + * Get the view adapter for a marker. + * + * @param markerView the marker to get the view adapter. + * @return the MarkerView adapter. + */ + @Nullable + public MapboxMap.MarkerViewAdapter getViewAdapter(MarkerView markerView) { + MapboxMap.MarkerViewAdapter adapter = null; + for (MapboxMap.MarkerViewAdapter a : markerViewAdapters) { + if (a.getMarkerClass().equals(markerView.getClass())) { + adapter = a; + } } - - /** - * Animate a MarkerView to a selected state. - * - * @param marker the MarkerView object to select. - * @param callbackToMap indicates if select marker must be called on {@link MapboxMap}. - */ - public void select(@NonNull MarkerView marker, boolean callbackToMap) { - final View convertView = markerViewMap.get(marker); - for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - select(marker, convertView, adapter, callbackToMap); - } + return adapter; + } + + /** + * Remove a MarkerView from a map. + * <p> + * The {@link MarkerView} will be removed using an alpha animation and related {@link View} + * will be released to the android.support.v4.util.Pools.SimplePool from the related + * {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter}. It's possible to remove + * the {@link MarkerView} from the underlying collection if needed. + * </p> + * + * @param marker the MarkerView to remove. + */ + public void removeMarkerView(MarkerView marker) { + final View viewHolder = markerViewMap.get(marker); + if (viewHolder != null && marker != null) { + for (final MapboxMap.MarkerViewAdapter<?> adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + if (adapter.prepareViewForReuse(marker, viewHolder)) { + // reset offset for reuse + marker.setOffset(MapboxConstants.UNMEASURED, MapboxConstants.UNMEASURED); + adapter.releaseView(viewHolder); + } } + } } - - /** - * Animate a MarkerView to a selected state. - * <p> - * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onSelect(MarkerView, View, boolean)} - * will be called to execute an animation. - * </p> - * - * @param marker the MarkerView object to select. - * @param convertView the View presentation of the MarkerView. - * @param adapter the adapter used to adapt the marker to the convertView. - */ - public void select(@NonNull MarkerView marker, View convertView, MapboxMap.MarkerViewAdapter adapter) { - select(marker, convertView, adapter, true); + marker.setMapboxMap(null); + markerViewMap.remove(marker); + } + + /** + * Add a MarkerViewAdapter to the MarkerViewManager. + * <p> + * The provided MarkerViewAdapter must supply a generic subclass of MarkerView. + * </p> + * + * @param markerViewAdapter the MarkerViewAdapter to add. + */ + public void addMarkerViewAdapter(MapboxMap.MarkerViewAdapter markerViewAdapter) { + if (markerViewAdapter.getMarkerClass().equals(MarkerView.class)) { + throw new RuntimeException("Providing a custom MarkerViewAdapter requires subclassing MarkerView"); } - - /** - * Animate a MarkerView to a selected state. - * <p> - * The {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter#onSelect(MarkerView, View, boolean)} - * will be called to execute an animation. - * </p> - * - * @param marker the MarkerView object to select. - * @param convertView the View presentation of the MarkerView. - * @param adapter the adapter used to adapt the marker to the convertView. - * @param callbackToMap indicates if select marker must be called on MapboxMap. - */ - public void select(@NonNull MarkerView marker, View convertView, MapboxMap.MarkerViewAdapter adapter, boolean callbackToMap) { - if (convertView != null) { - if (adapter.onSelect(marker, convertView, false)) { - if (callbackToMap) { - mapboxMap.selectMarker(marker); - } - } - marker.setSelected(true); - convertView.bringToFront(); - } + if (!markerViewAdapters.contains(markerViewAdapter)) { + markerViewAdapters.add(markerViewAdapter); + invalidateViewMarkersInVisibleRegion(); } - - /** - * Get view representation from a MarkerView. If marker is not found in current viewport, - * {@code null} is returned. - * - * @param marker the marker to get the view. - * @return the Android SDK View object. - */ - @Nullable - public View getView(MarkerView marker) { - return markerViewMap.get(marker); + } + + /** + * Get all MarkerViewAdapters associated with this MarkerViewManager. + * + * @return a List of MarkerViewAdapters. + */ + public List<MapboxMap.MarkerViewAdapter> getMarkerViewAdapters() { + return markerViewAdapters; + } + + /** + * Register a callback to be invoked when this view is clicked. + * + * @param listener the callback to be invoked. + */ + public void setOnMarkerViewClickListener(@Nullable MapboxMap.OnMarkerViewClickListener listener) { + onMarkerViewClickListener = listener; + } + + /** + * Schedule that ViewMarkers found in the viewport are invalidated. + * <p> + * This method is rate limited, and {@link #invalidateViewMarkersInVisibleRegion} will only be called + * once each 250 ms. + * </p> + */ + public void scheduleViewMarkerInvalidation() { + if (!markerViewAdapters.isEmpty()) { + long currentTime = SystemClock.elapsedRealtime(); + if (currentTime < viewMarkerBoundsUpdateTime) { + return; + } + invalidateViewMarkersInVisibleRegion(); + viewMarkerBoundsUpdateTime = currentTime + 250; } - - /** - * Get the view adapter for a marker. - * - * @param markerView the marker to get the view adapter. - * @return the MarkerView adapter. - */ - @Nullable - public MapboxMap.MarkerViewAdapter getViewAdapter(MarkerView markerView) { - MapboxMap.MarkerViewAdapter adapter = null; - for (MapboxMap.MarkerViewAdapter a : markerViewAdapters) { - if (a.getMarkerClass().equals(markerView.getClass())) { - adapter = a; - } + } + + /** + * Invalidate the ViewMarkers found in the viewport. + * <p> + * This method will remove any markers that aren't in the viewport anymore and will add new + * ones for each found Marker in the changed viewport. + * </p> + */ + public void invalidateViewMarkersInVisibleRegion() { + RectF mapViewRect = new RectF(0, 0, markerViewContainer.getWidth(), markerViewContainer.getHeight()); + List<MarkerView> markers = mapboxMap.getMarkerViewsInRect(mapViewRect); + View convertView; + + // remove old markers + Iterator<MarkerView> iterator = markerViewMap.keySet().iterator(); + while (iterator.hasNext()) { + MarkerView marker = iterator.next(); + if (!markers.contains(marker)) { + // remove marker + convertView = markerViewMap.get(marker); + for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + adapter.prepareViewForReuse(marker, convertView); + adapter.releaseView(convertView); + marker.setMapboxMap(null); + iterator.remove(); + } } - return adapter; + } } - /** - * Remove a MarkerView from a map. - * <p> - * The {@link MarkerView} will be removed using an alpha animation and related {@link View} - * will be released to the android.support.v4.util.Pools.SimplePool from the related - * {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter}. It's possible to remove - * the {@link MarkerView} from the underlying collection if needed. - * </p> - * - * @param marker the MarkerView to remove. - */ - public void removeMarkerView(MarkerView marker) { - final View viewHolder = markerViewMap.get(marker); - if (viewHolder != null && marker != null) { - for (final MapboxMap.MarkerViewAdapter<?> adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - if (adapter.prepareViewForReuse(marker, viewHolder)) { - // reset offset for reuse - marker.setOffset(MapboxConstants.UNMEASURED, MapboxConstants.UNMEASURED); - adapter.releaseView(viewHolder); - } + // introduce new markers + for (final MarkerView marker : markers) { + if (!markerViewMap.containsKey(marker)) { + for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + + // Inflate View + convertView = (View) adapter.getViewReusePool().acquire(); + final View adaptedView = adapter.getView(marker, convertView, markerViewContainer); + if (adaptedView != null) { + adaptedView.setRotationX(marker.getTilt()); + adaptedView.setRotation(marker.getRotation()); + adaptedView.setAlpha(marker.getAlpha()); + adaptedView.setVisibility(View.GONE); + + if (mapboxMap.getSelectedMarkers().contains(marker)) { + // if a marker to be shown was selected + // replay that animation with duration 0 + if (adapter.onSelect(marker, adaptedView, true)) { + mapboxMap.selectMarker(marker); } + } + + marker.setMapboxMap(mapboxMap); + markerViewMap.put(marker, adaptedView); + if (convertView == null) { + adaptedView.setVisibility(View.GONE); + markerViewContainer.addView(adaptedView); + } } - } - marker.setMapboxMap(null); - markerViewMap.remove(marker); - } - /** - * Add a MarkerViewAdapter to the MarkerViewManager. - * <p> - * The provided MarkerViewAdapter must supply a generic subclass of MarkerView. - * </p> - * - * @param markerViewAdapter the MarkerViewAdapter to add. - */ - public void addMarkerViewAdapter(MapboxMap.MarkerViewAdapter markerViewAdapter) { - if (markerViewAdapter.getMarkerClass().equals(MarkerView.class)) { - throw new RuntimeException("Providing a custom MarkerViewAdapter requires subclassing MarkerView"); - } - - if (!markerViewAdapters.contains(markerViewAdapter)) { - markerViewAdapters.add(markerViewAdapter); - invalidateViewMarkersInVisibleRegion(); + // notify listener is marker view is rendered + OnMarkerViewAddedListener onViewAddedListener = markerViewAddedListenerMap.get(marker.getId()); + if (onViewAddedListener != null) { + onViewAddedListener.onViewAdded(marker); + markerViewAddedListenerMap.remove(marker.getId()); + } + } } + } } - /** - * Get all MarkerViewAdapters associated with this MarkerViewManager. - * - * @return a List of MarkerViewAdapters. - */ - public List<MapboxMap.MarkerViewAdapter> getMarkerViewAdapters() { - return markerViewAdapters; + // clear map, don't keep references to MarkerView listeners that are not found in the bounds of the map. + markerViewAddedListenerMap.clear(); + + // trigger update to make newly added ViewMarker visible, + // these would only be updated when the map is moved. + update(); + } + + /** + * When the provided {@link MarkerView} is clicked on by a user, we check if a custom click + * event has been created and if not, display a {@link InfoWindow}. + * + * @param markerView that the click event occurred. + */ + public boolean onClickMarkerView(MarkerView markerView) { + boolean clickHandled = false; + + MapboxMap.MarkerViewAdapter adapter = getViewAdapter(markerView); + View view = getView(markerView); + if (adapter == null || view == null) { + // not a valid state + return true; } - /** - * Register a callback to be invoked when this view is clicked. - * - * @param listener the callback to be invoked. - */ - public void setOnMarkerViewClickListener(@Nullable MapboxMap.OnMarkerViewClickListener listener) { - onMarkerViewClickListener = listener; + if (onMarkerViewClickListener != null) { + clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter); } - /** - * Schedule that ViewMarkers found in the viewport are invalidated. - * <p> - * This method is rate limited, and {@link #invalidateViewMarkersInVisibleRegion} will only be called - * once each 250 ms. - * </p> - */ - public void scheduleViewMarkerInvalidation() { - if (!markerViewAdapters.isEmpty()) { - long currentTime = SystemClock.elapsedRealtime(); - if (currentTime < viewMarkerBoundsUpdateTime) { - return; - } - invalidateViewMarkersInVisibleRegion(); - viewMarkerBoundsUpdateTime = currentTime + 250; - } + if (!clickHandled) { + ensureInfoWindowOffset(markerView); + select(markerView, view, adapter); } - /** - * Invalidate the ViewMarkers found in the viewport. - * <p> - * This method will remove any markers that aren't in the viewport anymore and will add new - * ones for each found Marker in the changed viewport. - * </p> - */ - public void invalidateViewMarkersInVisibleRegion() { - RectF mapViewRect = new RectF(0, 0, markerViewContainer.getWidth(), markerViewContainer.getHeight()); - List<MarkerView> markers = mapboxMap.getMarkerViewsInRect(mapViewRect); - View convertView; - - // remove old markers - Iterator<MarkerView> iterator = markerViewMap.keySet().iterator(); - while (iterator.hasNext()) { - MarkerView marker = iterator.next(); - if (!markers.contains(marker)) { - // remove marker - convertView = markerViewMap.get(marker); - for (MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - adapter.prepareViewForReuse(marker, convertView); - adapter.releaseView(convertView); - marker.setMapboxMap(null); - iterator.remove(); - } - } - } - } - - // introduce new markers - for (final MarkerView marker : markers) { - if (!markerViewMap.containsKey(marker)) { - for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - - // Inflate View - convertView = (View) adapter.getViewReusePool().acquire(); - final View adaptedView = adapter.getView(marker, convertView, markerViewContainer); - if (adaptedView != null) { - adaptedView.setRotationX(marker.getTilt()); - adaptedView.setRotation(marker.getRotation()); - adaptedView.setAlpha(marker.getAlpha()); - adaptedView.setVisibility(View.GONE); - - if (mapboxMap.getSelectedMarkers().contains(marker)) { - // if a marker to be shown was selected - // replay that animation with duration 0 - if (adapter.onSelect(marker, adaptedView, true)) { - mapboxMap.selectMarker(marker); - } - } - - marker.setMapboxMap(mapboxMap); - markerViewMap.put(marker, adaptedView); - if (convertView == null) { - adaptedView.setVisibility(View.GONE); - markerViewContainer.addView(adaptedView); - } - } - - // notify listener is marker view is rendered - OnMarkerViewAddedListener onViewAddedListener = markerViewAddedListenerMap.get(marker.getId()); - if (onViewAddedListener != null) { - onViewAddedListener.onViewAdded(marker); - markerViewAddedListenerMap.remove(marker.getId()); - } - } - } - } + return clickHandled; + } + + /** + * Handles the {@link MarkerView}'s info window offset. + * + * @param marker that we are ensuring info window offset. + */ + public void ensureInfoWindowOffset(MarkerView marker) { + View view = null; + if (markerViewMap.containsKey(marker)) { + view = markerViewMap.get(marker); + } else { + for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { + if (adapter.getMarkerClass().equals(marker.getClass())) { + View convertView = (View) adapter.getViewReusePool().acquire(); + view = adapter.getView(marker, convertView, markerViewContainer); + break; } - - // clear map, don't keep references to MarkerView listeners that are not found in the bounds of the map. - markerViewAddedListenerMap.clear(); - - // trigger update to make newly added ViewMarker visible, - // these would only be updated when the map is moved. - update(); + } } - /** - * When the provided {@link MarkerView} is clicked on by a user, we check if a custom click - * event has been created and if not, display a {@link InfoWindow}. - * - * @param markerView that the click event occurred. - */ - public boolean onClickMarkerView(MarkerView markerView) { - boolean clickHandled = false; - - MapboxMap.MarkerViewAdapter adapter = getViewAdapter(markerView); - View view = getView(markerView); - if (adapter == null || view == null) { - // not a valid state - return true; + if (view != null) { + if (marker.getWidth() == 0) { + if (view.getMeasuredWidth() == 0) { + //Ensure the marker's view is measured first + view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); } - - if (onMarkerViewClickListener != null) { - clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter); - } - - if (!clickHandled) { - ensureInfoWindowOffset(markerView); - select(markerView, view, adapter); - } - - return clickHandled; + marker.setWidth(view.getMeasuredWidth()); + marker.setHeight(view.getMeasuredHeight()); + } + + // update position on map + if (marker.getOffsetX() == MapboxConstants.UNMEASURED) { + int x = (int) (marker.getAnchorU() * marker.getWidth()); + int y = (int) (marker.getAnchorV() * marker.getHeight()); + marker.setOffset(x, y); + } + + // InfoWindow offset + int infoWindowOffsetX = (int) ((view.getMeasuredWidth() * marker.getInfoWindowAnchorU()) - marker.getOffsetX()); + int infoWindowOffsetY = (int) ((view.getMeasuredHeight() * marker.getInfoWindowAnchorV()) - marker.getOffsetY()); + marker.setTopOffsetPixels(infoWindowOffsetY); + marker.setRightOffsetPixels(infoWindowOffsetX); } + } - /** - * Handles the {@link MarkerView}'s info window offset. - * - * @param marker that we are ensuring info window offset. - */ - public void ensureInfoWindowOffset(MarkerView marker) { - View view = null; - if (markerViewMap.containsKey(marker)) { - view = markerViewMap.get(marker); - } else { - for (final MapboxMap.MarkerViewAdapter adapter : markerViewAdapters) { - if (adapter.getMarkerClass().equals(marker.getClass())) { - View convertView = (View) adapter.getViewReusePool().acquire(); - view = adapter.getView(marker, convertView, markerViewContainer); - break; - } - } - } + public ViewGroup getMarkerViewContainer() { + return markerViewContainer; + } - if (view != null) { - if (marker.getWidth() == 0) { - if (view.getMeasuredWidth() == 0) { - //Ensure the marker's view is measured first - view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); - } - marker.setWidth(view.getMeasuredWidth()); - marker.setHeight(view.getMeasuredHeight()); - } + public void addOnMarkerViewAddedListener(MarkerView markerView, OnMarkerViewAddedListener onMarkerViewAddedListener) { + markerViewAddedListenerMap.put(markerView.getId(), onMarkerViewAddedListener); + } - // update position on map - if (marker.getOffsetX() == MapboxConstants.UNMEASURED) { - int x = (int) (marker.getAnchorU() * marker.getWidth()); - int y = (int) (marker.getAnchorV() * marker.getHeight()); - marker.setOffset(x, y); - } + /** + * Default MarkerViewAdapter used for base class of {@link MarkerView} to adapt a MarkerView to + * an ImageView. + */ + public static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> { - // InfoWindow offset - int infoWindowOffsetX = (int) ((view.getMeasuredWidth() * marker.getInfoWindowAnchorU()) - marker.getOffsetX()); - int infoWindowOffsetY = (int) ((view.getMeasuredHeight() * marker.getInfoWindowAnchorV()) - marker.getOffsetY()); - marker.setTopOffsetPixels(infoWindowOffsetY); - marker.setRightOffsetPixels(infoWindowOffsetX); - } - } + private LayoutInflater inflater; - public ViewGroup getMarkerViewContainer() { - return markerViewContainer; + public ImageMarkerViewAdapter(Context context) { + super(context); + inflater = LayoutInflater.from(context); } - public void addOnMarkerViewAddedListener(MarkerView markerView, OnMarkerViewAddedListener onMarkerViewAddedListener) { - markerViewAddedListenerMap.put(markerView.getId(), onMarkerViewAddedListener); + @Nullable + @Override + public View getView(@NonNull MarkerView marker, @Nullable View convertView, @NonNull ViewGroup parent) { + ViewHolder viewHolder; + if (convertView == null) { + viewHolder = new ViewHolder(); + convertView = inflater.inflate(R.layout.mapbox_view_image_marker, parent, false); + viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image); + convertView.setTag(viewHolder); + } else { + viewHolder = (ViewHolder) convertView.getTag(); + } + viewHolder.imageView.setImageBitmap(marker.getIcon().getBitmap()); + return convertView; } - /** - * Default MarkerViewAdapter used for base class of {@link MarkerView} to adapt a MarkerView to - * an ImageView. - */ - public static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> { - - private LayoutInflater inflater; - - public ImageMarkerViewAdapter(Context context) { - super(context); - inflater = LayoutInflater.from(context); - } - - @Nullable - @Override - public View getView(@NonNull MarkerView marker, @Nullable View convertView, @NonNull ViewGroup parent) { - ViewHolder viewHolder; - if (convertView == null) { - viewHolder = new ViewHolder(); - convertView = inflater.inflate(R.layout.mapbox_view_image_marker, parent, false); - viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image); - convertView.setTag(viewHolder); - } else { - viewHolder = (ViewHolder) convertView.getTag(); - } - viewHolder.imageView.setImageBitmap(marker.getIcon().getBitmap()); - return convertView; - } - - private static class ViewHolder { - ImageView imageView; - } + private static class ViewHolder { + ImageView imageView; } + } + + /** + * Interface definition invoked when the View of a MarkerView has been added to the map. + * <p> + * {@link MapboxMap#addMarker(BaseMarkerOptions)} + * and only when the related MarkerView is found in the viewport of the map. + * </p> + */ + public interface OnMarkerViewAddedListener { /** - * Interface definition invoked when the View of a MarkerView has been added to the map. - * <p> - * {@link MapboxMap#addMarker(BaseMarkerOptions)} - * and only when the related MarkerView is found in the viewport of the map. - * </p> + * Invoked when the View of a MarkerView has been added to the Map. + * + * @param markerView The MarkerView the View was added for */ - public interface OnMarkerViewAddedListener { - - /** - * Invoked when the View of a MarkerView has been added to the Map. - * - * @param markerView The MarkerView the View was added for - */ - void onViewAdded(@NonNull MarkerView markerView); - } + void onViewAdded(@NonNull MarkerView markerView); + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java index 1a763a72a1..2d829537fc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java @@ -15,146 +15,150 @@ import com.mapbox.mapboxsdk.geometry.LatLng; */ public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerViewOptions> { - private MarkerView marker; + private MarkerView marker; - /** - * Defines default options for a MarkerView. Extend {@link BaseMarkerViewOptions} if you need - * more customization. - */ - public MarkerViewOptions() { - marker = new MarkerView(); - } + /** + * Defines default options for a MarkerView. Extend {@link BaseMarkerViewOptions} if you need + * more customization. + */ + public MarkerViewOptions() { + marker = new MarkerView(); + } - protected MarkerViewOptions(Parcel in) { - marker = new MarkerView(); - position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); - snippet(in.readString()); - title(in.readString()); - flat(in.readByte() != 0); - anchor(in.readFloat(), in.readFloat()); - infoWindowAnchor(in.readFloat(), in.readFloat()); - rotation(in.readFloat()); - visible(in.readByte() != 0); - alpha(in.readFloat()); - if (in.readByte() != 0) { - // this means we have an icon - String iconId = in.readString(); - Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); - Icon icon = new Icon(iconId, iconBitmap); - icon(icon); - } + protected MarkerViewOptions(Parcel in) { + marker = new MarkerView(); + position((LatLng) in.readParcelable(LatLng.class.getClassLoader())); + snippet(in.readString()); + title(in.readString()); + flat(in.readByte() != 0); + anchor(in.readFloat(), in.readFloat()); + infoWindowAnchor(in.readFloat(), in.readFloat()); + rotation(in.readFloat()); + visible(in.readByte() != 0); + alpha(in.readFloat()); + if (in.readByte() != 0) { + // this means we have an icon + String iconId = in.readString(); + Bitmap iconBitmap = in.readParcelable(Bitmap.class.getClassLoader()); + Icon icon = new Icon(iconId, iconBitmap); + icon(icon); } + } - /** - * Get the instance of the object for which this method was called. - * - * @return the object for which this method was called. - */ - @Override - public MarkerViewOptions getThis() { - return this; - } + /** + * Get the instance of the object for which this method was called. + * + * @return the object for which this method was called. + */ + @Override + public MarkerViewOptions getThis() { + return this; + } - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + * + * @return integer 0. + */ + @Override + public int describeContents() { + return 0; + } - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeParcelable(getPosition(), flags); - out.writeString(getSnippet()); - out.writeString(getTitle()); - out.writeByte((byte) (isFlat() ? 1 : 0)); - out.writeFloat(getAnchorU()); - out.writeFloat(getAnchorV()); - out.writeFloat(getInfoWindowAnchorU()); - out.writeFloat(getInfoWindowAnchorV()); - out.writeFloat(getRotation()); - out.writeByte((byte) (isVisible() ? 1 : 0)); - out.writeFloat(alpha); - Icon icon = getIcon(); - out.writeByte((byte) (icon != null ? 1 : 0)); - if (icon != null) { - out.writeString(getIcon().getId()); - out.writeParcelable(getIcon().getBitmap(), flags); - } + /** + * Flatten this object in to a Parcel. + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. May be 0 or + * {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(getPosition(), flags); + out.writeString(getSnippet()); + out.writeString(getTitle()); + out.writeByte((byte) (isFlat() ? 1 : 0)); + out.writeFloat(getAnchorU()); + out.writeFloat(getAnchorV()); + out.writeFloat(getInfoWindowAnchorU()); + out.writeFloat(getInfoWindowAnchorV()); + out.writeFloat(getRotation()); + out.writeByte((byte) (isVisible() ? 1 : 0)); + out.writeFloat(alpha); + Icon icon = getIcon(); + out.writeByte((byte) (icon != null ? 1 : 0)); + if (icon != null) { + out.writeString(getIcon().getId()); + out.writeParcelable(getIcon().getBitmap(), flags); } + } - /** - * Get the {@link MarkerView}. - * - * @return {@link MarkerView}. - */ - @Override - public MarkerView getMarker() { - if (position == null) { - throw new InvalidMarkerPositionException(); - } - - marker.setPosition(position); - marker.setSnippet(snippet); - marker.setTitle(title); - marker.setIcon(icon); - marker.setFlat(flat); - marker.setAnchor(anchorU, anchorV); - marker.setInfoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV); - marker.setRotation(rotation); - marker.setVisible(visible); - marker.setAlpha(alpha); - return marker; + /** + * Get the {@link MarkerView}. + * + * @return {@link MarkerView}. + */ + @Override + public MarkerView getMarker() { + if (position == null) { + throw new InvalidMarkerPositionException(); } - public static final Parcelable.Creator<MarkerViewOptions> CREATOR - = new Parcelable.Creator<MarkerViewOptions>() { - public MarkerViewOptions createFromParcel(Parcel in) { - return new MarkerViewOptions(in); - } + marker.setPosition(position); + marker.setSnippet(snippet); + marker.setTitle(title); + marker.setIcon(icon); + marker.setFlat(flat); + marker.setAnchor(anchorU, anchorV); + marker.setInfoWindowAnchor(infoWindowAnchorU, infoWindowAnchorV); + marker.setRotation(rotation); + marker.setVisible(visible); + marker.setAlpha(alpha); + return marker; + } - public MarkerViewOptions[] newArray(int size) { - return new MarkerViewOptions[size]; - } + public static final Parcelable.Creator<MarkerViewOptions> CREATOR = + new Parcelable.Creator<MarkerViewOptions>() { + public MarkerViewOptions createFromParcel(Parcel in) { + return new MarkerViewOptions(in); + } + + public MarkerViewOptions[] newArray(int size) { + return new MarkerViewOptions[size]; + } }; - /** - * Compares this {@link MarkerViewOptions} object with another {@link MarkerViewOptions} and - * determines if they match. - * - * @param o Another {@link MarkerViewOptions} to compare with this object. - * @return True if the {@link MarkerViewOptions} being passed in matches this - * {@link PolylineOptions} object. Else, false. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - MarkerViewOptions that = (MarkerViewOptions) o; - return marker != null ? marker.equals(that.marker) : that.marker == null; + /** + * Compares this {@link MarkerViewOptions} object with another {@link MarkerViewOptions} and + * determines if they match. + * + * @param object Another {@link MarkerViewOptions} to compare with this object. + * @return True if the {@link MarkerViewOptions} being passed in matches this + * {@link PolylineOptions} object. Else, false. + */ + @Override + public boolean equals(Object object) { + if (this == object) { + return true; } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - return marker != null ? marker.hashCode() : 0; + if (object == null || getClass() != object.getClass()) { + return false; } + MarkerViewOptions that = (MarkerViewOptions) object; + return marker != null ? marker.equals(that.marker) : that.marker == null; + } + + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + return marker != null ? marker.hashCode() : 0; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java index 78d21db2e9..2bd3c82786 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MultiPoint.java @@ -10,62 +10,62 @@ import java.util.List; */ public abstract class MultiPoint extends Annotation { - private List<LatLng> points; - private float alpha = 1.0f; + private List<LatLng> points; + private float alpha = 1.0f; - protected MultiPoint() { - super(); - points = new ArrayList<>(); - } + protected MultiPoint() { + super(); + points = new ArrayList<>(); + } - /** - * Returns a copy of the points. - * - * @return A {@link List} of points. - */ - public List<LatLng> getPoints() { - return new ArrayList<>(points); - } + /** + * Returns a copy of the points. + * + * @return A {@link List} of points. + */ + public List<LatLng> getPoints() { + 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 A {@link List} of {@link LatLng} points making up the polyline. - */ - public void setPoints(List<LatLng> points) { - this.points = new ArrayList<>(points); - update(); - } + /** + * 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 A {@link List} of {@link LatLng} points making up the polyline. + */ + public void setPoints(List<LatLng> points) { + this.points = new ArrayList<>(points); + update(); + } - /** - * Add a point to the polyline. - * - * @param point A {@link LatLng} point to be added. - */ - public void addPoint(LatLng point) { - points.add(point); - update(); - } + /** + * Add a point to the polyline. + * + * @param point A {@link LatLng} point to be added. + */ + public void addPoint(LatLng point) { + points.add(point); + update(); + } - /** - * Value between 0 and 1 defining the polyline alpha. - * - * @return float value between 0 and 1. - */ - public float getAlpha() { - return alpha; - } + /** + * Value between 0 and 1 defining the polyline alpha. + * + * @return float value between 0 and 1. + */ + public float getAlpha() { + return alpha; + } - /** - * Set this {@link MultiPoint}s alpha. - * - * @param alpha float value between 0 and 1. - */ - public void setAlpha(float alpha) { - this.alpha = alpha; - update(); - } + /** + * Set this {@link MultiPoint}s alpha. + * + * @param alpha float value between 0 and 1. + */ + public void setAlpha(float alpha) { + this.alpha = alpha; + update(); + } - abstract void update(); + abstract void update(); } 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 a06938e3cb..7b9de86bc4 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 @@ -9,56 +9,56 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; */ public final class Polygon extends MultiPoint { - private int fillColor = Color.BLACK; // default fillColor is black - private int strokeColor = Color.BLACK; // default strokeColor is black + private int fillColor = Color.BLACK; // default fillColor is black + private int strokeColor = Color.BLACK; // default strokeColor is black - Polygon() { - super(); - } + Polygon() { + super(); + } - /** - * Get the color of the fill region of the polygon. - * - * @return The color of the fill. - */ - public int getFillColor() { - return fillColor; - } + /** + * Get the color of the fill region of the polygon. + * + * @return The color of the fill. + */ + public int getFillColor() { + return fillColor; + } - /** - * Get the color fo the stroke of the polygon. - * - * @return The color of the stroke. - */ - public int getStrokeColor() { - return strokeColor; - } + /** + * Get the color fo the stroke of the polygon. + * + * @return The color of the stroke. + */ + public int getStrokeColor() { + return strokeColor; + } - /** - * Sets the color of the fill region of the polygon. - * - * @param color The color in ARGB format. - */ - public void setFillColor(int color) { - fillColor = color; - update(); - } + /** + * Sets the color of the fill region of the polygon. + * + * @param color The color in ARGB format. + */ + public void setFillColor(int color) { + fillColor = color; + update(); + } - /** - * Sets the color of the stroke of the polygon. - * - * @param color The color in ARGB format. - */ - public void setStrokeColor(int color) { - strokeColor = color; - update(); - } + /** + * Sets the color of the stroke of the polygon. + * + * @param color The color in ARGB format. + */ + public void setStrokeColor(int color) { + strokeColor = color; + update(); + } - @Override - void update() { - MapboxMap mapboxMap = getMapboxMap(); - if (mapboxMap != null) { - mapboxMap.updatePolygon(this); - } + @Override + void update() { + MapboxMap mapboxMap = getMapboxMap(); + if (mapboxMap != null) { + mapboxMap.updatePolygon(this); } + } } 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 53a4e0995b..22f1258fc7 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 @@ -14,210 +14,220 @@ import java.util.List; */ public final class PolygonOptions implements Parcelable { - public static final Parcelable.Creator<PolygonOptions> CREATOR - = new Parcelable.Creator<PolygonOptions>() { - public PolygonOptions createFromParcel(Parcel in) { - return new PolygonOptions(in); - } - - public PolygonOptions[] newArray(int size) { - return new PolygonOptions[size]; - } + public static final Parcelable.Creator<PolygonOptions> CREATOR = + new Parcelable.Creator<PolygonOptions>() { + public PolygonOptions createFromParcel(Parcel in) { + return new PolygonOptions(in); + } + + public PolygonOptions[] newArray(int size) { + return new PolygonOptions[size]; + } }; - private PolygonOptions(Parcel in) { - polygon = new Polygon(); - ArrayList<LatLng> pointsList = new ArrayList<>(); - in.readList(pointsList, LatLng.class.getClassLoader()); - addAll(pointsList); - alpha(in.readFloat()); - fillColor(in.readInt()); - strokeColor(in.readInt()); - } - - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } - - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeList(getPoints()); - out.writeFloat(getAlpha()); - out.writeInt(getFillColor()); - out.writeInt(getStrokeColor()); - } - - private Polygon polygon; - - /** - * Defines options for a polygon. - */ - public PolygonOptions() { - polygon = new Polygon(); - } - - /** - * Adds a vertex to the outline of the polygon being built. - * - * @param point {@link LatLng} point to be added to polygon geometry. - * @return This {@link PolygonOptions} object with the given point added to the outline. - */ - public PolygonOptions add(LatLng point) { - polygon.addPoint(point); - return this; - } - - /** - * Adds vertices to the outline of the polygon being built. - * - * @param points {@link LatLng} points to be added to polygon geometry. - * @return This {@link PolygonOptions} object with the given points added to the outline. - */ - public PolygonOptions add(LatLng... points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Adds vertices to the outline of the polygon being built. - * - * @param points {@link Iterable} list made up of {@link LatLng} points defining the polygon - * geometry - * @return This {@link PolygonOptions} object with the given points added to the outline. - */ - public PolygonOptions addAll(Iterable<LatLng> points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Set the alpha value of the polyline. - * - * @param alpha float value between 0 (not visible) and 1. - * @return This {@link PolygonOptions} object with the given polygon alpha value. - */ - public PolygonOptions alpha(float alpha) { - polygon.setAlpha(alpha); - return this; - } - - /** - * Gets the alpha set for this {@link PolygonOptions} object. - * - * @return float value between 0 and 1 defining the alpha. - */ - public float getAlpha() { - return polygon.getAlpha(); - } - - /** - * Specifies the polygon's fill color, as 32-bit ARGB. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolylineOptions} object with a new color set. - */ - public PolygonOptions fillColor(int color) { - polygon.setFillColor(color); - return this; - } - - /** - * Gets the fill color set for this {@link PolygonOptions} object. - * - * @return The fill color of the polygon in ARGB format. - */ - public int getFillColor() { - return polygon.getFillColor(); - } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return Polygon the Polygon to return - */ - public Polygon getPolygon() { - return polygon; - } - - /** - * Specifies the polygon's stroke color, as 32-bit ARGB. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolygonOptions} object with a new stroke color set. - */ - public PolygonOptions strokeColor(int color) { - polygon.setStrokeColor(color); - return this; - } - - /** - * Gets the stroke color set for this {@link PolygonOptions} object. - * - * @return The stroke color of the polygon in ARGB format. - */ - public int getStrokeColor() { - return polygon.getStrokeColor(); - } - - public List<LatLng> getPoints() { - // the getter gives us a copy, which is the safe thing to do... - return polygon.getPoints(); - } - - /** - * Compares this {@link PolygonOptions} object with another {@link PolygonOptions} and - * determines if their color, alpha, stroke color, and vertices 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. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - PolygonOptions polygon = (PolygonOptions) o; - - if (Float.compare(polygon.getAlpha(), getAlpha()) != 0) return false; - if (getFillColor() != polygon.getFillColor()) return false; - if (getStrokeColor() != polygon.getStrokeColor()) return false; - return !(getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); - result = 31 * result + getFillColor(); - result = 31 * result + getStrokeColor(); - result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); - return result; - } + private PolygonOptions(Parcel in) { + polygon = new Polygon(); + ArrayList<LatLng> pointsList = new ArrayList<>(); + in.readList(pointsList, LatLng.class.getClassLoader()); + addAll(pointsList); + alpha(in.readFloat()); + fillColor(in.readInt()); + strokeColor(in.readInt()); + } + + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + * + * @return integer 0. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Flatten this object in to a Parcel. + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. May be 0 or + * {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeList(getPoints()); + out.writeFloat(getAlpha()); + out.writeInt(getFillColor()); + out.writeInt(getStrokeColor()); + } + + private Polygon polygon; + + /** + * Defines options for a polygon. + */ + public PolygonOptions() { + polygon = new Polygon(); + } + + /** + * Adds a vertex to the outline of the polygon being built. + * + * @param point {@link LatLng} point to be added to polygon geometry. + * @return This {@link PolygonOptions} object with the given point added to the outline. + */ + public PolygonOptions add(LatLng point) { + polygon.addPoint(point); + return this; + } + + /** + * Adds vertices to the outline of the polygon being built. + * + * @param points {@link LatLng} points to be added to polygon geometry. + * @return This {@link PolygonOptions} object with the given points added to the outline. + */ + public PolygonOptions add(LatLng... points) { + for (LatLng point : points) { + add(point); + } + return this; + } + + /** + * Adds vertices to the outline of the polygon being built. + * + * @param points {@link Iterable} list made up of {@link LatLng} points defining the polygon + * geometry + * @return This {@link PolygonOptions} object with the given points added to the outline. + */ + public PolygonOptions addAll(Iterable<LatLng> points) { + for (LatLng point : points) { + add(point); + } + return this; + } + + /** + * Set the alpha value of the polyline. + * + * @param alpha float value between 0 (not visible) and 1. + * @return This {@link PolygonOptions} object with the given polygon alpha value. + */ + public PolygonOptions alpha(float alpha) { + polygon.setAlpha(alpha); + return this; + } + + /** + * Gets the alpha set for this {@link PolygonOptions} object. + * + * @return float value between 0 and 1 defining the alpha. + */ + public float getAlpha() { + return polygon.getAlpha(); + } + + /** + * Specifies the polygon's fill color, as 32-bit ARGB. The default color is black. + * + * @param color 32-bit ARGB color. + * @return This {@link PolylineOptions} object with a new color set. + */ + public PolygonOptions fillColor(int color) { + polygon.setFillColor(color); + return this; + } + + /** + * Gets the fill color set for this {@link PolygonOptions} object. + * + * @return The fill color of the polygon in ARGB format. + */ + public int getFillColor() { + return polygon.getFillColor(); + } + + /** + * Do not use this method. Used internally by the SDK. + * + * @return Polygon the Polygon to return + */ + public Polygon getPolygon() { + return polygon; + } + + /** + * Specifies the polygon's stroke color, as 32-bit ARGB. The default color is black. + * + * @param color 32-bit ARGB color. + * @return This {@link PolygonOptions} object with a new stroke color set. + */ + public PolygonOptions strokeColor(int color) { + polygon.setStrokeColor(color); + return this; + } + + /** + * Gets the stroke color set for this {@link PolygonOptions} object. + * + * @return The stroke color of the polygon in ARGB format. + */ + public int getStrokeColor() { + return polygon.getStrokeColor(); + } + + public List<LatLng> getPoints() { + // the getter gives us a copy, which is the safe thing to do... + return polygon.getPoints(); + } + + /** + * Compares this {@link PolygonOptions} object with another {@link PolygonOptions} and + * determines if their color, alpha, stroke color, and vertices 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. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + PolygonOptions polygon = (PolygonOptions) o; + + if (Float.compare(polygon.getAlpha(), getAlpha()) != 0) { + return false; + } + if (getFillColor() != polygon.getFillColor()) { + return false; + } + if (getStrokeColor() != polygon.getStrokeColor()) { + return false; + } + return !(getPoints() != null ? !getPoints().equals(polygon.getPoints()) : polygon.getPoints() != null); + } + + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); + result = 31 * result + getFillColor(); + result = 31 * result + getStrokeColor(); + result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); + return result; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java index 49d8d5d6e8..a430d11009 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Polyline.java @@ -9,56 +9,56 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; */ public final class Polyline extends MultiPoint { - private int color = Color.BLACK; // default color is black - private float width = 10; // As specified by Google API Docs (in pixels) + private int color = Color.BLACK; // default color is black + private float width = 10; // As specified by Google API Docs (in pixels) - Polyline() { - super(); - } + Polyline() { + super(); + } - /** - * Gets the color of this polyline. - * - * @return The color in ARGB format. - */ - public int getColor() { - return color; - } + /** + * Gets the color of this polyline. + * + * @return The color in ARGB format. + */ + public int getColor() { + return color; + } - /** - * Gets the width of this polyline. - * - * @return The width in screen pixels. - */ - public float getWidth() { - return width; - } + /** + * Gets the width of this polyline. + * + * @return The width in screen pixels. + */ + public float getWidth() { + return width; + } - /** - * Sets the color of the polyline. - * - * @param color - the color in ARGB format - */ - public void setColor(int color) { - this.color = color; - update(); - } + /** + * Sets the color of the polyline. + * + * @param color - the color in ARGB format + */ + public void setColor(int color) { + this.color = color; + update(); + } - /** - * Sets the width of the polyline. - * - * @param width in pixels - */ - public void setWidth(float width) { - this.width = width; - update(); - } + /** + * Sets the width of the polyline. + * + * @param width in pixels + */ + public void setWidth(float width) { + this.width = width; + update(); + } - @Override - void update() { - MapboxMap mapboxMap = getMapboxMap(); - if (mapboxMap != null) { - mapboxMap.updatePolyline(this); - } + @Override + void update() { + MapboxMap mapboxMap = getMapboxMap(); + if (mapboxMap != null) { + mapboxMap.updatePolyline(this); } + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java index c74f6d196f..ab22109a4e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java @@ -14,215 +14,225 @@ import java.util.List; public final class PolylineOptions implements Parcelable { - public static final Parcelable.Creator<PolylineOptions> CREATOR - = new Parcelable.Creator<PolylineOptions>() { - public PolylineOptions createFromParcel(Parcel in) { - return new PolylineOptions(in); - } - - public PolylineOptions[] newArray(int size) { - return new PolylineOptions[size]; - } + public static final Parcelable.Creator<PolylineOptions> CREATOR = + new Parcelable.Creator<PolylineOptions>() { + public PolylineOptions createFromParcel(Parcel in) { + return new PolylineOptions(in); + } + + public PolylineOptions[] newArray(int size) { + return new PolylineOptions[size]; + } }; - private PolylineOptions(Parcel in) { - polyline = new Polyline(); - ArrayList<LatLng> pointsList = new ArrayList<>(); - in.readList(pointsList, LatLng.class.getClassLoader()); - addAll(pointsList); - alpha(in.readFloat()); - color(in.readInt()); - width(in.readFloat()); - } - - /** - * Describe the kinds of special objects contained in this Parcelable's - * marshalled representation. - * - * @return integer 0. - */ - @Override - public int describeContents() { - return 0; - } - - /** - * Flatten this object in to a Parcel. - * - * @param out The Parcel in which the object should be written. - * @param flags Additional flags about how the object should be written. May be 0 or - * {@link #PARCELABLE_WRITE_RETURN_VALUE}. - */ - @Override - public void writeToParcel(Parcel out, int flags) { - out.writeList(getPoints()); - out.writeFloat(getAlpha()); - out.writeInt(getColor()); - out.writeFloat(getWidth()); - } - - private Polyline polyline; - - /** - * Defines options for a polyline. - */ - public PolylineOptions() { - polyline = new Polyline(); - } - - /** - * Adds a vertex to the end of the polyline being built. - * - * @param point {@link LatLng} point to be added to polyline geometry. - * @return This {@link PolylineOptions} object with the given point on the end. - */ - public PolylineOptions add(LatLng point) { - polyline.addPoint(point); - return this; - } - - /** - * Adds vertices to the end of the polyline being built. - * - * @param points {@link LatLng} points defining the polyline geometry. - * @return This {@link PolylineOptions} object with the given point on the end. - */ - public PolylineOptions add(LatLng... points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Adds vertices to the end of the polyline being built. - * - * @param points {@link Iterable} list made up of {@link LatLng} points defining the polyline - * geometry - * @return This {@link PolylineOptions} object with the given points on the end. - */ - public PolylineOptions addAll(Iterable<LatLng> points) { - for (LatLng point : points) { - add(point); - } - return this; - } - - /** - * Set the alpha value of the polyline. - * - * @param alpha float value between 0 (not visible) and 1. - * @return This {@link PolylineOptions} object with the given polyline alpha value. - */ - public PolylineOptions alpha(float alpha) { - polyline.setAlpha(alpha); - return this; - } - - /** - * Gets the alpha set for this {@link PolylineOptions} object. - * - * @return float value between 0 and 1 defining the alpha. - */ - public float getAlpha() { - return polyline.getAlpha(); - } - - /** - * Sets the color of the polyline as a 32-bit ARGB color. The default color is black. - * - * @param color 32-bit ARGB color. - * @return This {@link PolylineOptions} object with a new color set. - */ - public PolylineOptions color(int color) { - polyline.setColor(color); - return this; - } - - /** - * Gets the color set for this {@link PolylineOptions} object. - * - * @return The color of the polyline in ARGB format. - */ - public int getColor() { - return polyline.getColor(); - } - - /** - * Do not use this method. Used internally by the SDK. - * - * @return PolyLine The polyline build by this class. - */ - public Polyline getPolyline() { - return polyline; - } - - /** - * Gets the width set for this {@link PolylineOptions} object. - * - * @return The width of the polyline in screen pixels. - */ - public float getWidth() { - return polyline.getWidth(); - } - - /** - * Sets the width of the polyline in screen pixels. The default is 10. - * - * @param width float value defining width of polyline using unit pixels. - * @return This {@link PolylineOptions} object with a new width set. - */ - public PolylineOptions width(float width) { - polyline.setWidth(width); - return this; - } - - /** - * Gets the points set for this {@link PolylineOptions} object. - * - * @return a {@link List} of {@link LatLng}s specifying the vertices of the polyline. - */ - public List<LatLng> getPoints() { - // the getter gives us a copy, which is the safe thing to do... - return polyline.getPoints(); - } - - /** - * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and - * determines if their color, alpha, width, and vertices match. - * - * @param o Another {@link PolylineOptions} to compare with this object. - * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object. - * Else, false. - */ - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - PolylineOptions polyline = (PolylineOptions) o; - - if (Float.compare(polyline.getAlpha(), getAlpha()) != 0) return false; - if (getColor() != polyline.getColor()) return false; - if (Float.compare(polyline.getWidth(), getWidth()) != 0) return false; - return !(getPoints() != null ? !getPoints().equals(polyline.getPoints()) : polyline.getPoints() != null); - } - - /** - * Gives an integer which can be used as the bucket number for storing elements of the set/map. - * This bucket number is the address of the element inside the set/map. There's no guarantee - * that this hash value will be consistent between different Java implementations, or even - * between different execution runs of the same program. - * - * @return integer value you can use for storing element. - */ - @Override - public int hashCode() { - int result = 1; - result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); - result = 31 * result + getColor(); - result = 31 * result + (getWidth() != +0.0f ? Float.floatToIntBits(getWidth()) : 0); - result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); - return result; - } + private PolylineOptions(Parcel in) { + polyline = new Polyline(); + ArrayList<LatLng> pointsList = new ArrayList<>(); + in.readList(pointsList, LatLng.class.getClassLoader()); + addAll(pointsList); + alpha(in.readFloat()); + color(in.readInt()); + width(in.readFloat()); + } + + /** + * Describe the kinds of special objects contained in this Parcelable's + * marshalled representation. + * + * @return integer 0. + */ + @Override + public int describeContents() { + return 0; + } + + /** + * Flatten this object in to a Parcel. + * + * @param out The Parcel in which the object should be written. + * @param flags Additional flags about how the object should be written. May be 0 or + * {@link #PARCELABLE_WRITE_RETURN_VALUE}. + */ + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeList(getPoints()); + out.writeFloat(getAlpha()); + out.writeInt(getColor()); + out.writeFloat(getWidth()); + } + + private Polyline polyline; + + /** + * Defines options for a polyline. + */ + public PolylineOptions() { + polyline = new Polyline(); + } + + /** + * Adds a vertex to the end of the polyline being built. + * + * @param point {@link LatLng} point to be added to polyline geometry. + * @return This {@link PolylineOptions} object with the given point on the end. + */ + public PolylineOptions add(LatLng point) { + polyline.addPoint(point); + return this; + } + + /** + * Adds vertices to the end of the polyline being built. + * + * @param points {@link LatLng} points defining the polyline geometry. + * @return This {@link PolylineOptions} object with the given point on the end. + */ + public PolylineOptions add(LatLng... points) { + for (LatLng point : points) { + add(point); + } + return this; + } + + /** + * Adds vertices to the end of the polyline being built. + * + * @param points {@link Iterable} list made up of {@link LatLng} points defining the polyline + * geometry + * @return This {@link PolylineOptions} object with the given points on the end. + */ + public PolylineOptions addAll(Iterable<LatLng> points) { + for (LatLng point : points) { + add(point); + } + return this; + } + + /** + * Set the alpha value of the polyline. + * + * @param alpha float value between 0 (not visible) and 1. + * @return This {@link PolylineOptions} object with the given polyline alpha value. + */ + public PolylineOptions alpha(float alpha) { + polyline.setAlpha(alpha); + return this; + } + + /** + * Gets the alpha set for this {@link PolylineOptions} object. + * + * @return float value between 0 and 1 defining the alpha. + */ + public float getAlpha() { + return polyline.getAlpha(); + } + + /** + * Sets the color of the polyline as a 32-bit ARGB color. The default color is black. + * + * @param color 32-bit ARGB color. + * @return This {@link PolylineOptions} object with a new color set. + */ + public PolylineOptions color(int color) { + polyline.setColor(color); + return this; + } + + /** + * Gets the color set for this {@link PolylineOptions} object. + * + * @return The color of the polyline in ARGB format. + */ + public int getColor() { + return polyline.getColor(); + } + + /** + * Do not use this method. Used internally by the SDK. + * + * @return PolyLine The polyline build by this class. + */ + public Polyline getPolyline() { + return polyline; + } + + /** + * Gets the width set for this {@link PolylineOptions} object. + * + * @return The width of the polyline in screen pixels. + */ + public float getWidth() { + return polyline.getWidth(); + } + + /** + * Sets the width of the polyline in screen pixels. The default is 10. + * + * @param width float value defining width of polyline using unit pixels. + * @return This {@link PolylineOptions} object with a new width set. + */ + public PolylineOptions width(float width) { + polyline.setWidth(width); + return this; + } + + /** + * Gets the points set for this {@link PolylineOptions} object. + * + * @return a {@link List} of {@link LatLng}s specifying the vertices of the polyline. + */ + public List<LatLng> getPoints() { + // the getter gives us a copy, which is the safe thing to do... + return polyline.getPoints(); + } + + /** + * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and + * determines if their color, alpha, width, and vertices match. + * + * @param o Another {@link PolylineOptions} to compare with this object. + * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object. + * Else, false. + */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + PolylineOptions polyline = (PolylineOptions) o; + + if (Float.compare(polyline.getAlpha(), getAlpha()) != 0) { + return false; + } + if (getColor() != polyline.getColor()) { + return false; + } + if (Float.compare(polyline.getWidth(), getWidth()) != 0) { + return false; + } + return !(getPoints() != null ? !getPoints().equals(polyline.getPoints()) : polyline.getPoints() != null); + } + + /** + * Gives an integer which can be used as the bucket number for storing elements of the set/map. + * This bucket number is the address of the element inside the set/map. There's no guarantee + * that this hash value will be consistent between different Java implementations, or even + * between different execution runs of the same program. + * + * @return integer value you can use for storing element. + */ + @Override + public int hashCode() { + int result = 1; + result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0); + result = 31 * result + getColor(); + result = 31 * result + (getWidth() != +0.0f ? Float.floatToIntBits(getWidth()) : 0); + result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0); + return result; + } } |