summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/CalledFromWorkerThreadException.java8
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java213
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java34
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java25
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java24
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java17
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java19
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java18
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java38
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java21
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java83
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs10
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java21
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs13
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java20
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java8
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java15
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ThreadUtils.java17
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/MapboxMapAction.java2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java177
29 files changed, 644 insertions, 197 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/CalledFromWorkerThreadException.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/CalledFromWorkerThreadException.java
new file mode 100644
index 0000000000..32e852d31b
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/exceptions/CalledFromWorkerThreadException.java
@@ -0,0 +1,8 @@
+package com.mapbox.mapboxsdk.exceptions;
+
+public class CalledFromWorkerThreadException extends RuntimeException {
+
+ public CalledFromWorkerThreadException(String message) {
+ super(message);
+ }
+}
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 d258064908..d72e1a74a9 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
@@ -11,7 +11,6 @@ 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;
@@ -20,6 +19,7 @@ import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.Polygon;
import com.mapbox.mapboxsdk.annotations.Polyline;
import com.mapbox.mapboxsdk.camera.CameraPosition;
+import com.mapbox.mapboxsdk.exceptions.CalledFromWorkerThreadException;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.ProjectedMeters;
@@ -32,6 +32,7 @@ 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 timber.log.Timber;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -41,8 +42,6 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
-import timber.log.Timber;
-
// Class that wraps the native methods for convenience
final class NativeMapView {
@@ -52,6 +51,9 @@ final class NativeMapView {
// Used to schedule work on the MapRenderer Thread
private final MapRenderer mapRenderer;
+ // Used to validate if methods are called from the correct thread
+ private final Thread thread;
+
// Used for callbacks
private ViewCallback viewCallback;
@@ -87,6 +89,7 @@ final class NativeMapView {
this.viewCallback = viewCallback;
this.fileSource = FileSource.getInstance(context);
this.pixelRatio = pixelRatio;
+ this.thread = Thread.currentThread();
nativeInitialize(this, fileSource, mapRenderer, pixelRatio);
}
@@ -94,7 +97,17 @@ final class NativeMapView {
// Methods
//
- private boolean isDestroyedOn(String callingMethod) {
+ private boolean checkState(String callingMethod) {
+ // validate if invocation has occurred on the main thread
+ if (thread != Thread.currentThread()) {
+ throw new CalledFromWorkerThreadException(
+ String.format(
+ "Map interactions should happen on the UI thread. Method invoked from wrong thread is %s.",
+ callingMethod)
+ );
+ }
+
+ // validate if map has already been destroyed
if (destroyed && !TextUtils.isEmpty(callingMethod)) {
Timber.e(
"You're calling `%s` after the `MapView` was destroyed, were you invoking it after `onDestroy()`?",
@@ -112,7 +125,7 @@ final class NativeMapView {
}
public void update() {
- if (isDestroyedOn("update")) {
+ if (checkState("update")) {
return;
}
@@ -120,7 +133,7 @@ final class NativeMapView {
}
public void resizeView(int width, int height) {
- if (isDestroyedOn("resizeView")) {
+ if (checkState("resizeView")) {
return;
}
width = (int) (width / pixelRatio);
@@ -152,84 +165,84 @@ final class NativeMapView {
}
public void setStyleUrl(String url) {
- if (isDestroyedOn("setStyleUrl")) {
+ if (checkState("setStyleUrl")) {
return;
}
nativeSetStyleUrl(url);
}
public String getStyleUrl() {
- if (isDestroyedOn("getStyleUrl")) {
+ if (checkState("getStyleUrl")) {
return null;
}
return nativeGetStyleUrl();
}
public void setStyleJson(String newStyleJson) {
- if (isDestroyedOn("setStyleJson")) {
+ if (checkState("setStyleJson")) {
return;
}
nativeSetStyleJson(newStyleJson);
}
public String getStyleJson() {
- if (isDestroyedOn("getStyleJson")) {
+ if (checkState("getStyleJson")) {
return null;
}
return nativeGetStyleJson();
}
public void setLatLngBounds(LatLngBounds latLngBounds) {
- if (isDestroyedOn("setLatLngBounds")) {
+ if (checkState("setLatLngBounds")) {
return;
}
nativeSetLatLngBounds(latLngBounds);
}
public void cancelTransitions() {
- if (isDestroyedOn("cancelTransitions")) {
+ if (checkState("cancelTransitions")) {
return;
}
nativeCancelTransitions();
}
public void setGestureInProgress(boolean inProgress) {
- if (isDestroyedOn("setGestureInProgress")) {
+ if (checkState("setGestureInProgress")) {
return;
}
nativeSetGestureInProgress(inProgress);
}
public void moveBy(double dx, double dy) {
- if (isDestroyedOn("moveBy")) {
+ if (checkState("moveBy")) {
return;
}
moveBy(dx, dy, 0);
}
public void moveBy(double dx, double dy, long duration) {
- if (isDestroyedOn("moveBy")) {
+ if (checkState("moveBy")) {
return;
}
nativeMoveBy(dx / pixelRatio, dy / pixelRatio, duration);
}
public void setLatLng(LatLng latLng) {
- if (isDestroyedOn("setLatLng")) {
+ if (checkState("setLatLng")) {
return;
}
setLatLng(latLng, 0);
}
public void setLatLng(LatLng latLng, long duration) {
- if (isDestroyedOn("setLatLng")) {
+ if (checkState("setLatLng")) {
return;
}
nativeSetLatLng(latLng.getLatitude(), latLng.getLongitude(), duration);
}
public LatLng getLatLng() {
- if (isDestroyedOn("")) {
+ if (checkState("")) {
return new LatLng();
}
// wrap longitude values coming from core
@@ -237,7 +250,7 @@ final class NativeMapView {
}
public CameraPosition getCameraForLatLngBounds(LatLngBounds latLngBounds, int[] padding) {
- if (isDestroyedOn("getCameraForLatLngBounds")) {
+ if (checkState("getCameraForLatLngBounds")) {
return null;
}
return nativeGetCameraForLatLngBounds(
@@ -249,7 +262,7 @@ final class NativeMapView {
}
public CameraPosition getCameraForGeometry(Geometry geometry, double bearing, int[] padding) {
- if (isDestroyedOn("getCameraForGeometry")) {
+ if (checkState("getCameraForGeometry")) {
return null;
}
return nativeGetCameraForGeometry(
@@ -261,77 +274,77 @@ final class NativeMapView {
}
public void resetPosition() {
- if (isDestroyedOn("resetPosition")) {
+ if (checkState("resetPosition")) {
return;
}
nativeResetPosition();
}
public double getPitch() {
- if (isDestroyedOn("getPitch")) {
+ if (checkState("getPitch")) {
return 0;
}
return nativeGetPitch();
}
public void setPitch(double pitch, long duration) {
- if (isDestroyedOn("setPitch")) {
+ if (checkState("setPitch")) {
return;
}
nativeSetPitch(pitch, duration);
}
public void setZoom(double zoom, PointF focalPoint, long duration) {
- if (isDestroyedOn("setZoom")) {
+ if (checkState("setZoom")) {
return;
}
nativeSetZoom(zoom, focalPoint.x / pixelRatio, focalPoint.y / pixelRatio, duration);
}
public double getZoom() {
- if (isDestroyedOn("getZoom")) {
+ if (checkState("getZoom")) {
return 0;
}
return nativeGetZoom();
}
public void resetZoom() {
- if (isDestroyedOn("resetZoom")) {
+ if (checkState("resetZoom")) {
return;
}
nativeResetZoom();
}
public void setMinZoom(double zoom) {
- if (isDestroyedOn("setMinZoom")) {
+ if (checkState("setMinZoom")) {
return;
}
nativeSetMinZoom(zoom);
}
public double getMinZoom() {
- if (isDestroyedOn("getMinZoom")) {
+ if (checkState("getMinZoom")) {
return 0;
}
return nativeGetMinZoom();
}
public void setMaxZoom(double zoom) {
- if (isDestroyedOn("setMaxZoom")) {
+ if (checkState("setMaxZoom")) {
return;
}
nativeSetMaxZoom(zoom);
}
public double getMaxZoom() {
- if (isDestroyedOn("getMaxZoom")) {
+ if (checkState("getMaxZoom")) {
return 0;
}
return nativeGetMaxZoom();
}
public void rotateBy(double sx, double sy, double ex, double ey) {
- if (isDestroyedOn("rotateBy")) {
+ if (checkState("rotateBy")) {
return;
}
rotateBy(sx, sy, ex, ey, 0);
@@ -339,14 +352,14 @@ final class NativeMapView {
public void rotateBy(double sx, double sy, double ex, double ey,
long duration) {
- if (isDestroyedOn("rotateBy")) {
+ if (checkState("rotateBy")) {
return;
}
nativeRotateBy(sx / pixelRatio, sy / pixelRatio, ex, ey, duration);
}
public void setContentPadding(int[] padding) {
- if (isDestroyedOn("setContentPadding")) {
+ if (checkState("setContentPadding")) {
return;
}
nativeSetContentPadding(
@@ -357,49 +370,49 @@ final class NativeMapView {
}
public void setBearing(double degrees) {
- if (isDestroyedOn("setBearing")) {
+ if (checkState("setBearing")) {
return;
}
setBearing(degrees, 0);
}
public void setBearing(double degrees, long duration) {
- if (isDestroyedOn("setBearing")) {
+ if (checkState("setBearing")) {
return;
}
nativeSetBearing(degrees, duration);
}
public void setBearing(double degrees, double cx, double cy) {
- if (isDestroyedOn("setBearing")) {
+ if (checkState("setBearing")) {
return;
}
setBearing(degrees, cx, cy, 0);
}
public void setBearing(double degrees, double fx, double fy, long duration) {
- if (isDestroyedOn("setBearing")) {
+ if (checkState("setBearing")) {
return;
}
nativeSetBearingXY(degrees, fx / pixelRatio, fy / pixelRatio, duration);
}
public double getBearing() {
- if (isDestroyedOn("getBearing")) {
+ if (checkState("getBearing")) {
return 0;
}
return nativeGetBearing();
}
public void resetNorth() {
- if (isDestroyedOn("resetNorth")) {
+ if (checkState("resetNorth")) {
return;
}
nativeResetNorth();
}
public long addMarker(Marker marker) {
- if (isDestroyedOn("addMarker")) {
+ if (checkState("addMarker")) {
return 0;
}
Marker[] markers = {marker};
@@ -407,14 +420,14 @@ final class NativeMapView {
}
public long[] addMarkers(List<Marker> markers) {
- if (isDestroyedOn("addMarkers")) {
+ if (checkState("addMarkers")) {
return new long[] {};
}
return nativeAddMarkers(markers.toArray(new Marker[markers.size()]));
}
public long addPolyline(Polyline polyline) {
- if (isDestroyedOn("addPolyline")) {
+ if (checkState("addPolyline")) {
return 0;
}
Polyline[] polylines = {polyline};
@@ -422,14 +435,14 @@ final class NativeMapView {
}
public long[] addPolylines(List<Polyline> polylines) {
- if (isDestroyedOn("addPolylines")) {
+ if (checkState("addPolylines")) {
return new long[] {};
}
return nativeAddPolylines(polylines.toArray(new Polyline[polylines.size()]));
}
public long addPolygon(Polygon polygon) {
- if (isDestroyedOn("addPolygon")) {
+ if (checkState("addPolygon")) {
return 0;
}
Polygon[] polygons = {polygon};
@@ -437,14 +450,14 @@ final class NativeMapView {
}
public long[] addPolygons(List<Polygon> polygons) {
- if (isDestroyedOn("addPolygons")) {
+ if (checkState("addPolygons")) {
return new long[] {};
}
return nativeAddPolygons(polygons.toArray(new Polygon[polygons.size()]));
}
public void updateMarker(Marker marker) {
- if (isDestroyedOn("updateMarker")) {
+ if (checkState("updateMarker")) {
return;
}
LatLng position = marker.getPosition();
@@ -453,21 +466,21 @@ final class NativeMapView {
}
public void updatePolygon(Polygon polygon) {
- if (isDestroyedOn("updatePolygon")) {
+ if (checkState("updatePolygon")) {
return;
}
nativeUpdatePolygon(polygon.getId(), polygon);
}
public void updatePolyline(Polyline polyline) {
- if (isDestroyedOn("updatePolyline")) {
+ if (checkState("updatePolyline")) {
return;
}
nativeUpdatePolyline(polyline.getId(), polyline);
}
public void removeAnnotation(long id) {
- if (isDestroyedOn("removeAnnotation")) {
+ if (checkState("removeAnnotation")) {
return;
}
long[] ids = {id};
@@ -475,105 +488,105 @@ final class NativeMapView {
}
public void removeAnnotations(long[] ids) {
- if (isDestroyedOn("removeAnnotations")) {
+ if (checkState("removeAnnotations")) {
return;
}
nativeRemoveAnnotations(ids);
}
public long[] queryPointAnnotations(RectF rect) {
- if (isDestroyedOn("queryPointAnnotations")) {
+ if (checkState("queryPointAnnotations")) {
return new long[] {};
}
return nativeQueryPointAnnotations(rect);
}
public long[] queryShapeAnnotations(RectF rectF) {
- if (isDestroyedOn("queryShapeAnnotations")) {
+ if (checkState("queryShapeAnnotations")) {
return new long[] {};
}
return nativeQueryShapeAnnotations(rectF);
}
public void addAnnotationIcon(String symbol, int width, int height, float scale, byte[] pixels) {
- if (isDestroyedOn("addAnnotationIcon")) {
+ if (checkState("addAnnotationIcon")) {
return;
}
nativeAddAnnotationIcon(symbol, width, height, scale, pixels);
}
public void removeAnnotationIcon(String symbol) {
- if (isDestroyedOn("removeAnnotationIcon")) {
+ if (checkState("removeAnnotationIcon")) {
return;
}
nativeRemoveAnnotationIcon(symbol);
}
public void setVisibleCoordinateBounds(LatLng[] coordinates, RectF padding, double direction, long duration) {
- if (isDestroyedOn("setVisibleCoordinateBounds")) {
+ if (checkState("setVisibleCoordinateBounds")) {
return;
}
nativeSetVisibleCoordinateBounds(coordinates, padding, direction, duration);
}
public void onLowMemory() {
- if (isDestroyedOn("onLowMemory")) {
+ if (checkState("onLowMemory")) {
return;
}
nativeOnLowMemory();
}
public void setDebug(boolean debug) {
- if (isDestroyedOn("setDebug")) {
+ if (checkState("setDebug")) {
return;
}
nativeSetDebug(debug);
}
public void cycleDebugOptions() {
- if (isDestroyedOn("cycleDebugOptions")) {
+ if (checkState("cycleDebugOptions")) {
return;
}
nativeCycleDebugOptions();
}
public boolean getDebug() {
- if (isDestroyedOn("getDebug")) {
+ if (checkState("getDebug")) {
return false;
}
return nativeGetDebug();
}
public boolean isFullyLoaded() {
- if (isDestroyedOn("isFullyLoaded")) {
+ if (checkState("isFullyLoaded")) {
return false;
}
return nativeIsFullyLoaded();
}
public void setReachability(boolean status) {
- if (isDestroyedOn("setReachability")) {
+ if (checkState("setReachability")) {
return;
}
nativeSetReachability(status);
}
public double getMetersPerPixelAtLatitude(double lat) {
- if (isDestroyedOn("getMetersPerPixelAtLatitude")) {
+ if (checkState("getMetersPerPixelAtLatitude")) {
return 0;
}
return nativeGetMetersPerPixelAtLatitude(lat, getZoom()) / pixelRatio;
}
public ProjectedMeters projectedMetersForLatLng(LatLng latLng) {
- if (isDestroyedOn("projectedMetersForLatLng")) {
+ if (checkState("projectedMetersForLatLng")) {
return null;
}
return nativeProjectedMetersForLatLng(latLng.getLatitude(), latLng.getLongitude());
}
public LatLng latLngForProjectedMeters(ProjectedMeters projectedMeters) {
- if (isDestroyedOn("latLngForProjectedMeters")) {
+ if (checkState("latLngForProjectedMeters")) {
return new LatLng();
}
return nativeLatLngForProjectedMeters(projectedMeters.getNorthing(),
@@ -581,7 +594,7 @@ final class NativeMapView {
}
public PointF pixelForLatLng(LatLng latLng) {
- if (isDestroyedOn("pixelForLatLng")) {
+ if (checkState("pixelForLatLng")) {
return new PointF();
}
PointF pointF = nativePixelForLatLng(latLng.getLatitude(), latLng.getLongitude());
@@ -590,21 +603,21 @@ final class NativeMapView {
}
public LatLng latLngForPixel(PointF pixel) {
- if (isDestroyedOn("latLngForPixel")) {
+ if (checkState("latLngForPixel")) {
return new LatLng();
}
return nativeLatLngForPixel(pixel.x / pixelRatio, pixel.y / pixelRatio).wrap();
}
public double getTopOffsetPixelsForAnnotationSymbol(String symbolName) {
- if (isDestroyedOn("getTopOffsetPixelsForAnnotationSymbol")) {
+ if (checkState("getTopOffsetPixelsForAnnotationSymbol")) {
return 0;
}
return nativeGetTopOffsetPixelsForAnnotationSymbol(symbolName);
}
public void jumpTo(double angle, LatLng center, double pitch, double zoom) {
- if (isDestroyedOn("jumpTo")) {
+ if (checkState("jumpTo")) {
return;
}
nativeJumpTo(angle, center.getLatitude(), center.getLongitude(), pitch, zoom);
@@ -612,7 +625,7 @@ final class NativeMapView {
public void easeTo(double angle, LatLng center, long duration, double pitch, double zoom,
boolean easingInterpolator) {
- if (isDestroyedOn("easeTo")) {
+ if (checkState("easeTo")) {
return;
}
nativeEaseTo(angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom,
@@ -620,28 +633,28 @@ final class NativeMapView {
}
public void flyTo(double angle, LatLng center, long duration, double pitch, double zoom) {
- if (isDestroyedOn("flyTo")) {
+ if (checkState("flyTo")) {
return;
}
nativeFlyTo(angle, center.getLatitude(), center.getLongitude(), duration, pitch, zoom);
}
public CameraPosition getCameraPosition() {
- if (isDestroyedOn("getCameraValues")) {
+ if (checkState("getCameraValues")) {
return new CameraPosition.Builder().build();
}
return nativeGetCameraPosition();
}
public void setPrefetchesTiles(boolean enable) {
- if (isDestroyedOn("setPrefetchesTiles")) {
+ if (checkState("setPrefetchesTiles")) {
return;
}
nativeSetPrefetchesTiles(enable);
}
public boolean getPrefetchesTiles() {
- if (isDestroyedOn("getPrefetchesTiles")) {
+ if (checkState("getPrefetchesTiles")) {
return false;
}
return nativeGetPrefetchesTiles();
@@ -666,42 +679,42 @@ final class NativeMapView {
}
public List<Layer> getLayers() {
- if (isDestroyedOn("getLayers")) {
+ if (checkState("getLayers")) {
return null;
}
return Arrays.asList(nativeGetLayers());
}
public Layer getLayer(String layerId) {
- if (isDestroyedOn("getLayer")) {
+ if (checkState("getLayer")) {
return null;
}
return nativeGetLayer(layerId);
}
public void addLayer(@NonNull Layer layer) {
- if (isDestroyedOn("addLayer")) {
+ if (checkState("addLayer")) {
return;
}
nativeAddLayer(layer.getNativePtr(), null);
}
public void addLayerBelow(@NonNull Layer layer, @NonNull String below) {
- if (isDestroyedOn("addLayerBelow")) {
+ if (checkState("addLayerBelow")) {
return;
}
nativeAddLayer(layer.getNativePtr(), below);
}
public void addLayerAbove(@NonNull Layer layer, @NonNull String above) {
- if (isDestroyedOn("addLayerAbove")) {
+ if (checkState("addLayerAbove")) {
return;
}
nativeAddLayerAbove(layer.getNativePtr(), above);
}
public void addLayerAt(@NonNull Layer layer, @IntRange(from = 0) int index) {
- if (isDestroyedOn("addLayerAt")) {
+ if (checkState("addLayerAt")) {
return;
}
nativeAddLayerAt(layer.getNativePtr(), index);
@@ -709,7 +722,7 @@ final class NativeMapView {
@Nullable
public Layer removeLayer(@NonNull String layerId) {
- if (isDestroyedOn("removeLayer")) {
+ if (checkState("removeLayer")) {
return null;
}
return nativeRemoveLayerById(layerId);
@@ -717,7 +730,7 @@ final class NativeMapView {
@Nullable
public Layer removeLayer(@NonNull Layer layer) {
- if (isDestroyedOn("removeLayer")) {
+ if (checkState("removeLayer")) {
return null;
}
nativeRemoveLayer(layer.getNativePtr());
@@ -726,28 +739,28 @@ final class NativeMapView {
@Nullable
public Layer removeLayerAt(@IntRange(from = 0) int index) {
- if (isDestroyedOn("removeLayerAt")) {
+ if (checkState("removeLayerAt")) {
return null;
}
return nativeRemoveLayerAt(index);
}
public List<Source> getSources() {
- if (isDestroyedOn("getSources")) {
+ if (checkState("getSources")) {
return null;
}
return Arrays.asList(nativeGetSources());
}
public Source getSource(@NonNull String sourceId) {
- if (isDestroyedOn("getSource")) {
+ if (checkState("getSource")) {
return null;
}
return nativeGetSource(sourceId);
}
public void addSource(@NonNull Source source) {
- if (isDestroyedOn("addSource")) {
+ if (checkState("addSource")) {
return;
}
nativeAddSource(source, source.getNativePtr());
@@ -755,7 +768,7 @@ final class NativeMapView {
@Nullable
public Source removeSource(@NonNull String sourceId) {
- if (isDestroyedOn("removeSource")) {
+ if (checkState("removeSource")) {
return null;
}
Source source = getSource(sourceId);
@@ -767,7 +780,7 @@ final class NativeMapView {
@Nullable
public Source removeSource(@NonNull Source source) {
- if (isDestroyedOn("removeSource")) {
+ if (checkState("removeSource")) {
return null;
}
nativeRemoveSource(source, source.getNativePtr());
@@ -775,7 +788,7 @@ final class NativeMapView {
}
public void addImage(@NonNull String name, @NonNull Bitmap image) {
- if (isDestroyedOn("addImage")) {
+ if (checkState("addImage")) {
return;
}
@@ -785,7 +798,7 @@ final class NativeMapView {
}
public void addImages(@NonNull HashMap<String, Bitmap> bitmapHashMap) {
- if (isDestroyedOn("addImages")) {
+ if (checkState("addImages")) {
return;
}
//noinspection unchecked
@@ -793,14 +806,14 @@ final class NativeMapView {
}
public void removeImage(String name) {
- if (isDestroyedOn("removeImage")) {
+ if (checkState("removeImage")) {
return;
}
nativeRemoveImage(name);
}
public Bitmap getImage(String name) {
- if (isDestroyedOn("getImage")) {
+ if (checkState("getImage")) {
return null;
}
return nativeGetImage(name);
@@ -812,7 +825,7 @@ final class NativeMapView {
public List<Feature> queryRenderedFeatures(@NonNull PointF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter) {
- if (isDestroyedOn("queryRenderedFeatures")) {
+ if (checkState("queryRenderedFeatures")) {
return new ArrayList<>();
}
Feature[] features = nativeQueryRenderedFeaturesForPoint(coordinates.x / pixelRatio,
@@ -824,7 +837,7 @@ final class NativeMapView {
public List<Feature> queryRenderedFeatures(@NonNull RectF coordinates,
@Nullable String[] layerIds,
@Nullable Expression filter) {
- if (isDestroyedOn("queryRenderedFeatures")) {
+ if (checkState("queryRenderedFeatures")) {
return new ArrayList<>();
}
Feature[] features = nativeQueryRenderedFeaturesForBox(
@@ -838,14 +851,14 @@ final class NativeMapView {
}
public void setApiBaseUrl(String baseUrl) {
- if (isDestroyedOn("setApiBaseUrl")) {
+ if (checkState("setApiBaseUrl")) {
return;
}
fileSource.setApiBaseUrl(baseUrl);
}
public Light getLight() {
- if (isDestroyedOn("getLight")) {
+ if (checkState("getLight")) {
return null;
}
return nativeGetLight();
@@ -879,7 +892,7 @@ final class NativeMapView {
}
protected void onSnapshotReady(Bitmap mapContent) {
- if (isDestroyedOn("OnSnapshotReady")) {
+ if (checkState("OnSnapshotReady")) {
return;
}
@@ -1078,14 +1091,14 @@ final class NativeMapView {
private native boolean nativeGetPrefetchesTiles();
int getWidth() {
- if (isDestroyedOn("")) {
+ if (checkState("")) {
return 0;
}
return viewCallback.getWidth();
}
int getHeight() {
- if (isDestroyedOn("")) {
+ if (checkState("")) {
return 0;
}
return viewCallback.getHeight();
@@ -1110,7 +1123,7 @@ final class NativeMapView {
//
void addSnapshotCallback(@NonNull MapboxMap.SnapshotReadyCallback callback) {
- if (isDestroyedOn("addSnapshotCallback")) {
+ if (checkState("addSnapshotCallback")) {
return;
}
snapshotReadyCallback = callback;
@@ -1185,7 +1198,7 @@ final class NativeMapView {
@Override
protected void onPostExecute(List<Image> images) {
super.onPostExecute(images);
- if (nativeMapView != null && !nativeMapView.isDestroyedOn("nativeAddImages")) {
+ if (nativeMapView != null && !nativeMapView.checkState("nativeAddImages")) {
nativeMapView.nativeAddImages(images.toArray(new Image[images.size()]));
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
index 38d5277a80..641c283798 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/snapshotter/MapSnapshotter.java
@@ -16,7 +16,6 @@ import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
-
import com.mapbox.mapboxsdk.R;
import com.mapbox.mapboxsdk.attribution.AttributionLayout;
import com.mapbox.mapboxsdk.attribution.AttributionMeasure;
@@ -25,7 +24,7 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.storage.FileSource;
-
+import com.mapbox.mapboxsdk.utils.ThreadUtils;
import timber.log.Timber;
/**
@@ -213,6 +212,7 @@ public class MapSnapshotter {
* @param options the options to use for the snapshot
*/
public MapSnapshotter(@NonNull Context context, @NonNull Options options) {
+ checkThread();
this.context = context.getApplicationContext();
FileSource fileSource = FileSource.getInstance(context);
String programCacheDir = context.getCacheDir().getAbsolutePath();
@@ -243,7 +243,7 @@ public class MapSnapshotter {
if (this.callback != null) {
throw new IllegalStateException("Snapshotter was already started");
}
-
+ checkThread();
this.callback = callback;
this.errorHandler = errorHandler;
nativeStart();
@@ -284,6 +284,7 @@ public class MapSnapshotter {
* the object was created on.
*/
public void cancel() {
+ checkThread();
reset();
nativeCancel();
}
@@ -465,6 +466,10 @@ public class MapSnapshotter {
}
}
+ private void checkThread() {
+ ThreadUtils.checkThread("MapSnapshotter");
+ }
+
protected void reset() {
callback = null;
errorHandler = null;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java
index 60c2aa907b..0a0c3f1e43 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/BackgroundLayer.java
@@ -36,6 +36,7 @@ public class BackgroundLayer extends Layer {
* @param layerId the id of the layer
*/
public BackgroundLayer(String layerId) {
+ super();
initialize(layerId);
}
@@ -61,6 +62,7 @@ public class BackgroundLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("background-color", nativeGetBackgroundColor());
}
@@ -72,6 +74,7 @@ public class BackgroundLayer extends Layer {
*/
@ColorInt
public int getBackgroundColorAsInt() {
+ checkThread();
PropertyValue<String> value = getBackgroundColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -86,6 +89,7 @@ public class BackgroundLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getBackgroundColorTransition() {
+ checkThread();
return nativeGetBackgroundColorTransition();
}
@@ -95,6 +99,7 @@ public class BackgroundLayer extends Layer {
* @param options transition options for String
*/
public void setBackgroundColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetBackgroundColorTransition(options.getDuration(), options.getDelay());
}
@@ -105,6 +110,7 @@ public class BackgroundLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getBackgroundPattern() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("background-pattern", nativeGetBackgroundPattern());
}
@@ -114,6 +120,7 @@ public class BackgroundLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getBackgroundPatternTransition() {
+ checkThread();
return nativeGetBackgroundPatternTransition();
}
@@ -123,6 +130,7 @@ public class BackgroundLayer extends Layer {
* @param options transition options for String
*/
public void setBackgroundPatternTransition(TransitionOptions options) {
+ checkThread();
nativeSetBackgroundPatternTransition(options.getDuration(), options.getDelay());
}
@@ -133,6 +141,7 @@ public class BackgroundLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getBackgroundOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("background-opacity", nativeGetBackgroundOpacity());
}
@@ -142,6 +151,7 @@ public class BackgroundLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getBackgroundOpacityTransition() {
+ checkThread();
return nativeGetBackgroundOpacityTransition();
}
@@ -151,6 +161,7 @@ public class BackgroundLayer extends Layer {
* @param options transition options for Float
*/
public void setBackgroundOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetBackgroundOpacityTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
index 94929398d5..c85cfba0a5 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/CircleLayer.java
@@ -37,6 +37,7 @@ public class CircleLayer extends Layer {
* @param sourceId the id of the source
*/
public CircleLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class CircleLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class CircleLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class CircleLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class CircleLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleRadius() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-radius", nativeGetCircleRadius());
}
@@ -135,6 +141,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getCircleRadiusTransition() {
+ checkThread();
return nativeGetCircleRadiusTransition();
}
@@ -144,6 +151,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float
*/
public void setCircleRadiusTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleRadiusTransition(options.getDuration(), options.getDelay());
}
@@ -154,6 +162,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("circle-color", nativeGetCircleColor());
}
@@ -165,6 +174,7 @@ public class CircleLayer extends Layer {
*/
@ColorInt
public int getCircleColorAsInt() {
+ checkThread();
PropertyValue<String> value = getCircleColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -179,6 +189,7 @@ public class CircleLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getCircleColorTransition() {
+ checkThread();
return nativeGetCircleColorTransition();
}
@@ -188,6 +199,7 @@ public class CircleLayer extends Layer {
* @param options transition options for String
*/
public void setCircleColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleColorTransition(options.getDuration(), options.getDelay());
}
@@ -198,6 +210,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleBlur() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-blur", nativeGetCircleBlur());
}
@@ -207,6 +220,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getCircleBlurTransition() {
+ checkThread();
return nativeGetCircleBlurTransition();
}
@@ -216,6 +230,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float
*/
public void setCircleBlurTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleBlurTransition(options.getDuration(), options.getDelay());
}
@@ -226,6 +241,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-opacity", nativeGetCircleOpacity());
}
@@ -235,6 +251,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getCircleOpacityTransition() {
+ checkThread();
return nativeGetCircleOpacityTransition();
}
@@ -244,6 +261,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float
*/
public void setCircleOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -254,6 +272,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getCircleTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("circle-translate", nativeGetCircleTranslate());
}
@@ -263,6 +282,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getCircleTranslateTransition() {
+ checkThread();
return nativeGetCircleTranslateTransition();
}
@@ -272,6 +292,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float[]
*/
public void setCircleTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -282,6 +303,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("circle-translate-anchor", nativeGetCircleTranslateAnchor());
}
@@ -292,6 +314,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchScale() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("circle-pitch-scale", nativeGetCirclePitchScale());
}
@@ -302,6 +325,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCirclePitchAlignment() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("circle-pitch-alignment", nativeGetCirclePitchAlignment());
}
@@ -312,6 +336,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleStrokeWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-stroke-width", nativeGetCircleStrokeWidth());
}
@@ -321,6 +346,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getCircleStrokeWidthTransition() {
+ checkThread();
return nativeGetCircleStrokeWidthTransition();
}
@@ -330,6 +356,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float
*/
public void setCircleStrokeWidthTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleStrokeWidthTransition(options.getDuration(), options.getDelay());
}
@@ -340,6 +367,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getCircleStrokeColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("circle-stroke-color", nativeGetCircleStrokeColor());
}
@@ -351,6 +379,7 @@ public class CircleLayer extends Layer {
*/
@ColorInt
public int getCircleStrokeColorAsInt() {
+ checkThread();
PropertyValue<String> value = getCircleStrokeColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -365,6 +394,7 @@ public class CircleLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getCircleStrokeColorTransition() {
+ checkThread();
return nativeGetCircleStrokeColorTransition();
}
@@ -374,6 +404,7 @@ public class CircleLayer extends Layer {
* @param options transition options for String
*/
public void setCircleStrokeColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleStrokeColorTransition(options.getDuration(), options.getDelay());
}
@@ -384,6 +415,7 @@ public class CircleLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getCircleStrokeOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("circle-stroke-opacity", nativeGetCircleStrokeOpacity());
}
@@ -393,6 +425,7 @@ public class CircleLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getCircleStrokeOpacityTransition() {
+ checkThread();
return nativeGetCircleStrokeOpacityTransition();
}
@@ -402,6 +435,7 @@ public class CircleLayer extends Layer {
* @param options transition options for Float
*/
public void setCircleStrokeOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetCircleStrokeOpacityTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java
index 29e2b49d76..fdfc8c51a9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillExtrusionLayer.java
@@ -37,6 +37,7 @@ public class FillExtrusionLayer extends Layer {
* @param sourceId the id of the source
*/
public FillExtrusionLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class FillExtrusionLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class FillExtrusionLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class FillExtrusionLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class FillExtrusionLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillExtrusionOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("fill-extrusion-opacity", nativeGetFillExtrusionOpacity());
}
@@ -135,6 +141,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getFillExtrusionOpacityTransition() {
+ checkThread();
return nativeGetFillExtrusionOpacityTransition();
}
@@ -144,6 +151,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for Float
*/
public void setFillExtrusionOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -154,6 +162,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillExtrusionColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-extrusion-color", nativeGetFillExtrusionColor());
}
@@ -165,6 +174,7 @@ public class FillExtrusionLayer extends Layer {
*/
@ColorInt
public int getFillExtrusionColorAsInt() {
+ checkThread();
PropertyValue<String> value = getFillExtrusionColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -179,6 +189,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getFillExtrusionColorTransition() {
+ checkThread();
return nativeGetFillExtrusionColorTransition();
}
@@ -188,6 +199,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for String
*/
public void setFillExtrusionColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionColorTransition(options.getDuration(), options.getDelay());
}
@@ -198,6 +210,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getFillExtrusionTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("fill-extrusion-translate", nativeGetFillExtrusionTranslate());
}
@@ -207,6 +220,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getFillExtrusionTranslateTransition() {
+ checkThread();
return nativeGetFillExtrusionTranslateTransition();
}
@@ -216,6 +230,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for Float[]
*/
public void setFillExtrusionTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -226,6 +241,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillExtrusionTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-extrusion-translate-anchor", nativeGetFillExtrusionTranslateAnchor());
}
@@ -236,6 +252,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillExtrusionPattern() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-extrusion-pattern", nativeGetFillExtrusionPattern());
}
@@ -245,6 +262,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getFillExtrusionPatternTransition() {
+ checkThread();
return nativeGetFillExtrusionPatternTransition();
}
@@ -254,6 +272,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for String
*/
public void setFillExtrusionPatternTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionPatternTransition(options.getDuration(), options.getDelay());
}
@@ -264,6 +283,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillExtrusionHeight() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("fill-extrusion-height", nativeGetFillExtrusionHeight());
}
@@ -273,6 +293,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getFillExtrusionHeightTransition() {
+ checkThread();
return nativeGetFillExtrusionHeightTransition();
}
@@ -282,6 +303,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for Float
*/
public void setFillExtrusionHeightTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionHeightTransition(options.getDuration(), options.getDelay());
}
@@ -292,6 +314,7 @@ public class FillExtrusionLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillExtrusionBase() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("fill-extrusion-base", nativeGetFillExtrusionBase());
}
@@ -301,6 +324,7 @@ public class FillExtrusionLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getFillExtrusionBaseTransition() {
+ checkThread();
return nativeGetFillExtrusionBaseTransition();
}
@@ -310,6 +334,7 @@ public class FillExtrusionLayer extends Layer {
* @param options transition options for Float
*/
public void setFillExtrusionBaseTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillExtrusionBaseTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java
index ed780811c0..b51c49e517 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/FillLayer.java
@@ -37,6 +37,7 @@ public class FillLayer extends Layer {
* @param sourceId the id of the source
*/
public FillLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class FillLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class FillLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class FillLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class FillLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getFillAntialias() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("fill-antialias", nativeGetFillAntialias());
}
@@ -136,6 +142,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getFillOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("fill-opacity", nativeGetFillOpacity());
}
@@ -145,6 +152,7 @@ public class FillLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getFillOpacityTransition() {
+ checkThread();
return nativeGetFillOpacityTransition();
}
@@ -154,6 +162,7 @@ public class FillLayer extends Layer {
* @param options transition options for Float
*/
public void setFillOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -164,6 +173,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-color", nativeGetFillColor());
}
@@ -175,6 +185,7 @@ public class FillLayer extends Layer {
*/
@ColorInt
public int getFillColorAsInt() {
+ checkThread();
PropertyValue<String> value = getFillColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -189,6 +200,7 @@ public class FillLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getFillColorTransition() {
+ checkThread();
return nativeGetFillColorTransition();
}
@@ -198,6 +210,7 @@ public class FillLayer extends Layer {
* @param options transition options for String
*/
public void setFillColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillColorTransition(options.getDuration(), options.getDelay());
}
@@ -208,6 +221,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillOutlineColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-outline-color", nativeGetFillOutlineColor());
}
@@ -219,6 +233,7 @@ public class FillLayer extends Layer {
*/
@ColorInt
public int getFillOutlineColorAsInt() {
+ checkThread();
PropertyValue<String> value = getFillOutlineColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -233,6 +248,7 @@ public class FillLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getFillOutlineColorTransition() {
+ checkThread();
return nativeGetFillOutlineColorTransition();
}
@@ -242,6 +258,7 @@ public class FillLayer extends Layer {
* @param options transition options for String
*/
public void setFillOutlineColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillOutlineColorTransition(options.getDuration(), options.getDelay());
}
@@ -252,6 +269,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getFillTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("fill-translate", nativeGetFillTranslate());
}
@@ -261,6 +279,7 @@ public class FillLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getFillTranslateTransition() {
+ checkThread();
return nativeGetFillTranslateTransition();
}
@@ -270,6 +289,7 @@ public class FillLayer extends Layer {
* @param options transition options for Float[]
*/
public void setFillTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -280,6 +300,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-translate-anchor", nativeGetFillTranslateAnchor());
}
@@ -290,6 +311,7 @@ public class FillLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getFillPattern() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("fill-pattern", nativeGetFillPattern());
}
@@ -299,6 +321,7 @@ public class FillLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getFillPatternTransition() {
+ checkThread();
return nativeGetFillPatternTransition();
}
@@ -308,6 +331,7 @@ public class FillLayer extends Layer {
* @param options transition options for String
*/
public void setFillPatternTransition(TransitionOptions options) {
+ checkThread();
nativeSetFillPatternTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java
index 42b4210710..d28e4bd838 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HeatmapLayer.java
@@ -37,6 +37,7 @@ public class HeatmapLayer extends Layer {
* @param sourceId the id of the source
*/
public HeatmapLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class HeatmapLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class HeatmapLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class HeatmapLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class HeatmapLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class HeatmapLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHeatmapRadius() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("heatmap-radius", nativeGetHeatmapRadius());
}
@@ -135,6 +141,7 @@ public class HeatmapLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getHeatmapRadiusTransition() {
+ checkThread();
return nativeGetHeatmapRadiusTransition();
}
@@ -144,6 +151,7 @@ public class HeatmapLayer extends Layer {
* @param options transition options for Float
*/
public void setHeatmapRadiusTransition(TransitionOptions options) {
+ checkThread();
nativeSetHeatmapRadiusTransition(options.getDuration(), options.getDelay());
}
@@ -154,6 +162,7 @@ public class HeatmapLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHeatmapWeight() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("heatmap-weight", nativeGetHeatmapWeight());
}
@@ -164,6 +173,7 @@ public class HeatmapLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHeatmapIntensity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("heatmap-intensity", nativeGetHeatmapIntensity());
}
@@ -173,6 +183,7 @@ public class HeatmapLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getHeatmapIntensityTransition() {
+ checkThread();
return nativeGetHeatmapIntensityTransition();
}
@@ -182,6 +193,7 @@ public class HeatmapLayer extends Layer {
* @param options transition options for Float
*/
public void setHeatmapIntensityTransition(TransitionOptions options) {
+ checkThread();
nativeSetHeatmapIntensityTransition(options.getDuration(), options.getDelay());
}
@@ -192,6 +204,7 @@ public class HeatmapLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getHeatmapColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("heatmap-color", nativeGetHeatmapColor());
}
@@ -203,6 +216,7 @@ public class HeatmapLayer extends Layer {
*/
@ColorInt
public int getHeatmapColorAsInt() {
+ checkThread();
PropertyValue<String> value = getHeatmapColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -218,6 +232,7 @@ public class HeatmapLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHeatmapOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("heatmap-opacity", nativeGetHeatmapOpacity());
}
@@ -227,6 +242,7 @@ public class HeatmapLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getHeatmapOpacityTransition() {
+ checkThread();
return nativeGetHeatmapOpacityTransition();
}
@@ -236,6 +252,7 @@ public class HeatmapLayer extends Layer {
* @param options transition options for Float
*/
public void setHeatmapOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetHeatmapOpacityTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java
index fb086f424b..75a2607b05 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/HillshadeLayer.java
@@ -37,6 +37,7 @@ public class HillshadeLayer extends Layer {
* @param sourceId the id of the source
*/
public HillshadeLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class HillshadeLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -82,6 +84,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHillshadeIlluminationDirection() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("hillshade-illumination-direction", nativeGetHillshadeIlluminationDirection());
}
@@ -92,6 +95,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeIlluminationAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-illumination-anchor", nativeGetHillshadeIlluminationAnchor());
}
@@ -102,6 +106,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getHillshadeExaggeration() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("hillshade-exaggeration", nativeGetHillshadeExaggeration());
}
@@ -111,6 +116,7 @@ public class HillshadeLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getHillshadeExaggerationTransition() {
+ checkThread();
return nativeGetHillshadeExaggerationTransition();
}
@@ -120,6 +126,7 @@ public class HillshadeLayer extends Layer {
* @param options transition options for Float
*/
public void setHillshadeExaggerationTransition(TransitionOptions options) {
+ checkThread();
nativeSetHillshadeExaggerationTransition(options.getDuration(), options.getDelay());
}
@@ -130,6 +137,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeShadowColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-shadow-color", nativeGetHillshadeShadowColor());
}
@@ -141,6 +149,7 @@ public class HillshadeLayer extends Layer {
*/
@ColorInt
public int getHillshadeShadowColorAsInt() {
+ checkThread();
PropertyValue<String> value = getHillshadeShadowColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -155,6 +164,7 @@ public class HillshadeLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getHillshadeShadowColorTransition() {
+ checkThread();
return nativeGetHillshadeShadowColorTransition();
}
@@ -164,6 +174,7 @@ public class HillshadeLayer extends Layer {
* @param options transition options for String
*/
public void setHillshadeShadowColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetHillshadeShadowColorTransition(options.getDuration(), options.getDelay());
}
@@ -174,6 +185,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeHighlightColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-highlight-color", nativeGetHillshadeHighlightColor());
}
@@ -185,6 +197,7 @@ public class HillshadeLayer extends Layer {
*/
@ColorInt
public int getHillshadeHighlightColorAsInt() {
+ checkThread();
PropertyValue<String> value = getHillshadeHighlightColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -199,6 +212,7 @@ public class HillshadeLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getHillshadeHighlightColorTransition() {
+ checkThread();
return nativeGetHillshadeHighlightColorTransition();
}
@@ -208,6 +222,7 @@ public class HillshadeLayer extends Layer {
* @param options transition options for String
*/
public void setHillshadeHighlightColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetHillshadeHighlightColorTransition(options.getDuration(), options.getDelay());
}
@@ -218,6 +233,7 @@ public class HillshadeLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getHillshadeAccentColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("hillshade-accent-color", nativeGetHillshadeAccentColor());
}
@@ -229,6 +245,7 @@ public class HillshadeLayer extends Layer {
*/
@ColorInt
public int getHillshadeAccentColorAsInt() {
+ checkThread();
PropertyValue<String> value = getHillshadeAccentColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -243,6 +260,7 @@ public class HillshadeLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getHillshadeAccentColorTransition() {
+ checkThread();
return nativeGetHillshadeAccentColorTransition();
}
@@ -252,6 +270,7 @@ public class HillshadeLayer extends Layer {
* @param options transition options for String
*/
public void setHillshadeAccentColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetHillshadeAccentColorTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java
index 411fbe4435..0de9234b7f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/Layer.java
@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.mapbox.mapboxsdk.style.expressions.Expression;
+import com.mapbox.mapboxsdk.utils.ThreadUtils;
/**
* Base class for the different Layer types
@@ -15,13 +16,23 @@ public abstract class Layer {
private boolean invalidated;
public Layer(long nativePtr) {
+ checkThread();
this.nativePtr = nativePtr;
}
public Layer() {
+ checkThread();
+ }
+
+ /**
+ * Validates if layer interaction is happening on the UI thread
+ */
+ protected void checkThread(){
+ ThreadUtils.checkThread("Layer");
}
public void setProperties(@NonNull PropertyValue<?>... properties) {
+ checkThread();
if (properties.length == 0) {
return;
}
@@ -37,26 +48,32 @@ public abstract class Layer {
}
public String getId() {
+ checkThread();
return nativeGetId();
}
public PropertyValue<String> getVisibility() {
+ checkThread();
return new PaintPropertyValue<>("visibility", (String) nativeGetVisibility());
}
public float getMinZoom() {
+ checkThread();
return nativeGetMinZoom();
}
public float getMaxZoom() {
+ checkThread();
return nativeGetMaxZoom();
}
public void setMinZoom(float zoom) {
+ checkThread();
nativeSetMinZoom(zoom);
}
public void setMaxZoom(float zoom) {
+ checkThread();
nativeSetMaxZoom(zoom);
}
@@ -97,5 +114,4 @@ public abstract class Layer {
}
return value;
}
-
} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java
index 5e6e6d38e7..b094162c4b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/LineLayer.java
@@ -37,6 +37,7 @@ public class LineLayer extends Layer {
* @param sourceId the id of the source
*/
public LineLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class LineLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class LineLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class LineLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class LineLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineCap() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("line-cap", nativeGetLineCap());
}
@@ -136,6 +142,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineJoin() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("line-join", nativeGetLineJoin());
}
@@ -146,6 +153,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineMiterLimit() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-miter-limit", nativeGetLineMiterLimit());
}
@@ -156,6 +164,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineRoundLimit() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-round-limit", nativeGetLineRoundLimit());
}
@@ -166,6 +175,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-opacity", nativeGetLineOpacity());
}
@@ -175,6 +185,7 @@ public class LineLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getLineOpacityTransition() {
+ checkThread();
return nativeGetLineOpacityTransition();
}
@@ -184,6 +195,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float
*/
public void setLineOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -194,6 +206,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("line-color", nativeGetLineColor());
}
@@ -205,6 +218,7 @@ public class LineLayer extends Layer {
*/
@ColorInt
public int getLineColorAsInt() {
+ checkThread();
PropertyValue<String> value = getLineColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -219,6 +233,7 @@ public class LineLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getLineColorTransition() {
+ checkThread();
return nativeGetLineColorTransition();
}
@@ -228,6 +243,7 @@ public class LineLayer extends Layer {
* @param options transition options for String
*/
public void setLineColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineColorTransition(options.getDuration(), options.getDelay());
}
@@ -238,6 +254,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("line-translate", nativeGetLineTranslate());
}
@@ -247,6 +264,7 @@ public class LineLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getLineTranslateTransition() {
+ checkThread();
return nativeGetLineTranslateTransition();
}
@@ -256,6 +274,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float[]
*/
public void setLineTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -266,6 +285,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getLineTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("line-translate-anchor", nativeGetLineTranslateAnchor());
}
@@ -276,6 +296,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-width", nativeGetLineWidth());
}
@@ -285,6 +306,7 @@ public class LineLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getLineWidthTransition() {
+ checkThread();
return nativeGetLineWidthTransition();
}
@@ -294,6 +316,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float
*/
public void setLineWidthTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineWidthTransition(options.getDuration(), options.getDelay());
}
@@ -304,6 +327,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineGapWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-gap-width", nativeGetLineGapWidth());
}
@@ -313,6 +337,7 @@ public class LineLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getLineGapWidthTransition() {
+ checkThread();
return nativeGetLineGapWidthTransition();
}
@@ -322,6 +347,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float
*/
public void setLineGapWidthTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineGapWidthTransition(options.getDuration(), options.getDelay());
}
@@ -332,6 +358,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineOffset() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-offset", nativeGetLineOffset());
}
@@ -341,6 +368,7 @@ public class LineLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getLineOffsetTransition() {
+ checkThread();
return nativeGetLineOffsetTransition();
}
@@ -350,6 +378,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float
*/
public void setLineOffsetTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineOffsetTransition(options.getDuration(), options.getDelay());
}
@@ -360,6 +389,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getLineBlur() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("line-blur", nativeGetLineBlur());
}
@@ -369,6 +399,7 @@ public class LineLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getLineBlurTransition() {
+ checkThread();
return nativeGetLineBlurTransition();
}
@@ -378,6 +409,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float
*/
public void setLineBlurTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineBlurTransition(options.getDuration(), options.getDelay());
}
@@ -388,6 +420,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getLineDasharray() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("line-dasharray", nativeGetLineDasharray());
}
@@ -397,6 +430,7 @@ public class LineLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getLineDasharrayTransition() {
+ checkThread();
return nativeGetLineDasharrayTransition();
}
@@ -406,6 +440,7 @@ public class LineLayer extends Layer {
* @param options transition options for Float[]
*/
public void setLineDasharrayTransition(TransitionOptions options) {
+ checkThread();
nativeSetLineDasharrayTransition(options.getDuration(), options.getDelay());
}
@@ -416,6 +451,7 @@ public class LineLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getLinePattern() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("line-pattern", nativeGetLinePattern());
}
@@ -425,6 +461,7 @@ public class LineLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getLinePatternTransition() {
+ checkThread();
return nativeGetLinePatternTransition();
}
@@ -434,6 +471,7 @@ public class LineLayer extends Layer {
* @param options transition options for String
*/
public void setLinePatternTransition(TransitionOptions options) {
+ checkThread();
nativeSetLinePatternTransition(options.getDuration(), options.getDelay());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
index 0c7948f62a..218ed36744 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/RasterLayer.java
@@ -37,6 +37,7 @@ public class RasterLayer extends Layer {
* @param sourceId the id of the source
*/
public RasterLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class RasterLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -82,6 +84,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-opacity", nativeGetRasterOpacity());
}
@@ -91,6 +94,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterOpacityTransition() {
+ checkThread();
return nativeGetRasterOpacityTransition();
}
@@ -100,6 +104,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -110,6 +115,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterHueRotate() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-hue-rotate", nativeGetRasterHueRotate());
}
@@ -119,6 +125,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterHueRotateTransition() {
+ checkThread();
return nativeGetRasterHueRotateTransition();
}
@@ -128,6 +135,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterHueRotateTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterHueRotateTransition(options.getDuration(), options.getDelay());
}
@@ -138,6 +146,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMin() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-brightness-min", nativeGetRasterBrightnessMin());
}
@@ -147,6 +156,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterBrightnessMinTransition() {
+ checkThread();
return nativeGetRasterBrightnessMinTransition();
}
@@ -156,6 +166,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterBrightnessMinTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterBrightnessMinTransition(options.getDuration(), options.getDelay());
}
@@ -166,6 +177,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterBrightnessMax() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-brightness-max", nativeGetRasterBrightnessMax());
}
@@ -175,6 +187,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterBrightnessMaxTransition() {
+ checkThread();
return nativeGetRasterBrightnessMaxTransition();
}
@@ -184,6 +197,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterBrightnessMaxTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterBrightnessMaxTransition(options.getDuration(), options.getDelay());
}
@@ -194,6 +208,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterSaturation() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-saturation", nativeGetRasterSaturation());
}
@@ -203,6 +218,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterSaturationTransition() {
+ checkThread();
return nativeGetRasterSaturationTransition();
}
@@ -212,6 +228,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterSaturationTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterSaturationTransition(options.getDuration(), options.getDelay());
}
@@ -222,6 +239,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterContrast() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-contrast", nativeGetRasterContrast());
}
@@ -231,6 +249,7 @@ public class RasterLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getRasterContrastTransition() {
+ checkThread();
return nativeGetRasterContrastTransition();
}
@@ -240,6 +259,7 @@ public class RasterLayer extends Layer {
* @param options transition options for Float
*/
public void setRasterContrastTransition(TransitionOptions options) {
+ checkThread();
nativeSetRasterContrastTransition(options.getDuration(), options.getDelay());
}
@@ -250,6 +270,7 @@ public class RasterLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getRasterFadeDuration() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("raster-fade-duration", nativeGetRasterFadeDuration());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
index 6a2e131d7d..4aefad3956 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/SymbolLayer.java
@@ -37,6 +37,7 @@ public class SymbolLayer extends Layer {
* @param sourceId the id of the source
*/
public SymbolLayer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -48,6 +49,7 @@ public class SymbolLayer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -68,6 +70,7 @@ public class SymbolLayer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -77,6 +80,7 @@ public class SymbolLayer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -98,6 +102,7 @@ public class SymbolLayer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -126,6 +131,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getSymbolPlacement() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("symbol-placement", nativeGetSymbolPlacement());
}
@@ -136,6 +142,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getSymbolSpacing() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("symbol-spacing", nativeGetSymbolSpacing());
}
@@ -146,6 +153,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getSymbolAvoidEdges() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("symbol-avoid-edges", nativeGetSymbolAvoidEdges());
}
@@ -156,6 +164,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconAllowOverlap() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("icon-allow-overlap", nativeGetIconAllowOverlap());
}
@@ -166,6 +175,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconIgnorePlacement() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("icon-ignore-placement", nativeGetIconIgnorePlacement());
}
@@ -176,6 +186,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconOptional() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("icon-optional", nativeGetIconOptional());
}
@@ -186,6 +197,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconRotationAlignment() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-rotation-alignment", nativeGetIconRotationAlignment());
}
@@ -196,6 +208,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconSize() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-size", nativeGetIconSize());
}
@@ -206,6 +219,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTextFit() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-text-fit", nativeGetIconTextFit());
}
@@ -216,6 +230,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTextFitPadding() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("icon-text-fit-padding", nativeGetIconTextFitPadding());
}
@@ -226,6 +241,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconImage() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-image", nativeGetIconImage());
}
@@ -236,6 +252,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconRotate() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-rotate", nativeGetIconRotate());
}
@@ -246,6 +263,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconPadding() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-padding", nativeGetIconPadding());
}
@@ -256,6 +274,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getIconKeepUpright() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("icon-keep-upright", nativeGetIconKeepUpright());
}
@@ -266,6 +285,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconOffset() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("icon-offset", nativeGetIconOffset());
}
@@ -276,6 +296,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-anchor", nativeGetIconAnchor());
}
@@ -286,6 +307,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconPitchAlignment() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-pitch-alignment", nativeGetIconPitchAlignment());
}
@@ -296,6 +318,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextPitchAlignment() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-pitch-alignment", nativeGetTextPitchAlignment());
}
@@ -306,6 +329,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextRotationAlignment() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-rotation-alignment", nativeGetTextRotationAlignment());
}
@@ -316,6 +340,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextField() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-field", nativeGetTextField());
}
@@ -326,6 +351,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String[]> getTextFont() {
+ checkThread();
return (PropertyValue<String[]>) new PropertyValue("text-font", nativeGetTextFont());
}
@@ -336,6 +362,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextSize() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-size", nativeGetTextSize());
}
@@ -346,6 +373,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-max-width", nativeGetTextMaxWidth());
}
@@ -356,6 +384,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLineHeight() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-line-height", nativeGetTextLineHeight());
}
@@ -366,6 +395,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextLetterSpacing() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-letter-spacing", nativeGetTextLetterSpacing());
}
@@ -376,6 +406,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextJustify() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-justify", nativeGetTextJustify());
}
@@ -386,6 +417,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-anchor", nativeGetTextAnchor());
}
@@ -396,6 +428,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextMaxAngle() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-max-angle", nativeGetTextMaxAngle());
}
@@ -406,6 +439,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextRotate() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-rotate", nativeGetTextRotate());
}
@@ -416,6 +450,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextPadding() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-padding", nativeGetTextPadding());
}
@@ -426,6 +461,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextKeepUpright() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("text-keep-upright", nativeGetTextKeepUpright());
}
@@ -436,6 +472,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTransform() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-transform", nativeGetTextTransform());
}
@@ -446,6 +483,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextOffset() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("text-offset", nativeGetTextOffset());
}
@@ -456,6 +494,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextAllowOverlap() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("text-allow-overlap", nativeGetTextAllowOverlap());
}
@@ -466,6 +505,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextIgnorePlacement() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("text-ignore-placement", nativeGetTextIgnorePlacement());
}
@@ -476,6 +516,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Boolean> getTextOptional() {
+ checkThread();
return (PropertyValue<Boolean>) new PropertyValue("text-optional", nativeGetTextOptional());
}
@@ -486,6 +527,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-opacity", nativeGetIconOpacity());
}
@@ -495,6 +537,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getIconOpacityTransition() {
+ checkThread();
return nativeGetIconOpacityTransition();
}
@@ -504,6 +547,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setIconOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -514,6 +558,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-color", nativeGetIconColor());
}
@@ -525,6 +570,7 @@ public class SymbolLayer extends Layer {
*/
@ColorInt
public int getIconColorAsInt() {
+ checkThread();
PropertyValue<String> value = getIconColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -539,6 +585,7 @@ public class SymbolLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getIconColorTransition() {
+ checkThread();
return nativeGetIconColorTransition();
}
@@ -548,6 +595,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for String
*/
public void setIconColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconColorTransition(options.getDuration(), options.getDelay());
}
@@ -558,6 +606,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconHaloColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-halo-color", nativeGetIconHaloColor());
}
@@ -569,6 +618,7 @@ public class SymbolLayer extends Layer {
*/
@ColorInt
public int getIconHaloColorAsInt() {
+ checkThread();
PropertyValue<String> value = getIconHaloColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -583,6 +633,7 @@ public class SymbolLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getIconHaloColorTransition() {
+ checkThread();
return nativeGetIconHaloColorTransition();
}
@@ -592,6 +643,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for String
*/
public void setIconHaloColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconHaloColorTransition(options.getDuration(), options.getDelay());
}
@@ -602,6 +654,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconHaloWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-halo-width", nativeGetIconHaloWidth());
}
@@ -611,6 +664,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getIconHaloWidthTransition() {
+ checkThread();
return nativeGetIconHaloWidthTransition();
}
@@ -620,6 +674,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setIconHaloWidthTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconHaloWidthTransition(options.getDuration(), options.getDelay());
}
@@ -630,6 +685,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getIconHaloBlur() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("icon-halo-blur", nativeGetIconHaloBlur());
}
@@ -639,6 +695,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getIconHaloBlurTransition() {
+ checkThread();
return nativeGetIconHaloBlurTransition();
}
@@ -648,6 +705,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setIconHaloBlurTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconHaloBlurTransition(options.getDuration(), options.getDelay());
}
@@ -658,6 +716,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getIconTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("icon-translate", nativeGetIconTranslate());
}
@@ -667,6 +726,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getIconTranslateTransition() {
+ checkThread();
return nativeGetIconTranslateTransition();
}
@@ -676,6 +736,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float[]
*/
public void setIconTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetIconTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -686,6 +747,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getIconTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("icon-translate-anchor", nativeGetIconTranslateAnchor());
}
@@ -696,6 +758,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextOpacity() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-opacity", nativeGetTextOpacity());
}
@@ -705,6 +768,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getTextOpacityTransition() {
+ checkThread();
return nativeGetTextOpacityTransition();
}
@@ -714,6 +778,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setTextOpacityTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextOpacityTransition(options.getDuration(), options.getDelay());
}
@@ -724,6 +789,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-color", nativeGetTextColor());
}
@@ -735,6 +801,7 @@ public class SymbolLayer extends Layer {
*/
@ColorInt
public int getTextColorAsInt() {
+ checkThread();
PropertyValue<String> value = getTextColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -749,6 +816,7 @@ public class SymbolLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getTextColorTransition() {
+ checkThread();
return nativeGetTextColorTransition();
}
@@ -758,6 +826,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for String
*/
public void setTextColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextColorTransition(options.getDuration(), options.getDelay());
}
@@ -768,6 +837,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextHaloColor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-halo-color", nativeGetTextHaloColor());
}
@@ -779,6 +849,7 @@ public class SymbolLayer extends Layer {
*/
@ColorInt
public int getTextHaloColorAsInt() {
+ checkThread();
PropertyValue<String> value = getTextHaloColor();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -793,6 +864,7 @@ public class SymbolLayer extends Layer {
* @return transition options for String
*/
public TransitionOptions getTextHaloColorTransition() {
+ checkThread();
return nativeGetTextHaloColorTransition();
}
@@ -802,6 +874,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for String
*/
public void setTextHaloColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextHaloColorTransition(options.getDuration(), options.getDelay());
}
@@ -812,6 +885,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextHaloWidth() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-halo-width", nativeGetTextHaloWidth());
}
@@ -821,6 +895,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getTextHaloWidthTransition() {
+ checkThread();
return nativeGetTextHaloWidthTransition();
}
@@ -830,6 +905,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setTextHaloWidthTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextHaloWidthTransition(options.getDuration(), options.getDelay());
}
@@ -840,6 +916,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float> getTextHaloBlur() {
+ checkThread();
return (PropertyValue<Float>) new PropertyValue("text-halo-blur", nativeGetTextHaloBlur());
}
@@ -849,6 +926,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float
*/
public TransitionOptions getTextHaloBlurTransition() {
+ checkThread();
return nativeGetTextHaloBlurTransition();
}
@@ -858,6 +936,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float
*/
public void setTextHaloBlurTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextHaloBlurTransition(options.getDuration(), options.getDelay());
}
@@ -868,6 +947,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<Float[]> getTextTranslate() {
+ checkThread();
return (PropertyValue<Float[]>) new PropertyValue("text-translate", nativeGetTextTranslate());
}
@@ -877,6 +957,7 @@ public class SymbolLayer extends Layer {
* @return transition options for Float[]
*/
public TransitionOptions getTextTranslateTransition() {
+ checkThread();
return nativeGetTextTranslateTransition();
}
@@ -886,6 +967,7 @@ public class SymbolLayer extends Layer {
* @param options transition options for Float[]
*/
public void setTextTranslateTransition(TransitionOptions options) {
+ checkThread();
nativeSetTextTranslateTransition(options.getDuration(), options.getDelay());
}
@@ -896,6 +978,7 @@ public class SymbolLayer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<String> getTextTranslateAnchor() {
+ checkThread();
return (PropertyValue<String>) new PropertyValue("text-translate-anchor", nativeGetTextTranslateAnchor());
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs
index 851a85f3d6..21b0a1d59e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs
@@ -42,6 +42,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @param layerId the id of the layer
*/
public <%- camelize(type) %>Layer(String layerId) {
+ super();
initialize(layerId);
}
@@ -55,6 +56,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @param sourceId the id of the source
*/
public <%- camelize(type) %>Layer(String layerId, String sourceId) {
+ super();
initialize(layerId, sourceId);
}
@@ -66,6 +68,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @param sourceLayer the source layer to set
*/
public void setSourceLayer(String sourceLayer) {
+ checkThread();
nativeSetSourceLayer(sourceLayer);
}
@@ -88,6 +91,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @return sourceLayer the source layer to get
*/
public String getSourceLayer() {
+ checkThread();
return nativeGetSourceLayer();
}
@@ -97,6 +101,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @param filter the expression filter to set
*/
public void setFilter(Expression filter) {
+ checkThread();
nativeSetFilter(filter.toArray());
}
@@ -118,6 +123,7 @@ public class <%- camelize(type) %>Layer extends Layer {
*/
@Nullable
public Expression getFilter() {
+ checkThread();
Expression expression = null;
JsonArray array = (JsonArray) nativeGetFilter();
if (array != null) {
@@ -148,6 +154,7 @@ public class <%- camelize(type) %>Layer extends Layer {
*/
@SuppressWarnings("unchecked")
public PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() {
+ checkThread();
return (PropertyValue<<%- propertyType(property) %>>) new PropertyValue("<%- property.name %>", nativeGet<%- camelize(property.name) %>());
}
<% if (property.type == 'color') { -%>
@@ -160,6 +167,7 @@ public class <%- camelize(type) %>Layer extends Layer {
*/
@ColorInt
public int get<%- camelize(property.name) %>AsInt() {
+ checkThread();
PropertyValue<<%- propertyType(property) %>> value = get<%- camelize(property.name) %>();
if (value.isValue()) {
return rgbaToColor(value.getValue());
@@ -176,6 +184,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @return transition options for <%- propertyType(property) %>
*/
public TransitionOptions get<%- camelize(property.name) %>Transition() {
+ checkThread();
return nativeGet<%- camelize(property.name) %>Transition();
}
@@ -185,6 +194,7 @@ public class <%- camelize(type) %>Layer extends Layer {
* @param options transition options for <%- propertyType(property) %>
*/
public void set<%- camelize(property.name) %>Transition(TransitionOptions options) {
+ checkThread();
nativeSet<%- camelize(property.name) %>Transition(options.getDuration(), options.getDelay());
}
<% } -%>
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java
index 7df48001cc..411c4c9652 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/Light.java
@@ -9,6 +9,7 @@ import android.support.annotation.UiThread;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
+import com.mapbox.mapboxsdk.utils.ThreadUtils;
/**
* The global light source.
@@ -26,6 +27,7 @@ public class Light {
* @param nativePtr pointer used by core
*/
public Light(long nativePtr) {
+ checkThread();
this.nativePtr = nativePtr;
}
@@ -35,6 +37,7 @@ public class Light {
* @param anchor as String
*/
public void setAnchor(@Property.ANCHOR String anchor) {
+ checkThread();
nativeSetAnchor(anchor);
}
@@ -44,6 +47,7 @@ public class Light {
* @return anchor as String
*/
@Property.ANCHOR public String getAnchor() {
+ checkThread();
return nativeGetAnchor();
}
@@ -53,6 +57,7 @@ public class Light {
* @param position of the light
*/
public void setPosition(@NonNull Position position) {
+ checkThread();
nativeSetPosition(position);
}
@@ -62,6 +67,7 @@ public class Light {
* @return position as Position
*/
public Position getPosition() {
+ checkThread();
return nativeGetPosition();
}
@@ -71,6 +77,7 @@ public class Light {
* @return transition options for position
*/
public TransitionOptions getPositionTransition() {
+ checkThread();
return nativeGetPositionTransition();
}
@@ -80,6 +87,7 @@ public class Light {
* @param options transition options for position
*/
public void setPositionTransition(TransitionOptions options) {
+ checkThread();
nativeSetPositionTransition(options.getDuration(), options.getDelay());
}
@@ -89,6 +97,7 @@ public class Light {
* @param color as int
*/
public void setColor(@ColorInt int color) {
+ checkThread();
nativeSetColor(PropertyFactory.colorToRgbaString(color));
}
@@ -98,6 +107,7 @@ public class Light {
* @param color as String
*/
public void setColor(String color) {
+ checkThread();
nativeSetColor(color);
}
@@ -107,6 +117,7 @@ public class Light {
* @return color as String
*/
public String getColor() {
+ checkThread();
return nativeGetColor();
}
@@ -116,6 +127,7 @@ public class Light {
* @return transition options for color
*/
public TransitionOptions getColorTransition() {
+ checkThread();
return nativeGetColorTransition();
}
@@ -125,6 +137,7 @@ public class Light {
* @param options transition options for color
*/
public void setColorTransition(TransitionOptions options) {
+ checkThread();
nativeSetColorTransition(options.getDuration(), options.getDelay());
}
@@ -134,6 +147,7 @@ public class Light {
* @param intensity as Float
*/
public void setIntensity(float intensity) {
+ checkThread();
nativeSetIntensity(intensity);
}
@@ -143,6 +157,7 @@ public class Light {
* @return intensity as Float
*/
public float getIntensity() {
+ checkThread();
return nativeGetIntensity();
}
@@ -152,6 +167,7 @@ public class Light {
* @return transition options for intensity
*/
public TransitionOptions getIntensityTransition() {
+ checkThread();
return nativeGetIntensityTransition();
}
@@ -161,9 +177,14 @@ public class Light {
* @param options transition options for intensity
*/
public void setIntensityTransition(TransitionOptions options) {
+ checkThread();
nativeSetIntensityTransition(options.getDuration(), options.getDelay());
}
+ private void checkThread(){
+ ThreadUtils.checkThread("Light");
+ }
+
private native void nativeSetAnchor(String anchor);
private native String nativeGetAnchor();
private native void nativeSetPosition(Position position);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs
index 80d927128d..f3e7c31a4f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/light/light.java.ejs
@@ -13,6 +13,7 @@ import android.support.annotation.UiThread;
import com.mapbox.mapboxsdk.style.layers.Property;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
+import com.mapbox.mapboxsdk.utils.ThreadUtils;
/**
* The global light source.
@@ -30,6 +31,7 @@ public class Light {
* @param nativePtr pointer used by core
*/
public Light(long nativePtr) {
+ checkThread();
this.nativePtr = nativePtr;
}
<% for (const property of properties) { -%>
@@ -41,6 +43,7 @@ public class Light {
* @param position of the light
*/
public void set<%- camelize(property.name) %>(@NonNull Position position) {
+ checkThread();
nativeSet<%- camelize(property.name) %>(position);
}
@@ -50,6 +53,7 @@ public class Light {
* @return <%- property.name %> as Position
*/
public Position get<%- camelize(property.name) %>() {
+ checkThread();
return nativeGet<%- camelize(property.name) %>();
}
<% } else { -%>
@@ -61,6 +65,7 @@ public class Light {
* @param <%- property.name %> as int
*/
public void set<%- camelize(property.name) %>(@ColorInt int <%- property.name %>) {
+ checkThread();
nativeSet<%- camelize(property.name) %>(PropertyFactory.colorToRgbaString(<%- property.name %>));
}
<% } -%>
@@ -71,6 +76,7 @@ public class Light {
* @param <%- property.name %> as <%- propertyType(property) %>
*/
public void set<%- camelize(property.name) %>(<%- propertyTypeAnnotation(property) %><%- iff(() => propertyTypeAnnotation(property), " ") %><%- propertyJavaType(property) %> <%- property.name %>) {
+ checkThread();
nativeSet<%- camelize(property.name) %>(<%- property.name %>);
}
@@ -80,6 +86,7 @@ public class Light {
* @return <%- property.name %> as <%- propertyType(property) %>
*/
<%- propertyTypeAnnotation(property) %> public <%- propertyJavaType(property) %> get<%- camelize(property.name) %>() {
+ checkThread();
return nativeGet<%- camelize(property.name) %>();
}
<% } -%>
@@ -91,6 +98,7 @@ public class Light {
* @return transition options for <%- property.name %>
*/
public TransitionOptions get<%- camelize(property.name) %>Transition() {
+ checkThread();
return nativeGet<%- camelize(property.name) %>Transition();
}
@@ -100,11 +108,16 @@ public class Light {
* @param options transition options for <%- property.name %>
*/
public void set<%- camelize(property.name) %>Transition(TransitionOptions options) {
+ checkThread();
nativeSet<%- camelize(property.name) %>Transition(options.getDuration(), options.getDelay());
}
<% } -%>
<% } -%>
+ private void checkThread(){
+ ThreadUtils.checkThread("Light");
+ }
+
<% for (const property of properties) { -%>
<% if (property.name == "position") {-%>
private native void nativeSet<%- camelize(property.name) %>(Position position);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
index 21a34f6064..469bfa8f39 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/CustomGeometrySource.java
@@ -49,6 +49,7 @@ public class CustomGeometrySource extends Source {
* @param options CustomGeometrySourceOptions.
*/
public CustomGeometrySource(String id, GeometryTileProvider provider, CustomGeometrySourceOptions options) {
+ super();
this.provider = provider;
executor = Executors.newFixedThreadPool(4);
initialize(id, options);
@@ -62,6 +63,7 @@ public class CustomGeometrySource extends Source {
* @param bounds The region in which features should be invalidated at all zoom levels
*/
public void invalidateRegion(LatLngBounds bounds) {
+ checkThread();
nativeInvalidateBounds(bounds);
}
@@ -74,6 +76,7 @@ public class CustomGeometrySource extends Source {
* @param y Tile Y coordinate.
*/
public void invalidateTile(int zoomLevel, int x, int y) {
+ checkThread();
nativeInvalidateTile(zoomLevel, x, y);
}
@@ -88,6 +91,7 @@ public class CustomGeometrySource extends Source {
* @param data Feature collection for the tile.
*/
public void setTileData(int zoomLevel, int x, int y, FeatureCollection data) {
+ checkThread();
nativeSetTileData(zoomLevel, x, y, data);
}
@@ -99,6 +103,7 @@ public class CustomGeometrySource extends Source {
*/
@NonNull
public List<Feature> querySourceFeatures(@Nullable Expression filter) {
+ checkThread();
Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
index efacc18741..9ecc70e123 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/GeoJsonSource.java
@@ -37,6 +37,7 @@ public class GeoJsonSource extends Source {
* @param id the source id
*/
public GeoJsonSource(String id) {
+ super();
initialize(id, null);
setGeoJson(FeatureCollection.fromFeatures(new ArrayList<Feature>()));
}
@@ -48,6 +49,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, GeoJsonOptions options) {
+ super();
initialize(id, options);
setGeoJson(FeatureCollection.fromFeatures(new ArrayList<Feature>()));
}
@@ -59,6 +61,7 @@ public class GeoJsonSource extends Source {
* @param geoJson raw Json FeatureCollection
*/
public GeoJsonSource(String id, String geoJson) {
+ super();
if (geoJson == null || geoJson.startsWith("http")) {
throw new IllegalArgumentException("Expected a raw json body");
}
@@ -74,6 +77,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, String geoJson, GeoJsonOptions options) {
+ super();
if (geoJson == null || geoJson.startsWith("http")) {
throw new IllegalArgumentException("Expected a raw json body");
}
@@ -88,6 +92,7 @@ public class GeoJsonSource extends Source {
* @param url remote json file
*/
public GeoJsonSource(String id, URL url) {
+ super();
initialize(id, null);
nativeSetUrl(url.toExternalForm());
}
@@ -100,6 +105,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, URL url, GeoJsonOptions options) {
+ super();
initialize(id, options);
nativeSetUrl(url.toExternalForm());
}
@@ -111,6 +117,7 @@ public class GeoJsonSource extends Source {
* @param features the features
*/
public GeoJsonSource(String id, FeatureCollection features) {
+ super();
initialize(id, null);
setGeoJson(features);
}
@@ -123,6 +130,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, FeatureCollection features, GeoJsonOptions options) {
+ super();
initialize(id, options);
setGeoJson(features);
}
@@ -134,6 +142,7 @@ public class GeoJsonSource extends Source {
* @param feature the feature
*/
public GeoJsonSource(String id, Feature feature) {
+ super();
initialize(id, null);
setGeoJson(feature);
}
@@ -146,6 +155,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, Feature feature, GeoJsonOptions options) {
+ super();
initialize(id, options);
setGeoJson(feature);
}
@@ -157,6 +167,7 @@ public class GeoJsonSource extends Source {
* @param geometry the geometry
*/
public GeoJsonSource(String id, Geometry geometry) {
+ super();
initialize(id, null);
setGeoJson(geometry);
}
@@ -169,6 +180,7 @@ public class GeoJsonSource extends Source {
* @param options options
*/
public GeoJsonSource(String id, Geometry geometry, GeoJsonOptions options) {
+ super();
initialize(id, options);
setGeoJson(geometry);
}
@@ -179,6 +191,7 @@ public class GeoJsonSource extends Source {
* @param feature the GeoJSON {@link Feature} to set
*/
public void setGeoJson(Feature feature) {
+ checkThread();
nativeSetFeature(feature);
}
@@ -188,6 +201,7 @@ public class GeoJsonSource extends Source {
* @param geometry the GeoJSON {@link Geometry} to set
*/
public void setGeoJson(Geometry geometry) {
+ checkThread();
nativeSetGeometry(geometry);
}
@@ -197,6 +211,7 @@ public class GeoJsonSource extends Source {
* @param features the GeoJSON FeatureCollection
*/
public void setGeoJson(FeatureCollection features) {
+ checkThread();
nativeSetFeatureCollection(features);
}
@@ -206,6 +221,7 @@ public class GeoJsonSource extends Source {
* @param json the raw GeoJson FeatureCollection string
*/
public void setGeoJson(String json) {
+ checkThread();
nativeSetGeoJsonString(json);
}
@@ -215,6 +231,7 @@ public class GeoJsonSource extends Source {
* @param url the GeoJSON FeatureCollection url
*/
public void setUrl(URL url) {
+ checkThread();
setUrl(url.toExternalForm());
}
@@ -224,6 +241,7 @@ public class GeoJsonSource extends Source {
* @param url the GeoJSON FeatureCollection url
*/
public void setUrl(String url) {
+ checkThread();
nativeSetUrl(url);
}
@@ -232,6 +250,7 @@ public class GeoJsonSource extends Source {
*/
@Nullable
public String getUrl() {
+ checkThread();
return nativeGetUrl();
}
@@ -243,6 +262,7 @@ public class GeoJsonSource extends Source {
*/
@NonNull
public List<Feature> querySourceFeatures(@Nullable Expression filter) {
+ checkThread();
Feature[] features = querySourceFeatures(filter != null ? filter.toArray() : null);
return features != null ? Arrays.asList(features) : new ArrayList<Feature>();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java
index b7679b5a16..2faf0d67ae 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/ImageSource.java
@@ -45,6 +45,7 @@ public class ImageSource extends Source {
* @param url remote json file
*/
public ImageSource(String id, LatLngQuad coordinates, URL url) {
+ super();
initialize(id, coordinates);
setUrl(url);
}
@@ -57,6 +58,7 @@ public class ImageSource extends Source {
* @param bitmap A Bitmap image
*/
public ImageSource(String id, LatLngQuad coordinates, @NonNull android.graphics.Bitmap bitmap) {
+ super();
initialize(id, coordinates);
setImage(bitmap);
}
@@ -69,6 +71,7 @@ public class ImageSource extends Source {
* @param resourceId The resource ID of a Bitmap image
*/
public ImageSource(String id, LatLngQuad coordinates, @DrawableRes int resourceId) {
+ super();
initialize(id, coordinates);
setImage(resourceId);
}
@@ -88,6 +91,7 @@ public class ImageSource extends Source {
* @param url An image url
*/
public void setUrl(String url) {
+ checkThread();
nativeSetUrl(url);
}
@@ -97,6 +101,7 @@ public class ImageSource extends Source {
* @param bitmap A Bitmap image
*/
public void setImage(@NonNull android.graphics.Bitmap bitmap) {
+ checkThread();
nativeSetImage(bitmap);
}
@@ -106,6 +111,7 @@ public class ImageSource extends Source {
* @param resourceId The resource ID of a Bitmap image
*/
public void setImage(@DrawableRes int resourceId) throws IllegalArgumentException {
+ checkThread();
Context context = Mapbox.getApplicationContext();
Drawable drawable = ContextCompat.getDrawable(context, resourceId);
if (drawable instanceof BitmapDrawable) {
@@ -121,6 +127,7 @@ public class ImageSource extends Source {
*/
@Nullable
public String getUrl() {
+ checkThread();
return nativeGetUrl();
}
@@ -130,6 +137,7 @@ public class ImageSource extends Source {
* @param latLngQuad latitude and longitude of the four corners of the image
*/
public void setCoordinates(LatLngQuad latLngQuad) {
+ checkThread();
nativeSetCoordinates(latLngQuad);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java
index ee6fc5d7b7..0c510f7594 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterDemSource.java
@@ -40,6 +40,7 @@ public class RasterDemSource extends Source {
* @param url the source url
*/
public RasterDemSource(String id, String url) {
+ super();
initialize(id, url, DEFAULT_TILE_SIZE);
}
@@ -51,6 +52,7 @@ public class RasterDemSource extends Source {
* @param tileSize the tile size
*/
public RasterDemSource(String id, String url, int tileSize) {
+ super();
initialize(id, url, tileSize);
}
@@ -61,6 +63,7 @@ public class RasterDemSource extends Source {
* @param tileSet the {@link TileSet}
*/
public RasterDemSource(String id, TileSet tileSet) {
+ super();
initialize(id, tileSet.toValueObject(), DEFAULT_TILE_SIZE);
}
@@ -72,6 +75,7 @@ public class RasterDemSource extends Source {
* @param tileSize tje tile size
*/
public RasterDemSource(String id, TileSet tileSet, int tileSize) {
+ super();
initialize(id, tileSet.toValueObject(), tileSize);
}
@@ -80,6 +84,7 @@ public class RasterDemSource extends Source {
*/
@Nullable
public String getUrl() {
+ checkThread();
return nativeGetUrl();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java
index 38ed208618..f1f4cc1ff1 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/RasterSource.java
@@ -39,6 +39,7 @@ public class RasterSource extends Source {
* @param url the source url
*/
public RasterSource(String id, String url) {
+ super();
initialize(id, url, DEFAULT_TILE_SIZE);
}
@@ -50,6 +51,7 @@ public class RasterSource extends Source {
* @param tileSize the tile size
*/
public RasterSource(String id, String url, int tileSize) {
+ super();
initialize(id, url, tileSize);
}
@@ -60,6 +62,7 @@ public class RasterSource extends Source {
* @param tileSet the {@link TileSet}
*/
public RasterSource(String id, TileSet tileSet) {
+ super();
initialize(id, tileSet.toValueObject(), DEFAULT_TILE_SIZE);
}
@@ -71,6 +74,7 @@ public class RasterSource extends Source {
* @param tileSize tje tile size
*/
public RasterSource(String id, TileSet tileSet, int tileSize) {
+ super();
initialize(id, tileSet.toValueObject(), tileSize);
}
@@ -79,6 +83,7 @@ public class RasterSource extends Source {
*/
@Nullable
public String getUrl() {
+ checkThread();
return nativeGetUrl();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java
index 22b2244537..6a0939569a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/Source.java
@@ -1,9 +1,12 @@
package com.mapbox.mapboxsdk.style.sources;
+import com.mapbox.mapboxsdk.utils.ThreadUtils;
+
/**
* Base Peer class for sources. see source.hpp for the other half of the peer.
*/
public abstract class Source {
+
private long nativePtr;
/**
@@ -12,10 +15,19 @@ public abstract class Source {
* @param nativePtr - pointer to native peer
*/
public Source(long nativePtr) {
+ checkThread();
this.nativePtr = nativePtr;
}
public Source() {
+ checkThread();
+ }
+
+ /**
+ * Validates if source interaction is happening on the UI thread
+ */
+ protected void checkThread() {
+ ThreadUtils.checkThread("Source");
}
/**
@@ -24,6 +36,7 @@ public abstract class Source {
* @return the source id
*/
public String getId() {
+ checkThread();
return nativeGetId();
}
@@ -36,6 +49,7 @@ public abstract class Source {
* @return the string representation of the attribution in html format
*/
public String getAttribution() {
+ checkThread();
return nativeGetAttribution();
}
@@ -51,5 +65,4 @@ public abstract class Source {
protected native String nativeGetId();
protected native String nativeGetAttribution();
-
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
index d82eaaa1c7..0df17572e9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/sources/VectorSource.java
@@ -47,6 +47,7 @@ public class VectorSource extends Source {
* @param url the url
*/
public VectorSource(String id, String url) {
+ super();
initialize(id, url);
}
@@ -57,6 +58,7 @@ public class VectorSource extends Source {
* @param tileSet the tileset
*/
public VectorSource(String id, TileSet tileSet) {
+ super();
initialize(id, tileSet.toValueObject());
}
@@ -70,6 +72,7 @@ public class VectorSource extends Source {
@NonNull
public List<Feature> querySourceFeatures(@Size(min = 1) String[] sourceLayerIds,
@Nullable Expression filter) {
+ checkThread();
Feature[] features = querySourceFeatures(
sourceLayerIds,
filter != null ? filter.toArray() : null);
@@ -81,6 +84,7 @@ public class VectorSource extends Source {
*/
@Nullable
public String getUrl() {
+ checkThread();
return nativeGetUrl();
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ThreadUtils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ThreadUtils.java
new file mode 100644
index 0000000000..7dfd5ddd98
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/utils/ThreadUtils.java
@@ -0,0 +1,17 @@
+package com.mapbox.mapboxsdk.utils;
+
+import android.os.Looper;
+import com.mapbox.mapboxsdk.exceptions.CalledFromWorkerThreadException;
+
+public class ThreadUtils {
+
+ /**
+ * Validates if execution is occuring on the main thread.
+ */
+ public static void checkThread(String origin) {
+ if (Looper.myLooper() != Looper.getMainLooper()) {
+ throw new CalledFromWorkerThreadException(
+ String.format("%s interactions should happen on the UI thread.",origin));
+ }
+ }
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java
index 1c259af2d0..e56ca559d4 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/annotations/IconTest.java
@@ -1,7 +1,6 @@
package com.mapbox.mapboxsdk.annotations;
import android.graphics.Bitmap;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
index 38fd8491a8..1dca34b95d 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/maps/MapboxMapTest.java
@@ -634,7 +634,7 @@ public class MapboxMapTest extends BaseActivityTest {
}));
}
- private class MapboxMapAction implements ViewAction {
+ public class MapboxMapAction implements ViewAction {
private InvokeViewAction invokeViewAction;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/MapboxMapAction.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/MapboxMapAction.java
index 47af80cab9..5e8f3ed365 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/MapboxMapAction.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/action/MapboxMapAction.java
@@ -17,7 +17,7 @@ public class MapboxMapAction implements ViewAction {
private OnInvokeActionListener invokeViewAction;
private MapboxMap mapboxMap;
- private MapboxMapAction(OnInvokeActionListener invokeViewAction, MapboxMap mapboxMap) {
+ public MapboxMapAction(OnInvokeActionListener invokeViewAction, MapboxMap mapboxMap) {
this.invokeViewAction = invokeViewAction;
this.mapboxMap = mapboxMap;
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
index 6d90c20a46..5480aa7a1c 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/activity/BaseActivityTest.java
@@ -6,19 +6,17 @@ import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.IdlingResourceTimeoutException;
+import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
-
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
+import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
import com.mapbox.mapboxsdk.testapp.action.WaitAction;
import com.mapbox.mapboxsdk.testapp.utils.OnMapReadyIdlingResource;
-
import junit.framework.Assert;
-
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
-
import timber.log.Timber;
import static android.support.test.espresso.Espresso.onView;
@@ -83,6 +81,14 @@ public abstract class BaseActivityTest {
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
+ protected ViewInteraction onMapView() {
+ return onView(withId(R.id.mapView));
+ }
+
+ protected MapboxMapAction getMapboxMapAction(MapboxMapAction.OnInvokeActionListener onInvokeActionListener) {
+ return new MapboxMapAction(onInvokeActionListener, mapboxMap);
+ }
+
@After
public void afterTest() {
Timber.e("@After test: unregister idle resource");
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java
index 33a946d0a1..c0bf35e3ce 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/annotations/IconTest.java
@@ -2,19 +2,16 @@ package com.mapbox.mapboxsdk.testapp.annotations;
import android.app.Activity;
import android.support.v4.content.res.ResourcesCompat;
-
import com.mapbox.mapboxsdk.annotations.Icon;
import com.mapbox.mapboxsdk.annotations.IconFactory;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.IconManagerResolver;
-import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
import com.mapbox.mapboxsdk.testapp.utils.IconUtils;
-
import org.junit.Before;
import org.junit.Test;
@@ -39,104 +36,114 @@ public class IconTest extends BaseActivityTest {
}
@Test
- public void testEmpty() throws Exception {
+ public void testEmpty() {
assertTrue(iconMap.isEmpty());
}
@Test
- public void testAddSameIconMarker() throws Exception {
- Icon defaultMarker = IconFactory.getInstance(rule.getActivity()).defaultMarker();
- getMapboxMap().addMarker(new MarkerOptions().position(new LatLng()));
- getMapboxMap().addMarker(new MarkerOptions().position(new LatLng(1, 1)));
- assertEquals(1, iconMap.size());
- assertEquals(2, iconMap.get(defaultMarker), 0);
+ public void testAddSameIconMarker() {
+ validateTestSetup();
+ onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
+ Icon defaultMarker = IconFactory.getInstance(rule.getActivity()).defaultMarker();
+ mapboxMap.addMarker(new MarkerOptions().position(new LatLng()));
+ mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
+ assertEquals(1, iconMap.size());
+ assertEquals(2, iconMap.get(defaultMarker), 0);
+ }));
}
@Test
- public void testAddDifferentIconMarker() throws Exception {
- Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon);
- getMapboxMap().addMarker(new MarkerOptions().icon(icon).position(new LatLng()));
- getMapboxMap().addMarker(new MarkerOptions().position(new LatLng(1, 1)));
- assertEquals(iconMap.size(), 2);
- assertTrue(iconMap.containsKey(icon));
- assertTrue(iconMap.get(icon) == 1);
+ public void testAddDifferentIconMarker() {
+ validateTestSetup();
+ onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
+ Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon);
+ getMapboxMap().addMarker(new MarkerOptions().icon(icon).position(new LatLng()));
+ getMapboxMap().addMarker(new MarkerOptions().position(new LatLng(1, 1)));
+ assertEquals(iconMap.size(), 2);
+ assertTrue(iconMap.containsKey(icon));
+ assertTrue(iconMap.get(icon) == 1);
+ }));
}
@Test
- public void testAddRemoveIconMarker() throws Exception {
- MapboxMap mapboxMap = getMapboxMap();
-
- Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon);
- Marker marker = mapboxMap.addMarker(new MarkerOptions().icon(icon).position(new LatLng()));
- mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
- assertEquals(iconMap.size(), 2);
- assertTrue(iconMap.containsKey(icon));
- assertTrue(iconMap.get(icon) == 1);
-
- mapboxMap.removeMarker(marker);
- assertEquals(iconMap.size(), 1);
- assertFalse(iconMap.containsKey(icon));
+ public void testAddRemoveIconMarker() {
+ validateTestSetup();
+ onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
+ Icon icon = IconFactory.getInstance(rule.getActivity()).fromResource(R.drawable.mapbox_logo_icon);
+ Marker marker = mapboxMap.addMarker(new MarkerOptions().icon(icon).position(new LatLng()));
+ mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
+ assertEquals(iconMap.size(), 2);
+ assertTrue(iconMap.containsKey(icon));
+ assertTrue(iconMap.get(icon) == 1);
+
+ mapboxMap.removeMarker(marker);
+ assertEquals(iconMap.size(), 1);
+ assertFalse(iconMap.containsKey(icon));
+ }));
}
@Test
- public void testAddRemoveDefaultMarker() throws Exception {
- MapboxMap mapboxMap = getMapboxMap();
-
- Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
- assertEquals(iconMap.size(), 1);
-
- mapboxMap.removeMarker(marker);
- assertEquals(iconMap.size(), 0);
-
- mapboxMap.addMarker(new MarkerOptions().position(new LatLng()));
- assertEquals(iconMap.size(), 1);
+ public void testAddRemoveDefaultMarker() {
+ validateTestSetup();
+ onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
+ Marker marker = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
+ assertEquals(iconMap.size(), 1);
+
+ mapboxMap.removeMarker(marker);
+ assertEquals(iconMap.size(), 0);
+
+ mapboxMap.addMarker(new MarkerOptions().position(new LatLng()));
+ assertEquals(iconMap.size(), 1);
+ }));
}
@Test
- public void testAddRemoveMany() throws Exception {
- Activity activity = rule.getActivity();
- MapboxMap mapboxMap = getMapboxMap();
- IconFactory iconFactory = IconFactory.getInstance(activity);
-
- // add 2 default icon markers
- Marker defaultMarkerOne = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
- Marker defaultMarkerTwo = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(2, 1)));
-
- // add 4 unique icon markers
- mapboxMap.addMarker(new MarkerOptions()
- .icon(iconFactory.fromResource(R.drawable.mapbox_logo_icon))
- .position(new LatLng(3, 1))
- );
- mapboxMap.addMarker(new MarkerOptions()
- .icon(iconFactory.fromResource(R.drawable.mapbox_compass_icon))
- .position(new LatLng(4, 1))
- );
- mapboxMap.addMarker(new MarkerOptions()
- .icon(IconUtils.drawableToIcon(activity, R.drawable.ic_stars,
- ResourcesCompat.getColor(activity.getResources(),
- R.color.blueAccent, activity.getTheme())))
- .position(new LatLng(5, 1))
- );
- mapboxMap.addMarker(new MarkerOptions()
- .icon(iconFactory.fromResource(R.drawable.ic_android))
- .position(new LatLng(6, 1))
- );
-
- assertEquals("Amount of icons should match 5", 5, iconMap.size());
- assertEquals("Refcounter of default marker should match 2", 2, iconMap.get(iconFactory.defaultMarker()), 0);
-
- mapboxMap.removeMarker(defaultMarkerOne);
-
- assertEquals("Amount of icons should match 5", 5, iconMap.size());
- assertEquals("Refcounter of default marker should match 1", 1, iconMap.get(iconFactory.defaultMarker()), 0);
-
- mapboxMap.removeMarker(defaultMarkerTwo);
-
- assertEquals("Amount of icons should match 4", 4, iconMap.size());
- assertNull("DefaultMarker shouldn't exist anymore", iconMap.get(iconFactory.defaultMarker()));
-
- mapboxMap.clear();
- assertEquals("Amount of icons should match 0", 0, iconMap.size());
+ public void testAddRemoveMany() {
+ validateTestSetup();
+ onMapView().perform(getMapboxMapAction((uiController, mapboxMap) -> {
+ Activity activity = rule.getActivity();
+ IconFactory iconFactory = IconFactory.getInstance(activity);
+
+ // add 2 default icon markers
+ Marker defaultMarkerOne = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(1, 1)));
+ Marker defaultMarkerTwo = mapboxMap.addMarker(new MarkerOptions().position(new LatLng(2, 1)));
+
+ // add 4 unique icon markers
+ mapboxMap.addMarker(new MarkerOptions()
+ .icon(iconFactory.fromResource(R.drawable.mapbox_logo_icon))
+ .position(new LatLng(3, 1))
+ );
+ mapboxMap.addMarker(new MarkerOptions()
+ .icon(iconFactory.fromResource(R.drawable.mapbox_compass_icon))
+ .position(new LatLng(4, 1))
+ );
+ mapboxMap.addMarker(new MarkerOptions()
+ .icon(IconUtils.drawableToIcon(activity, R.drawable.ic_stars,
+ ResourcesCompat.getColor(activity.getResources(),
+ R.color.blueAccent, activity.getTheme())))
+ .position(new LatLng(5, 1))
+ );
+ mapboxMap.addMarker(new MarkerOptions()
+ .icon(iconFactory.fromResource(R.drawable.ic_android))
+ .position(new LatLng(6, 1))
+ );
+
+ assertEquals("Amount of icons should match 5", 5, iconMap.size());
+ assertEquals("Refcounter of default marker should match 2", 2, iconMap.get(iconFactory.defaultMarker()), 0);
+
+ mapboxMap.removeMarker(defaultMarkerOne);
+
+ assertEquals("Amount of icons should match 5", 5, iconMap.size());
+ assertEquals("Refcounter of default marker should match 1", 1, iconMap.get(iconFactory.defaultMarker()), 0);
+
+ mapboxMap.removeMarker(defaultMarkerTwo);
+
+ assertEquals("Amount of icons should match 4", 4, iconMap.size());
+ assertNull("DefaultMarker shouldn't exist anymore", iconMap.get(iconFactory.defaultMarker()));
+
+ mapboxMap.clear();
+ assertEquals("Amount of icons should match 0", 0, iconMap.size());
+ }));
}
@Override