diff options
author | tobrun <tobrun.van.nuland@gmail.com> | 2019-05-09 13:14:00 +0200 |
---|---|---|
committer | Tobrun <tobrun.van.nuland@gmail.com> | 2019-05-09 15:58:09 +0200 |
commit | f586ec378e7fdf670906819278dffa62ef21f158 (patch) | |
tree | 0fd80dbc8508bcbcf7ba1378a6529bd1c606f5ac | |
parent | 842ee6b6f5e9cb17cff4654a8f7cbcacea72fdfd (diff) | |
download | qtlocation-mapboxgl-f586ec378e7fdf670906819278dffa62ef21f158.tar.gz |
[android] - add javadoc to highlight imcompatible onIdle with snapshot API, update test app example to use OnFullyRenderedFrame callback instead
2 files changed, 15 insertions, 6 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 b04b1f8271..a2c49b0d8f 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 @@ -937,6 +937,10 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback { /** * Interface definition for a callback to be invoked when the map has entered the idle state. * <p> + * Calling {@link MapboxMap#snapshot(MapboxMap.SnapshotReadyCallback)} from this callback + * will result in recursive execution. Use {@link OnDidFinishRenderingFrameListener} instead. + * </p> + * <p> * {@link MapView#addOnDidBecomeIdleListener(OnDidBecomeIdleListener)} * </p> */ diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.kt index 51b1c08ba5..a432996723 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.kt @@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk.testapp.activity.imagegenerator import android.os.Bundle import android.support.v7.app.AppCompatActivity +import com.mapbox.mapboxsdk.log.Logger import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.maps.OnMapReadyCallback @@ -17,12 +18,11 @@ class SnapshotActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mapboxMap: MapboxMap - private val idleListener = object : MapView.OnDidBecomeIdleListener { - override fun onDidBecomeIdle() { - mapView.removeOnDidBecomeIdleListener(this) + private val idleListener = MapView.OnDidFinishRenderingFrameListener { fully -> + if (fully) { + Logger.v(TAG, LOG_MESSAGE) mapboxMap.snapshot { snapshot -> imageView.setImageBitmap(snapshot) - mapView.addOnDidBecomeIdleListener(this) } } } @@ -36,7 +36,7 @@ class SnapshotActivity : AppCompatActivity(), OnMapReadyCallback { override fun onMapReady(map: MapboxMap) { mapboxMap = map - mapboxMap.setStyle(Style.Builder().fromUrl(Style.OUTDOORS)) { mapView.addOnDidBecomeIdleListener(idleListener) } + mapboxMap.setStyle(Style.Builder().fromUrl(Style.OUTDOORS)) { mapView.addOnDidFinishRenderingFrameListener(idleListener) } } override fun onStart() { @@ -74,7 +74,12 @@ class SnapshotActivity : AppCompatActivity(), OnMapReadyCallback { public override fun onDestroy() { super.onDestroy() - mapView.removeOnDidBecomeIdleListener(idleListener) + mapView.removeOnDidFinishRenderingFrameListener(idleListener) mapView.onDestroy() } + + companion object { + const val TAG ="Mbgl-SnapshotActivity" + const val LOG_MESSAGE = "OnSnapshot" + } } |