summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-12-05 15:32:06 +0100
committerTobrun <tobrun@mapbox.com>2018-12-10 16:59:50 +0100
commitf8f8e0b7494a07467f177cd7ec8d8094af61c665 (patch)
tree61c9c1a2abb9d16e0fc5dffe53908a72ca620f3a
parentacbe2475f91127cda76ff0857d36ab3c29e58257 (diff)
downloadqtlocation-mapboxgl-f8f8e0b7494a07467f177cd7ec8d8094af61c665.tar.gz
[android] move style callback invocation to MapboxMap
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java109
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java69
-rwxr-xr-xplatform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/NativeMapView.java12
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java53
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java52
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/MapboxTestingUtils.kt2
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java4
10 files changed, 138 insertions, 176 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
index aa281ee314..c6ab96f320 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java
@@ -11,6 +11,7 @@ import android.support.annotation.RequiresPermission;
import android.support.annotation.StyleRes;
import android.support.annotation.VisibleForTesting;
import android.view.WindowManager;
+
import com.mapbox.android.core.location.LocationEngine;
import com.mapbox.android.core.location.LocationEngineCallback;
import com.mapbox.android.core.location.LocationEngineProvider;
@@ -27,6 +28,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraIdleListener;
import com.mapbox.mapboxsdk.maps.MapboxMap.OnCameraMoveListener;
import com.mapbox.mapboxsdk.maps.MapboxMap.OnMapClickListener;
+import com.mapbox.mapboxsdk.maps.Style;
import java.lang.ref.WeakReference;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -125,11 +127,6 @@ public final class LocationComponent {
private boolean isComponentInitialized;
/**
- * Indicates whether the style has been initialized.
- */
- private boolean isStyleInitialized;
-
- /**
* Indicates that the component is enabled and should be displaying location if Mapbox components are available and
* the lifecycle is in a started state.
*/
@@ -461,14 +458,16 @@ public final class LocationComponent {
*
* @param options to update the current style
*/
- public void applyStyle(@NonNull LocationComponentOptions options) {
- this.options = options;
- locationLayerController.applyStyle(options);
- locationCameraController.initializeOptions(options);
- staleStateManager.setEnabled(options.enableStaleState());
- staleStateManager.setDelayTime(options.staleStateTimeout());
- locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
- updateMapWithOptions(options);
+ public void applyStyle(@NonNull final LocationComponentOptions options) {
+ LocationComponent.this.options = options;
+ if (mapboxMap.getStyle() != null) {
+ locationLayerController.applyStyle(options);
+ locationCameraController.initializeOptions(options);
+ staleStateManager.setEnabled(options.enableStaleState());
+ staleStateManager.setDelayTime(options.staleStateTimeout());
+ locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
+ updateMapWithOptions(options);
+ }
}
/**
@@ -838,7 +837,6 @@ public final class LocationComponent {
* Internal use.
*/
public void onFinishLoadingStyle() {
- isStyleInitialized = true;
if (isComponentInitialized) {
locationLayerController.initializeComponents(options);
locationCameraController.initializeOptions(options);
@@ -848,7 +846,7 @@ public final class LocationComponent {
@SuppressLint("MissingPermission")
private void onLocationLayerStart() {
- if (!isComponentInitialized || !isComponentStarted) {
+ if (!isComponentInitialized || !isComponentStarted || mapboxMap.getStyle() == null) {
return;
}
@@ -894,45 +892,48 @@ public final class LocationComponent {
mapboxMap.removeOnCameraIdleListener(onCameraIdleListener);
}
- private void initialize(@NonNull Context context, @NonNull LocationComponentOptions options) {
- if (isComponentInitialized) {
- return;
- }
- isComponentInitialized = true;
- this.options = options;
-
- mapboxMap.addOnMapClickListener(onMapClickListener);
- mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
-
- LayerSourceProvider sourceProvider = new LayerSourceProvider();
- LayerFeatureProvider featureProvider = new LayerFeatureProvider();
- LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context);
- locationLayerController = new LocationLayerController(mapboxMap, sourceProvider, featureProvider, bitmapProvider,
- options);
- locationCameraController = new LocationCameraController(
- context, mapboxMap, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener);
-
- locationAnimatorCoordinator = new LocationAnimatorCoordinator();
- locationAnimatorCoordinator.addLayerListener(locationLayerController);
- locationAnimatorCoordinator.addCameraListener(locationCameraController);
- locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier());
-
- WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
- compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
- compassEngine.addCompassListener(compassListener);
- staleStateManager = new StaleStateManager(onLocationStaleListener, options);
-
- updateMapWithOptions(options);
-
- setRenderMode(RenderMode.NORMAL);
- setCameraMode(CameraMode.NONE);
-
- if (isStyleInitialized) {
- onFinishLoadingStyle();
- }
-
- onLocationLayerStart();
+ private void initialize(@NonNull final Context context, @NonNull final LocationComponentOptions options) {
+ mapboxMap.getStyle(new Style.OnStyleLoaded() {
+ @Override
+ public void onStyleLoaded(@NonNull Style style) {
+ if (isComponentInitialized) {
+ return;
+ }
+ isComponentInitialized = true;
+ LocationComponent.this.options = options;
+
+ mapboxMap.addOnMapClickListener(onMapClickListener);
+ mapboxMap.addOnMapLongClickListener(onMapLongClickListener);
+
+ LayerSourceProvider sourceProvider = new LayerSourceProvider();
+ LayerFeatureProvider featureProvider = new LayerFeatureProvider();
+ LayerBitmapProvider bitmapProvider = new LayerBitmapProvider(context);
+ locationLayerController = new LocationLayerController(mapboxMap, sourceProvider, featureProvider,
+ bitmapProvider,
+ options);
+ locationCameraController = new LocationCameraController(
+ context, mapboxMap, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener);
+
+ locationAnimatorCoordinator = new LocationAnimatorCoordinator();
+ locationAnimatorCoordinator.addLayerListener(locationLayerController);
+ locationAnimatorCoordinator.addCameraListener(locationCameraController);
+ locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options
+ .trackingAnimationDurationMultiplier());
+
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
+ compassEngine = new LocationComponentCompassEngine(windowManager, sensorManager);
+ compassEngine.addCompassListener(compassListener);
+ staleStateManager = new StaleStateManager(onLocationStaleListener, options);
+
+ updateMapWithOptions(options);
+
+ setRenderMode(RenderMode.NORMAL);
+ setCameraMode(CameraMode.NONE);
+
+ onLocationLayerStart();
+ }
+ });
}
private void initializeLocationEngine(@NonNull Context context) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
index b2ba5e6846..0e7508ab74 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationLayerController.java
@@ -78,6 +78,7 @@ final class LocationLayerController implements MapboxAnimator.OnLayerAnimationsV
this.layerSourceProvider = layerSourceProvider;
this.bitmapProvider = bitmapProvider;
this.locationFeature = featureProvider.generateLocationFeature(locationFeature, options);
+ initializeComponents(options);
setRenderMode(RenderMode.NORMAL);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 8ec5a923bf..1883e539f3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -1059,14 +1059,13 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
}
- private class MapCallback implements OnWillStartLoadingMapListener, OnDidFinishLoadingStyleListener,
+ private class MapCallback implements OnDidFinishLoadingStyleListener,
OnDidFinishRenderingFrameListener, OnDidFinishLoadingMapListener,
OnCameraIsChangingListener, OnCameraDidChangeListener {
private final List<OnMapReadyCallback> onMapReadyCallbackList = new ArrayList<>();
MapCallback() {
- addOnWillStartLoadingMapListener(this);
addOnDidFinishLoadingStyleListener(this);
addOnDidFinishRenderingFrameListener(this);
addOnDidFinishLoadingMapListener(this);
@@ -1103,7 +1102,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
void onDestroy() {
onMapReadyCallbackList.clear();
- removeOnWillStartLoadingMapListener(this);
removeOnDidFinishLoadingStyleListener(this);
removeOnDidFinishRenderingFrameListener(this);
removeOnDidFinishLoadingMapListener(this);
@@ -1112,13 +1110,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
}
@Override
- public void onWillStartLoadingMap() {
- if (mapboxMap != null) {
- mapboxMap.onStartLoadingMap();
- }
- }
-
- @Override
public void onDidFinishLoadingStyle() {
if (mapboxMap != null) {
mapboxMap.onFinishLoadingStyle();
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index f9560e9edd..a3d8e9fb5c 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -12,6 +12,7 @@ import android.support.annotation.Size;
import android.support.annotation.UiThread;
import android.text.TextUtils;
import android.view.View;
+
import com.mapbox.android.gestures.AndroidGesturesManager;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
@@ -19,6 +20,7 @@ import com.mapbox.android.gestures.ShoveGestureDetector;
import com.mapbox.android.gestures.StandardScaleGestureDetector;
import com.mapbox.geojson.Feature;
import com.mapbox.geojson.Geometry;
+import com.mapbox.mapboxsdk.MapStrictMode;
import com.mapbox.mapboxsdk.annotations.Annotation;
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
import com.mapbox.mapboxsdk.annotations.Marker;
@@ -69,7 +71,7 @@ public final class MapboxMap {
@Nullable
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
- private List<Style.OnStyleLoaded> styleLoadedCallbacks = new ArrayList<>();
+ private final List<Style.OnStyleLoaded> styleLoadedCallbacks = new ArrayList<>();
@Nullable
private Style style;
@@ -102,10 +104,10 @@ public final class MapboxMap {
* Get the Style of the map asynchronously.
*/
public void getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded) {
- if (style == null) {
- styleLoadedCallbacks.add(onStyleLoaded);
- } else {
+ if (style != null && style.isStyleLoaded()) {
onStyleLoaded.onStyleLoaded(style);
+ } else {
+ styleLoadedCallbacks.add(onStyleLoaded);
}
}
@@ -119,7 +121,11 @@ public final class MapboxMap {
*/
@Nullable
public Style getStyle() {
- return style;
+ if (style == null || !style.isStyleLoaded()) {
+ return null;
+ } else {
+ return style;
+ }
}
/**
@@ -195,17 +201,10 @@ public final class MapboxMap {
}
/**
- * Called when the map will start loading style.
- */
- void onStartLoadingMap() {
- locationComponent.onStartLoadingMap();
- }
-
- /**
* Called the map finished loading style.
*/
void onFinishLoadingStyle() {
- locationComponent.onFinishLoadingStyle();
+ notifyStyleLoaded();
}
/**
@@ -750,19 +749,39 @@ public final class MapboxMap {
}
public void setStyle(Style.Builder builder, final Style.OnStyleLoaded callback) {
- builder.build(nativeMapView, new Style.OnStyleLoaded() {
- @Override
- public void onStyleLoaded(Style style) {
- MapboxMap.this.style = style;
- if (callback != null) {
- callback.onStyleLoaded(style);
- }
- for (Style.OnStyleLoaded styleLoadedCallback : styleLoadedCallbacks) {
- styleLoadedCallback.onStyleLoaded(style);
- }
- styleLoadedCallbacks.clear();
+ locationComponent.onStartLoadingMap();
+ if (style != null) {
+ style.onWillStartLoadingMap();
+ }
+
+ if (callback != null) {
+ styleLoadedCallbacks.add(callback);
+ }
+
+ style = builder.build(nativeMapView);
+ if (!TextUtils.isEmpty(style.getUrl())) {
+ nativeMapView.setStyleUrl(style.getUrl());
+ } else if (!TextUtils.isEmpty(style.getJson())) {
+ nativeMapView.setStyleJson(style.getJson());
+ } else {
+ // user didn't provide a `from` component,
+ // flag the style as loaded,
+ // add components defined added using the `with` prefix.
+ notifyStyleLoaded();
+ }
+ }
+
+ private void notifyStyleLoaded() {
+ if (style != null) {
+ style.onDidFinishLoadingStyle();
+ locationComponent.onFinishLoadingStyle();
+ for (Style.OnStyleLoaded styleLoadedCallback : styleLoadedCallbacks) {
+ styleLoadedCallback.onStyleLoaded(style);
}
- });
+ } else {
+ MapStrictMode.strictModeViolation("No style to provide.");
+ }
+ styleLoadedCallbacks.clear();
}
/**
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 0f1a447a6c..02d3117b8a 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
@@ -12,6 +12,7 @@ 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;
@@ -71,9 +72,6 @@ final class NativeMapView {
// Flag to indicating destroy was called
private boolean destroyed = false;
- // Used for style load callbacks
- private StyleCallback styleCallback;
-
// Holds the pointer to JNI NativeMapView
@Keep
long nativePtr = 0;
@@ -940,9 +938,6 @@ final class NativeMapView {
@Keep
private void onWillStartLoadingMap() {
stateCallback.onWillStartLoadingMap();
- if (styleCallback != null) {
- styleCallback.onWillStartLoadingMap();
- }
}
@Keep
@@ -977,7 +972,6 @@ final class NativeMapView {
@Keep
private void onDidFinishLoadingStyle() {
- styleCallback.onDidFinishLoadingStyle();
stateCallback.onDidFinishLoadingStyle();
}
@@ -1342,10 +1336,6 @@ final class NativeMapView {
});
}
- void setStyleCallback(@NonNull StyleCallback callback) {
- this.styleCallback = callback;
- }
-
//
// Image conversion
//
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
index ac9a6936b8..2ba193b412 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Style.java
@@ -5,6 +5,7 @@ import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringDef;
+
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
@@ -26,14 +27,15 @@ import java.util.Map;
* has been loaded by underlying map.
* </p>
*/
-public class Style implements NativeMapView.StyleCallback {
+public class Style {
private final NativeMapView nativeMapView;
private final HashMap<String, Source> sources = new HashMap<>();
private final HashMap<String, Layer> layers = new HashMap<>();
private final HashMap<String, Bitmap> images = new HashMap<>();
- private final OnStyleLoaded onStyleLoaded;
private final Builder builder;
+ private String styleUrl;
+ private String styleJson;
private boolean styleLoaded;
/**
@@ -41,12 +43,12 @@ public class Style implements NativeMapView.StyleCallback {
*
* @param builder the builder used for creating this style
* @param nativeMapView the map object used to load this style
- * @param styleLoaded the callback used to notify about finish style loading
*/
- private Style(@NonNull Builder builder, @NonNull NativeMapView nativeMapView, @Nullable OnStyleLoaded styleLoaded) {
+ private Style(@NonNull Builder builder, @NonNull NativeMapView nativeMapView) {
this.builder = builder;
+ styleUrl = builder.styleUrl;
+ styleJson = builder.styleJson;
this.nativeMapView = nativeMapView;
- this.onStyleLoaded = styleLoaded;
}
/**
@@ -54,9 +56,9 @@ public class Style implements NativeMapView.StyleCallback {
*
* @return the style url
*/
- @NonNull
+ @Nullable
public String getUrl() {
- return nativeMapView.getStyleUrl();
+ return styleUrl;
}
/**
@@ -64,9 +66,9 @@ public class Style implements NativeMapView.StyleCallback {
*
* @return the style json
*/
- @NonNull
+ @Nullable
public String getJson() {
- return nativeMapView.getStyleJson();
+ return styleJson;
}
//
@@ -367,8 +369,7 @@ public class Style implements NativeMapView.StyleCallback {
* Called when the underlying map will start loading a new style. This method will clean up this style
* by setting the java sources and layers in a detached state and removing them from core.
*/
- @Override
- public void onWillStartLoadingMap() {
+ void onWillStartLoadingMap() {
for (Source source : sources.values()) {
if (source != null) {
source.setDetached();
@@ -397,8 +398,7 @@ public class Style implements NativeMapView.StyleCallback {
* Called when the underlying map has finished loading this style.
* This method will add all components added to the builder that were defined with the 'with' prefix.
*/
- @Override
- public void onDidFinishLoadingStyle() {
+ void onDidFinishLoadingStyle() {
if (!styleLoaded) {
styleLoaded = true;
for (Source source : builder.sources) {
@@ -425,13 +425,13 @@ public class Style implements NativeMapView.StyleCallback {
if (builder.transitionOptions != null) {
setTransition(builder.transitionOptions);
}
-
- if (onStyleLoaded != null) {
- onStyleLoaded.onStyleLoaded(this);
- }
}
}
+ boolean isStyleLoaded() {
+ return styleLoaded;
+ }
+
//
// Builder
//
@@ -601,24 +601,9 @@ public class Style implements NativeMapView.StyleCallback {
/**
* Build the composed style.
- *
- * @param nativeMapView the native map used for style loading
- * @param styleLoaded the callback to be invoked when the style has loaded
*/
- void build(@NonNull NativeMapView nativeMapView, @Nullable OnStyleLoaded styleLoaded) {
- Style style = new Style(this, nativeMapView, styleLoaded);
- nativeMapView.setStyleCallback(style);
-
- if (styleUrl != null) {
- nativeMapView.setStyleUrl(styleUrl);
- } else if (styleJson != null) {
- nativeMapView.setStyleJson(styleJson);
- } else {
- // user didn't provide a `from` component,
- // flag the style as loaded,
- // add components defined added using the `with` prefix.
- style.onDidFinishLoadingStyle();
- }
+ Style build(@NonNull NativeMapView nativeMapView) {
+ return new Style(this, nativeMapView);
}
private class ImageWrapper {
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java
index f72dcc2ff5..475fb81684 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.java
@@ -1,8 +1,8 @@
package com.mapbox.mapboxsdk.location;
import android.graphics.Bitmap;
-
import android.support.annotation.NonNull;
+
import com.google.gson.JsonElement;
import com.mapbox.geojson.Feature;
import com.mapbox.mapboxsdk.geometry.LatLng;
@@ -56,8 +56,7 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addSource(locationSource);
}
@@ -72,8 +71,7 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER);
}
@@ -88,8 +86,7 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER);
}
@@ -104,8 +101,7 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER);
}
@@ -122,8 +118,7 @@ public class LocationLayerControllerTest {
String layerBelow = "layer-below";
when(options.layerBelow()).thenReturn(layerBelow);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addLayerBelow(bearingLayer, layerBelow);
}
@@ -138,8 +133,7 @@ public class LocationLayerControllerTest {
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
LocationComponentOptions options = mock(LocationComponentOptions.class);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER);
}
@@ -155,8 +149,7 @@ public class LocationLayerControllerTest {
when(options.elevation()).thenReturn(2f);
// Style is applied on initialization
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(SHADOW_ICON, bitmap);
}
@@ -171,8 +164,7 @@ public class LocationLayerControllerTest {
LocationComponentOptions options = mock(LocationComponentOptions.class);
when(options.elevation()).thenReturn(0f);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style, times(0)).addImage(SHADOW_ICON, bitmap);
}
@@ -190,8 +182,7 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(FOREGROUND_ICON, bitmap);
}
@@ -209,8 +200,7 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(FOREGROUND_STALE_ICON, bitmap);
}
@@ -228,8 +218,7 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(BACKGROUND_ICON, bitmap);
}
@@ -247,8 +236,7 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(BACKGROUND_STALE_ICON, bitmap);
}
@@ -266,8 +254,7 @@ public class LocationLayerControllerTest {
Bitmap bitmap = mock(Bitmap.class);
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
- new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options)
- .initializeComponents(options);
+ new LocationLayerController(mapboxMap, sourceProvider, buildFeatureProvider(options), bitmapProvider, options);
verify(style).addImage(BEARING_ICON, bitmap);
}
@@ -283,7 +270,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.updateForegroundOffset(2d);
@@ -301,8 +287,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
-
layer.updateForegroundOffset(2d);
verify(locationFeature).addProperty(eq(PROPERTY_SHADOW_ICON_OFFSET), any(JsonElement.class));
@@ -320,8 +304,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
-
layer.onNewLatLngValue(new LatLng());
// wanted twice (once for initialization)
@@ -340,7 +322,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.setRenderMode(RenderMode.GPS);
float gpsBearing = 2f;
@@ -361,7 +342,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.setRenderMode(RenderMode.COMPASS);
float gpsBearing = 2f;
@@ -382,7 +362,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.setRenderMode(RenderMode.COMPASS);
float compassBearing = 2f;
@@ -403,7 +382,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.setRenderMode(RenderMode.GPS);
float compassBearing = 2f;
@@ -424,7 +402,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
float accuracyRadiusValue = 2f;
layer.onNewAccuracyRadiusValue(accuracyRadiusValue);
@@ -444,7 +421,6 @@ public class LocationLayerControllerTest {
LocationLayerController layer = new LocationLayerController(
mapboxMap, sourceProvider, buildFeatureProvider(locationFeature, options), bitmapProvider, options
);
- layer.initializeComponents(options);
layer.setRenderMode(RenderMode.GPS);
float accuracyRadiusValue = 2f;
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
index d643dd1173..9f756239e1 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
@@ -168,7 +168,6 @@ class LocationComponentTest : BaseActivityTest() {
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
assertThat(mapboxMap.isLayerVisible(BACKGROUND_LAYER), `is`(true))
assertThat(mapboxMap.isLayerVisible(SHADOW_LAYER), `is`(true))
- assertThat(mapboxMap.isLayerVisible(ACCURACY_LAYER), `is`(true))
assertThat(mapboxMap.isLayerVisible(BEARING_LAYER), `is`(false))
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/MapboxTestingUtils.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/MapboxTestingUtils.kt
index 429f4e7ab1..0a9aa48503 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/MapboxTestingUtils.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/MapboxTestingUtils.kt
@@ -41,7 +41,7 @@ fun MapboxMap.waitForLayer(uiController: UiController, location: Location, layer
var counter = 0
val delay = MapboxTestingUtils.MAP_RENDER_DELAY
while (
- if (shouldDisappear) this.queryRenderedFeatures(location, layerId).isNotEmpty() else this.queryRenderedFeatures(location, layerId).isEmpty()
+ if (shouldDisappear) this.queryRenderedFeatures(location, layerId).isNotEmpty() else (this.style == null || this.queryRenderedFeatures(location, layerId).isEmpty())
&& delay * counter < MapboxTestingUtils.RENDER_TIMEOUT) {
uiController.loopMainThreadForAtLeast(delay)
counter++
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java
index 371ace1137..8c021af38a 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ExpressionTest.java
@@ -504,9 +504,9 @@ public class ExpressionTest extends BaseActivityTest {
validateTestSetup();
invoke(mapboxMap, (uiController, mapboxMap) -> {
LatLng latLng = new LatLng(51, 17);
- mapboxMap.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
+ mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
SymbolLayer layer = new SymbolLayer("layer", "source");
- mapboxMap.addLayer(layer);
+ mapboxMap.getStyle().addLayer(layer);
Formatted formatted = new Formatted(
new FormattedSection("test", 1.5),