diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations')
4 files changed, 52 insertions, 61 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java index 813e489e94..ce6a3ee55f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Annotation.java @@ -2,7 +2,8 @@ package com.mapbox.mapboxsdk.annotations; import android.support.annotation.NonNull; -import com.mapbox.mapboxsdk.views.MapView; +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; /** * Annotation is a overlay on top of a {@link MapView}, @@ -21,7 +22,7 @@ public abstract class Annotation implements Comparable<Annotation> { * Internal C++ id is stored as unsigned int. */ private long id = -1; // -1 unless added to a MapView - private MapView mapView; + private MapboxMap mapboxMap; protected Annotation() { } @@ -38,10 +39,10 @@ public abstract class Annotation implements Comparable<Annotation> { } public void remove() { - if (mapView == null) { + if (mapboxMap == null) { return; } - mapView.removeAnnotation(this); + mapboxMap.removeAnnotation(this); } /** @@ -54,15 +55,12 @@ public abstract class Annotation implements Comparable<Annotation> { /** * Do not use this method. Used internally by the SDK. */ - public void setMapView(MapView mapView) { - this.mapView = mapView; + public void setMapboxMap(MapboxMap mapView) { + this.mapboxMap = mapView; } - protected MapView getMapView() { - if (mapView == null) { - return null; - } - return mapView; + protected MapboxMap getMapboxMap() { + return mapboxMap; } @Override diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java index b9691914e2..e30b81d4c9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/Icon.java @@ -2,8 +2,10 @@ package com.mapbox.mapboxsdk.annotations; import android.graphics.Bitmap; +import com.mapbox.mapboxsdk.maps.MapView; + /** - * Icon is the visual representation of a {@link Marker} on a {@link com.mapbox.mapboxsdk.views.MapView}. + * Icon is the visual representation of a {@link Marker} on a {@link MapView}. * @see Marker */ public final class Icon { 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 696301cf54..e936b7bd23 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 @@ -9,9 +9,10 @@ import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.views.MapView; +import com.mapbox.mapboxsdk.maps.MapView; import java.lang.ref.WeakReference; @@ -26,7 +27,7 @@ import java.lang.ref.WeakReference; public class InfoWindow { private WeakReference<Marker> mBoundMarker; - private WeakReference<MapView> mMapView; + private WeakReference<MapboxMap> mMapboxMap; protected WeakReference<View> mView; private float mMarkerHeightOffset; @@ -37,18 +38,18 @@ public class InfoWindow { @LayoutRes private int mLayoutRes; - InfoWindow(int layoutResId, MapView mapView) { + InfoWindow(MapView mapView, int layoutResId, MapboxMap mapboxMap) { mLayoutRes = layoutResId; View view = LayoutInflater.from(mapView.getContext()).inflate(layoutResId, mapView, false); - initialize(view, mapView); + initialize(view, mapboxMap); } - InfoWindow(View view, MapView mapView) { - initialize(view, mapView); + InfoWindow(View view, MapboxMap mapboxMap) { + initialize(view, mapboxMap); } - private void initialize(View view, MapView mapView) { - mMapView = new WeakReference<>(mapView); + private void initialize(View view, MapboxMap mapboxMap) { + mMapboxMap = new WeakReference<>(mapboxMap); mIsVisible = false; mView = new WeakReference<>(view); @@ -58,8 +59,8 @@ public class InfoWindow { public boolean onTouch(View v, MotionEvent e) { if (e.getAction() == MotionEvent.ACTION_UP) { boolean handledDefaultClick = false; - MapView.OnInfoWindowClickListener onInfoWindowClickListener = - mMapView.get().getOnInfoWindowClickListener(); + MapboxMap.OnInfoWindowClickListener onInfoWindowClickListener = + mMapboxMap.get().getOnInfoWindowClickListener(); if (onInfoWindowClickListener != null) { handledDefaultClick = onInfoWindowClickListener.onMarkerClick(getBoundMarker()); } @@ -88,15 +89,17 @@ public class InfoWindow { MapView.LayoutParams lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT, MapView.LayoutParams.WRAP_CONTENT); + MapboxMap mapboxMap = mMapboxMap.get(); View view = mView.get(); - if (view != null) { + if (view != null && mapboxMap != null) { view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); // Calculate y-offset for update method mMarkerHeightOffset = -view.getMeasuredHeight() + offsetY; // Calculate default Android x,y coordinate - mCoordinates = mapView.toScreenLocation(position); + + mCoordinates = mapboxMap.toScreenLocation(position); float x = mCoordinates.x - (view.getMeasuredWidth() / 2) + offsetX; float y = mCoordinates.y - view.getMeasuredHeight() + offsetY; @@ -191,13 +194,13 @@ public class InfoWindow { * * @param overlayItem the tapped overlay item */ - void adaptDefaultMarker(Marker overlayItem, MapView mapView) { + void adaptDefaultMarker(Marker overlayItem, MapboxMap mapboxMap, MapView mapView) { View view = mView.get(); if (view == null) { view = LayoutInflater.from(mapView.getContext()).inflate(mLayoutRes, mapView, false); - initialize(view, mapView); + initialize(view, mapboxMap); } - mMapView = new WeakReference<>(mapView); + mMapboxMap = new WeakReference<>(mapboxMap); String title = overlayItem.getTitle(); ((TextView) view.findViewById(R.id.infowindow_title)).setText(title); String snippet = overlayItem.getSnippet(); @@ -205,7 +208,10 @@ public class InfoWindow { } private void onClose() { - mMapView.get().deselectMarker(getBoundMarker()); + MapboxMap mapboxMap = mMapboxMap.get(); + if (mapboxMap != null) { + mapboxMap.deselectMarker(getBoundMarker()); + } } InfoWindow setBoundMarker(Marker boundMarker) { @@ -221,11 +227,11 @@ public class InfoWindow { } public void update() { - MapView mapView = mMapView.get(); + MapboxMap mapboxMap = mMapboxMap.get(); Marker marker = mBoundMarker.get(); View view = mView.get(); - if (mapView != null && marker != null && view != null) { - mCoordinates = mapView.toScreenLocation(marker.getPosition()); + if (mapboxMap != null && marker != null && view != null) { + mCoordinates = mapboxMap.toScreenLocation(marker.getPosition()); view.setX(mCoordinates.x + mViewWidthOffset); view.setY(mCoordinates.y + mMarkerHeightOffset); } 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 3463801448..27c9c03697 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 @@ -4,15 +4,16 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.view.View; +import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.geometry.LatLng; -import com.mapbox.mapboxsdk.views.MapView; +import com.mapbox.mapboxsdk.maps.MapView; /** * Marker is an annotation that shows an icon image at a geographical location. * </p> * An {@link InfoWindow} can be shown when a Marker is pressed - * <p> + * <p/> */ public final class Marker extends Annotation { @@ -55,8 +56,6 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. - * - * @return boolean State of a InfoWindow */ public boolean isInfoWindowShown() { return infoWindowShown; @@ -72,8 +71,6 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. - * - * @param icon The icon to be used as Marker image */ public void setIcon(@Nullable Icon icon) { this.icon = icon; @@ -89,25 +86,25 @@ public final class Marker extends Annotation { /** * Do not use this method. Used internally by the SDK. - * - * @param mapView The MapView to show the InfoWindow on. - * @return infoWindow The infoWindow to show */ - public InfoWindow showInfoWindow(@NonNull MapView mapView) { - setMapView(mapView); - MapView.InfoWindowAdapter infoWindowAdapter = getMapView().getInfoWindowAdapter(); + public InfoWindow showInfoWindow(@NonNull MapboxMap mapboxMap, @NonNull MapView mapView) { + setMapboxMap(mapboxMap); + MapboxMap.InfoWindowAdapter infoWindowAdapter = getMapboxMap().getInfoWindowAdapter(); if (infoWindowAdapter != null) { // end developer is using a custom InfoWindowAdapter View content = infoWindowAdapter.getInfoWindow(this); if (content != null) { - infoWindow = new InfoWindow(content, getMapView()); + infoWindow = new InfoWindow(content, mapboxMap); showInfoWindow(infoWindow, mapView); return infoWindow; } } - getInfoWindow().adaptDefaultMarker(this, mapView); - return showInfoWindow(getInfoWindow(), mapView); + InfoWindow infoWindow = getInfoWindow(mapView); + if (mapView.getContext() != null) { + infoWindow.adaptDefaultMarker(this, mapboxMap, mapView); + } + return showInfoWindow(infoWindow, mapView); } private InfoWindow showInfoWindow(InfoWindow iw, MapView mapView) { @@ -116,27 +113,15 @@ public final class Marker extends Annotation { return iw; } - private InfoWindow getInfoWindow() { - if (infoWindow == null) { - infoWindow = new InfoWindow(R.layout.infowindow_view, getMapView()); + private InfoWindow getInfoWindow(@NonNull MapView mapView) { + if (infoWindow == null && mapView.getContext() != null) { + infoWindow = new InfoWindow(mapView, R.layout.infowindow_view, getMapboxMap()); } return infoWindow; } - /* - @Override - void setVisible(boolean visible) { - super.setVisible(visible); - if (!visible && infoWindowShown) { - hideInfoWindow(); - } - } - */ - /** * Do not use this method. Used internally by the SDK. - * - * @param topOffsetPixels the pixels to have as offset */ public void setTopOffsetPixels(int topOffsetPixels) { this.topOffsetPixels = topOffsetPixels; |