diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
15 files changed, 34 insertions, 2093 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; - } -} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java index 958ceb352c..8875e7164b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java @@ -12,10 +12,7 @@ import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerView; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.Polyline; @@ -29,7 +26,7 @@ import java.util.List; * Responsible for managing and tracking state of Annotations linked to Map. All events related to * annotations that occur on {@link MapboxMap} are forwarded to this class. * <p> - * Responsible for referencing {@link InfoWindowManager} and {@link MarkerViewManager}. + * Responsible for referencing {@link InfoWindowManager}. * </p> * <p> * Exposes convenience methods to add/remove/update all subtypes of annotations found in @@ -42,11 +39,10 @@ class AnnotationManager { private static final long NO_ANNOTATION_ID = -1; - @Nullable + @NonNull private final MapView mapView; private final IconManager iconManager; private final InfoWindowManager infoWindowManager = new InfoWindowManager(); - private final MarkerViewManager markerViewManager; private final LongSparseArray<Annotation> annotationsArray; private final List<Marker> selectedMarkers = new ArrayList<>(); @@ -64,22 +60,17 @@ class AnnotationManager { private Polygons polygons; private Polylines polylines; - AnnotationManager(@Nullable MapView mapView, LongSparseArray<Annotation> annotationsArray, - MarkerViewManager markerViewManager, IconManager iconManager, Annotations annotations, - Markers markers, Polygons polygons, Polylines polylines, ShapeAnnotations shapeAnnotations) { + AnnotationManager(@NonNull MapView mapView, LongSparseArray<Annotation> annotationsArray, + IconManager iconManager, Annotations annotations, Markers markers, Polygons polygons, + Polylines polylines, ShapeAnnotations shapeAnnotations) { this.mapView = mapView; this.annotationsArray = annotationsArray; - this.markerViewManager = markerViewManager; this.iconManager = iconManager; this.annotations = annotations; this.markers = markers; this.polygons = polygons; this.polylines = polylines; this.shapeAnnotations = shapeAnnotations; - if (mapView != null) { - // null checking needed for unit tests - mapView.addOnDidFinishRenderingFrameListener(markerViewManager); - } } // TODO refactor MapboxMap out for Projection and Transform @@ -87,12 +78,10 @@ class AnnotationManager { @NonNull AnnotationManager bind(MapboxMap mapboxMap) { this.mapboxMap = mapboxMap; - this.markerViewManager.bind(mapboxMap); return this; } void update() { - markerViewManager.update(); infoWindowManager.update(); } @@ -119,13 +108,8 @@ class AnnotationManager { if (selectedMarkers.contains(marker)) { selectedMarkers.remove(marker); } - - if (marker instanceof MarkerView) { - markerViewManager.removeMarkerView((MarkerView) marker); - } else { - // do icon cleanup - iconManager.iconCleanup(marker.getIcon()); - } + // do icon cleanup + iconManager.iconCleanup(marker.getIcon()); } annotations.removeBy(annotation); } @@ -138,12 +122,7 @@ class AnnotationManager { if (selectedMarkers.contains(marker)) { selectedMarkers.remove(marker); } - - if (marker instanceof MarkerView) { - markerViewManager.removeMarkerView((MarkerView) marker); - } else { - iconManager.iconCleanup(marker.getIcon()); - } + iconManager.iconCleanup(marker.getIcon()); } } annotations.removeBy(annotationList); @@ -160,11 +139,7 @@ class AnnotationManager { if (annotation instanceof Marker) { Marker marker = (Marker) annotation; marker.hideInfoWindow(); - if (marker instanceof MarkerView) { - markerViewManager.removeMarkerView((MarkerView) marker); - } else { - iconManager.iconCleanup(marker.getIcon()); - } + iconManager.iconCleanup(marker.getIcon()); } } annotations.removeAll(); @@ -199,20 +174,6 @@ class AnnotationManager { return markers.obtainAllIn(rectangle); } - MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap, - @Nullable MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) { - return markers.addViewBy(markerOptions, mapboxMap, onMarkerViewAddedListener); - } - - List<MarkerView> addMarkerViews(@NonNull List<? extends BaseMarkerViewOptions> markerViewOptions, - @NonNull MapboxMap mapboxMap) { - return markers.addViewsBy(markerViewOptions, mapboxMap); - } - - List<MarkerView> getMarkerViewsInRect(@NonNull RectF rectangle) { - return markers.obtainViewsIn(rectangle); - } - void reloadMarkers() { markers.reload(); } @@ -288,11 +249,6 @@ class AnnotationManager { deselectMarkers(); } - if (marker instanceof MarkerView) { - markerViewManager.select((MarkerView) marker, false); - markerViewManager.ensureInfoWindowOffset((MarkerView) marker); - } - if (infoWindowManager.isInfoWindowValidForMarker(marker) || infoWindowManager.getInfoWindowAdapter() != null) { infoWindowManager.add(marker.showInfoWindow(mapboxMap, mapView)); } @@ -311,10 +267,6 @@ class AnnotationManager { if (marker.isInfoWindowShown()) { marker.hideInfoWindow(); } - - if (marker instanceof MarkerView) { - markerViewManager.deselect((MarkerView) marker, false); - } } } @@ -330,11 +282,6 @@ class AnnotationManager { if (marker.isInfoWindowShown()) { marker.hideInfoWindow(); } - - if (marker instanceof MarkerView) { - markerViewManager.deselect((MarkerView) marker, false); - } - selectedMarkers.remove(marker); } @@ -348,10 +295,6 @@ class AnnotationManager { return infoWindowManager; } - MarkerViewManager getMarkerViewManager() { - return markerViewManager; - } - void adjustTopOffsetPixels(@NonNull MapboxMap mapboxMap) { int count = annotationsArray.size(); for (int i = 0; i < count; i++) { @@ -433,14 +376,8 @@ class AnnotationManager { } private boolean isClickHandledForMarker(long markerId) { - boolean handledDefaultClick; Marker marker = (Marker) getAnnotation(markerId); - if (marker instanceof MarkerView) { - handledDefaultClick = markerViewManager.onClickMarkerView((MarkerView) marker); - } else { - handledDefaultClick = onClickMarker(marker); - } - + boolean handledDefaultClick = onClickMarker(marker); if (!handledDefaultClick) { toggleMarkerSelectionState(marker); } @@ -481,13 +418,12 @@ class AnnotationManager { private static class MarkerHitResolver { @NonNull - private final MarkerViewManager markerViewManager; - @NonNull private final Projection projection; private final int minimalTouchSize; @Nullable private View view; + private Bitmap bitmap; private int bitmapWidth; private int bitmapHeight; @@ -503,7 +439,6 @@ class AnnotationManager { private long closestMarkerId = NO_ANNOTATION_ID; MarkerHitResolver(@NonNull MapboxMap mapboxMap) { - this.markerViewManager = mapboxMap.getMarkerViewManager(); this.projection = mapboxMap.getProjection(); this.minimalTouchSize = (int) (32 * Mapbox.getApplicationContext().getResources().getDisplayMetrics().density); } @@ -515,20 +450,7 @@ class AnnotationManager { private void resolveForMarkers(MarkerHit markerHit) { for (Marker marker : markerHit.markers) { - if (marker instanceof MarkerView) { - resolveForMarkerView(markerHit, (MarkerView) marker); - } else { - resolveForMarker(markerHit, marker); - } - } - } - - private void resolveForMarkerView(@NonNull MarkerHit markerHit, @NonNull MarkerView markerView) { - view = markerViewManager.getView(markerView); - if (view != null) { - view.getHitRect(hitRectView); - hitRectMarker = new RectF(hitRectView); - hitTestMarker(markerHit, markerView, hitRectMarker); + resolveForMarker(markerHit, marker); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java index 7aca93fe2e..28f594c62e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/IconManager.java @@ -7,7 +7,6 @@ import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.annotations.Icon; import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerView; import java.util.HashMap; import java.util.List; @@ -16,8 +15,7 @@ import java.util.Map; /** * Responsible for managing icons added to the Map. * <p> - * Maintains a {@link List} of {@link Icon} and is responsible for initialising default markers and - * setting up {@link MarkerView} annotation ghosting. + * Maintains a {@link List} of {@link Icon} and is responsible for initialising default markers. * </p> * <p> * Keep track of icons added and the resulting average icon size. This is used internally by our @@ -34,15 +32,12 @@ class IconManager { IconManager(NativeMapView nativeMapView) { this.nativeMapView = nativeMapView; - // load transparent icon for MarkerView to trace actual markers, see #6352 - loadIcon(IconFactory.recreate(IconFactory.ICON_MARKERVIEW_ID, IconFactory.ICON_MARKERVIEW_BITMAP)); } Icon loadIconForMarker(@NonNull Marker marker) { Icon icon = marker.getIcon(); if (icon == null) { // TODO replace with anchor implementation, we are faking an anchor by adding extra pixels and diving height by 2 - // TODO we can move this code afterwards to getIcon as with MarkerView.getIcon icon = loadDefaultIconForMarker(marker); } else { updateHighestIconSize(icon); @@ -51,13 +46,6 @@ class IconManager { return icon; } - void loadIconForMarkerView(@NonNull MarkerView marker) { - Icon icon = marker.getIcon(); - Bitmap bitmap = icon.getBitmap(); - updateHighestIconSize(bitmap); - addIcon(icon, false); - } - int getTopOffsetPixelsForIcon(@NonNull Icon icon) { return (int) (nativeMapView.getTopOffsetPixelsForAnnotationSymbol(icon.getId()) * nativeMapView.getPixelRatio()); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 8d1592046f..676fd25505 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -15,7 +15,6 @@ import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.TextureView; import android.view.View; -import android.view.ViewGroup; import android.view.KeyEvent; import android.view.MotionEvent; import android.widget.FrameLayout; @@ -25,7 +24,6 @@ import com.mapbox.mapboxsdk.MapStrictMode; import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; @@ -157,17 +155,15 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { Projection proj = new Projection(nativeMapView); UiSettings uiSettings = new UiSettings(proj, focalInvalidator, compassView, attrView, logoView, getPixelRatio()); LongSparseArray<Annotation> annotationsArray = new LongSparseArray<>(); - MarkerViewManager markerViewManager = new MarkerViewManager((ViewGroup) findViewById(R.id.markerViewContainer)); IconManager iconManager = new IconManager(nativeMapView); Annotations annotations = new AnnotationContainer(nativeMapView, annotationsArray); - Markers markers = new MarkerContainer(nativeMapView, this, annotationsArray, iconManager, markerViewManager); + Markers markers = new MarkerContainer(nativeMapView, annotationsArray, iconManager); Polygons polygons = new PolygonContainer(nativeMapView, annotationsArray); Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray); ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray); - AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, - markerViewManager, iconManager, annotations, markers, polygons, polylines, shapeAnnotations); - Transform transform = new Transform(this, nativeMapView, annotationManager.getMarkerViewManager(), - cameraChangeDispatcher); + AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager, + annotations, markers, polygons, polylines, shapeAnnotations); + Transform transform = new Transform(this, nativeMapView, cameraChangeDispatcher); // MapboxMap mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, @@ -1159,7 +1155,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { // Style has loaded before the drawing surface has been initialized, delivering OnMapReady mapboxMap.onPreMapReady(); onMapReady(); - mapboxMap.onPostMapReady(); } } @@ -1212,7 +1207,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { initialLoad = false; mapboxMap.onPreMapReady(); onMapReady(); - mapboxMap.onPostMapReady(); } else { mapboxMap.onFinishLoadingStyle(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index f986d9d96c..58fc66407f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -11,10 +11,8 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.Size; import android.support.annotation.UiThread; -import android.support.v4.util.Pools; import android.text.TextUtils; import android.view.View; -import android.view.ViewGroup; import com.mapbox.android.gestures.AndroidGesturesManager; import com.mapbox.android.gestures.MoveGestureDetector; @@ -26,11 +24,8 @@ import com.mapbox.geojson.Geometry; import com.mapbox.mapboxsdk.MapStrictMode; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; -import com.mapbox.mapboxsdk.annotations.MarkerView; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import com.mapbox.mapboxsdk.annotations.Polygon; import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.Polyline; @@ -172,23 +167,12 @@ public final class MapboxMap { * Called before the OnMapReadyCallback is invoked. */ void onPreMapReady() { - invalidateCameraPosition(); + transform.invalidateCameraPosition(); annotationManager.reloadMarkers(); annotationManager.adjustTopOffsetPixels(this); } /** - * Called when the OnMapReadyCallback has finished executing. - * <p> - * Invalidation of the camera position is required to update the added components in - * OnMapReadyCallback with the correct transformation. - * </p> - */ - void onPostMapReady() { - invalidateCameraPosition(); - } - - /** * Called when the map will start loading style. */ void onStartLoadingMap() { @@ -858,16 +842,6 @@ public final class MapboxMap { } /** - * Invalidates the current camera position by reconstructing it from mbgl - */ - private void invalidateCameraPosition() { - CameraPosition cameraPosition = transform.invalidateCameraPosition(); - if (cameraPosition != null) { - transform.updateCameraPosition(cameraPosition); - } - } - - /** * Scrolls the camera over the map, shifting the center of view by the specified number of pixels in the x and y * directions. * @@ -1187,85 +1161,6 @@ public final class MapboxMap { /** * <p> - * Adds a marker to this map. - * </p> - * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * - * @param markerOptions A marker options object that defines how to render the marker - * @return The {@code Marker} that was added to the map - * @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 - */ - @NonNull - @Deprecated - public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions) { - return annotationManager.addMarker(markerOptions, this, null); - } - - /** - * <p> - * Adds a marker to this map. - * </p> - * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * - * @param markerOptions A marker options object that defines how to render the marker - * @param onMarkerViewAddedListener Callback invoked when the View has been added to the map - * @return The {@code Marker} that was added to the map - * @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 - @NonNull - public MarkerView addMarker(@NonNull BaseMarkerViewOptions markerOptions, - final MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) { - return annotationManager.addMarker(markerOptions, this, onMarkerViewAddedListener); - } - - /** - * Adds multiple markersViews to this map. - * <p> - * The marker's icon is rendered on the map at the location {@code Marker.position}. - * If {@code Marker.title} is defined, the map shows an info box with the marker's title and snippet. - * </p> - * - * @param markerViewOptions A list of markerView options objects that defines how to render the markers - * @return A list of the {@code MarkerView}s that were added to the map - * @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 - */ - @NonNull - @Deprecated - public List<MarkerView> addMarkerViews(@NonNull List<? extends - BaseMarkerViewOptions> markerViewOptions) { - return annotationManager.addMarkerViews(markerViewOptions, this); - } - - /** - * Returns markerViews found inside of a rectangle on this map. - * - * @param rect the rectangular area on the map to query for markerViews - * @return A list of the markerViews that were found in the rectangle - * @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 - */ - @NonNull - @Deprecated - public List<MarkerView> getMarkerViewsInRect(@NonNull RectF rect) { - return annotationManager.getMarkerViewsInRect(rect); - } - - /** - * <p> * Adds multiple markers to this map. * </p> * The marker's icon is rendered on the map at the location {@code Marker.position}. @@ -1559,16 +1454,6 @@ public final class MapboxMap { return annotationManager.getSelectedMarkers(); } - /** - * Get the MarkerViewManager associated to the MapView. - * - * @return the associated MarkerViewManager - */ - @NonNull - public MarkerViewManager getMarkerViewManager() { - return annotationManager.getMarkerViewManager(); - } - // // InfoWindow // @@ -2544,145 +2429,6 @@ public final class MapboxMap { } /** - * Interface definition for a callback to be invoked when an MarkerView will be shown. - * - * @param <U> the instance type of MarkerView - * @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 static class MarkerViewAdapter<U extends MarkerView> { - - private Context context; - private final Class<U> persistentClass; - @NonNull - private final Pools.SimplePool<View> viewReusePool; - - /** - * Create an instance of MarkerViewAdapter. - * - * @param context the context associated to a MapView - */ - public MarkerViewAdapter(Context context, Class<U> persistentClass) { - this.context = context; - this.persistentClass = persistentClass; - viewReusePool = new Pools.SimplePool<>(10000); - } - - /** - * Called when an MarkerView will be added to the MapView. - * - * @param marker the model representing the MarkerView - * @param convertView the reusable view - * @param parent the parent ViewGroup of the convertview - * @return the View that is adapted to the contents of MarkerView - */ - @Nullable - public abstract View getView(@NonNull U marker, @Nullable View convertView, @NonNull ViewGroup parent); - - /** - * Called when an MarkerView is removed from the MapView or the View object is going to be reused. - * <p> - * This method should be used to reset an animated view back to it's original state for view reuse. - * </p> - * <p> - * Returning true indicates you want to the view reuse to be handled automatically. - * Returning false indicates you want to perform an animation and you are required calling - * {@link #releaseView(View)} yourself. - * </p> - * - * @param marker the model representing the MarkerView - * @param convertView the reusable view - * @return true if you want reuse to occur automatically, false if you want to manage this yourself. - */ - public boolean prepareViewForReuse(@NonNull MarkerView marker, @NonNull View convertView) { - return true; - } - - /** - * Called when a MarkerView is selected from the MapView. - * <p> - * Returning true from this method indicates you want to move the MarkerView to the selected state. - * Returning false indicates you want to animate the View first an manually select the MarkerView when appropriate. - * </p> - * - * @param marker the model representing the MarkerView - * @param convertView the reusable view - * @param reselectionFromRecycling indicates if the onSelect callback is the initial selection - * callback or that selection occurs due to recreation of selected marker - * @return true if you want to select the Marker immediately, false if you want to manage this yourself. - */ - public boolean onSelect(@NonNull U marker, @NonNull View convertView, boolean reselectionFromRecycling) { - return true; - } - - /** - * Called when a MarkerView is deselected from the MapView. - * - * @param marker the model representing the MarkerView - * @param convertView the reusable view - */ - public void onDeselect(@NonNull U marker, @NonNull View convertView) { - } - - /** - * Returns the generic type of the used MarkerView. - * - * @return the generic type - */ - public final Class<U> getMarkerClass() { - return persistentClass; - } - - /** - * Returns the pool used to store reusable Views. - * - * @return the pool associated to this adapter - */ - @NonNull - public final Pools.SimplePool<View> getViewReusePool() { - return viewReusePool; - } - - /** - * Returns the context associated to the hosting MapView. - * - * @return the context used - */ - public final Context getContext() { - return context; - } - - /** - * Release a View to the ViewPool. - * - * @param view the view to be released - */ - public final void releaseView(View view) { - view.setVisibility(View.GONE); - viewReusePool.release(view); - } - } - - /** - * Interface definition for a callback to be invoked when the user clicks on a MarkerView. - */ - public interface OnMarkerViewClickListener { - - /** - * Called when the user clicks on a MarkerView. - * - * @param marker the MarkerView associated to the clicked View - * @param view the clicked View - * @param adapter the adapter used to adapt the MarkerView to the View - * @return If true the listener has consumed the event and the info window will not be shown - */ - boolean onMarkerClick(@NonNull Marker marker, @NonNull View view, @NonNull MarkerViewAdapter adapter); - } - - /** * Interface definition for a callback to be invoked when a task is complete or cancelled. */ public interface CancelableCallback { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java index 8b9ff78aa3..26ac74904a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MarkerContainer.java @@ -1,19 +1,13 @@ package com.mapbox.mapboxsdk.maps; - import android.graphics.RectF; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import android.support.v4.util.LongSparseArray; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; import com.mapbox.mapboxsdk.annotations.Icon; -import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerView; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import java.util.ArrayList; import java.util.List; @@ -24,18 +18,13 @@ import java.util.List; class MarkerContainer implements Markers { private final NativeMapView nativeMapView; - private final MapView mapView; private final LongSparseArray<Annotation> annotations; private final IconManager iconManager; - private final MarkerViewManager markerViewManager; - MarkerContainer(NativeMapView nativeMapView, MapView mapView, LongSparseArray<Annotation> annotations, IconManager - iconManager, MarkerViewManager markerViewManager) { + MarkerContainer(NativeMapView nativeMapView, LongSparseArray<Annotation> annotations, IconManager iconManager) { this.nativeMapView = nativeMapView; - this.mapView = mapView; this.annotations = annotations; this.iconManager = iconManager; - this.markerViewManager = markerViewManager; } @Override @@ -121,78 +110,6 @@ class MarkerContainer implements Markers { } @Override - public MarkerView addViewBy(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap, @Nullable - MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener) { - final MarkerView marker = prepareViewMarker(markerOptions); - - // add marker to map - marker.setMapboxMap(mapboxMap); - long id = nativeMapView.addMarker(marker); - marker.setId(id); - annotations.put(id, marker); - - if (onMarkerViewAddedListener != null) { - markerViewManager.addOnMarkerViewAddedListener(marker, onMarkerViewAddedListener); - } - markerViewManager.setEnabled(true); - markerViewManager.setWaitingForRenderInvoke(true); - return marker; - } - - @NonNull - @Override - public List<MarkerView> addViewsBy(@NonNull List<? extends BaseMarkerViewOptions> markerViewOptions, @NonNull - MapboxMap mapboxMap) { - List<MarkerView> markers = new ArrayList<>(); - for (BaseMarkerViewOptions markerViewOption : markerViewOptions) { - // if last marker - if (markerViewOptions.indexOf(markerViewOption) == markerViewOptions.size() - 1) { - // get notified when render occurs to invalidate and draw MarkerViews - markerViewManager.setWaitingForRenderInvoke(true); - } - // add marker to map - MarkerView marker = prepareViewMarker(markerViewOption); - marker.setMapboxMap(mapboxMap); - long id = nativeMapView.addMarker(marker); - marker.setId(id); - annotations.put(id, marker); - markers.add(marker); - } - markerViewManager.setEnabled(true); - markerViewManager.update(); - return markers; - } - - @NonNull - @Override - public List<MarkerView> obtainViewsIn(@NonNull RectF rectangle) { - float pixelRatio = nativeMapView.getPixelRatio(); - RectF rect = new RectF(rectangle.left / pixelRatio, - rectangle.top / pixelRatio, - rectangle.right / pixelRatio, - rectangle.bottom / pixelRatio); - - long[] ids = nativeMapView.queryPointAnnotations(rect); - - List<Long> idsList = new ArrayList<>(ids.length); - for (long id : ids) { - idsList.add(id); - } - - List<MarkerView> annotations = new ArrayList<>(ids.length); - List<Annotation> annotationList = obtainAnnotations(); - int count = annotationList.size(); - for (int i = 0; i < count; i++) { - Annotation annotation = annotationList.get(i); - if (annotation instanceof MarkerView && idsList.contains(annotation.getId())) { - annotations.add((MarkerView) annotation); - } - } - - return new ArrayList<>(annotations); - } - - @Override public void reload() { iconManager.reloadIcons(); int count = annotations.size(); @@ -215,9 +132,7 @@ class MarkerContainer implements Markers { } private void ensureIconLoaded(Marker marker, @NonNull MapboxMap mapboxMap) { - if (!(marker instanceof MarkerView)) { - iconManager.ensureIconLoaded(marker, mapboxMap); - } + iconManager.ensureIconLoaded(marker, mapboxMap); } @NonNull @@ -228,15 +143,4 @@ class MarkerContainer implements Markers { } return annotations; } - - private MarkerView prepareViewMarker(BaseMarkerViewOptions markerViewOptions) { - MarkerView marker = markerViewOptions.getMarker(); - Icon icon = markerViewOptions.getIcon(); - if (icon == null) { - icon = IconFactory.getInstance(mapView.getContext()).defaultMarkerView(); - } - iconManager.loadIconForMarkerView(marker); - marker.setIcon(icon); - return marker; - } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java index d85f388d09..62859d58a8 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Markers.java @@ -1,15 +1,10 @@ package com.mapbox.mapboxsdk.maps; - import android.graphics.RectF; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions; -import com.mapbox.mapboxsdk.annotations.BaseMarkerViewOptions; import com.mapbox.mapboxsdk.annotations.Marker; -import com.mapbox.mapboxsdk.annotations.MarkerView; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import java.util.List; @@ -28,13 +23,5 @@ interface Markers { @NonNull List<Marker> obtainAllIn(@NonNull RectF rectangle); - MarkerView addViewBy(@NonNull BaseMarkerViewOptions markerOptions, @NonNull MapboxMap mapboxMap, - @Nullable MarkerViewManager.OnMarkerViewAddedListener onMarkerViewAddedListener); - - List<MarkerView> addViewsBy(@NonNull List<? extends BaseMarkerViewOptions> markerViewOptions, - @NonNull MapboxMap mapboxMap); - - List<MarkerView> obtainViewsIn(@NonNull RectF rectangle); - void reload(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index 457353d4b9..0ba40642f5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -5,7 +5,6 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.UiThread; -import com.mapbox.mapboxsdk.annotations.MarkerViewManager; import com.mapbox.mapboxsdk.camera.CameraPosition; import com.mapbox.mapboxsdk.camera.CameraUpdate; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; @@ -27,14 +26,12 @@ final class Transform implements MapView.OnCameraDidChangeListener { private final NativeMapView nativeMapView; private final MapView mapView; - private final MarkerViewManager markerViewManager; private final Handler handler = new Handler(); @Nullable private CameraPosition cameraPosition; @Nullable private MapboxMap.CancelableCallback cameraCancelableCallback; - private CameraChangeDispatcher cameraChangeDispatcher; private final MapView.OnCameraDidChangeListener moveByChangeListener = new MapView.OnCameraDidChangeListener() { @@ -47,11 +44,9 @@ final class Transform implements MapView.OnCameraDidChangeListener { } }; - Transform(MapView mapView, NativeMapView nativeMapView, MarkerViewManager markerViewManager, - CameraChangeDispatcher cameraChangeDispatcher) { + Transform(MapView mapView, NativeMapView nativeMapView, CameraChangeDispatcher cameraChangeDispatcher) { this.mapView = mapView; this.nativeMapView = nativeMapView; - this.markerViewManager = markerViewManager; this.cameraChangeDispatcher = cameraChangeDispatcher; } @@ -77,15 +72,10 @@ final class Transform implements MapView.OnCameraDidChangeListener { return cameraPosition; } - @UiThread - void updateCameraPosition(@NonNull CameraPosition position) { - markerViewManager.setTilt((float) position.tilt); - } - @Override public void onCameraDidChange(boolean animated) { if (animated) { - updateCameraPosition(invalidateCameraPosition()); + invalidateCameraPosition(); if (cameraCancelableCallback != null) { handler.post(new Runnable() { @Override @@ -170,20 +160,11 @@ final class Transform implements MapView.OnCameraDidChangeListener { cameraChangeDispatcher.onCameraMove(); } - if (isComponentUpdateRequired(cameraPosition)) { - updateCameraPosition(cameraPosition); - } - this.cameraPosition = cameraPosition; } return cameraPosition; } - private boolean isComponentUpdateRequired(@NonNull CameraPosition cameraPosition) { - return this.cameraPosition != null && (this.cameraPosition.tilt != cameraPosition.tilt - || this.cameraPosition.bearing != cameraPosition.bearing); - } - void cancelTransitions() { // notify user about cancel cameraChangeDispatcher.onCameraMoveCanceled(); @@ -279,7 +260,6 @@ final class Transform implements MapView.OnCameraDidChangeListener { } void setTilt(Double pitch) { - markerViewManager.setTilt(pitch.floatValue()); nativeMapView.setPitch(pitch, 0); } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java index 0c529aa464..9617f94fce 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java @@ -5,6 +5,7 @@ import android.support.annotation.CallSuper; import android.support.annotation.Keep; import android.support.annotation.NonNull; +import com.mapbox.mapboxsdk.log.Logger; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.storage.FileSource; @@ -21,6 +22,8 @@ import javax.microedition.khronos.opengles.GL10; @Keep public abstract class MapRenderer implements MapRendererScheduler { + private static final String TAG = "Mbgl-MapRenderer"; + // Holds the pointer to the native peer after initialisation private long nativePtr = 0; @@ -72,8 +75,11 @@ public abstract class MapRenderer implements MapRendererScheduler { @CallSuper protected void onDrawFrame(GL10 gl) { - nativeRender(); - + try { + nativeRender(); + } catch (java.lang.Error error) { + Logger.e(TAG, error.getMessage()); + } if (onFpsChangedListener != null) { updateFps(); } |