summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2018-10-31 12:20:02 +0100
committerTobrun <tobrun@mapbox.com>2018-10-31 18:26:47 +0100
commitcd90f878cf789f3f862c2e3c929d8ebf78e85b4c (patch)
tree8a852ba265e914fc0dade50323c30cd4ba3877dc
parent90f4d7f63ae084c81bee2cdbc1ef4bca699ff362 (diff)
downloadqtlocation-mapboxgl-cd90f878cf789f3f862c2e3c929d8ebf78e85b4c.tar.gz
[android] - remove deprecated OnMapChange interface and implementation
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AnnotationManager.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java294
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java42
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java61
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java108
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java3
8 files changed, 87 insertions, 437 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
index 8baec7879c..69bf92ecb4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/MarkerViewManager.java
@@ -34,7 +34,7 @@ import java.util.Map;
* 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.OnMapChangedListener {
+public class MarkerViewManager implements MapView.OnDidFinishRenderingFrameListener {
private final ViewGroup markerViewContainer;
private final ViewTreeObserver.OnPreDrawListener markerViewPreDrawObserver =
@@ -76,8 +76,8 @@ public class MarkerViewManager implements MapView.OnMapChangedListener {
}
@Override
- public void onMapChanged(@MapView.MapChange int change) {
- if (isWaitingForRenderInvoke && change == MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) {
+ public void onDidFinishRenderingFrame(boolean fully) {
+ if (isWaitingForRenderInvoke && fully) {
isWaitingForRenderInvoke = false;
invalidateViewMarkersInVisibleRegion();
}
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 95795f6bb9..8ebc2beba2 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
@@ -60,7 +60,7 @@ class AnnotationManager {
private Polygons polygons;
private Polylines polylines;
- AnnotationManager(NativeMapView view, MapView mapView, LongSparseArray<Annotation> annotationsArray,
+ AnnotationManager(MapView mapView, LongSparseArray<Annotation> annotationsArray,
MarkerViewManager markerViewManager, IconManager iconManager, Annotations annotations,
Markers markers, Polygons polygons, Polylines polylines, ShapeAnnotations shapeAnnotations) {
this.mapView = mapView;
@@ -72,9 +72,9 @@ class AnnotationManager {
this.polygons = polygons;
this.polylines = polylines;
this.shapeAnnotations = shapeAnnotations;
- if (view != null) {
+ if (mapView != null) {
// null checking needed for unit tests
- view.addOnMapChangedListener(markerViewManager);
+ mapView.addOnDidFinishRenderingFrameListener(markerViewManager);
}
}
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 8649af7f2e..90046dc5b8 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
@@ -9,7 +9,6 @@ import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.UiThread;
import android.support.annotation.Nullable;
-import android.support.annotation.IntDef;
import android.support.annotation.CallSuper;
import android.support.v4.util.LongSparseArray;
import android.util.AttributeSet;
@@ -43,12 +42,9 @@ import com.mapbox.mapboxsdk.utils.BitmapUtils;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_MAP_NORTH_ANIMATION;
import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
@@ -69,7 +65,6 @@ import static com.mapbox.mapboxsdk.maps.widgets.CompassView.TIME_WAIT_IDLE;
*/
public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
- private final CopyOnWriteArrayList<OnMapChangedListener> onMapChangedListeners = new CopyOnWriteArrayList<>();
private final MapChangeReceiver mapChangeReceiver = new MapChangeReceiver();
private final MapCallback mapCallback = new MapCallback();
private final InitialRenderCallback initialRenderCallback = new InitialRenderCallback();
@@ -129,9 +124,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
// inflate view
View view = LayoutInflater.from(context).inflate(R.layout.mapbox_mapview_internal, this);
- compassView = (CompassView) view.findViewById(R.id.compassView);
- attrView = (ImageView) view.findViewById(R.id.attributionView);
- logoView = (ImageView) view.findViewById(R.id.logoView);
+ compassView = view.findViewById(R.id.compassView);
+ attrView = view.findViewById(R.id.attributionView);
+ logoView = view.findViewById(R.id.logoView);
// add accessibility support
setContentDescription(context.getString(R.string.mapbox_mapActionDescription));
@@ -163,14 +158,14 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
Polygons polygons = new PolygonContainer(nativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray);
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray);
- AnnotationManager annotationManager = new AnnotationManager(nativeMapView, this, annotationsArray,
+ AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray,
markerViewManager, iconManager, annotations, markers, polygons, polylines, shapeAnnotations);
- Transform transform = new Transform(nativeMapView, annotationManager.getMarkerViewManager(),
+ Transform transform = new Transform(this, nativeMapView, annotationManager.getMarkerViewManager(),
cameraChangeDispatcher);
// MapboxMap
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener,
- annotationManager, cameraChangeDispatcher);
+ annotationManager, cameraChangeDispatcher, mapChangeReceiver);
// user input
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings,
@@ -402,7 +397,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
public void onDestroy() {
destroyed = true;
mapChangeReceiver.clear();
- onMapChangedListeners.clear();
mapCallback.onDestroy();
initialRenderCallback.onDestroy();
@@ -501,10 +495,11 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
* </ul>
* <p>
* This method is asynchronous and will return immediately before the style finishes loading.
- * If you wish to wait for the map to finish loading listen for the {@link MapView#DID_FINISH_LOADING_MAP} event.
+ * If you wish to wait for the map to finish loading listen to {@link OnDidFinishLoadingStyleListener} callback.
* </p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be sent.
+ * An error message will be logged in the Android logcat and provided to the {@link OnDidFailLoadingMapListener}
+ * callback.
*
* @param url The URL of the map style
* @see Style
@@ -950,35 +945,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
/**
- * <p>
- * Add a callback that's invoked when the displayed map view changes.
- * </p>
- * To remove the callback, use {@link MapView#removeOnMapChangedListener(OnMapChangedListener)}.
- *
- * @param listener The callback that's invoked on every frame rendered to the map view.
- * @see MapView#removeOnMapChangedListener(OnMapChangedListener)
- * @deprecated use specific map change callbacks instead
- */
- @Deprecated
- public void addOnMapChangedListener(@NonNull OnMapChangedListener listener) {
- onMapChangedListeners.add(listener);
- }
-
- /**
- * Remove a callback added with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}
- *
- * @param listener The previously added callback to remove.
- * @see MapView#addOnMapChangedListener(OnMapChangedListener)
- * @deprecated use specific map change callbacks instead
- */
- @Deprecated
- public void removeOnMapChangedListener(@NonNull OnMapChangedListener listener) {
- if (onMapChangedListeners.contains(listener)) {
- onMapChangedListeners.remove(listener);
- }
- }
-
- /**
* Sets a callback object which will be triggered when the {@link MapboxMap} instance is ready to be used.
*
* @param callback The callback object that will be triggered when the map is ready to be used.
@@ -1004,247 +970,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
this.mapboxMap = mapboxMap;
}
- /**
- * Definition of a map change event.
- *
- * @see MapView.OnMapChangedListener#onMapChanged(int)
- */
- @IntDef( {REGION_WILL_CHANGE,
- REGION_WILL_CHANGE_ANIMATED,
- REGION_IS_CHANGING,
- REGION_DID_CHANGE,
- REGION_DID_CHANGE_ANIMATED,
- WILL_START_LOADING_MAP,
- DID_FINISH_LOADING_MAP,
- DID_FAIL_LOADING_MAP,
- WILL_START_RENDERING_FRAME,
- DID_FINISH_RENDERING_FRAME,
- DID_FINISH_RENDERING_FRAME_FULLY_RENDERED,
- WILL_START_RENDERING_MAP,
- DID_FINISH_RENDERING_MAP,
- DID_FINISH_RENDERING_MAP_FULLY_RENDERED,
- DID_FINISH_LOADING_STYLE,
- SOURCE_DID_CHANGE
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface MapChange {
- }
-
- /**
- * This event is triggered whenever the currently displayed map region is about to changing
- * without an animation.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int REGION_WILL_CHANGE = 0;
-
- /**
- * This event is triggered whenever the currently displayed map region is about to changing
- * with an animation.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int REGION_WILL_CHANGE_ANIMATED = 1;
-
- /**
- * This event is triggered whenever the currently displayed map region is changing.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int REGION_IS_CHANGING = 2;
-
- /**
- * This event is triggered whenever the currently displayed map region finished changing
- * without an animation.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int REGION_DID_CHANGE = 3;
-
- /**
- * This event is triggered whenever the currently displayed map region finished changing
- * with an animation.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int REGION_DID_CHANGE_ANIMATED = 4;
-
- /**
- * This event is triggered when the map is about to start loading a new map style.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int WILL_START_LOADING_MAP = 5;
-
- /**
- * This is triggered when the map has successfully loaded a new map style.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_LOADING_MAP = 6;
-
- /**
- * This event is triggered when the map has failed to load a new map style.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FAIL_LOADING_MAP = 7;
-
- /**
- * This event is triggered when the map will start rendering a frame.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int WILL_START_RENDERING_FRAME = 8;
-
- /**
- * This event is triggered when the map finished rendering a frame.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_FRAME = 9;
-
- /**
- * This event is triggered when the map finished rendering the frame fully.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_FRAME_FULLY_RENDERED = 10;
-
- /**
- * This event is triggered when the map will start rendering the map.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int WILL_START_RENDERING_MAP = 11;
-
- /**
- * This event is triggered when the map finished rendering the map.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_MAP = 12;
-
- /**
- * This event is triggered when the map is fully rendered.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_RENDERING_MAP_FULLY_RENDERED = 13;
-
- /**
- * This {@link MapChange} is triggered when a style has finished loading.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int DID_FINISH_LOADING_STYLE = 14;
-
- /**
- * This {@link MapChange} is triggered when a source changes.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapChange
- * @see MapView.OnMapChangedListener
- */
- public static final int SOURCE_DID_CHANGE = 15;
-
- /**
- * Interface definition for a callback to be invoked when the displayed map view changes.
- * <p>
- * Register to {@link MapChange} events with {@link MapView#addOnMapChangedListener(OnMapChangedListener)}.
- * </p>
- *
- * @see MapView#addOnMapChangedListener(OnMapChangedListener)
- * @see MapView.MapChange
- * @deprecated use specific map change callbacks instead
- */
- @Deprecated
- public interface OnMapChangedListener {
- /**
- * Called when the displayed map view changes.
- *
- * @param change Type of map change event, one of {@link #REGION_WILL_CHANGE},
- * {@link #REGION_WILL_CHANGE_ANIMATED},
- * {@link #REGION_IS_CHANGING},
- * {@link #REGION_DID_CHANGE},
- * {@link #REGION_DID_CHANGE_ANIMATED},
- * {@link #WILL_START_LOADING_MAP},
- * {@link #DID_FAIL_LOADING_MAP},
- * {@link #DID_FINISH_LOADING_MAP},
- * {@link #WILL_START_RENDERING_FRAME},
- * {@link #DID_FINISH_RENDERING_FRAME},
- * {@link #DID_FINISH_RENDERING_FRAME_FULLY_RENDERED},
- * {@link #WILL_START_RENDERING_MAP},
- * {@link #DID_FINISH_RENDERING_MAP},
- * {@link #DID_FINISH_RENDERING_MAP_FULLY_RENDERED}.
- * {@link #DID_FINISH_LOADING_STYLE},
- * {@link #SOURCE_DID_CHANGE}.
- */
- void onMapChanged(@MapChange int change);
- }
-
private class FocalPointInvalidator implements FocalPointChangeListener {
private final List<FocalPointChangeListener> focalPointChangeListeners = new ArrayList<>();
@@ -1508,7 +1233,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
}
-
@Override
public void onCameraIsChanging() {
if (mapboxMap != null) {
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 f34a30f140..1fd1017c5f 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
@@ -73,6 +73,7 @@ public final class MapboxMap {
private final Transform transform;
private final AnnotationManager annotationManager;
private final CameraChangeDispatcher cameraChangeDispatcher;
+ private final MapChangeReceiver mapChangeReceiver;
private final OnGesturesManagerInteractionListener onGesturesManagerInteractionListener;
@@ -81,7 +82,7 @@ public final class MapboxMap {
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection,
OnGesturesManagerInteractionListener listener, AnnotationManager annotations,
- CameraChangeDispatcher cameraChangeDispatcher) {
+ CameraChangeDispatcher cameraChangeDispatcher, MapChangeReceiver mapChangeReceiver) {
this.nativeMapView = map;
this.uiSettings = ui;
this.projection = projection;
@@ -89,6 +90,7 @@ public final class MapboxMap {
this.transform = transform;
this.onGesturesManagerInteractionListener = listener;
this.cameraChangeDispatcher = cameraChangeDispatcher;
+ this.mapChangeReceiver = mapChangeReceiver;
}
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
@@ -961,12 +963,12 @@ public final class MapboxMap {
* </ul>
* <p>
* This method is asynchronous and will return before the style finishes loading.
- * If you wish to wait for the map to finish loading, listen for the {@link MapView#DID_FINISH_LOADING_MAP} event
- * or use the {@link #setStyleUrl(String, OnStyleLoadedListener)} method instead.
+ * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener}
+ * callback or use the {@link #setStyleUrl(String, OnStyleLoadedListener)} method instead.
* </p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
- * emitted.
+ * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
+ * will be triggered.
*
* @param url The URL of the map style
* @see Style
@@ -995,8 +997,8 @@ public final class MapboxMap {
* </ul>
* <p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
- * emitted.
+ * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
+ * will be triggered.
* <p>
*
* @param url The URL of the map style
@@ -1005,13 +1007,11 @@ public final class MapboxMap {
*/
public void setStyleUrl(@NonNull final String url, @Nullable final OnStyleLoadedListener callback) {
if (callback != null) {
- nativeMapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
+ mapChangeReceiver.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
@Override
- public void onMapChanged(@MapView.MapChange int change) {
- if (change == MapView.DID_FINISH_LOADING_STYLE) {
- callback.onStyleLoaded(url);
- nativeMapView.removeOnMapChangedListener(this);
- }
+ public void onDidFinishLoadingStyle() {
+ callback.onStyleLoaded(url);
+ mapChangeReceiver.removeOnDidFinishLoadingStyleListener(this);
}
});
}
@@ -1024,12 +1024,12 @@ public final class MapboxMap {
* </p>
* <p>
* This method is asynchronous and will return before the style finishes loading.
- * If you wish to wait for the map to finish loading, listen for the {@link MapView#DID_FINISH_LOADING_MAP} event
- * or use the {@link #setStyle(String, OnStyleLoadedListener)} method instead.
+ * If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener}
+ * callback or use the {@link #setStyle(String, OnStyleLoadedListener)} method instead.
* </p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
- * sent.
+ * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
+ * will be triggered.
*
* @param style The bundled style.
* @see Style
@@ -1043,8 +1043,8 @@ public final class MapboxMap {
* Loads a new map style from the specified bundled style.
* </p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
- * sent.
+ * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
+ * will be triggered.
*
* @param style The bundled style.
* @param callback The callback to be invoked when the style has finished loading
@@ -1080,8 +1080,8 @@ public final class MapboxMap {
* Loads a new map style from a json string.
* <p>
* If the style fails to load or an invalid style URL is set, the map view will become blank.
- * An error message will be logged in the Android logcat and {@link MapView#DID_FAIL_LOADING_MAP} event will be
- * sent.
+ * An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
+ * will be triggered.
* </p>
*/
public void setStyleJson(@NonNull String styleJson) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
index 48c571ee98..eaba89e31b 100755
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java
@@ -42,7 +42,6 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CopyOnWriteArrayList;
// Class that wraps the native methods for convenience
final class NativeMapView {
@@ -77,8 +76,6 @@ final class NativeMapView {
// Listener invoked to return a bitmap of the map
private MapboxMap.SnapshotReadyCallback snapshotReadyCallback;
- private final CopyOnWriteArrayList<MapView.OnMapChangedListener> onMapChangedListeners = new CopyOnWriteArrayList<>();
-
static {
LibraryLoader.load();
}
@@ -133,7 +130,6 @@ final class NativeMapView {
public void destroy() {
destroyed = true;
- onMapChangedListeners.clear();
viewCallback = null;
nativeDestroy();
}
@@ -911,99 +907,63 @@ final class NativeMapView {
//
@Keep
- protected void onMapChanged(int rawChange) {
- for (MapView.OnMapChangedListener onMapChangedListener : onMapChangedListeners) {
- try {
- onMapChangedListener.onMapChanged(rawChange);
- } catch (RuntimeException err) {
- Logger.e(TAG, "Exception in MapView.OnMapChangedListener", err);
- MapStrictMode.strictModeViolation(err);
- }
- }
- }
-
- @Keep
private void onCameraWillChange(boolean animated) {
stateCallback.onCameraWillChange(animated);
- // deprecated API
- onMapChanged(animated ? MapView.REGION_WILL_CHANGE_ANIMATED : MapView.REGION_WILL_CHANGE);
}
@Keep
private void onCameraIsChanging() {
stateCallback.onCameraIsChanging();
- // deprecated API
- onMapChanged(MapView.REGION_IS_CHANGING);
}
@Keep
private void onCameraDidChange(boolean animated) {
stateCallback.onCameraDidChange(animated);
- // deprecated API
- onMapChanged(animated ? MapView.REGION_DID_CHANGE_ANIMATED : MapView.REGION_DID_CHANGE);
}
@Keep
private void onWillStartLoadingMap() {
stateCallback.onWillStartLoadingMap();
- // deprecated API
- onMapChanged(MapView.WILL_START_LOADING_MAP);
}
@Keep
private void onDidFinishLoadingMap() {
stateCallback.onDidFinishLoadingMap();
- // deprecated API
- onMapChanged(MapView.DID_FINISH_LOADING_MAP);
}
@Keep
private void onDidFailLoadingMap(String error) {
stateCallback.onDidFailLoadingMap(error);
- // deprecated API
- onMapChanged(MapView.DID_FAIL_LOADING_MAP);
}
@Keep
private void onWillStartRenderingFrame() {
stateCallback.onWillStartRenderingFrame();
- // deprecated API
- onMapChanged(MapView.WILL_START_RENDERING_FRAME);
}
@Keep
private void onDidFinishRenderingFrame(boolean fully) {
stateCallback.onDidFinishRenderingFrame(fully);
- // deprecated API
- onMapChanged(fully ? MapView.DID_FINISH_RENDERING_FRAME_FULLY_RENDERED : MapView.DID_FINISH_RENDERING_FRAME);
}
@Keep
private void onWillStartRenderingMap() {
stateCallback.onWillStartRenderingMap();
- // deprecated API
- onMapChanged(MapView.WILL_START_RENDERING_MAP);
}
@Keep
private void onDidFinishRenderingMap(boolean fully) {
stateCallback.onDidFinishRenderingMap(fully);
- // deprecated API
- onMapChanged(fully ? MapView.DID_FINISH_RENDERING_MAP_FULLY_RENDERED : MapView.DID_FINISH_RENDERING_MAP);
}
@Keep
private void onDidFinishLoadingStyle() {
stateCallback.onDidFinishLoadingStyle();
- // deprecated API
- onMapChanged(MapView.DID_FINISH_LOADING_STYLE);
}
@Keep
private void onSourceChanged(String sourceId) {
stateCallback.onSourceChanged(sourceId);
- // deprecated API
- onMapChanged(MapView.SOURCE_DID_CHANGE);
}
@Keep
@@ -1307,27 +1267,6 @@ final class NativeMapView {
}
//
- // MapChangeEvents
- //
-
- /**
- * @deprecated use {@link StateCallback} instead
- */
- @Deprecated
- void addOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
- onMapChangedListeners.add(listener);
- }
-
- /**
- * @deprecated use {@link StateCallback} instead
- */
- void removeOnMapChangedListener(@NonNull MapView.OnMapChangedListener listener) {
- if (onMapChangedListeners.contains(listener)) {
- onMapChangedListeners.remove(listener);
- }
- }
-
- //
// Snapshot
//
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 c70266eea2..41bb70f9dc 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
@@ -13,7 +13,6 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.log.Logger;
-import static com.mapbox.mapboxsdk.maps.MapView.REGION_DID_CHANGE_ANIMATED;
import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
/**
@@ -23,11 +22,12 @@ import static com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveStartedListener;
* {@link com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraChangeListener}.
* </p>
*/
-final class Transform implements MapView.OnMapChangedListener {
+final class Transform implements MapView.OnCameraDidChangeListener {
private static final String TAG = "Mbgl-Transform";
- private final NativeMapView mapView;
+ private final NativeMapView nativeMapView;
+ private final MapView mapView;
private final MarkerViewManager markerViewManager;
private final Handler handler = new Handler();
@@ -38,9 +38,20 @@ final class Transform implements MapView.OnMapChangedListener {
private CameraChangeDispatcher cameraChangeDispatcher;
- Transform(NativeMapView mapView, MarkerViewManager markerViewManager,
+ private final MapView.OnCameraDidChangeListener moveByChangeListener = new MapView.OnCameraDidChangeListener() {
+ @Override
+ public void onCameraDidChange(boolean animated) {
+ if (animated) {
+ cameraChangeDispatcher.onCameraIdle();
+ mapView.removeOnCameraDidChangeListener(this);
+ }
+ }
+ };
+
+ Transform(MapView mapView, NativeMapView nativeMapView, MarkerViewManager markerViewManager,
CameraChangeDispatcher cameraChangeDispatcher) {
this.mapView = mapView;
+ this.nativeMapView = nativeMapView;
this.markerViewManager = markerViewManager;
this.cameraChangeDispatcher = cameraChangeDispatcher;
}
@@ -72,8 +83,8 @@ final class Transform implements MapView.OnMapChangedListener {
}
@Override
- public void onMapChanged(@MapView.MapChange int change) {
- if (change == REGION_DID_CHANGE_ANIMATED) {
+ public void onCameraDidChange(boolean animated) {
+ if (animated) {
updateCameraPosition(invalidateCameraPosition());
if (cameraCancelableCallback != null) {
handler.post(new Runnable() {
@@ -87,7 +98,7 @@ final class Transform implements MapView.OnMapChangedListener {
});
}
cameraChangeDispatcher.onCameraIdle();
- mapView.removeOnMapChangedListener(this);
+ mapView.removeOnCameraDidChangeListener(this);
}
}
@@ -97,7 +108,7 @@ final class Transform implements MapView.OnMapChangedListener {
if (isValidCameraPosition(cameraPosition)) {
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
- mapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
+ nativeMapView.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
cameraChangeDispatcher.onCameraIdle();
invalidateCameraPosition();
handler.post(new Runnable() {
@@ -122,8 +133,8 @@ final class Transform implements MapView.OnMapChangedListener {
if (callback != null) {
cameraCancelableCallback = callback;
}
- mapView.addOnMapChangedListener(this);
- mapView.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
+ mapView.addOnCameraDidChangeListener(this);
+ nativeMapView.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom, easingInterpolator);
}
}
@@ -139,8 +150,8 @@ final class Transform implements MapView.OnMapChangedListener {
if (callback != null) {
cameraCancelableCallback = callback;
}
- mapView.addOnMapChangedListener(this);
- mapView.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
+ mapView.addOnCameraDidChangeListener(this);
+ nativeMapView.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom);
}
}
@@ -152,8 +163,8 @@ final class Transform implements MapView.OnMapChangedListener {
@UiThread
@Nullable
CameraPosition invalidateCameraPosition() {
- if (mapView != null) {
- CameraPosition cameraPosition = mapView.getCameraPosition();
+ if (nativeMapView != null) {
+ CameraPosition cameraPosition = nativeMapView.getCameraPosition();
if (this.cameraPosition != null && !this.cameraPosition.equals(cameraPosition)) {
cameraChangeDispatcher.onCameraMove();
}
@@ -193,7 +204,7 @@ final class Transform implements MapView.OnMapChangedListener {
}
// cancel ongoing transitions
- mapView.cancelTransitions();
+ nativeMapView.cancelTransitions();
cameraChangeDispatcher.onCameraIdle();
}
@@ -201,7 +212,7 @@ final class Transform implements MapView.OnMapChangedListener {
@UiThread
void resetNorth() {
cancelTransitions();
- mapView.resetNorth();
+ nativeMapView.resetNorth();
}
//
@@ -219,37 +230,20 @@ final class Transform implements MapView.OnMapChangedListener {
// Zoom in or out
double getRawZoom() {
- return mapView.getZoom();
+ return nativeMapView.getZoom();
}
void zoomBy(double zoomAddition, @NonNull PointF focalPoint) {
- setZoom(mapView.getZoom() + zoomAddition, focalPoint);
+ setZoom(nativeMapView.getZoom() + zoomAddition, focalPoint);
}
void setZoom(double zoom, @NonNull PointF focalPoint) {
- setZoom(zoom, focalPoint, 0);
- }
-
- void setZoom(double zoom, @NonNull PointF focalPoint, final long duration) {
- if (mapView != null) {
- mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
- @Override
- public void onMapChanged(int change) {
- if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
- if (duration > 0) {
- cameraChangeDispatcher.onCameraIdle();
- }
- mapView.removeOnMapChangedListener(this);
- }
- }
- });
- mapView.setZoom(zoom, focalPoint, duration);
- }
+ nativeMapView.setZoom(zoom, focalPoint, 0);
}
// Direction
double getBearing() {
- double direction = -mapView.getBearing();
+ double direction = -nativeMapView.getBearing();
while (direction > 360) {
direction -= 360;
@@ -262,19 +256,19 @@ final class Transform implements MapView.OnMapChangedListener {
}
double getRawBearing() {
- return mapView.getBearing();
+ return nativeMapView.getBearing();
}
void setBearing(double bearing) {
- mapView.setBearing(bearing);
+ nativeMapView.setBearing(bearing);
}
void setBearing(double bearing, float focalX, float focalY) {
- mapView.setBearing(bearing, focalX, focalY);
+ nativeMapView.setBearing(bearing, focalX, focalY);
}
void setBearing(double bearing, float focalX, float focalY, long duration) {
- mapView.setBearing(bearing, focalX, focalY, duration);
+ nativeMapView.setBearing(bearing, focalX, focalY, duration);
}
@@ -283,7 +277,7 @@ final class Transform implements MapView.OnMapChangedListener {
//
LatLng getLatLng() {
- return mapView.getLatLng();
+ return nativeMapView.getLatLng();
}
//
@@ -291,12 +285,12 @@ final class Transform implements MapView.OnMapChangedListener {
//
double getTilt() {
- return mapView.getPitch();
+ return nativeMapView.getPitch();
}
void setTilt(Double pitch) {
markerViewManager.setTilt(pitch.floatValue());
- mapView.setPitch(pitch, 0);
+ nativeMapView.setPitch(pitch, 0);
}
//
@@ -304,15 +298,15 @@ final class Transform implements MapView.OnMapChangedListener {
//
LatLng getCenterCoordinate() {
- return mapView.getLatLng();
+ return nativeMapView.getLatLng();
}
void setCenterCoordinate(LatLng centerCoordinate) {
- mapView.setLatLng(centerCoordinate);
+ nativeMapView.setLatLng(centerCoordinate);
}
void setGestureInProgress(boolean gestureInProgress) {
- mapView.setGestureInProgress(gestureInProgress);
+ nativeMapView.setGestureInProgress(gestureInProgress);
if (!gestureInProgress) {
invalidateCameraPosition();
}
@@ -320,17 +314,9 @@ final class Transform implements MapView.OnMapChangedListener {
void moveBy(double offsetX, double offsetY, long duration) {
if (duration > 0) {
- mapView.addOnMapChangedListener(new MapView.OnMapChangedListener() {
- @Override
- public void onMapChanged(int change) {
- if (change == MapView.REGION_DID_CHANGE_ANIMATED) {
- mapView.removeOnMapChangedListener(this);
- cameraChangeDispatcher.onCameraIdle();
- }
- }
- });
+ mapView.addOnCameraDidChangeListener(moveByChangeListener);
}
- mapView.moveBy(offsetX, offsetY, duration);
+ nativeMapView.moveBy(offsetX, offsetY, duration);
}
//
@@ -342,11 +328,11 @@ final class Transform implements MapView.OnMapChangedListener {
Logger.e(TAG, String.format("Not setting minZoomPreference, value is in unsupported range: %s", minZoom));
return;
}
- mapView.setMinZoom(minZoom);
+ nativeMapView.setMinZoom(minZoom);
}
double getMinZoom() {
- return mapView.getMinZoom();
+ return nativeMapView.getMinZoom();
}
void setMaxZoom(double maxZoom) {
@@ -354,10 +340,10 @@ final class Transform implements MapView.OnMapChangedListener {
Logger.e(TAG, String.format("Not setting maxZoomPreference, value is in unsupported range: %s", maxZoom));
return;
}
- mapView.setMaxZoom(maxZoom);
+ nativeMapView.setMaxZoom(maxZoom);
}
double getMaxZoom() {
- return mapView.getMaxZoom();
+ return nativeMapView.getMaxZoom();
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
index 239ad7392b..a2f0486020 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/AnnotationManagerTest.java
@@ -34,7 +34,7 @@ public class AnnotationManagerTest {
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
- AnnotationManager annotationManager = new AnnotationManager(aNativeMapView, aMapView, annotationsArray,
+ AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
Marker aMarker = mock(Marker.class);
long aId = 5L;
@@ -61,7 +61,7 @@ public class AnnotationManagerTest {
Polygons polygons = new PolygonContainer(aNativeMapView, annotationsArray);
Polylines polylines = new PolylineContainer(aNativeMapView, annotationsArray);
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(aNativeMapView, annotationsArray);
- AnnotationManager annotationManager = new AnnotationManager(aNativeMapView, aMapView, annotationsArray,
+ AnnotationManager annotationManager = new AnnotationManager(aMapView, annotationsArray,
aMarkerViewManager, aIconManager, annotations, markers, polygons, polylines, shapeAnnotations);
long firstId = 1L;
long secondId = 2L;
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
index 9a323a1d75..4d10d22732 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -22,7 +22,8 @@ public class MapboxMapTest {
mock(Projection.class),
mock(MapboxMap.OnGesturesManagerInteractionListener.class),
mock(AnnotationManager.class),
- mock(CameraChangeDispatcher.class));
+ mock(CameraChangeDispatcher.class),
+ mock(MapChangeReceiver.class));
}
@Test(expected = IllegalArgumentException.class)