From 7bfcce02662a9c429c3ac715728de63e2850231e Mon Sep 17 00:00:00 2001 From: Tobrun Date: Wed, 14 Jun 2017 14:34:03 +0200 Subject: [PATCH] Cherry pick release (#9263) * [core] - bump earcut version dependency to handle unused lamba warning (#9242) * [android] - snapshot bitmap contains view based content (#9252) --- CMakeLists.txt | 2 +- .../mapbox/mapboxsdk/maps/NativeMapView.java | 16 ++++++--- .../mapbox/mapboxsdk/utils/BitmapUtils.java | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c7a2ac572..8144d880ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,7 +50,7 @@ mason_use(boost VERSION 1.62.0 HEADER_ONLY) mason_use(geojsonvt VERSION 6.2.0 HEADER_ONLY) mason_use(supercluster VERSION 0.2.0-1 HEADER_ONLY) mason_use(kdbush VERSION 0.1.1-1 HEADER_ONLY) -mason_use(earcut VERSION 0.12.1 HEADER_ONLY) +mason_use(earcut VERSION 0.12.3 HEADER_ONLY) mason_use(protozero VERSION 1.4.2 HEADER_ONLY) mason_use(pixelmatch VERSION 0.10.0 HEADER_ONLY) mason_use(geojson VERSION 0.4.0 HEADER_ONLY) 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 a31babc1c54..af3b57151d6 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 @@ -29,6 +29,7 @@ import com.mapbox.mapboxsdk.style.light.Light; import com.mapbox.mapboxsdk.style.sources.CannotAddSourceException; import com.mapbox.mapboxsdk.style.sources.Source; +import com.mapbox.mapboxsdk.utils.BitmapUtils; import com.mapbox.services.commons.geojson.Feature; import java.nio.ByteBuffer; @@ -39,7 +40,6 @@ import timber.log.Timber; - // Class that wraps the native methods for convenience final class NativeMapView { @@ -920,12 +920,20 @@ protected void onMapChanged(int rawChange) { } protected void onFpsChanged(double fps) { + if (isDestroyedOn("OnFpsChanged")) { + return; + } mapView.onFpsChanged(fps); } - protected void onSnapshotReady(Bitmap bitmap) { - if (snapshotReadyCallback != null && bitmap != null) { - snapshotReadyCallback.onSnapshotReady(bitmap); + protected void onSnapshotReady(Bitmap mapContent) { + if (isDestroyedOn("OnSnapshotReady")) { + return; + } + + Bitmap viewContent = BitmapUtils.createBitmapFromView(mapView); + if (snapshotReadyCallback != null && mapContent != null && viewContent != null) { + snapshotReadyCallback.onSnapshotReady(BitmapUtils.mergeBitmap(mapContent, viewContent)); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java new file mode 100644 index 00000000000..e3fc7657342 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java @@ -0,0 +1,33 @@ +package com.mapbox.mapboxsdk.utils; + +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.support.annotation.NonNull; +import android.view.View; + +public class BitmapUtils { + + public static Bitmap createBitmapFromView(@NonNull View view) { + view.setDrawingCacheEnabled(true); + view.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW); + view.buildDrawingCache(); + + if (view.getDrawingCache() == null) { + return null; + } + + Bitmap snapshot = Bitmap.createBitmap(view.getDrawingCache()); + view.setDrawingCacheEnabled(false); + view.destroyDrawingCache(); + return snapshot; + } + + public static Bitmap mergeBitmap(@NonNull Bitmap background, @NonNull Bitmap foreground) { + Bitmap result = Bitmap.createBitmap(background.getWidth(), background.getHeight(), background.getConfig()); + Canvas canvas = new Canvas(result); + canvas.drawBitmap(background, 0f, 0f, null); + canvas.drawBitmap(foreground, 10, 10, null); + return result; + } + +}