diff options
author | Tobrun <tobrun.van.nuland@gmail.com> | 2017-01-05 00:14:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-05 00:14:35 +0100 |
commit | cf859d6d0b782b03f7cda175757daed08731b440 (patch) | |
tree | da99364b253f4d4c9c84345e4cd014e3eb5440ad | |
parent | b515762528ce1b14b23fc7c445dc9c8702ac6600 (diff) | |
download | qtlocation-mapboxgl-cf859d6d0b782b03f7cda175757daed08731b440.tar.gz |
[android] - move snapshot t NativeMapView (#7463)
3 files changed, 50 insertions, 71 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 47a5000de1..3cb074d209 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 @@ -8,8 +8,6 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.PointF; import android.graphics.SurfaceTexture; @@ -86,7 +84,6 @@ public class MapView extends FrameLayout { private MapZoomButtonController mapZoomButtonController; private ConnectivityReceiver connectivityReceiver; - private SnapshotRequest snapshotRequest; @UiThread public MapView(@NonNull Context context) { @@ -609,14 +606,6 @@ public class MapView extends FrameLayout { } } - // Called when the map view transformation has changed - // Called via JNI from NativeMapView - // Forward to any listeners - protected void onMapChanged(int mapChange) { - nativeMapView.onMapChangedEventDispatch(mapChange); - } - - /** * Sets a callback object which will be triggered when the {@link MapboxMap} instance is ready to be used. * @@ -641,53 +630,6 @@ public class MapView extends FrameLayout { this.mapboxMap = mapboxMap; } - // - // Snapshot API - // - - @UiThread - void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) { - snapshotRequest = new SnapshotRequest(bitmap, callback); - nativeMapView.scheduleTakeSnapshot(); - nativeMapView.render(); - } - - // Called when the snapshot method was executed - // Called via JNI from NativeMapView - // Forward to any listeners - protected void onSnapshotReady(byte[] bytes) { - if (snapshotRequest != null && bytes != null) { - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inBitmap = snapshotRequest.getBitmap(); // the old Bitmap to be reused - options.inMutable = true; - options.inSampleSize = 1; - Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); - - MapboxMap.SnapshotReadyCallback callback = snapshotRequest.getCallback(); - if (callback != null) { - callback.onSnapshotReady(bitmap); - } - } - } - - private class SnapshotRequest { - private Bitmap bitmap; - private MapboxMap.SnapshotReadyCallback callback; - - SnapshotRequest(Bitmap bitmap, MapboxMap.SnapshotReadyCallback callback) { - this.bitmap = bitmap; - this.callback = callback; - } - - public Bitmap getBitmap() { - return bitmap; - } - - public MapboxMap.SnapshotReadyCallback getCallback() { - return callback; - } - } - private static class AttributionOnClickListener implements View.OnClickListener, DialogInterface.OnClickListener { private static final int ATTRIBUTION_INDEX_IMPROVE_THIS_MAP = 2; @@ -1062,7 +1004,7 @@ public class MapView extends FrameLayout { } } - public boolean isInitialLoad() { + boolean isInitialLoad() { return initialLoad; } 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 dd310776e9..f460a77229 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 @@ -1560,8 +1560,7 @@ public final class MapboxMap { */ @UiThread public void snapshot(@NonNull SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) { - // FIXME 12/02/2016 - //mapView.snapshot(callback, bitmap); + nativeMapView.addSnapshotCallback(callback, bitmap); } /** @@ -1571,8 +1570,7 @@ public final class MapboxMap { */ @UiThread public void snapshot(@NonNull SnapshotReadyCallback callback) { - // FIXME 12/02/2016 - //mapView.snapshot(callback, null); + snapshot(callback, null); } /** @@ -1989,4 +1987,4 @@ public final class MapboxMap { Transform getTransform() { return transform; } -} +}
\ No newline at end of file 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 95c0ae5327..8300e8024b 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 @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.maps; import android.app.ActivityManager; import android.content.Context; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.PointF; import android.graphics.RectF; import android.os.Build; @@ -50,6 +51,9 @@ final class NativeMapView { // Listeners for Map change events private CopyOnWriteArrayList<MapView.OnMapChangedListener> onMapChangedListeners; + // Listener invoked to return a bitmap of the map + private SnapshotRequest snapshotRequest; + // // Static methods // @@ -603,7 +607,11 @@ final class NativeMapView { } protected void onMapChanged(int rawChange) { - mapView.onMapChanged(rawChange); + if (onMapChangedListeners != null) { + for (MapView.OnMapChangedListener onMapChangedListener : onMapChangedListeners) { + onMapChangedListener.onMapChanged(rawChange); + } + } } protected void onFpsChanged(double fps) { @@ -611,7 +619,18 @@ final class NativeMapView { } protected void onSnapshotReady(byte[] bytes) { - mapView.onSnapshotReady(bytes); + if (snapshotRequest != null && bytes != null) { + BitmapFactory.Options options = new BitmapFactory.Options(); + options.inBitmap = snapshotRequest.getBitmap(); // the old Bitmap to be reused + options.inMutable = true; + options.inSampleSize = 1; + Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options); + + MapboxMap.SnapshotReadyCallback callback = snapshotRequest.getCallback(); + if (callback != null) { + callback.onSnapshotReady(bitmap); + } + } } // @@ -833,11 +852,31 @@ final class NativeMapView { onMapChangedListeners.remove(listener); } - void onMapChangedEventDispatch(int mapChange) { - if (onMapChangedListeners != null) { - for (MapView.OnMapChangedListener onMapChangedListener : onMapChangedListeners) { - onMapChangedListener.onMapChanged(mapChange); - } + // + // Snapshot + // + + void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback, @Nullable Bitmap bitmap) { + snapshotRequest = new SnapshotRequest(bitmap, callback); + scheduleTakeSnapshot(); + render(); + } + + private static class SnapshotRequest { + private Bitmap bitmap; + private MapboxMap.SnapshotReadyCallback callback; + + SnapshotRequest(Bitmap bitmap, MapboxMap.SnapshotReadyCallback callback) { + this.bitmap = bitmap; + this.callback = callback; + } + + public Bitmap getBitmap() { + return bitmap; + } + + public MapboxMap.SnapshotReadyCallback getCallback() { + return callback; } } } |