diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java')
-rw-r--r-- | platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java | 795 |
1 files changed, 384 insertions, 411 deletions
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 bd0a010900..cb9459d5f2 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 @@ -10,7 +10,9 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.ServiceInfo; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -27,8 +29,8 @@ import android.support.annotation.FloatRange; import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.annotation.RequiresPermission; import android.support.annotation.UiThread; +import android.support.v4.content.ContextCompat; import android.support.v4.view.GestureDetectorCompat; import android.support.v4.view.ScaleGestureDetectorCompat; import android.support.v7.app.AlertDialog; @@ -47,44 +49,50 @@ import android.view.Surface; import android.view.TextureView; import android.view.View; import android.view.ViewConfiguration; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.FrameLayout; import android.widget.ImageView; +import android.widget.ListView; import android.widget.ZoomButtonsController; - import com.almeros.android.multitouch.gesturedetectors.RotateGestureDetector; import com.almeros.android.multitouch.gesturedetectors.ShoveGestureDetector; import com.almeros.android.multitouch.gesturedetectors.TwoFingerGestureDetector; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.annotations.Annotation; import com.mapbox.mapboxsdk.annotations.Icon; +import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.annotations.InfoWindow; import com.mapbox.mapboxsdk.annotations.Marker; import com.mapbox.mapboxsdk.annotations.MarkerOptions; import com.mapbox.mapboxsdk.annotations.Polygon; -import com.mapbox.mapboxsdk.annotations.PolygonOptions; import com.mapbox.mapboxsdk.annotations.Polyline; -import com.mapbox.mapboxsdk.annotations.PolylineOptions; -import com.mapbox.mapboxsdk.annotations.IconFactory; import com.mapbox.mapboxsdk.camera.CameraPosition; +import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.MapboxConstants; import com.mapbox.mapboxsdk.constants.MyBearingTracking; import com.mapbox.mapboxsdk.constants.MyLocationTracking; import com.mapbox.mapboxsdk.constants.Style; import com.mapbox.mapboxsdk.exceptions.IconBitmapChangedException; import com.mapbox.mapboxsdk.exceptions.InvalidAccessTokenException; +import com.mapbox.mapboxsdk.exceptions.TelemetryServiceNotConfiguredException; import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLngBounds; import com.mapbox.mapboxsdk.layers.CustomLayer; +import com.mapbox.mapboxsdk.maps.widgets.CompassView; +import com.mapbox.mapboxsdk.maps.widgets.UserLocationView; +import com.mapbox.mapboxsdk.telemetry.MapboxEvent; +import com.mapbox.mapboxsdk.telemetry.MapboxEventManager; import com.mapbox.mapboxsdk.utils.ApiAccess; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; +import java.util.Hashtable; +import java.util.Iterator; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; /** * <p> @@ -111,7 +119,6 @@ public class MapView extends FrameLayout { private static final float DIMENSION_SEVENTYSIX_DP = 76f; private MapboxMap mMapboxMap; - private List<Annotation> mAnnotations; private List<Icon> mIcons; private NativeMapView mNativeMapView; @@ -120,7 +127,7 @@ public class MapView extends FrameLayout { private ImageView mAttributionsView; private UserLocationView mUserLocationView; - private List<OnMapChangedListener> mOnMapChangedListener; + private CopyOnWriteArrayList<OnMapChangedListener> mOnMapChangedListener; private ZoomButtonsController mZoomButtonsController; private ConnectivityReceiver mConnectivityReceiver; private float mScreenDensity = 1.0f; @@ -133,13 +140,12 @@ public class MapView extends FrameLayout { private boolean mTwoTap = false; private boolean mZoomStarted = false; private boolean mQuickZoom = false; + private boolean mScrollInProgress = false; - /* private int mContentPaddingLeft; private int mContentPaddingTop; private int mContentPaddingRight; private int mContentPaddingBottom; -*/ @UiThread public MapView(@NonNull Context context) { @@ -160,11 +166,9 @@ public class MapView extends FrameLayout { } private void initialize(@NonNull Context context, @Nullable AttributeSet attrs) { - mOnMapChangedListener = new ArrayList<>(); + mOnMapChangedListener = new CopyOnWriteArrayList<>(); mMapboxMap = new MapboxMap(this); - mAnnotations = new ArrayList<>(); mIcons = new ArrayList<>(); - View view = LayoutInflater.from(context).inflate(R.layout.mapview_internal, this); if (!isInEditMode()) { @@ -200,7 +204,7 @@ public class MapView extends FrameLayout { // Shows the zoom controls if (!context.getPackageManager() .hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) { - mMapboxMap.setZoomControlsEnabled(true); + mMapboxMap.getUiSettings().setZoomControlsEnabled(true); } mZoomButtonsController = new ZoomButtonsController(this); mZoomButtonsController.setZoomSpeed(MapboxConstants.ANIMATION_DURATION); @@ -210,9 +214,9 @@ public class MapView extends FrameLayout { onConnectivityChanged(isConnected()); mUserLocationView = (UserLocationView) view.findViewById(R.id.userLocationView); - mUserLocationView.setMapView(this); + mUserLocationView.setMapboxMap(mMapboxMap); mCompassView = (CompassView) view.findViewById(R.id.compassView); - mCompassView.setOnClickListener(new CompassView.CompassClickListener(this)); + mCompassView.setOnClickListener(new CompassView.CompassClickListener(mMapboxMap)); mLogoView = (ImageView) view.findViewById(R.id.logoView); // Setup Attributions control @@ -232,13 +236,15 @@ public class MapView extends FrameLayout { mMapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); // Access token - if (typedArray.getString(R.styleable.MapView_access_token) != null) { + String accessToken = typedArray.getString(R.styleable.MapView_access_token); + if (accessToken != null) { setAccessToken(typedArray.getString(R.styleable.MapView_access_token)); } // Style url - if (typedArray.getString(R.styleable.MapView_style_url) != null) { - mMapboxMap.setStyleUrl(typedArray.getString(R.styleable.MapView_style_url)); + String styleUrl = typedArray.getString(R.styleable.MapView_style_url); + if (styleUrl != null) { + mMapboxMap.setStyleUrl(styleUrl); } // Enable gestures @@ -249,6 +255,10 @@ public class MapView extends FrameLayout { uiSettings.setTiltGesturesEnabled(typedArray.getBoolean(R.styleable.MapView_tilt_enabled, true)); uiSettings.setZoomControlsEnabled(typedArray.getBoolean(R.styleable.MapView_zoom_controls_enabled, false)); + // Zoom + uiSettings.setMaxZoom(typedArray.getFloat(R.styleable.MapView_zoom_max, (float) MapboxConstants.MAXIMUM_ZOOM)); + uiSettings.setMinZoom(typedArray.getFloat(R.styleable.MapView_zoom_min, (float) MapboxConstants.MINIMUM_ZOOM)); + // Compass uiSettings.setCompassEnabled(typedArray.getBoolean(R.styleable.MapView_compass_enabled, true)); uiSettings.setCompassGravity(typedArray.getInt(R.styleable.MapView_compass_gravity, Gravity.TOP | Gravity.END)); @@ -274,13 +284,7 @@ public class MapView extends FrameLayout { , (int) (typedArray.getDimension(R.styleable.MapView_attribution_margin_bottom, DIMENSION_SEVEN_DP) * mScreenDensity)); // User location - try { - //noinspection ResourceType - mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false)); - } catch (SecurityException ignore) { - // User did not accept location permissions - } - + mMapboxMap.setMyLocationEnabled(typedArray.getBoolean(R.styleable.MapView_my_location_enabled, false)); } finally { typedArray.recycle(); } @@ -303,7 +307,7 @@ public class MapView extends FrameLayout { */ @UiThread public void onCreate(@Nullable Bundle savedInstanceState) { - if (savedInstanceState != null) { + if (savedInstanceState != null && savedInstanceState.getBoolean(MapboxConstants.STATE_HAS_SAVED_STATE)) { // Get previous camera position CameraPosition cameraPosition = savedInstanceState.getParcelable(MapboxConstants.STATE_CAMERA_POSITION); @@ -357,10 +361,17 @@ public class MapView extends FrameLayout { // User did not accept location permissions } + TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); //noinspection ResourceType - mMapboxMap.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE)); + trackingSettings.setMyLocationTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, MyLocationTracking.TRACKING_NONE)); //noinspection ResourceType - mMapboxMap.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE)); + trackingSettings.setMyBearingTrackingMode(savedInstanceState.getInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, MyBearingTracking.NONE)); + } else { + // Force a check for Telemetry + validateTelemetryServiceConfigured(); + + // Start Telemetry (authorization determined in initial MapboxEventManager constructor) + MapboxEventManager.getMapboxEventManager(getContext()).isTelemetryEnabled(); } // Force a check for an access token @@ -381,6 +392,16 @@ public class MapView extends FrameLayout { } } }); + + // Fire MapLoad + if (savedInstanceState == null) { + Hashtable<String, Object> evt = new Hashtable<>(); + evt.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_MAP_LOAD); + evt.put(MapboxEvent.KEY_LATITUDE, mMapboxMap.getCameraPosition().target.getLatitude()); + evt.put(MapboxEvent.KEY_LONGITUDE, mMapboxMap.getCameraPosition().target.getLongitude()); + evt.put(MapboxEvent.KEY_ZOOM, mMapboxMap.getCameraPosition().zoom); + MapboxEventManager.getMapboxEventManager(getContext()).pushEvent(evt); + } } /** @@ -392,14 +413,19 @@ public class MapView extends FrameLayout { @UiThread public void onSaveInstanceState(@NonNull Bundle outState) { + outState.putBoolean(MapboxConstants.STATE_HAS_SAVED_STATE, true); outState.putParcelable(MapboxConstants.STATE_CAMERA_POSITION, mMapboxMap.getCameraPosition()); outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, mMapboxMap.isDebugActive()); outState.putString(MapboxConstants.STATE_STYLE_URL, mMapboxMap.getStyleUrl()); outState.putString(MapboxConstants.STATE_ACCESS_TOKEN, mMapboxMap.getAccessToken()); outState.putLong(MapboxConstants.STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration()); outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, mMapboxMap.isMyLocationEnabled()); - outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, mMapboxMap.getMyLocationTrackingMode()); - outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, mMapboxMap.getMyBearingTrackingMode()); + + + // TrackingSettings + TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); + outState.putInt(MapboxConstants.STATE_MY_LOCATION_TRACKING_MODE, trackingSettings.getMyLocationTrackingMode()); + outState.putInt(MapboxConstants.STATE_MY_BEARING_TRACKING_MODE, trackingSettings.getMyBearingTrackingMode()); // UiSettings UiSettings uiSettings = mMapboxMap.getUiSettings(); @@ -554,13 +580,13 @@ public class MapView extends FrameLayout { } // - // Rotation + // Direction // /** - * Returns the current heading of the map relative to true north. + * Returns the current direction of the map relative to true north. * - * @return The current heading measured in degrees. + * @return The current direction measured in degrees. */ @UiThread @FloatRange(from = MapboxConstants.MINIMUM_DIRECTION, to = MapboxConstants.MAXIMUM_DIRECTION) @@ -633,6 +659,46 @@ public class MapView extends FrameLayout { } // + // Content padding + // + + /** + * Return The current content padding left of the map view viewport. + * + * @return The current content padding left + */ + int getContentPaddingLeft() { + return mContentPaddingLeft; + } + + /** + * Return The current content padding left of the map view viewport. + * + * @return The current content padding left + */ + int getContentPaddingTop() { + return mContentPaddingTop; + } + + /** + * Return The current content padding left of the map view viewport. + * + * @return The current content padding right + */ + int getContentPaddingRight() { + return mContentPaddingRight; + } + + /** + * Return The current content padding left of the map view viewport. + * + * @return The current content padding bottom + */ + int getContentPaddingBottom() { + return mContentPaddingBottom; + } + + // // Zoom // @@ -647,51 +713,6 @@ public class MapView extends FrameLayout { return mNativeMapView.getZoom(); } -// /** -// * Return The current content padding left of the map view viewport. -// * -// * @return The current content padding left -// */ -///* -// public int getContentPaddingLeft() { -// return mContentPaddingLeft; -// } -//*/ -// -// /** -// * Return The current content padding left of the map view viewport. -// * -// * @return The current content padding left -// */ -///* -// public int getContentPaddingTop() { -// return mContentPaddingTop; -// } -//*/ -// -// /** -// * Return The current content padding left of the map view viewport. -// * -// * @return The current content padding left -// */ -///* -// public int getContentPaddingRight() { -// return mContentPaddingRight; -// } -//*/ -// -// /** -// * Return The current content padding left of the map view viewport. -// * -// * @param zoomLevel The new zoom level. -// * @param animated If true, animates the change. If false, immediately changes the map. -// * @see MapboxMap#MAXIMUM_ZOOM -// */ -///* -// public int getContentPaddingBottom() { -// return mContentPaddingBottom; -//*/ - /** * <p> * Sets the minimum zoom level the map can be displayed at. @@ -712,7 +733,7 @@ public class MapView extends FrameLayout { * @return The minimum zoom level. */ @UiThread - public double getMinZoom() { + double getMinZoom() { return mNativeMapView.getMinZoom(); } @@ -724,7 +745,7 @@ public class MapView extends FrameLayout { * @param maxZoom The new maximum zoom level. */ @UiThread - public void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) { + void setMaxZoom(@FloatRange(from = MapboxConstants.MINIMUM_ZOOM, to = MapboxConstants.MAXIMUM_ZOOM) double maxZoom) { mNativeMapView.setMaxZoom(maxZoom); } @@ -736,7 +757,7 @@ public class MapView extends FrameLayout { * @return The maximum zoom level. */ @UiThread - public double getMaxZoom() { + double getMaxZoom() { return mNativeMapView.getMaxZoom(); } @@ -866,6 +887,28 @@ public class MapView extends FrameLayout { } } + // Checks that TelemetryService has been configured by developer + private void validateTelemetryServiceConfigured() { + + try { + // Check Implementing app's AndroidManifest.xml + PackageInfo packageInfo = getContext().getPackageManager().getPackageInfo(getContext().getPackageName(), PackageManager.GET_SERVICES); + + if (packageInfo.services != null) { + + for (ServiceInfo service : packageInfo.services) { + if (TextUtils.equals("com.mapbox.mapboxsdk.telemetry.TelemetryService", service.name)) { + return; + } + } + } + + } catch (Exception e) { + Log.w(TAG, "Error checking for Telemetry Service Config: " + e); + } + throw new TelemetryServiceNotConfiguredException(); + } + /** * <p> * Sets the current Mapbox access token used to load map styles and tiles. @@ -942,7 +985,25 @@ public class MapView extends FrameLayout { // Annotations // - private void loadIcon(Icon icon) { + Icon loadIconForMarker(Marker marker) { + Icon icon = marker.getIcon(); + if (icon == null) { + icon = IconFactory.getInstance(getContext()).defaultMarker(); + marker.setIcon(icon); + } + if (!mIcons.contains(icon)) { + mIcons.add(icon); + loadIcon(icon); + } else { + Icon oldIcon = mIcons.get(mIcons.indexOf(icon)); + if (!oldIcon.getBitmap().sameAs(icon.getBitmap())) { + throw new IconBitmapChangedException(); + } + } + return icon; + } + + void loadIcon(Icon icon) { Bitmap bitmap = icon.getBitmap(); String id = icon.getId(); if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) { @@ -964,7 +1025,7 @@ public class MapView extends FrameLayout { scale, buffer.array()); } - private void reloadIcons() { + void reloadIcons() { int count = mIcons.size(); for (int i = 0; i < count; i++) { Icon icon = mIcons.get(i); @@ -972,8 +1033,35 @@ public class MapView extends FrameLayout { } } + /** + * <p> + * Updates a marker on this map. Does nothing if the marker is already added. + * </p> + * + * @param updatedMarker An updated marker object. + */ + @UiThread + void updateMarker(@NonNull Marker updatedMarker) { + if (updatedMarker == null) { + Log.w(TAG, "marker was null, doing nothing"); + return; + } + + if (updatedMarker.getId() == -1) { + Log.w(TAG, "marker has an id of -1, possibly was not added yet, doing nothing"); + } + + ensureIconLoaded(updatedMarker); + mNativeMapView.updateMarker(updatedMarker); + } + private Marker prepareMarker(MarkerOptions markerOptions) { Marker marker = markerOptions.getMarker(); + ensureIconLoaded(marker); + return marker; + } + + private void ensureIconLoaded(Marker marker) { Icon icon = marker.getIcon(); if (icon == null) { icon = IconFactory.getInstance(getContext()).defaultMarker(); @@ -988,270 +1076,48 @@ public class MapView extends FrameLayout { throw new IconBitmapChangedException(); } } - marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon)); - return marker; - } - /** - * <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. - */ - @UiThread - @NonNull - Marker addMarker(@NonNull MarkerOptions markerOptions) { - if (markerOptions == null) { - Log.w(TAG, "markerOptions was null, so just returning null"); - return null; + // this seems to be a costly operation according to the profiler so I'm trying to save some calls + Marker previousMarker = marker.getId() != -1 ? (Marker) mMapboxMap.getAnnotation(marker.getId()) : null; + if (previousMarker == null || previousMarker.getIcon() == null || previousMarker.getIcon() != marker.getIcon()) { + marker.setTopOffsetPixels(getTopOffsetPixelsForIcon(icon)); } - - Marker marker = prepareMarker(markerOptions); - long id = mNativeMapView.addMarker(marker); - marker.setId(id); // the annotation needs to know its id - marker.setMapboxMap(mMapboxMap); // the annotation needs to know which map view it is in - mAnnotations.add(marker); - return marker; } - /** - * <p> - * Adds multiple markers 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 markerOptionsList A list of marker options objects that defines how to render the markers. - * @return A list of the {@code Marker}s that were added to the map. - */ - @UiThread - @NonNull - List<Marker> addMarkers(@NonNull List<MarkerOptions> markerOptionsList) { - if (markerOptionsList == null) { - Log.w(TAG, "markerOptionsList was null, so just returning null"); - return null; - } - - int count = markerOptionsList.size(); - List<Marker> markers = new ArrayList<>(count); - for (int i = 0; i < count; i++) { - MarkerOptions markerOptions = markerOptionsList.get(i); - Marker marker = prepareMarker(markerOptions); - markers.add(marker); - } - - long[] ids = mNativeMapView.addMarkers(markers); - Marker m; - for (int i = 0; i < count; i++) { - m = markers.get(i); - m.setId(ids[i]); - m.setMapboxMap(mMapboxMap); - mAnnotations.add(m); + long addMarker(@NonNull Marker marker) { + if (mNativeMapView == null) { + return 0l; } - - return new ArrayList<>(markers); + return mNativeMapView.addMarker(marker); } - /** - * Adds a polyline to this map. - * - * @param polylineOptions A polyline options object that defines how to render the polyline. - * @return The {@code Polyine} that was added to the map. - */ - @UiThread - @NonNull - Polyline addPolyline(@NonNull PolylineOptions polylineOptions) { - if (polylineOptions == null) { - Log.w(TAG, "polylineOptions was null, so just returning null"); - return null; - } - - Polyline polyline = polylineOptions.getPolyline(); - long id = mNativeMapView.addPolyline(polyline); - polyline.setId(id); - polyline.setMapboxMap(mMapboxMap); - mAnnotations.add(polyline); - return polyline; + long[] addMarkers(@NonNull List<Marker> markerList) { + return mNativeMapView.addMarkers(markerList); } - /** - * Adds multiple polylines to this map. - * - * @param polylineOptionsList A list of polyline options objects that defines how to render the polylines. - * @return A list of the {@code Polyline}s that were added to the map. - */ - @UiThread - @NonNull - List<Polyline> addPolylines(@NonNull List<PolylineOptions> polylineOptionsList) { - if (polylineOptionsList == null) { - Log.w(TAG, "polylineOptionsList was null, so just returning null"); - return null; - } - - int count = polylineOptionsList.size(); - List<Polyline> polylines = new ArrayList<>(count); - for (PolylineOptions options : polylineOptionsList) { - polylines.add(options.getPolyline()); - } - - long[] ids = mNativeMapView.addPolylines(polylines); - - Polyline p; - for (int i = 0; i < count; i++) { - p = polylines.get(i); - p.setId(ids[i]); - p.setMapboxMap(mMapboxMap); - mAnnotations.add(p); - } - - return new ArrayList<>(polylines); + long addPolyline(@NonNull Polyline polyline) { + return mNativeMapView.addPolyline(polyline); } - /** - * Adds a polygon to this map. - * - * @param polygonOptions A polygon options object that defines how to render the polygon. - * @return The {@code Polygon} that was added to the map. - */ - @UiThread - @NonNull - Polygon addPolygon(@NonNull PolygonOptions polygonOptions) { - if (polygonOptions == null) { - Log.w(TAG, "polygonOptions was null, so just returning null"); - return null; - } - - Polygon polygon = polygonOptions.getPolygon(); - long id = mNativeMapView.addPolygon(polygon); - polygon.setId(id); - polygon.setMapboxMap(mMapboxMap); - mAnnotations.add(polygon); - return polygon; + long[] addPolylines(@NonNull List<Polyline> polylines) { + return mNativeMapView.addPolylines(polylines); } - - /** - * Adds multiple polygons to this map. - * - * @param polygonOptionsList A list of polygon options objects that defines how to render the polygons. - * @return A list of the {@code Polygon}s that were added to the map. - */ - @UiThread - @NonNull - List<Polygon> addPolygons(@NonNull List<PolygonOptions> polygonOptionsList) { - if (polygonOptionsList == null) { - Log.w(TAG, "polygonOptionsList was null, so just returning null"); - return null; - } - - int count = polygonOptionsList.size(); - List<Polygon> polygons = new ArrayList<>(count); - for (PolygonOptions polygonOptions : polygonOptionsList) { - polygons.add(polygonOptions.getPolygon()); - } - - long[] ids = mNativeMapView.addPolygons(polygons); - - Polygon p; - for (int i = 0; i < count; i++) { - p = polygons.get(i); - p.setId(ids[i]); - p.setMapboxMap(mMapboxMap); - mAnnotations.add(p); - } - - return new ArrayList<>(polygons); + long addPolygon(@NonNull Polygon polygon) { + return mNativeMapView.addPolygon(polygon); } - - /** - * <p> - * Convenience method for removing a Marker from the map. - * </p> - * Calls removeAnnotation() internally - * - * @param marker Marker to remove - */ - @UiThread - void removeMarker(@NonNull Marker marker) { - removeAnnotation(marker); + long[] addPolygons(@NonNull List<Polygon> polygons) { + return mNativeMapView.addPolygons(polygons); } - /** - * Removes an annotation from the map. - * - * @param annotation The annotation object to remove. - */ - @UiThread - void removeAnnotation(@NonNull Annotation annotation) { - if (annotation == null) { - Log.w(TAG, "annotation was null, so just returning"); - return; - } - - if (annotation instanceof Marker) { - ((Marker) annotation).hideInfoWindow(); - } - long id = annotation.getId(); + void removeAnnotation(long id) { mNativeMapView.removeAnnotation(id); - mAnnotations.remove(annotation); - } - - /** - * Removes multiple annotations from the map. - * - * @param annotationList A list of annotation objects to remove. - */ - @UiThread - void removeAnnotations(@NonNull List<? extends Annotation> annotationList) { - if (annotationList == null) { - Log.w(TAG, "annotationList was null, so just returning"); - return; - } - - int count = annotationList.size(); - long[] ids = new long[count]; - for (int i = 0; i < count; i++) { - ids[i] = annotationList.get(i).getId(); - } - mNativeMapView.removeAnnotations(ids); } - /** - * Removes all annotations from the map. - */ - @UiThread - void removeAllAnnotations() { - int count = mAnnotations.size(); - long[] ids = new long[mAnnotations.size()]; - - for (int i = 0; i < count; i++) { - Annotation annotation = mAnnotations.get(i); - long id = annotation.getId(); - ids[i] = id; - if (annotation instanceof Marker) { - ((Marker) annotation).hideInfoWindow(); - } - } - + void removeAnnotations(@NonNull long[] ids) { mNativeMapView.removeAnnotations(ids); - mAnnotations.clear(); - } - - /** - * Returns a list of all the annotations on the map. - * - * @return A list of all the annotation objects. The returned object is a copy so modifying this - * list will not update the map. - */ - @NonNull - List<Annotation> getAllAnnotations() { - return new ArrayList<>(mAnnotations); } private List<Marker> getMarkersInBounds(@NonNull LatLngBounds bbox) { @@ -1269,9 +1135,10 @@ public class MapView extends FrameLayout { } List<Marker> annotations = new ArrayList<>(ids.length); - int count = mAnnotations.size(); + List<Annotation> annotationList = mMapboxMap.getAnnotations(); + int count = annotationList.size(); for (int i = 0; i < count; i++) { - Annotation annotation = mAnnotations.get(i); + Annotation annotation = annotationList.get(i); if (annotation instanceof Marker && idsList.contains(annotation.getId())) { annotations.add((Marker) annotation); } @@ -1280,7 +1147,7 @@ public class MapView extends FrameLayout { return new ArrayList<>(annotations); } - private int getTopOffsetPixelsForIcon(Icon icon) { + int getTopOffsetPixelsForIcon(Icon icon) { // This method will dead lock if map paused. Causes a freeze if you add a marker in an // activity's onCreate() if (mNativeMapView.isPaused()) { @@ -1292,6 +1159,35 @@ public class MapView extends FrameLayout { } /** + * Sets the distance from the edges of the map view’s frame to the edges of the map + * view’s logical viewport. + * <p/> + * When the value of this property is equal to {0,0,0,0}, viewport + * properties such as `centerCoordinate` assume a viewport that matches the map + * view’s frame. Otherwise, those properties are inset, excluding part of the + * frame from the viewport. For instance, if the only the top edge is inset, the + * map center is effectively shifted downward. + * + * @param left The left margin in pixels. + * @param top The top margin in pixels. + * @param right The right margin in pixels. + * @param bottom The bottom margin in pixels. + */ + @UiThread + void setContentPadding(int left, int top, int right, int bottom) { + if (left == mContentPaddingLeft && top == mContentPaddingTop && right == mContentPaddingRight && bottom == mContentPaddingBottom) { + return; + } + + mContentPaddingLeft = left; + mContentPaddingTop = top; + mContentPaddingRight = right; + mContentPaddingBottom = bottom; + + mNativeMapView.setContentPadding(top / mScreenDensity, left / mScreenDensity, bottom / mScreenDensity, right / mScreenDensity); + } + + /** * <p> * Returns the distance spanned by one pixel at the specified latitude and current zoom level. * </p> @@ -1400,9 +1296,10 @@ public class MapView extends FrameLayout { } private void adjustTopOffsetPixels() { - int count = mAnnotations.size(); + List<Annotation> annotations = mMapboxMap.getAnnotations(); + int count = annotations.size(); for (int i = 0; i < count; i++) { - Annotation annotation = mAnnotations.get(i); + Annotation annotation = annotations.get(i); if (annotation instanceof Marker) { Marker marker = (Marker) annotation; marker.setTopOffsetPixels( @@ -1419,9 +1316,10 @@ public class MapView extends FrameLayout { } private void reloadMarkers() { - int count = mAnnotations.size(); + List<Annotation> annotations = mMapboxMap.getAnnotations(); + int count = annotations.size(); for (int i = 0; i < count; i++) { - Annotation annotation = mAnnotations.get(i); + Annotation annotation = annotations.get(i); if (annotation instanceof Marker) { Marker marker = (Marker) annotation; mNativeMapView.removeAnnotation(annotation.getId()); @@ -1572,6 +1470,26 @@ public class MapView extends FrameLayout { // Touch events // + /** + * Helper method for tracking gesture events + * @param gestureId Type of Gesture See {@see MapboxEvent#GESTURE_SINGLETAP MapboxEvent#GESTURE_DOUBLETAP MapboxEvent#GESTURE_TWO_FINGER_SINGLETAP MapboxEvent#GESTURE_QUICK_ZOOM MapboxEvent#GESTURE_PAN_START MapboxEvent#GESTURE_PINCH_START MapboxEvent#GESTURE_ROTATION_START MapboxEvent#GESTURE_PITCH_START} + * @param xCoordinate Original x screen coordinate at start of gesture + * @param yCoordinate Original y screen cooridnate at start of gesture + */ + private void trackGestureEvent(@NonNull String gestureId, @NonNull float xCoordinate, float yCoordinate) { + + LatLng tapLatLng = fromScreenLocation(new PointF(xCoordinate, yCoordinate)); + + Hashtable<String, Object> evt = new Hashtable<>(); + evt.put(MapboxEvent.ATTRIBUTE_EVENT, MapboxEvent.TYPE_MAP_CLICK); + evt.put(MapboxEvent.KEY_GESTURE_ID, gestureId); + evt.put(MapboxEvent.KEY_LATITUDE, tapLatLng.getLatitude()); + evt.put(MapboxEvent.KEY_LONGITUDE, tapLatLng.getLongitude()); + evt.put(MapboxEvent.KEY_ZOOM, mMapboxMap.getCameraPosition().zoom); + + MapboxEventManager.getMapboxEventManager(getContext()).pushEvent(evt); + } + // Called when user touches the screen, all positions are absolute @Override public boolean onTouchEvent(@NonNull MotionEvent event) { @@ -1596,6 +1514,10 @@ public class MapView extends FrameLayout { case MotionEvent.ACTION_POINTER_DOWN: // Second pointer down mTwoTap = event.getPointerCount() == 2; + if (mTwoTap) { + // Confirmed 2nd Finger Down + trackGestureEvent(MapboxEvent.GESTURE_TWO_FINGER_SINGLETAP, event.getX(), event.getY()); + } break; case MotionEvent.ACTION_POINTER_UP: @@ -1617,6 +1539,12 @@ public class MapView extends FrameLayout { return true; } + // Scroll / Pan Has Stopped + if (mScrollInProgress) { + trackGestureEvent(MapboxEvent.TYPE_MAP_DRAGEND, event.getX(), event.getY()); + mScrollInProgress = false; + } + mTwoTap = false; mNativeMapView.setGestureInProgress(false); break; @@ -1632,8 +1560,7 @@ public class MapView extends FrameLayout { } // This class handles one finger gestures - private class GestureListener extends - GestureDetector.SimpleOnGestureListener { + private class GestureListener extends GestureDetector.SimpleOnGestureListener { // Must always return true otherwise all events are ignored @Override @@ -1665,16 +1592,20 @@ public class MapView extends FrameLayout { } // Single finger double tap - if (mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) { + if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) { // Zoom in on gesture zoom(true, e.getX(), e.getY()); + trackGestureEvent(MapboxEvent.GESTURE_QUICK_ZOOM, e.getX(), e.getY()); } else { - // Zoom in on center map - zoom(true, getWidth() / 2, getHeight() / 2); + // Zoom in on user location view + PointF centerPoint = mUserLocationView.getMarkerScreenPoint(); + zoom(true, centerPoint.x, centerPoint.y); } break; } + trackGestureEvent(MapboxEvent.GESTURE_DOUBLETAP, e.getX(), e.getY()); + return true; } @@ -1725,9 +1656,10 @@ public class MapView extends FrameLayout { } if (newSelectedMarkerId >= 0) { - int count = mAnnotations.size(); + List<Annotation> annotations = mMapboxMap.getAnnotations(); + int count = annotations.size(); for (int i = 0; i < count; i++) { - Annotation annotation = mAnnotations.get(i); + Annotation annotation = annotations.get(i); if (annotation instanceof Marker) { if (annotation.getId() == newSelectedMarkerId) { if (selectedMarkers.isEmpty() || !selectedMarkers.contains(annotation)) { @@ -1749,6 +1681,8 @@ public class MapView extends FrameLayout { } } + trackGestureEvent(MapboxEvent.GESTURE_SINGLETAP, e.getX(), e.getY()); + return true; } @@ -1771,7 +1705,9 @@ public class MapView extends FrameLayout { } // reset tracking modes if gesture occurs - resetTrackingModes(); + if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) { + resetTrackingModes(); + } // Fling the map float ease = 0.25f; @@ -1793,18 +1729,25 @@ public class MapView extends FrameLayout { listener.onFling(); } + trackGestureEvent(MapboxEvent.GESTURE_PAN_START, e1.getX(), e1.getY()); return true; } // Called for drags @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + Log.i(TAG, "onScroll() started"); + if (!mScrollInProgress) { + mScrollInProgress = true; + } if (!mMapboxMap.getUiSettings().isScrollGesturesEnabled()) { return false; } - // reset tracking modes if gesture occurs - resetTrackingModes(); + if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) { + // reset tracking modes if gesture occurs + resetTrackingModes(); + } // Cancel any animation mNativeMapView.cancelTransitions(); @@ -1817,6 +1760,7 @@ public class MapView extends FrameLayout { listener.onScroll(); } + Log.i(TAG, "onScroll() done"); return true; } } @@ -1834,10 +1778,13 @@ public class MapView extends FrameLayout { return false; } - // reset tracking modes if gesture occurs - resetTrackingModes(); + if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) { + // reset tracking modes if gesture occurs + resetTrackingModes(); + } mBeginTime = detector.getEventTime(); + trackGestureEvent(MapboxEvent.GESTURE_PINCH_START, detector.getFocusX(), detector.getFocusY()); return true; } @@ -1853,7 +1800,8 @@ public class MapView extends FrameLayout { // Called for pinch zooms and quickzooms/quickscales @Override public boolean onScale(ScaleGestureDetector detector) { - if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { + UiSettings uiSettings = mMapboxMap.getUiSettings(); + if (!uiSettings.isZoomGesturesEnabled()) { return false; } @@ -1881,13 +1829,21 @@ public class MapView extends FrameLayout { // Gesture is a quickzoom if there aren't two fingers mQuickZoom = !mTwoTap; + TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); + // Scale the map - if (mMapboxMap.getUiSettings().isScrollGesturesEnabled() && !mQuickZoom && mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) { + if (uiSettings.isScrollGesturesEnabled() && !mQuickZoom && trackingSettings.isLocationTrackingDisabled()) { // around gesture mNativeMapView.scaleBy(detector.getScaleFactor(), detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity); } else { - // around center map - mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity); + if(trackingSettings.isLocationTrackingDisabled()) { + // around center map + mNativeMapView.scaleBy(detector.getScaleFactor(), (getWidth() / 2) / mScreenDensity, (getHeight() / 2) / mScreenDensity); + }else { + // around user location view + PointF centerPoint = mUserLocationView.getMarkerScreenPoint(); + mNativeMapView.scaleBy(detector.getScaleFactor(), centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity); + } } return true; } @@ -1907,10 +1863,13 @@ public class MapView extends FrameLayout { return false; } - // reset tracking modes if gesture occurs - resetTrackingModes(); + if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) { + // reset tracking modes if gesture occurs + resetTrackingModes(); + } mBeginTime = detector.getEventTime(); + trackGestureEvent(MapboxEvent.GESTURE_ROTATION_START, detector.getFocusX(), detector.getFocusY()); return true; } @@ -1957,16 +1916,15 @@ public class MapView extends FrameLayout { bearing += detector.getRotationDegreesDelta(); // Rotate the map - if (mUserLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE) { + if (mMapboxMap.getTrackingSettings().isLocationTrackingDisabled()) { // around gesture mNativeMapView.setBearing(bearing, detector.getFocusX() / mScreenDensity, detector.getFocusY() / mScreenDensity); } else { - // around center map - mNativeMapView.setBearing(bearing, - (getWidth() / 2) / mScreenDensity, - (getHeight() / 2) / mScreenDensity); + // around center userlocation + PointF centerPoint = mUserLocationView.getMarkerScreenPoint(); + mNativeMapView.setBearing(bearing, centerPoint.x / mScreenDensity, centerPoint.y / mScreenDensity); } return true; } @@ -1986,10 +1944,13 @@ public class MapView extends FrameLayout { return false; } - // reset tracking modes if gesture occurs - resetTrackingModes(); + if (mMapboxMap.getTrackingSettings().isDismissTrackingOnGesture()) { + // reset tracking modes if gesture occurs + resetTrackingModes(); + } mBeginTime = detector.getEventTime(); + trackGestureEvent(MapboxEvent.GESTURE_PITCH_START, detector.getFocusX(), detector.getFocusY()); return true; } @@ -2056,8 +2017,6 @@ public class MapView extends FrameLayout { if (!mMapboxMap.getUiSettings().isZoomGesturesEnabled()) { return; } - - // Zoom in or out zoom(zoomIn); } } @@ -2408,9 +2367,11 @@ public class MapView extends FrameLayout { // Forward to any listeners protected void onMapChanged(int mapChange) { if (mOnMapChangedListener != null) { - int count = mOnMapChangedListener.size(); - for (int i = 0; i < count; i++) { - mOnMapChangedListener.get(i).onMapChanged(mapChange); + OnMapChangedListener listener; + final Iterator<OnMapChangedListener> iterator = mOnMapChangedListener.iterator(); + while (iterator.hasNext()) { + listener = iterator.next(); + listener.onMapChanged(mapChange); } } } @@ -2419,6 +2380,11 @@ public class MapView extends FrameLayout { // User location // + boolean isPermissionsAccepted() { + return (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) || + ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; + } + /** * <p> * Enables or disables the my-location layer. @@ -2433,9 +2399,6 @@ public class MapView extends FrameLayout { * @throws SecurityException if no suitable permission is present */ @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) void setMyLocationEnabled(boolean enabled) { mUserLocationView.setEnabled(enabled); } @@ -2473,19 +2436,13 @@ public class MapView extends FrameLayout { * See {@link MyLocationTracking} for different values. * * @param myLocationTrackingMode The location tracking mode to be used. - * @throws SecurityException if no suitable permission is present * @see MyLocationTracking */ @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) { if (myLocationTrackingMode != MyLocationTracking.TRACKING_NONE && !mMapboxMap.isMyLocationEnabled()) { - //noinspection ResourceType mMapboxMap.setMyLocationEnabled(true); } - mUserLocationView.setMyLocationTrackingMode(myLocationTrackingMode); MapboxMap.OnMyLocationTrackingModeChangeListener listener = mMapboxMap.getOnMyLocationTrackingModeChangeListener(); if (listener != null) { @@ -2494,19 +2451,6 @@ public class MapView extends FrameLayout { } /** - * Returns the current user location tracking mode. - * - * @return The current user location tracking mode. - * One of the values from {@link MyLocationTracking.Mode}. - * @see MyLocationTracking.Mode - */ - @UiThread - @MyLocationTracking.Mode - int getMyLocationTrackingMode() { - return mUserLocationView.getMyLocationTrackingMode(); - } - - /** * <p> * Set the current my bearing tracking mode. * </p> @@ -2518,16 +2462,11 @@ public class MapView extends FrameLayout { * See {@link MyBearingTracking} for different values. * * @param myBearingTrackingMode The bearing tracking mode to be used. - * @throws SecurityException if no suitable permission is present * @see MyBearingTracking */ @UiThread - @RequiresPermission(anyOf = { - Manifest.permission.ACCESS_COARSE_LOCATION, - Manifest.permission.ACCESS_FINE_LOCATION}) void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) { if (myBearingTrackingMode != MyBearingTracking.NONE && !mMapboxMap.isMyLocationEnabled()) { - //noinspection ResourceType mMapboxMap.setMyLocationEnabled(true); } mUserLocationView.setMyBearingTrackingMode(myBearingTrackingMode); @@ -2537,26 +2476,11 @@ public class MapView extends FrameLayout { } } - /** - * Returns the current user bearing tracking mode. - * See {@link MyBearingTracking} for possible return values. - * - * @return the current user bearing tracking mode. - * @see MyBearingTracking - */ - @UiThread - @MyLocationTracking.Mode - int getMyBearingTrackingMode() { - //noinspection ResourceType - return mUserLocationView.getMyBearingTrackingMode(); - } - private void resetTrackingModes() { try { - //noinspection ResourceType - setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); - //noinspection ResourceType - setMyBearingTrackingMode(MyBearingTracking.NONE); + TrackingSettings trackingSettings = mMapboxMap.getTrackingSettings(); + trackingSettings.setMyLocationTrackingMode(MyLocationTracking.TRACKING_NONE); + trackingSettings.setMyBearingTrackingMode(MyBearingTracking.NONE); } catch (SecurityException ignore) { // User did not accept location permissions } @@ -2806,6 +2730,10 @@ public class MapView extends FrameLayout { private void setWidgetMargins(@NonNull final View view, int left, int top, int right, int bottom) { LayoutParams layoutParams = (LayoutParams) view.getLayoutParams(); + left += mContentPaddingLeft; + top += mContentPaddingTop; + right += mContentPaddingRight; + bottom += mContentPaddingBottom; layoutParams.setMargins(left, top, right, bottom); view.setLayoutParams(layoutParams); } @@ -2813,9 +2741,11 @@ public class MapView extends FrameLayout { private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2; + private static final int ATTRIBUTION_INDEX_TELEMETRY_SETTINGS = 3; private MapView mMapView; public AttributionOnClickListener(MapView mapView) { + super(); mMapView = mapView; } @@ -2825,7 +2755,7 @@ public class MapView extends FrameLayout { Context context = v.getContext(); String[] items = context.getResources().getStringArray(R.array.attribution_names); AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); - builder.setTitle(R.string.attributionsDialogTitle); + builder.setTitle(R.string.mapbox_attributionsDialogTitle); builder.setAdapter(new ArrayAdapter<>(context, R.layout.attribution_list_item, items), this); builder.show(); } @@ -2833,7 +2763,49 @@ public class MapView extends FrameLayout { // Called when someone selects an attribution, 'Improve this map' adds location data to the url @Override public void onClick(DialogInterface dialog, int which) { - Context context = ((Dialog) dialog).getContext(); + final Context context = ((Dialog) dialog).getContext(); + if (which == ATTRIBUTION_INDEX_TELEMETRY_SETTINGS) { + + int array = R.array.attribution_telemetry_options; + if (MapboxEventManager.getMapboxEventManager(context).isTelemetryEnabled()) { + array = R.array.attribution_telemetry_options_already_participating; + } + String[] items = context.getResources().getStringArray(array); + AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AttributionAlertDialogStyle); + builder.setTitle(R.string.mapbox_attributionTelemetryTitle); + LayoutInflater factory = LayoutInflater.from(context); + View content = factory.inflate(R.layout.attribution_telemetry_view, null); + + ListView lv = (ListView) content.findViewById(R.id.telemetryOptionsList); + lv.setAdapter(new ArrayAdapter<String>(context, R.layout.attribution_list_item, items)); + lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); + + builder.setView(content); + final AlertDialog telemDialog = builder.show(); + lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + switch (position) { + case 0: + String url = context.getResources().getStringArray(R.array.attribution_links)[3]; + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + context.startActivity(intent); + telemDialog.cancel(); + return; + case 1: + MapboxEventManager.getMapboxEventManager(context).setTelemetryEnabled(false); + telemDialog.cancel(); + return; + case 2: + MapboxEventManager.getMapboxEventManager(context).setTelemetryEnabled(true); + telemDialog.cancel(); + return; + } + } + }); + return; + } String url = context.getResources().getStringArray(R.array.attribution_links)[which]; if (which == ATTRIBUTION_INDEX_IMPROVE_THIS_MAP) { LatLng latLng = mMapView.getMapboxMap().getCameraPosition().target; @@ -3044,4 +3016,5 @@ public class MapView extends FrameLayout { void onMapChanged(@MapChange int change); } + } |