[android] move style callback invocation to MapboxMap
This commit is contained in:
@@ -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;
|
||||
@@ -124,11 +126,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;
|
||||
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);
|
||||
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);
|
||||
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());
|
||||
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);
|
||||
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);
|
||||
updateMapWithOptions(options);
|
||||
|
||||
setRenderMode(RenderMode.NORMAL);
|
||||
setCameraMode(CameraMode.NONE);
|
||||
setRenderMode(RenderMode.NORMAL);
|
||||
setCameraMode(CameraMode.NONE);
|
||||
|
||||
if (isStyleInitialized) {
|
||||
onFinishLoadingStyle();
|
||||
}
|
||||
|
||||
onLocationLayerStart();
|
||||
onLocationLayerStart();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initializeLocationEngine(@NonNull Context context) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
@@ -1111,13 +1109,6 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
removeOnCameraDidChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWillStartLoadingMap() {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.onStartLoadingMap();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
if (mapboxMap != null) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,18 +200,11 @@ public final class MapboxMap {
|
||||
transform.invalidateCameraPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
//
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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++
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user