From dcb3d5918d9cd68dcb62d142d9ca30191bb03770 Mon Sep 17 00:00:00 2001 From: tobrun Date: Mon, 7 Jan 2019 17:14:02 +0100 Subject: [android] - optimise interface definition --- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 6 +- .../java/com/mapbox/mapboxsdk/maps/NativeMap.java | 231 +++++++++++---------- .../com/mapbox/mapboxsdk/maps/NativeMapView.java | 185 +++-------------- .../main/java/com/mapbox/mapboxsdk/maps/Style.java | 90 +++++++- .../java/com/mapbox/mapboxsdk/maps/Transform.java | 16 +- .../mapboxsdk/style/layers/TransitionOptions.java | 2 + .../com/mapbox/mapboxsdk/maps/MapboxMapTest.kt | 12 +- .../java/com/mapbox/mapboxsdk/maps/StyleTest.kt | 47 +---- .../com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt | 30 +-- .../mapbox/mapboxsdk/testapp/style/ImageTest.java | 3 + platform/android/src/native_map_view.cpp | 41 ++-- platform/android/src/native_map_view.hpp | 12 +- platform/android/src/style/transition_options.cpp | 12 ++ platform/android/src/style/transition_options.hpp | 4 + 14 files changed, 309 insertions(+), 382 deletions(-) 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 dcd40326aa..3346bd6d64 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 @@ -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); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java index 96aec573cc..cf5961a313 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMap.java @@ -17,63 +17,67 @@ 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 setStyleUrl(String url); + void onLowMemory(); - @NonNull - String getStyleUrl(); + void destroy(); - void setStyleJson(String newStyleJson); + boolean isDestroyed(); - @NonNull - String getStyleJson(); + // + // Camera API + // - void setLatLngBounds(LatLngBounds latLngBounds); + void jumpTo(@NonNull LatLng center, double zoom, double pitch, double bearing); - void cancelTransitions(); + void easeTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration, + boolean easingInterpolator); - void setGestureInProgress(boolean inProgress); + void flyTo(@NonNull LatLng center, double zoom, double bearing, double pitch, long duration); + + void moveBy(double deltaX, double deltaY, long duration); + + @NonNull + CameraPosition getCameraPosition(); - void moveBy(double dx, double dy); + CameraPosition getCameraForLatLngBounds(@NonNull LatLngBounds bounds, int[] padding, double bearing, double pitch); - void moveBy(double dx, double dy, long duration); + CameraPosition getCameraForGeometry(@NonNull Geometry geometry, int[] padding, double bearing, double pitch); - void setLatLng(@NonNull LatLng latLng); + void resetPosition(); void setLatLng(@NonNull LatLng latLng, long duration); LatLng getLatLng(); - CameraPosition getCameraForLatLngBounds(LatLngBounds bounds, int[] padding, double bearing, double tilt); + void setLatLngBounds(@NonNull LatLngBounds latLngBounds); - CameraPosition getCameraForGeometry(Geometry geometry, int[] padding, double bearing, double tilt); + void setVisibleCoordinateBounds(@NonNull LatLng[] coordinates, @NonNull RectF padding, + double direction, long duration); - void resetPosition(); + void setPitch(double pitch, long duration); double getPitch(); - void setPitch(double pitch); - - void setPitch(double pitch, long duration); - void setZoom(double zoom, @NonNull PointF focalPoint, long duration); double getZoom(); - void resetZoom(); - void setMinZoom(double zoom); double getMinZoom(); @@ -82,75 +86,104 @@ interface NativeMap { double getMaxZoom(); - void rotateBy(double sx, double sy, double ex, double ey); - - void rotateBy(double sx, double sy, double ex, double ey, - long duration); - - void setContentPadding(float[] padding); - - float[] getContentPadding(); + void resetZoom(); - void setBearing(double degrees); + void rotateBy(double sx, double sy, double ex, double ey, long duration); void setBearing(double degrees, long duration); - void setBearing(double degrees, double cx, double cy); - void setBearing(double degrees, double fx, double fy, long duration); double getBearing(); void resetNorth(); - long addMarker(Marker marker); + void cancelTransitions(); + + // + // Style API + // + + void setStyleUrl(String url); @NonNull - long[] addMarkers(@NonNull List markers); + String getStyleUrl(); - long addPolyline(Polyline polyline); + void setStyleJson(String newStyleJson); @NonNull - long[] addPolylines(@NonNull List polylines); + String getStyleJson(); - long addPolygon(Polygon polygon); + boolean isFullyLoaded(); + + 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); @NonNull - long[] addPolygons(@NonNull List polygons); + List getLayers(); - void updateMarker(@NonNull Marker marker); + Layer getLayer(String layerId); - void updatePolygon(@NonNull Polygon polygon); + boolean removeLayer(@NonNull String layerId); - void updatePolyline(@NonNull Polyline polyline); + boolean removeLayer(@NonNull Layer layer); - void removeAnnotation(long id); + boolean removeLayerAt(@IntRange(from = 0) int index); - void removeAnnotations(long[] ids); + void addSource(@NonNull Source source); @NonNull - long[] queryPointAnnotations(RectF rect); + List getSources(); + + Source getSource(@NonNull String sourceId); + + boolean removeSource(@NonNull String sourceId); + + boolean removeSource(@NonNull Source source); + + void setTransitionOptions(@NonNull TransitionOptions transitionOptions); @NonNull - long[] queryShapeAnnotations(RectF rectF); + TransitionOptions getTransitionOptions(); - void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); + void addImages(Image[] images); - void removeAnnotationIcon(String symbol); + Bitmap getImage(String name); - void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration); + void removeImage(String name); - void onLowMemory(); + Light getLight(); - void setDebug(boolean debug); + // + // Content padding API + // - void cycleDebugOptions(); + void setContentPadding(float[] padding); - boolean getDebug(); + float[] getContentPadding(); - boolean isFullyLoaded(); + // + // Query API + // - void setReachability(boolean status); + @NonNull + List queryRenderedFeatures(@NonNull PointF coordinates, + @Nullable String[] layerIds, + @Nullable Expression filter); + + @NonNull + List queryRenderedFeatures(@NonNull RectF coordinates, + @Nullable String[] layerIds, + @Nullable Expression filter); + + // + // Projection API + // double getMetersPerPixelAtLatitude(double lat); @@ -163,85 +196,69 @@ interface NativeMap { 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); + // + // Utils API + // - @NonNull - CameraPosition getCameraPosition(); + void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener); - void setPrefetchesTiles(boolean enable); + void setDebug(boolean debug); - boolean getPrefetchesTiles(); + boolean getDebug(); - long getTransitionDuration(); + void cycleDebugOptions(); - void setTransitionDuration(long duration); + void setReachability(boolean status); - long getTransitionDelay(); + void setApiBaseUrl(String baseUrl); - void setTransitionDelay(long delay); + void setPrefetchTiles(boolean enable); - @NonNull - List getLayers(); + boolean getPrefetchTiles(); - Layer getLayer(String layerId); + void setGestureInProgress(boolean inProgress); - void addLayer(@NonNull Layer layer); + float getPixelRatio(); - void addLayerBelow(@NonNull Layer layer, @NonNull String below); + // + // Deprecated Annotations API + // - void addLayerAbove(@NonNull Layer layer, @NonNull String above); + long addMarker(Marker marker); - void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index); + @NonNull + long[] addMarkers(@NonNull List markers); - boolean removeLayer(@NonNull String layerId); + long addPolyline(Polyline polyline); - boolean removeLayer(@NonNull Layer layer); + @NonNull + long[] addPolylines(@NonNull List polylines); - boolean removeLayerAt(@IntRange(from = 0) int index); + long addPolygon(Polygon polygon); @NonNull - List getSources(); - - Source getSource(@NonNull String sourceId); + long[] addPolygons(@NonNull List polygons); - void addSource(@NonNull Source source); + void updateMarker(@NonNull Marker marker); - boolean removeSource(@NonNull String sourceId); + void updatePolygon(@NonNull Polygon polygon); - boolean removeSource(@NonNull Source source); + void updatePolyline(@NonNull Polyline polyline); - void addImage(@NonNull String name, @NonNull Bitmap image, boolean sdf); + void removeAnnotation(long id); - void addImages(@NonNull HashMap bitmapHashMap); + void removeAnnotations(long[] ids); - void addImages(@NonNull HashMap bitmapHashMap, boolean sdf); + double getTopOffsetPixelsForAnnotationSymbol(String symbolName); - void removeImage(String name); + void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels); - Bitmap getImage(String name); + void removeAnnotationIcon(String symbol); @NonNull - List queryRenderedFeatures(@NonNull PointF coordinates, - @Nullable String[] layerIds, - @Nullable Expression filter); + long[] queryPointAnnotations(RectF rectF); @NonNull - List queryRenderedFeatures(@NonNull RectF coordinates, - @Nullable String[] layerIds, - @Nullable Expression filter); - - void setApiBaseUrl(String baseUrl); - - Light getLight(); - - float getPixelRatio(); + long[] queryShapeAnnotations(RectF rectF); - void setOnFpsChangedListener(@NonNull MapboxMap.OnFpsChangedListener listener); -} +} \ 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 6b8d4b2bf5..3fe98efa34 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 @@ -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(); - } - - @Override - public void setTransitionDuration(long duration) { - nativeSetTransitionDuration(duration); - } - - @Override - public long getTransitionDelay() { - return nativeGetTransitionDelay(); + public void setTransitionOptions(@NonNull TransitionOptions transitionOptions) { + nativeSetTransitionOptions(transitionOptions); } + @NonNull @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 bitmapHashMap) { + public void addImages(@NonNull Image[] images) { if (checkState("addImages")) { return; } - this.addImages(bitmapHashMap, false); - } - - @Override - public void addImages(@NonNull HashMap 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, Void, List> { - - private NativeMapView nativeMapView; - private boolean sdf; - - BitmapImageConversionTask(NativeMapView nativeMapView, boolean sdf) { - this.nativeMapView = nativeMapView; - this.sdf = sdf; - } - - @NonNull - @Override - protected List doInBackground(HashMap... params) { - HashMap bitmapHashMap = params[0]; - - List images = new ArrayList<>(); - ByteBuffer buffer; - String name; - Bitmap bitmap; - - for (Map.Entry 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 images) { - super.onPostExecute(images); - if (nativeMapView != null && !nativeMapView.checkState("nativeAddImages")) { - nativeMapView.nativeAddImages(images.toArray(new Image[images.size()])); - } - } - } - public interface ViewCallback { int getWidth(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java index 49c39e94b3..14fc69f456 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java @@ -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. *

*/ +@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 images) { + addImages(images, false); + } + + /** + * Adds an images to be used in the map's style. + */ + public void addImages(@NonNull HashMap 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 bitmapHashMap, boolean sdf) { + ImageWrapper[] images = new ImageWrapper[bitmapHashMap.size()]; + List 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> { + + private WeakReference nativeMap; + private boolean sdf; + + BitmapImageConversionTask(NativeMap nativeMap, boolean sdf) { + this.nativeMap = new WeakReference<>(nativeMap); + this.sdf = sdf; + } + + @NonNull + @Override + protected List doInBackground(Builder.ImageWrapper... params) { + List 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 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. */ diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index be98f7e51d..9356b112ba 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -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) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java index dbd6d77761..acbff20e96 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/TransitionOptions.java @@ -11,7 +11,9 @@ import android.support.annotation.Nullable; */ public class TransitionOptions { + @Keep private long duration; + @Keep private long delay; /** diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt index 77fb272bd2..4c67049b39 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.kt @@ -29,8 +29,7 @@ class MapboxMapTest { nativeMapView = mockk() mapboxMap = MapboxMap(nativeMapView, Transform(mapView, nativeMapView, cameraChangeDispatcher), null, null, null, cameraChangeDispatcher) every { nativeMapView.styleUrl = any() } answers {} - every { nativeMapView.transitionDuration = any() } answers {} - every { nativeMapView.transitionDelay = any() } answers {} + every { nativeMapView.transitionOptions = any() } answers {} every { nativeMapView.isDestroyed } returns false every { nativeMapView.cameraPosition } returns CameraPosition.DEFAULT every { nativeMapView.cancelTransitions() } answers {} @@ -38,7 +37,7 @@ class MapboxMapTest { every { nativeMapView.minZoom = any() } answers {} every { nativeMapView.maxZoom = any() } answers {} every { nativeMapView.setOnFpsChangedListener(any()) } answers {} - every { nativeMapView.prefetchesTiles = any() } answers {} + every { nativeMapView.prefetchTiles = any() } answers {} every { nativeMapView.setLatLngBounds(any()) } answers {} mapboxMap.injectLocationComponent(spyk()) mapboxMap.setStyle(Style.MAPBOX_STREETS) @@ -49,8 +48,7 @@ class MapboxMapTest { fun testTransitionOptions() { val expected = TransitionOptions(100, 200) mapboxMap.style?.transition = expected - verify { nativeMapView.transitionDelay = 200 } - verify { nativeMapView.transitionDuration = 100 } + verify { nativeMapView.transitionOptions = expected } } @Test @@ -60,7 +58,7 @@ class MapboxMapTest { val target = LatLng(1.0, 2.0) val expected = CameraPosition.Builder().target(target).build() mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(expected), callback) - verify { nativeMapView.jumpTo(-1.0, target, -1.0, -1.0) } + verify { nativeMapView.jumpTo(target, -1.0, -1.0, -1.0) } verify { callback.onFinish() } } @@ -86,7 +84,7 @@ class MapboxMapTest { @Test fun testTilePrefetch() { mapboxMap.prefetchesTiles = true - verify { nativeMapView.prefetchesTiles = true } + verify { nativeMapView.prefetchTiles = true } } @Test diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt index 56223dadef..83769914ef 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/StyleTest.kt @@ -33,9 +33,8 @@ class StyleTest { every { nativeMapView.addLayerAbove(any(), any()) } answers {} every { nativeMapView.addLayerAt(any(), any()) } answers {} every { nativeMapView.addSource(any()) } answers {} - every { nativeMapView.addImage(any(), any(), any()) } answers {} - every { nativeMapView.transitionDuration = any() } answers {} - every { nativeMapView.transitionDelay = any() } answers {} + every { nativeMapView.addImages(any()) } answers {} + every { nativeMapView.transitionOptions = any() } answers {} every { nativeMapView.isDestroyed } returns false mapboxMap.injectLocationComponent(spyk()) } @@ -104,24 +103,7 @@ class StyleTest { val transitionOptions = TransitionOptions(100, 200) val builder = Style.Builder().withTransition(transitionOptions) mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.transitionDuration = 100 } - verify(exactly = 1) { nativeMapView.transitionDelay = 200 } - } - - @Test - fun testWithImage() { - val image = mockk() - val builder = Style.Builder().withImage("id", image) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.addImage("id", image, false) } - } - - @Test - fun testWithImageSdf() { - val image = mockk() - val builder = Style.Builder().withImage("id", image, true) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.addImage("id", image, true) } + verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions } } @Test @@ -186,28 +168,7 @@ class StyleTest { mapboxMap.setStyle(builder) verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS } mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.transitionDuration = 100 } - verify(exactly = 1) { nativeMapView.transitionDelay = 200 } - } - - @Test - fun testWithFromImage() { - val bitmap = mockk() - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addImage("id", bitmap, false) } - } - - @Test - fun testWithFromImageSdf() { - val bitmap = mockk() - val builder = Style.Builder().fromUrl(Style.MAPBOX_STREETS).withImage("id", bitmap, true) - mapboxMap.setStyle(builder) - verify(exactly = 1) { nativeMapView.styleUrl = Style.MAPBOX_STREETS } - mapboxMap.notifyStyleLoaded() - verify(exactly = 1) { nativeMapView.addImage("id", bitmap, true) } + verify(exactly = 1) { nativeMapView.transitionOptions = transitionOptions } } @Test diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt index 681a47aa73..8bd5dafadd 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/NativeMapViewTest.kt @@ -44,7 +44,7 @@ class NativeMapViewTest { @UiThreadTest fun testBearing() { val expected = BEARING_TEST - nativeMapView.bearing = expected + nativeMapView.setBearing(expected, 0) val actual = nativeMapView.bearing assertEquals("Bearing should match", expected, actual, DELTA) } @@ -53,7 +53,7 @@ class NativeMapViewTest { @UiThreadTest fun testLatLng() { val expected = LATLNG_TEST - nativeMapView.latLng = expected + nativeMapView.setLatLng(expected, 0) val actual = nativeMapView.latLng assertEquals("Latitude should match", expected.latitude, actual.latitude, DELTA) assertEquals("Longitude should match", expected.longitude, actual.longitude, DELTA) @@ -81,7 +81,7 @@ class NativeMapViewTest { @UiThreadTest fun testPitch() { val expected = PITCH_TEST - nativeMapView.pitch = expected + nativeMapView.setPitch(expected, 0) val actual = nativeMapView.pitch assertEquals("Pitch should match", expected, actual, DELTA) } @@ -120,7 +120,7 @@ class NativeMapViewTest { .tilt(PITCH_TEST) .zoom(ZOOM_TEST) .build() - nativeMapView.jumpTo(BEARING_TEST, LATLNG_TEST, PITCH_TEST, ZOOM_TEST) + nativeMapView.jumpTo(LATLNG_TEST, ZOOM_TEST, PITCH_TEST, BEARING_TEST) val actual = nativeMapView.cameraPosition assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, DELTA) assertEquals("Longitude should match", expected.target.longitude, actual.target.longitude, DELTA) @@ -133,7 +133,7 @@ class NativeMapViewTest { @UiThreadTest fun testLatLngForPixel() { val expected = LATLNG_TEST - nativeMapView.latLng = LATLNG_TEST + nativeMapView.setLatLng(LATLNG_TEST,0) val actual = nativeMapView.latLngForPixel( PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat()) ) @@ -145,7 +145,7 @@ class NativeMapViewTest { @UiThreadTest fun testPixelForLatLng() { val expected = PointF((WIDTH / 2).toFloat(), (HEIGHT / 2).toFloat()) - nativeMapView.latLng = LATLNG_TEST + nativeMapView.setLatLng(LATLNG_TEST, 0) val actual = nativeMapView.pixelForLatLng(LATLNG_TEST) assertEquals("X should match", expected.x.toDouble(), actual.x.toDouble(), DELTA_BIG) assertEquals("Y should match", expected.y.toDouble(), actual.y.toDouble(), DELTA_BIG) @@ -155,8 +155,8 @@ class NativeMapViewTest { @UiThreadTest fun testPrefetchTilesTrue() { val expected = true - nativeMapView.prefetchesTiles = true - val actual = nativeMapView.prefetchesTiles + nativeMapView.prefetchTiles = true + val actual = nativeMapView.prefetchTiles assertEquals("Flag should match", expected, actual) } @@ -164,8 +164,8 @@ class NativeMapViewTest { @UiThreadTest fun testPrefetchTilesFalse() { val expected = false - nativeMapView.prefetchesTiles = false - val actual = nativeMapView.prefetchesTiles + nativeMapView.prefetchTiles = false + val actual = nativeMapView.prefetchTiles assertEquals("Flag should match", expected, actual) } @@ -173,7 +173,7 @@ class NativeMapViewTest { @UiThreadTest fun testPrefetchTilesDefault() { val expected = true - val actual = nativeMapView.prefetchesTiles + val actual = nativeMapView.prefetchTiles assertEquals("Flag should match", expected, actual) } @@ -233,7 +233,7 @@ class NativeMapViewTest { .target(LatLng(12.0, 14.0)) .bearing(20.0) .build() - nativeMapView.flyTo(expected.bearing, expected.target, 0, expected.tilt, expected.zoom) + nativeMapView.flyTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0) val actual = nativeMapView.cameraPosition assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA) assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA) @@ -251,7 +251,7 @@ class NativeMapViewTest { .target(LatLng(12.0, 14.0)) .bearing(20.0) .build() - nativeMapView.easeTo(expected.bearing, expected.target, 0, expected.tilt, expected.zoom, false) + nativeMapView.easeTo(expected.target, expected.zoom, expected.bearing, expected.tilt, 0, false) val actual = nativeMapView.cameraPosition assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA) assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA) @@ -269,7 +269,7 @@ class NativeMapViewTest { .target(LatLng(0.0, 0.0)) .bearing(0.0) .build() - nativeMapView.jumpTo(1.0, LatLng(1.0, 2.0), 23.0, 12.0) + nativeMapView.jumpTo(LatLng(1.0, 2.0), 12.0, 23.0, 1.0) nativeMapView.resetPosition() val actual = nativeMapView.cameraPosition assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA) @@ -310,7 +310,7 @@ class NativeMapViewTest { .target(LatLng(4.21494310024160, -4.218749958739409)) .bearing(0.0) .build() - nativeMapView.moveBy(12.0, 12.0) + nativeMapView.moveBy(12.0, 12.0, 0) val actual = nativeMapView.cameraPosition assertEquals("Bearing should match", expected.bearing, actual.bearing, TestConstants.BEARING_DELTA) assertEquals("Latitude should match", expected.target.latitude, actual.target.latitude, TestConstants.LAT_LNG_DELTA) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ImageTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ImageTest.java index 66bfcb257e..0e4c8f3f2e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ImageTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ImageTest.java @@ -33,6 +33,9 @@ public class ImageTest extends EspressoTest { Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap(); mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet); + // adding an image requires converting the image with an asynctask + uiController.loopMainThreadForAtLeast(200); + Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID); assertTrue(bitmapGet.sameAs(bitmapSet)); diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp index c76b5c2610..2216b260ce 100755 --- a/platform/android/src/native_map_view.cpp +++ b/platform/android/src/native_map_view.cpp @@ -629,13 +629,11 @@ jni::Local> NativeMapView::addPolygons(JNIEnv& env, const jni: return result; } -//TODO: Move to Polyline class and make native peer void NativeMapView::updatePolyline(JNIEnv& env, jlong polylineId, const jni::Object& polyline) { mbgl::LineAnnotation annotation = Polyline::toAnnotation(env, polyline); map->updateAnnotation(polylineId, annotation); } -//TODO: Move to Polygon class and make native peer void NativeMapView::updatePolygon(JNIEnv& env, jlong polygonId, const jni::Object& polygon) { mbgl::FillAnnotation annotation = Polygon::toAnnotation(env, polygon); map->updateAnnotation(polygonId, annotation); @@ -680,25 +678,18 @@ jdouble NativeMapView::getTopOffsetPixelsForAnnotationSymbol(JNIEnv& env, const return map->getTopOffsetPixelsForAnnotationImage(jni::Make(env, symbolName)); } -jlong NativeMapView::getTransitionDuration(JNIEnv&) { +jni::Local> NativeMapView::getTransitionOptions(JNIEnv& env) { const auto transitionOptions = map->getStyle().getTransitionOptions(); - return std::chrono::duration_cast(transitionOptions.duration.value_or(mbgl::Duration::zero())).count(); + const auto duration = std::chrono::duration_cast(transitionOptions.duration.value_or(mbgl::Duration::zero())).count(); + const auto delay = std::chrono::duration_cast(transitionOptions.delay.value_or(mbgl::Duration::zero())).count(); + return TransitionOptions::fromTransitionOptions(env, duration, delay); } -void NativeMapView::setTransitionDuration(JNIEnv&, jlong duration) { - auto transitionOptions = map->getStyle().getTransitionOptions(); - transitionOptions.duration.emplace(mbgl::Milliseconds(duration)); - map->getStyle().setTransitionOptions(transitionOptions); -} - -jlong NativeMapView::getTransitionDelay(JNIEnv&) { - const auto transitionOptions = map->getStyle().getTransitionOptions(); - return std::chrono::duration_cast(transitionOptions.delay.value_or(mbgl::Duration::zero())).count(); -} - -void NativeMapView::setTransitionDelay(JNIEnv&, jlong delay) { - auto transitionOptions = map->getStyle().getTransitionOptions(); - transitionOptions.delay.emplace(mbgl::Milliseconds(delay)); +void NativeMapView::setTransitionOptions(JNIEnv& env, const jni::Object& options) { + const mbgl::style::TransitionOptions transitionOptions( + Duration(mbgl::Milliseconds(TransitionOptions::getDuration(env, options))), + Duration(mbgl::Milliseconds(TransitionOptions::getOffset(env, options))) + ); map->getStyle().setTransitionOptions(transitionOptions); } @@ -1012,11 +1003,11 @@ jni::Local> NativeMapView::getImage(JNIEnv& env, const jni:: } } -void NativeMapView::setPrefetchesTiles(JNIEnv&, jni::jboolean enable) { +void NativeMapView::setPrefetchTiles(JNIEnv&, jni::jboolean enable) { map->setPrefetchZoomDelta(enable ? util::DEFAULT_PREFETCH_ZOOM_DELTA : uint8_t(0)); } -jni::jboolean NativeMapView::getPrefetchesTiles(JNIEnv&) { +jni::jboolean NativeMapView::getPrefetchTiles(JNIEnv&) { return jni::jboolean(map->getPrefetchZoomDelta() > 0); } @@ -1093,10 +1084,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::addAnnotationIcon, "nativeAddAnnotationIcon"), METHOD(&NativeMapView::removeAnnotationIcon, "nativeRemoveAnnotationIcon"), METHOD(&NativeMapView::getTopOffsetPixelsForAnnotationSymbol, "nativeGetTopOffsetPixelsForAnnotationSymbol"), - METHOD(&NativeMapView::getTransitionDuration, "nativeGetTransitionDuration"), - METHOD(&NativeMapView::setTransitionDuration, "nativeSetTransitionDuration"), - METHOD(&NativeMapView::getTransitionDelay, "nativeGetTransitionDelay"), - METHOD(&NativeMapView::setTransitionDelay, "nativeSetTransitionDelay"), + METHOD(&NativeMapView::getTransitionOptions, "nativeGetTransitionOptions"), + METHOD(&NativeMapView::setTransitionOptions, "nativeSetTransitionOptions"), METHOD(&NativeMapView::queryPointAnnotations, "nativeQueryPointAnnotations"), METHOD(&NativeMapView::queryShapeAnnotations, "nativeQueryShapeAnnotations"), METHOD(&NativeMapView::queryRenderedFeaturesForPoint, "nativeQueryRenderedFeaturesForPoint"), @@ -1118,8 +1107,8 @@ void NativeMapView::registerNative(jni::JNIEnv& env) { METHOD(&NativeMapView::removeImage, "nativeRemoveImage"), METHOD(&NativeMapView::getImage, "nativeGetImage"), METHOD(&NativeMapView::setLatLngBounds, "nativeSetLatLngBounds"), - METHOD(&NativeMapView::setPrefetchesTiles, "nativeSetPrefetchesTiles"), - METHOD(&NativeMapView::getPrefetchesTiles, "nativeGetPrefetchesTiles") + METHOD(&NativeMapView::setPrefetchTiles, "nativeSetPrefetchTiles"), + METHOD(&NativeMapView::getPrefetchTiles, "nativeGetPrefetchTiles") ); } diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 82666a2475..1bb4f23cbe 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -187,13 +187,9 @@ public: jni::jdouble getTopOffsetPixelsForAnnotationSymbol(JNIEnv&, const jni::String&); - jni::jlong getTransitionDuration(JNIEnv&); + jni::Local> getTransitionOptions(JNIEnv&); - void setTransitionDuration(JNIEnv&, jni::jlong); - - jni::jlong getTransitionDelay(JNIEnv&); - - void setTransitionDelay(JNIEnv&, jni::jlong); + void setTransitionOptions(JNIEnv&, const jni::Object&); jni::Local> queryPointAnnotations(JNIEnv&, const jni::Object&); @@ -239,9 +235,9 @@ public: jni::Local> getImage(JNIEnv&, const jni::String&); - void setPrefetchesTiles(JNIEnv&, jni::jboolean); + void setPrefetchTiles(JNIEnv&, jni::jboolean); - jni::jboolean getPrefetchesTiles(JNIEnv&); + jni::jboolean getPrefetchTiles(JNIEnv&); mbgl::Map& getMap(); diff --git a/platform/android/src/style/transition_options.cpp b/platform/android/src/style/transition_options.cpp index b908c37089..320f3d64b1 100644 --- a/platform/android/src/style/transition_options.cpp +++ b/platform/android/src/style/transition_options.cpp @@ -9,6 +9,18 @@ jni::Local> TransitionOptions::fromTransitionOpti return javaClass.Call(env, method, duration, delay); } +long TransitionOptions::getDuration(jni::JNIEnv& env, const jni::Object& transitionOptions) { + static auto& javaClass = jni::Class::Singleton(env); + static auto field = javaClass.GetField(env, "duration"); + return transitionOptions.Get(env, field); +} + +long TransitionOptions::getOffset(jni::JNIEnv& env, const jni::Object& transitionOptions) { + static auto& javaClass = jni::Class::Singleton(env); + static auto field = javaClass.GetField(env, "offset"); + return transitionOptions.Get(env, field); +} + void TransitionOptions::registerNative(jni::JNIEnv& env) { jni::Class::Singleton(env); } diff --git a/platform/android/src/style/transition_options.hpp b/platform/android/src/style/transition_options.hpp index 0bac43fa16..cca56afdb6 100644 --- a/platform/android/src/style/transition_options.hpp +++ b/platform/android/src/style/transition_options.hpp @@ -13,6 +13,10 @@ public: static jni::Local> fromTransitionOptions(jni::JNIEnv&, jlong duration, jlong offset); + static long getDuration(jni::JNIEnv&, const jni::Object&); + + static long getOffset(jni::JNIEnv&, const jni::Object&); + static void registerNative(jni::JNIEnv&); }; -- cgit v1.2.1