summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2017-06-13 15:23:31 +0200
committerGitHub <noreply@github.com>2017-06-13 15:23:31 +0200
commit5a2dd1b5df6d2f1f37e940b43cc727b95ae08e8a (patch)
tree9c299a723d81cad03d95b7be8ea8312393335736 /platform
parenta05f060153497e1be6515120b65f580f4551f9e0 (diff)
downloadqtlocation-mapboxgl-5a2dd1b5df6d2f1f37e940b43cc727b95ae08e8a.tar.gz
[android] - snapshot bitmap contains view based content (#9252)
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java16
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/BitmapUtils.java33
2 files changed, 45 insertions, 4 deletions
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 6d9df8aebd..c0586a6449 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
@@ -30,6 +30,7 @@ import com.mapbox.mapboxsdk.style.layers.Layer;
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;
@@ -40,7 +41,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import timber.log.Timber;
-
// Class that wraps the native methods for convenience
final class NativeMapView {
@@ -917,12 +917,20 @@ final class NativeMapView {
}
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 0000000000..e3fc765734
--- /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;
+ }
+
+}