diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations')
7 files changed, 4 insertions, 1590 deletions
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 deleted file mode 100644 index 3fd2fa4ebf..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/BaseMarkerViewOptions.java +++ /dev/null @@ -1,285 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.os.Parcelable; -import android.support.annotation.FloatRange; -import android.support.annotation.NonNull; - -import com.mapbox.mapboxsdk.geometry.LatLng; - -/** - * Abstract builder class for composing custom MarkerView objects. - * <p> - * Extending this class requires implementing Parceable interface. - * </p> - * - * @param <U> Type of the marker view to be composed. - * @param <T> Type of the builder to be used for composing. - * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android - * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java - */ -@Deprecated -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; - - /** - * 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 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 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 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 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 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(); - } - - /** - * 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 geographical location of the {@link MarkerView}. - * - * @return the geographical location. - */ - public LatLng getPosition() { - return position; - } - - /** - * Get the snippet of the {@link MarkerView}. - * - * @return the snippet. - */ - public String getSnippet() { - return snippet; - } - - /** - * Get the title of the {@link MarkerView}. - * - * @return the title. - */ - public String getTitle() { - return title; - } - - /** - * Get the icon of the {@link MarkerView}. - * - * @return the icon. - */ - public Icon getIcon() { - return icon; - } - - /** - * Get the flat state of the {@link MarkerView}. - * - * @return the flat state. - */ - public boolean isFlat() { - return flat; - } - - /** - * Get the u-value of the {@link MarkerView} anchor. - * - * @return the u-value. - */ - public float getAnchorU() { - return anchorU; - } - - /** - * Get the v-value of the {@link MarkerView} anchor. - * - * @return the v-value. - */ - public float getAnchorV() { - return anchorV; - } - - /** - * Get the u-value of the MarkerView InfoWindow anchor. - * - * @return the u-value. - */ - public float getInfoWindowAnchorU() { - return infoWindowAnchorU; - } - - /** - * Get the v-value of the MarkerView InfoWindow anchor. - * - * @return the v-value. - */ - public float getInfoWindowAnchorV() { - return infoWindowAnchorV; - } - - /** - * Get the rotation of the MarkerView. - * - * @return the rotation value. - */ - public float getRotation() { - return rotation; - } - - /** - * 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 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/IconFactory.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/IconFactory.java index 61d4a877c2..b038f01c23 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 @@ -25,7 +25,7 @@ import java.io.InputStream; /** * Factory for creating Icons from bitmap images. * <p> - * icon is used to display bitmaps on top of the map using {@link Marker} and {@link MarkerView}. + * icon is used to display bitmaps on top of the map using {@link Marker}. * </p> * * @see Icon @@ -33,14 +33,11 @@ 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 context; @SuppressLint("StaticFieldLeak") private static IconFactory instance; private Icon defaultMarker; - private Icon defaultMarkerView; private BitmapFactory.Options options; private int nextId = 0; @@ -121,18 +118,6 @@ public final class IconFactory { return defaultMarker; } - /** - * Provides an icon using the default marker icon used for {@link MarkerView}. - * - * @return An icon with the default {@link MarkerView} icon. - */ - public Icon defaultMarkerView() { - if (defaultMarkerView == null) { - defaultMarkerView = fromResource(R.drawable.mapbox_markerview_icon_default); - } - return defaultMarkerView; - } - private Icon fromInputStream(@NonNull InputStream is) { Bitmap bitmap = BitmapFactory.decodeStream(is, null, options); return fromBitmap(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 66cd934d8d..e6c99a14c4 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 @@ -21,15 +21,14 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; import java.lang.ref.WeakReference; /** - * {@code InfoWindow} is a tooltip shown when a {@link Marker} or {@link MarkerView} is tapped. Only + * {@code InfoWindow} is a tooltip shown when a {@link Marker} is tapped. Only * one info window is displayed at a time. When the user clicks on a marker, the currently open info * window will be closed and the new info window will be displayed. If the user clicks the same * marker while its info window is currently open, the info window will be closed. * <p> * The info window is drawn oriented against the device's screen, centered above its associated - * marker by default. The info window anchoring can be adjusted using - * {@link MarkerView#setInfoWindowAnchor(float, float)} for {@link MarkerView}. The default info - * window contains the title in bold and snippet text below the title. While either the title and + * marker by default. The default info window contains the title in bold and snippet text below the title. + * While either the title and * snippet are optional, at least one is required to open the info window. * </p> */ 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 a99a7d08da..4ff56e1165 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 @@ -17,10 +17,6 @@ import com.mapbox.mapboxsdk.maps.MapboxMap; * {@link LatLng} and using {@link MapboxMap#addMarker(MarkerOptions)}. The marker icon will be * centered at this position so it is common to add padding to the icon image before usage. * <p> - * If more customization is needed, we offer {@link MarkerView} which places a {@link View} on top - * of the map at a geographical location. - * </p> - * <p> * Markers are designed to be interactive. They receive click events by default, and are often used * with event listeners to bring up info windows. An {@link InfoWindow} is displayed by default when * either a title or snippet is provided. @@ -62,11 +58,6 @@ public class Marker extends Annotation { this(baseMarkerOptions.position, baseMarkerOptions.icon, baseMarkerOptions.title, baseMarkerOptions.snippet); } - Marker(BaseMarkerViewOptions baseMarkerViewOptions) { - this(baseMarkerViewOptions.position, baseMarkerViewOptions.icon, - baseMarkerViewOptions.title, baseMarkerViewOptions.snippet); - } - Marker(LatLng position, Icon icon, String title, String snippet) { this.position = position; this.title = title; 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 deleted file mode 100644 index 9021ffbab4..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerView.java +++ /dev/null @@ -1,419 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.support.annotation.FloatRange; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; - -import com.mapbox.mapboxsdk.Mapbox; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.maps.MapboxMap; - -/** - * MarkerView is an annotation that shows a {@link android.view.View} at a geographical location. The - * default marker uses a provided icon. This icon can be customized using {@link IconFactory} to - * generate an {@link Icon} using a provided image. MarkerViews are added to the map by first giving - * a {@link LatLng} and using {@link MapboxMap#addMarker(BaseMarkerViewOptions)}. The marker view icon - * by default is anchored at the center bottom. - * <p> - * If many markers are needed to be displayed on the map at once we suggest using {@link Marker} - * instead. This class uses {@link com.mapbox.mapboxsdk.maps.MapboxMap.MarkerViewAdapter} to adapt a - * MarkerView model to an Android SDK {@link android.view.View} object. - * </p> - * <p> - * MarkerViews are designed to be interactive. They receive click events by default, and are often - * used with event listeners to bring up info windows. An {@link InfoWindow} is displayed by default - * when either a title or snippet is provided. - * </p> - * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android - * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java - */ -@Deprecated -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(@NonNull 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) { - this.rotation = rotation; - if (markerViewManager != null) { - markerViewManager.setRotation(this, rotation); - } - } - - /** - * 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.setWaitingForRenderInvoke(true); - 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() { - if (markerViewIcon == null) { - setIcon(IconFactory.getInstance(Mapbox.getApplicationContext()).defaultMarkerView()); - } - 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(@Nullable 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(); - } - } - - /** - * Invalidates the MarkerView resulting in remeasuring the View. - */ - void invalidate() { - width = height = 0; - offsetX = offsetY = MapboxConstants.UNMEASURED; - markerViewManager.invalidateViewMarkersInVisibleRegion(); - } - - /** - * Get the String representation of a MarkerView. - * - * @return the String representation. - */ - @NonNull - @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 deleted file mode 100644 index cd32fac942..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java +++ /dev/null @@ -1,687 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.content.Context; -import android.graphics.PointF; -import android.graphics.RectF; -import android.os.SystemClock; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.util.LongSparseArray; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.widget.ImageView; - -import com.mapbox.mapboxsdk.R; -import com.mapbox.mapboxsdk.constants.MapboxConstants; -import com.mapbox.mapboxsdk.maps.MapView; -import com.mapbox.mapboxsdk.maps.MapboxMap; -import com.mapbox.mapboxsdk.utils.AnimatorUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Interface for interacting with ViewMarkers objects inside of a MapView. - * <p> - * This class is responsible for managing a {@link MarkerView} item. - * </p> - * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android - * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java - */ -@Deprecated -public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListener { - - @NonNull - private final ViewGroup markerViewContainer; - private final ViewTreeObserver.OnPreDrawListener markerViewPreDrawObserver = - new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - invalidateViewMarkersInVisibleRegion(); - markerViewContainer.getViewTreeObserver().removeOnPreDrawListener(markerViewPreDrawObserver); - return false; - } - }; - 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 boolean enabled; - private long updateTime; - @Nullable - 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 onDidFinishRenderingFrame(boolean fully) { - if (isWaitingForRenderInvoke && fully) { - isWaitingForRenderInvoke = false; - invalidateViewMarkersInVisibleRegion(); - } - } - - /** - * Called to enable or disable MarkerView management. - * - * @param enabled true if management should be enabled - */ - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - /** - * Called with true to wait for the next render invocation. - * - * @param waitingForRenderInvoke true if waiting for next render event - */ - 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); - } - } - - /** - * 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); - } - } - - /** - * Set the rotation of a MarkerView to a given rotation value. - * - * @param marker The MarkerView to change its rotation value - * @param rotation The rotation value - */ - public void setRotation(@NonNull MarkerView marker, float rotation) { - View convertView = markerViewMap.get(marker); - if (convertView != null) { - convertView.animate().cancel(); - convertView.setRotation(rotation); - } - } - - /** - * 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 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); - } - } - - /** - * 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 updateMarkerViewsPosition() { - 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 - // #6805 invalidate marker views to ensure convertView width and height - // values are properly measured and up to date - if (marker.getWidth() == 0 && marker.isVisible()) { - convertView.getViewTreeObserver().addOnPreDrawListener(markerViewPreDrawObserver); - } - } - - marker.setWidth(convertView.getWidth()); - marker.setHeight(convertView.getHeight()); - - 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); - } - } - } - } - - /** - * 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); - } - } - } - } - - /** - * 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()); - markerView.invalidate(); - } - } - - /** - * 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); - } - } - } - if (callbackToMap) { - mapboxMap.deselectMarker(marker); - } - 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 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, @NonNull 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, @Nullable View convertView, - @NonNull MapboxMap.MarkerViewAdapter adapter, boolean callbackToMap) { - if (convertView != null) { - if (adapter.onSelect(marker, convertView, false)) { - if (callbackToMap) { - mapboxMap.selectMarker(marker); - } - } - marker.setSelected(true); - convertView.bringToFront(); - } - } - - /** - * 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(@NonNull MarkerView markerView) { - MapboxMap.MarkerViewAdapter adapter = null; - for (MapboxMap.MarkerViewAdapter a : markerViewAdapters) { - if (a.getMarkerClass().equals(markerView.getClass())) { - adapter = a; - } - } - 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(@Nullable 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); - } - } - } - } - 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(@NonNull 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(); - } - } - - /** - * Get all MarkerViewAdapters associated with this MarkerViewManager. - * - * @return a List of MarkerViewAdapters. - */ - @NonNull - 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 update() { - if (enabled) { - long currentTime = SystemClock.elapsedRealtime(); - if (currentTime < updateTime) { - updateMarkerViewsPosition(); - return; - } - invalidateViewMarkersInVisibleRegion(); - updateTime = currentTime + 250; - } - } - - /** - * 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); - 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()); - } - } - } - } - } - - // 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. - updateMarkerViewsPosition(); - } - - /** - * When the provided MarkerView is clicked on by a user, we check if a custom click - * event has been created and if not, display a InfoWindow. - * - * @param markerView that the click event occurred - * @return true if the marker view click has been handled, false if not - */ - public boolean onClickMarkerView(@NonNull 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 (onMarkerViewClickListener != null) { - clickHandled = onMarkerViewClickListener.onMarkerClick(markerView, view, adapter); - } - - return clickHandled; - } - - /** - * Handles the MarkerView info window offset. - * - * @param marker that we are ensuring info window offset - */ - public void ensureInfoWindowOffset(@NonNull 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; - } - } - } - - 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()); - } - - // 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); - } - } - - @NonNull - public ViewGroup getMarkerViewContainer() { - return markerViewContainer; - } - - public void addOnMarkerViewAddedListener(@NonNull MarkerView markerView, - OnMarkerViewAddedListener onMarkerViewAddedListener) { - markerViewAddedListenerMap.put(markerView.getId(), onMarkerViewAddedListener); - } - - /** - * Default MarkerViewAdapter used for base class of MarkerView to adapt a MarkerView to - * an ImageView. - */ - private static class ImageMarkerViewAdapter extends MapboxMap.MarkerViewAdapter<MarkerView> { - - private LayoutInflater inflater; - - ImageMarkerViewAdapter(Context context) { - super(context, MarkerView.class); - 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()); - viewHolder.imageView.setContentDescription(marker.getTitle()); - return convertView; - } - - 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 { - - /** - * 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); - } -} 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 deleted file mode 100644 index af56f126e3..0000000000 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewOptions.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.mapbox.mapboxsdk.annotations; - -import android.graphics.Bitmap; -import android.os.Parcel; -import android.os.Parcelable; - -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException; -import com.mapbox.mapboxsdk.geometry.LatLng; - -/** - * builder class for composing MarkerView objects. - * <p> - * Do not extend this class directly but extend {@link BaseMarkerViewOptions} instead. - * </p> - * @deprecated Use a {@link com.mapbox.mapboxsdk.style.layers.SymbolLayer} instead. An example of converting Android - * SDK views to be used as a symbol see https://github.com/mapbox/mapbox-gl-native/blob/68f32bc104422207c64da8d90e8411b138d87f04/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/style/SymbolGeneratorActivity.java - */ -@Deprecated -public class MarkerViewOptions extends BaseMarkerViewOptions<MarkerView, MarkerViewOptions> { - - private MarkerView marker; - - /** - * 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); - } - } - - /** - * Get the instance of the object for which this method was called. - * - * @return the object for which this method was called. - */ - @NonNull - @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; - } - - /** - * 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(@NonNull 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; - } - - public static final Parcelable.Creator<MarkerViewOptions> CREATOR = - new Parcelable.Creator<MarkerViewOptions>() { - public MarkerViewOptions createFromParcel(@NonNull 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 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(@Nullable Object object) { - if (this == object) { - return true; - } - 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; - } -} |