[android] use native image encoding and decoding

This commit is contained in:
Konstantin Käfer
2017-01-24 15:47:53 +01:00
parent 14d5c336d7
commit 4d35826014
10 changed files with 278 additions and 59 deletions

View File

@@ -1604,18 +1604,8 @@ public final class MapboxMap {
* @param bitmap A pre-allocated bitmap.
*/
@UiThread
public void snapshot(@NonNull SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
nativeMapView.addSnapshotCallback(callback, bitmap);
}
/**
* Takes a snapshot of the map.
*
* @param callback Callback method invoked when the snapshot is taken.
*/
@UiThread
public void snapshot(@NonNull SnapshotReadyCallback callback) {
snapshot(callback, null);
nativeMapView.addSnapshotCallback(callback);
}
/**

View File

@@ -3,7 +3,6 @@ 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;
@@ -54,7 +53,7 @@ final class NativeMapView {
private CopyOnWriteArrayList<MapView.OnMapChangedListener> onMapChangedListeners;
// Listener invoked to return a bitmap of the map
private SnapshotRequest snapshotRequest;
private MapboxMap.SnapshotReadyCallback snapshotReadyCallback;
//
// Static methods
@@ -935,18 +934,9 @@ final class NativeMapView {
mapView.onFpsChanged(fps);
}
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);
}
protected void onSnapshotReady(Bitmap bitmap) {
if (snapshotReadyCallback != null && bitmap != null) {
snapshotReadyCallback.onSnapshotReady(bitmap);
}
}
@@ -1187,27 +1177,9 @@ final class NativeMapView {
// Snapshot
//
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback, @Nullable Bitmap bitmap) {
snapshotRequest = new SnapshotRequest(bitmap, callback);
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
snapshotReadyCallback = 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;
}
}
}