[android] - optimise interface definition

This commit is contained in:
tobrun
2019-01-07 17:14:02 +01:00
committed by Tobrun
parent 99e369f45e
commit e6e07a6809
14 changed files with 344 additions and 417 deletions

View File

@@ -246,7 +246,7 @@ public final class MapboxMap {
* @param enable true to enable
*/
public void setPrefetchesTiles(boolean enable) {
nativeMapView.setPrefetchesTiles(enable);
nativeMapView.setPrefetchTiles(enable);
}
/**
@@ -256,7 +256,7 @@ public final class MapboxMap {
* @see MapboxMap#setPrefetchesTiles(boolean)
*/
public boolean getPrefetchesTiles() {
return nativeMapView.getPrefetchesTiles();
return nativeMapView.getPrefetchTiles();
}
//
@@ -597,7 +597,7 @@ public final class MapboxMap {
* @param y Amount of pixels to scroll to in y direction
*/
public void scrollBy(float x, float y) {
nativeMapView.moveBy(x, y);
nativeMapView.moveBy(x, y, 0);
}
/**

View File

@@ -17,19 +17,93 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
import com.mapbox.mapboxsdk.style.light.Light;
import com.mapbox.mapboxsdk.style.sources.Source;
import java.util.HashMap;
import java.util.List;
interface NativeMap {
void destroy();
//
// Lifecycle API
//
void update();
void resizeView(int width, int height);
void onLowMemory();
void destroy();
boolean isDestroyed();
//
// Camera API
//
void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing);
void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration,
boolean easingInterpolator);
void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration);
void moveBy(double deltaX, double deltaY, long duration);
@NonNull
CameraPosition getCameraPosition();
CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds bounds, int[] padding, double bearing, double pitch);
CameraPosition getCameraForGeometry(@NonNull Geometry geometry, int[] padding, double bearing, double pitch);
void resetPosition();
void setLatLng(@NonNull LatLng latLng, long duration);
LatLng getLatLng();
void setLatLngBounds(@NonNull LatLngBounds latLngBounds);
void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding,
double direction, long duration);
void setPitch(double pitch, long duration);
double getPitch();
void setZoom(double zoom, @NonNull PointF focalPoint, long duration);
double getZoom();
void setMinZoom(double zoom);
double getMinZoom();
void setMaxZoom(double zoom);
double getMaxZoom();
void resetZoom();
void rotateBy(double sx, double sy, double ex, double ey, long duration);
void setBearing(double degrees, long duration);
void setBearing(double degrees, double fx, double fy, long duration);
double getBearing();
void resetNorth();
void cancelTransitions();
//
// Style API
//
void setStyleUrl(String url);
@NonNull
@@ -40,68 +114,115 @@ interface NativeMap {
@NonNull
String getStyleJson();
void setLatLngBounds(LatLngBounds latLngBounds);
boolean isFullyLoaded();
void cancelTransitions();
void addLayer(@NonNull Layer layer);
void setGestureInProgress(boolean inProgress);
void addLayerBelow(@NonNull Layer layer, @NonNull String below);
void moveBy(double dx, double dy);
void addLayerAbove(@NonNull Layer layer, @NonNull String above);
void moveBy(double dx, double dy, long duration);
void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index);
void setLatLng(@NonNull LatLng latLng);
@NonNull
List<Layer> getLayers();
void setLatLng(@NonNull LatLng latLng, long duration);
Layer getLayer(String layerId);
LatLng getLatLng();
boolean removeLayer(@NonNull String layerId);
CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt);
boolean removeLayer(@NonNull Layer layer);
CameraPosition getCameraForGeometry(Geometry geometry, int[] padding, double bearing, double tilt);
boolean removeLayerAt(@IntRange(from = 0) int index);
void resetPosition();
void addSource(@NonNull Source source);
double getPitch();
@NonNull
List<Source> getSources();
void setPitch(double pitch);
Source getSource(@NonNull String sourceId);
void setPitch(double pitch, long duration);
boolean removeSource(@NonNull String sourceId);
void setZoom(double zoom, @NonNull PointF focalPoint, long duration);
boolean removeSource(@NonNull Source source);
double getZoom();
void setTransitionOptions(@NonNull TransitionOptions transitionOptions);
void resetZoom();
@NonNull
TransitionOptions getTransitionOptions();
void setMinZoom(double zoom);
void addImages(Image[] images);
double getMinZoom();
Bitmap getImage(String name);
void setMaxZoom(double zoom);
void removeImage(String name);
double getMaxZoom();
Light getLight();
void rotateBy(double sx, double sy, double ex, double ey);
void rotateBy(double sx, double sy, double ex, double ey,
long duration);
//
// Content padding API
//
void setContentPadding(float[] padding);
float[] getContentPadding();
void setBearing(double degrees);
//
// Query API
//
void setBearing(double degrees, long duration);
@NonNull
List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter);
void setBearing(double degrees, double cx, double cy);
@NonNull
List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter);
void setBearing(double degrees, double fx, double fy, long duration);
//
// Projection API
//
double getBearing();
double getMetersPerPixelAtLatitude(double lat);
void resetNorth();
ProjectedMeters projectedMetersForLatLng(@NonNull LatLng latLng);
LatLng latLngForProjectedMeters(@NonNull ProjectedMeters projectedMeters);
@NonNull
PointF pixelForLatLng(@NonNull LatLng latLng);
LatLng latLngForPixel(@NonNull PointF pixel);
//
// Utils API
//
void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener);
void setDebug(boolean debug);
boolean getDebug();
void cycleDebugOptions();
void setReachability(boolean status);
void setApiBaseUrl(String baseUrl);
void setPrefetchTiles(boolean enable);
boolean getPrefetchTiles();
void setGestureInProgress(boolean inProgress);
float getPixelRatio();
//
// Deprecated Annotations API
//
long addMarker(Marker marker);
@@ -128,120 +249,16 @@ interface NativeMap {
void removeAnnotations(long[] ids);
@NonNull
long[] queryPointAnnotations(RectF rect);
@NonNull
long[] queryShapeAnnotations(RectF rectF);
double getTopOffsetPixelsForAnnotationSymbol(String symbolName);
void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels);
void removeAnnotationIcon(String symbol);
void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration);
void onLowMemory();
void setDebug(boolean debug);
void cycleDebugOptions();
boolean getDebug();
boolean isFullyLoaded();
void setReachability(boolean status);
double getMetersPerPixelAtLatitude(double lat);
ProjectedMeters projectedMetersForLatLng(@NonNull LatLng latLng);
LatLng latLngForProjectedMeters(@NonNull ProjectedMeters projectedMeters);
@NonNull
long[] queryPointAnnotations(RectF rectF);
@NonNull
PointF pixelForLatLng(@NonNull LatLng latLng);
long[] queryShapeAnnotations(RectF rectF);
LatLng latLngForPixel(@NonNull PointF pixel);
double getTopOffsetPixelsForAnnotationSymbol(String symbolName);
void jumpTo(double angle, @NonNull LatLng center, double pitch, double zoom);
void easeTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom,
boolean easingInterpolator);
void flyTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom);
@NonNull
CameraPosition getCameraPosition();
void setPrefetchesTiles(boolean enable);
boolean getPrefetchesTiles();
long getTransitionDuration();
void setTransitionDuration(long duration);
long getTransitionDelay();
void setTransitionDelay(long delay);
@NonNull
List<Layer> getLayers();
Layer getLayer(String layerId);
void addLayer(@NonNull Layer layer);
void addLayerBelow(@NonNull Layer layer, @NonNull String below);
void addLayerAbove(@NonNull Layer layer, @NonNull String above);
void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index);
boolean removeLayer(@NonNull String layerId);
boolean removeLayer(@NonNull Layer layer);
boolean removeLayerAt(@IntRange(from = 0) int index);
@NonNull
List<Source> getSources();
Source getSource(@NonNull String sourceId);
void addSource(@NonNull Source source);
boolean removeSource(@NonNull String sourceId);
boolean removeSource(@NonNull Source source);
void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf);
void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap);
void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap, boolean sdf);
void removeImage(String name);
Bitmap getImage(String name);
@NonNull
List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter);
@NonNull
List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter);
void setApiBaseUrl(String baseUrl);
Light getLight();
float getPixelRatio();
void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener);
}
}

View File

@@ -4,15 +4,12 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.AsyncTask;
import android.os.Handler;
import android.support.annotation.IntRange;
import android.support.annotation.Keep;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
import com.mapbox.mapboxsdk.LibraryLoader;
@@ -32,17 +29,15 @@ import com.mapbox.mapboxsdk.storage.FileSource;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.CannotAddLayerException;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
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 java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// Class that wraps the native methods for convenience
final class NativeMapView implements NativeMap {
@@ -242,14 +237,6 @@ final class NativeMapView implements NativeMap {
nativeSetGestureInProgress(inProgress);
}
@Override
public void moveBy(double dx, double dy) {
if (checkState("moveBy")) {
return;
}
moveBy(dx, dy, 0);
}
@Override
public void moveBy(double dx, double dy, long duration) {
if (checkState("moveBy")) {
@@ -258,14 +245,6 @@ final class NativeMapView implements NativeMap {
nativeMoveBy(dx / pixelRatio, dy / pixelRatio, duration);
}
@Override
public void setLatLng(@NonNull LatLng latLng) {
if (checkState("setLatLng")) {
return;
}
setLatLng(latLng, 0);
}
@Override
public void setLatLng(@NonNull LatLng latLng, long duration) {
if (checkState("setLatLng")) {
@@ -330,11 +309,6 @@ final class NativeMapView implements NativeMap {
return nativeGetPitch();
}
@Override
public void setPitch(double pitch) {
setPitch(pitch, 0);
}
@Override
public void setPitch(double pitch, long duration) {
if (checkState("setPitch")) {
@@ -399,14 +373,6 @@ final class NativeMapView implements NativeMap {
return nativeGetMaxZoom();
}
@Override
public void rotateBy(double sx, double sy, double ex, double ey) {
if (checkState("rotateBy")) {
return;
}
rotateBy(sx, sy, ex, ey, 0);
}
@Override
public void rotateBy(double sx, double sy, double ex, double ey,
long duration) {
@@ -435,7 +401,7 @@ final class NativeMapView implements NativeMap {
return new float[] {0, 0, 0, 0};
}
float[] topLeftBottomRight = nativeGetContentPadding();
return new float[]{
return new float[] {
topLeftBottomRight[1] * pixelRatio,
topLeftBottomRight[0] * pixelRatio,
topLeftBottomRight[3] * pixelRatio,
@@ -443,14 +409,6 @@ final class NativeMapView implements NativeMap {
};
}
@Override
public void setBearing(double degrees) {
if (checkState("setBearing")) {
return;
}
setBearing(degrees, 0);
}
@Override
public void setBearing(double degrees, long duration) {
if (checkState("setBearing")) {
@@ -459,14 +417,6 @@ final class NativeMapView implements NativeMap {
nativeSetBearing(degrees, duration);
}
@Override
public void setBearing(double degrees, double cx, double cy) {
if (checkState("setBearing")) {
return;
}
setBearing(degrees, cx, cy, 0);
}
@Override
public void setBearing(double degrees, double fx, double fy, long duration) {
if (checkState("setBearing")) {
@@ -731,7 +681,7 @@ final class NativeMapView implements NativeMap {
}
@Override
public void jumpTo(double angle, @NonNull LatLng center, double pitch, double zoom) {
public void jumpTo(@NonNull LatLng center, double zoom, double pitch, double angle) {
if (checkState("jumpTo")) {
return;
}
@@ -739,7 +689,7 @@ final class NativeMapView implements NativeMap {
}
@Override
public void easeTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom,
public void easeTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration,
boolean easingInterpolator) {
if (checkState("easeTo")) {
return;
@@ -749,7 +699,7 @@ final class NativeMapView implements NativeMap {
}
@Override
public void flyTo(double angle, @NonNull LatLng center, long duration, double pitch, double zoom) {
public void flyTo(@NonNull LatLng center, double zoom, double angle, double pitch, long duration) {
if (checkState("flyTo")) {
return;
}
@@ -766,41 +716,32 @@ final class NativeMapView implements NativeMap {
}
@Override
public void setPrefetchesTiles(boolean enable) {
if (checkState("setPrefetchesTiles")) {
public void setPrefetchTiles(boolean enable) {
if (checkState("setPrefetchTiles")) {
return;
}
nativeSetPrefetchesTiles(enable);
nativeSetPrefetchTiles(enable);
}
@Override
public boolean getPrefetchesTiles() {
if (checkState("getPrefetchesTiles")) {
public boolean getPrefetchTiles() {
if (checkState("getPrefetchTiles")) {
return false;
}
return nativeGetPrefetchesTiles();
return nativeGetPrefetchTiles();
}
// Runtime style Api
@Override
public long getTransitionDuration() {
return nativeGetTransitionDuration();
public void setTransitionOptions(@NonNull TransitionOptions transitionOptions) {
nativeSetTransitionOptions(transitionOptions);
}
@NonNull
@Override
public void setTransitionDuration(long duration) {
nativeSetTransitionDuration(duration);
}
@Override
public long getTransitionDelay() {
return nativeGetTransitionDelay();
}
@Override
public void setTransitionDelay(long delay) {
nativeSetTransitionDelay(delay);
public TransitionOptions getTransitionOptions() {
return nativeGetTransitionOptions();
}
@Override
@@ -928,31 +869,11 @@ final class NativeMapView implements NativeMap {
}
@Override
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
if (checkState("addImage")) {
return;
}
// Determine pixel ratio, cast to float to avoid rounding, see mapbox-gl-native/issues/11809
float pixelRatio = (float) image.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
nativeAddImage(name, image, pixelRatio, sdf);
}
@Override
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) {
public void addImages(@NonNull Image[] images) {
if (checkState("addImages")) {
return;
}
this.addImages(bitmapHashMap, false);
}
@Override
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
if (checkState("addImages")) {
return;
}
//noinspection unchecked
new BitmapImageConversionTask(this, sdf).execute(bitmapHashMap);
nativeAddImages(images);
}
@Override
@@ -1342,6 +1263,13 @@ final class NativeMapView implements NativeMap {
@Keep
private native CameraPosition nativeGetCameraPosition();
@Keep
private native void nativeSetTransitionOptions(TransitionOptions transitionOptions);
@NonNull
@Keep
private native TransitionOptions nativeGetTransitionOptions();
@Keep
private native long nativeGetTransitionDuration();
@@ -1431,20 +1359,20 @@ final class NativeMapView implements NativeMap {
private native Light nativeGetLight();
@Keep
private native void nativeSetPrefetchesTiles(boolean enable);
private native void nativeSetPrefetchTiles(boolean enable);
@Keep
private native boolean nativeGetPrefetchesTiles();
private native boolean nativeGetPrefetchTiles();
int getWidth() {
if (checkState("")) {
if (checkState("") || viewCallback == null) {
return 0;
}
return viewCallback.getWidth();
}
int getHeight() {
if (checkState("")) {
if (checkState("") || viewCallback == null) {
return 0;
}
return viewCallback.getHeight();
@@ -1487,62 +1415,11 @@ final class NativeMapView implements NativeMap {
});
}
boolean isDestroyed() {
@Override
public boolean isDestroyed() {
return destroyed;
}
//
// Image conversion
//
private static class BitmapImageConversionTask extends AsyncTask<HashMap<String, Bitmap>, Void, List<Image>> {
private NativeMapView nativeMapView;
private boolean sdf;
BitmapImageConversionTask(NativeMapView nativeMapView, boolean sdf) {
this.nativeMapView = nativeMapView;
this.sdf = sdf;
}
@NonNull
@Override
protected List<Image> doInBackground(HashMap<String, Bitmap>... params) {
HashMap<String, Bitmap> bitmapHashMap = params[0];
List<Image> images = new ArrayList<>();
ByteBuffer buffer;
String name;
Bitmap bitmap;
for (Map.Entry<String, Bitmap> stringBitmapEntry : bitmapHashMap.entrySet()) {
name = stringBitmapEntry.getKey();
bitmap = stringBitmapEntry.getValue();
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
}
buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer);
float pixelRatio = (float) bitmap.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight(), sdf));
}
return images;
}
@Override
protected void onPostExecute(@NonNull List<Image> images) {
super.onPostExecute(images);
if (nativeMapView != null && !nativeMapView.checkState("nativeAddImages")) {
nativeMapView.nativeAddImages(images.toArray(new Image[images.size()]));
}
}
}
public interface ViewCallback {
int getWidth();

View File

@@ -1,10 +1,12 @@
package com.mapbox.mapboxsdk.maps;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
import android.util.DisplayMetrics;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
@@ -13,6 +15,8 @@ import com.mapbox.mapboxsdk.style.sources.Source;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.ref.WeakReference;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -26,6 +30,7 @@ import java.util.Map;
* has been loaded by underlying map.
* </p>
*/
@SuppressWarnings("unchecked")
public class Style {
private final NativeMap nativeMap;
@@ -38,7 +43,7 @@ public class Style {
/**
* Private constructor to build a style object.
*
* @param builder the builder used for creating this style
* @param builder the builder used for creating this style
* @param nativeMap the map object used to load this style
*/
private Style(@NonNull Builder builder, @NonNull NativeMap nativeMap) {
@@ -296,21 +301,28 @@ public class Style {
/**
* Adds an image to be used in the map's style
*
* @param name the name of the image
* @param image the pre-multiplied Bitmap
* @param sdf the flag indicating image is an SDF or template image
* @param name the name of the image
* @param bitmap the pre-multiplied Bitmap
* @param sdf the flag indicating image is an SDF or template image
*/
public void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf) {
public void addImage(@NonNull final String name, @NonNull final Bitmap bitmap, boolean sdf) {
validateState("addImage");
nativeMap.addImage(name, image, sdf);
new BitmapImageConversionTask(nativeMap, sdf).execute(new Builder.ImageWrapper(name, bitmap, sdf));
}
/**
* Adds an images to be used in the map's style.
*/
public void addImages(@NonNull HashMap<String, Bitmap> images) {
addImages(images, false);
}
/**
* Adds an images to be used in the map's style.
*/
public void addImages(@NonNull HashMap<String, Bitmap> images, boolean sdf) {
validateState("addImages");
nativeMap.addImages(images);
new BitmapImageConversionTask(nativeMap, sdf).execute(Builder.ImageWrapper.convertToImageArray(images, sdf));
}
/**
@@ -349,8 +361,7 @@ public class Style {
*/
public void setTransition(@NonNull TransitionOptions transitionOptions) {
validateState("setTransition");
nativeMap.setTransitionDuration(transitionOptions.getDuration());
nativeMap.setTransitionDelay(transitionOptions.getDelay());
nativeMap.setTransitionOptions(transitionOptions);
}
/**
@@ -364,7 +375,7 @@ public class Style {
@NonNull
public TransitionOptions getTransition() {
validateState("getTransition");
return new TransitionOptions(nativeMap.getTransitionDuration(), nativeMap.getTransitionDelay());
return nativeMap.getTransitionOptions();
}
//
@@ -675,7 +686,7 @@ public class Style {
return new Style(this, nativeMap);
}
class ImageWrapper {
static class ImageWrapper {
Bitmap bitmap;
String id;
boolean sdf;
@@ -685,6 +696,16 @@ public class Style {
this.bitmap = bitmap;
this.sdf = sdf;
}
static ImageWrapper[] convertToImageArray(HashMap<String, Bitmap> bitmapHashMap, boolean sdf) {
ImageWrapper[] images = new ImageWrapper[bitmapHashMap.size()];
List<String> keyList = new ArrayList<>(bitmapHashMap.keySet());
for (int i = 0; i < bitmapHashMap.size(); i++) {
String id = keyList.get(i);
images[i] = new ImageWrapper(id, bitmapHashMap.get(id), sdf);
}
return images;
}
}
class LayerWrapper {
@@ -723,6 +744,53 @@ public class Style {
}
}
private static class BitmapImageConversionTask extends AsyncTask<Builder.ImageWrapper, Void, List<Image>> {
private WeakReference<NativeMap> nativeMap;
private boolean sdf;
BitmapImageConversionTask(NativeMap nativeMap, boolean sdf) {
this.nativeMap = new WeakReference<>(nativeMap);
this.sdf = sdf;
}
@NonNull
@Override
protected List<Image> doInBackground(Builder.ImageWrapper... params) {
List<Image> images = new ArrayList<>();
ByteBuffer buffer;
String name;
Bitmap bitmap;
for (Builder.ImageWrapper param : params) {
name = param.id;
bitmap = param.bitmap;
if (bitmap.getConfig() != Bitmap.Config.ARGB_8888) {
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false);
}
buffer = ByteBuffer.allocate(bitmap.getByteCount());
bitmap.copyPixelsToBuffer(buffer);
float pixelRatio = (float) bitmap.getDensity() / DisplayMetrics.DENSITY_DEFAULT;
images.add(new Image(buffer.array(), pixelRatio, name, bitmap.getWidth(), bitmap.getHeight(), sdf));
}
return images;
}
@Override
protected void onPostExecute(@NonNull List<Image> images) {
super.onPostExecute(images);
NativeMap nativeMap = this.nativeMap.get();
if (nativeMap != null && !nativeMap.isDestroyed()) {
nativeMap.addImages(images.toArray(new Image[images.size()]));
}
}
}
/**
* Callback to be invoked when a style has finished loading.
*/

View File

@@ -99,7 +99,7 @@ final class Transform implements MapView.OnCameraDidChangeListener {
if (isValidCameraPosition(cameraPosition)) {
cancelTransitions();
cameraChangeDispatcher.onCameraMoveStarted(OnCameraMoveStartedListener.REASON_API_ANIMATION);
nativeMap.jumpTo(cameraPosition.bearing, cameraPosition.target, cameraPosition.tilt, cameraPosition.zoom);
nativeMap.jumpTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.tilt, cameraPosition.bearing);
cameraChangeDispatcher.onCameraIdle();
invalidateCameraPosition();
handler.post(new Runnable() {
@@ -125,8 +125,8 @@ final class Transform implements MapView.OnCameraDidChangeListener {
cameraCancelableCallback = callback;
}
mapView.addOnCameraDidChangeListener(this);
nativeMap.easeTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom, easingInterpolator);
nativeMap.easeTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing, cameraPosition.tilt,
durationMs, easingInterpolator);
}
}
@@ -142,8 +142,8 @@ final class Transform implements MapView.OnCameraDidChangeListener {
cameraCancelableCallback = callback;
}
mapView.addOnCameraDidChangeListener(this);
nativeMap.flyTo(cameraPosition.bearing, cameraPosition.target, durationMs, cameraPosition.tilt,
cameraPosition.zoom);
nativeMap.flyTo(cameraPosition.target, cameraPosition.zoom, cameraPosition.bearing,
cameraPosition.tilt, durationMs);
}
}
@@ -231,11 +231,11 @@ final class Transform implements MapView.OnCameraDidChangeListener {
}
void setBearing(double bearing) {
nativeMap.setBearing(bearing);
nativeMap.setBearing(bearing, 0);
}
void setBearing(double bearing, float focalX, float focalY) {
nativeMap.setBearing(bearing, focalX, focalY);
nativeMap.setBearing(bearing, focalX, focalY, 0);
}
void setBearing(double bearing, float focalX, float focalY, long duration) {
@@ -272,7 +272,7 @@ final class Transform implements MapView.OnCameraDidChangeListener {
}
void setCenterCoordinate(LatLng centerCoordinate) {
nativeMap.setLatLng(centerCoordinate);
nativeMap.setLatLng(centerCoordinate, 0);
}
void setGestureInProgress(boolean gestureInProgress) {

View File

@@ -11,7 +11,9 @@ import android.support.annotation.Nullable;
*/
public class TransitionOptions {
@Keep
private long duration;
@Keep
private long delay;
/**