From d8c919f1dde44f428b65a2ab7eca262f7398422a Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 23 Mar 2020 07:51:37 +0100 Subject: [PATCH] [mapview] expose queuEvent to schedule runnable to execut on thread of MapRenderer (#284) --- .../com/mapbox/mapboxsdk/maps/MapView.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 553a6a5f6..a57f56164 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -160,18 +160,18 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { Polylines polylines = new PolylineContainer(nativeMapView, annotationsArray); ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray); AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager, - annotations, markers, polygons, polylines, shapeAnnotations); + annotations, markers, polygons, polylines, shapeAnnotations); Transform transform = new Transform(this, nativeMapView, cameraDispatcher); // MapboxMap List developerAnimationListeners = new ArrayList<>(); mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, cameraDispatcher, - developerAnimationListeners); + developerAnimationListeners); mapboxMap.injectAnnotationManager(annotationManager); // user input mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings, - annotationManager, cameraDispatcher); + annotationManager, cameraDispatcher); mapKeyListener = new MapKeyListener(transform, uiSettings, mapGestureDetector); // LocationComponent @@ -245,7 +245,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } private MapboxMap.OnCompassAnimationListener createCompassAnimationListener(@NonNull final CameraChangeDispatcher - cameraChangeDispatcher) { + cameraChangeDispatcher) { return new MapboxMap.OnCompassAnimationListener() { @Override public void onCompassAnimation() { @@ -313,7 +313,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { TextureView textureView = new TextureView(getContext()); boolean translucentSurface = options.getTranslucentTextureSurface(); mapRenderer = new TextureViewMapRenderer(getContext(), - textureView, localFontFamily, translucentSurface) { + textureView, localFontFamily, translucentSurface) { @Override protected void onSurfaceCreated(GL10 gl, EGLConfig config) { MapView.this.onSurfaceCreated(); @@ -340,7 +340,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { boolean crossSourceCollisions = mapboxMapOptions.getCrossSourceCollisions(); nativeMapView = new NativeMapView( - getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer + getContext(), getPixelRatio(), crossSourceCollisions, this, mapChangeReceiver, mapRenderer ); } @@ -466,6 +466,18 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } } + /** + * Queue a runnable to be executed on the map renderer thread. + * + * @param runnable the runnable to queue + */ + public void queueEvent(@NonNull Runnable runnable) { + if (mapRenderer == null) { + throw new IllegalStateException("Calling MapView#queueEvent before mapRenderer is created."); + } + mapRenderer.queueEvent(runnable); + } + /** * The maximum frame rate at which the map view is rendered, * but it can't excess the ability of device hardware. @@ -1249,7 +1261,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { public void setGesturesManager(AndroidGesturesManager gesturesManager, boolean attachDefaultListeners, boolean setDefaultMutuallyExclusives) { mapGestureDetector.setGesturesManager( - getContext(), gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives); + getContext(), gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives); } @Override @@ -1259,8 +1271,8 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { } private class MapCallback implements OnDidFinishLoadingStyleListener, - OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener, - OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener { + OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener, + OnCameraIsChangingListener, OnCameraDidChangeListener, OnDidFailLoadingMapListener { private final List onMapReadyCallbackList = new ArrayList<>();