[android] - add unit tests for Style.java API
This commit is contained in:
@@ -164,6 +164,12 @@ public final class LocationComponent {
|
||||
this.mapboxMap = mapboxMap;
|
||||
}
|
||||
|
||||
// used for creating a spy
|
||||
LocationComponent() {
|
||||
//noinspection ConstantConditions
|
||||
mapboxMap = null;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
LocationComponent(@NonNull MapboxMap mapboxMap,
|
||||
@NonNull LocationEngineCallback<LocationEngineResult> currentlistener,
|
||||
|
||||
@@ -147,7 +147,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
GesturesManagerInteractionListener registerTouchListener = new GesturesManagerInteractionListener();
|
||||
|
||||
// callback for camera change events
|
||||
final CameraChangeDispatcher cameraChangeDispatcher = new CameraChangeDispatcher();
|
||||
final CameraChangeDispatcher cameraDispatcher = new CameraChangeDispatcher();
|
||||
|
||||
// setup components for MapboxMap creation
|
||||
Projection proj = new Projection(nativeMapView);
|
||||
@@ -161,20 +161,20 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
ShapeAnnotations shapeAnnotations = new ShapeAnnotationContainer(nativeMapView, annotationsArray);
|
||||
AnnotationManager annotationManager = new AnnotationManager(this, annotationsArray, iconManager,
|
||||
annotations, markers, polygons, polylines, shapeAnnotations);
|
||||
Transform transform = new Transform(this, nativeMapView, cameraChangeDispatcher);
|
||||
Transform transform = new Transform(this, nativeMapView, cameraDispatcher);
|
||||
|
||||
// MapboxMap
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener,
|
||||
annotationManager, cameraChangeDispatcher);
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener, cameraDispatcher);
|
||||
mapboxMap.injectAnnotationManager(annotationManager);
|
||||
|
||||
// user input
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings,
|
||||
annotationManager, cameraChangeDispatcher);
|
||||
annotationManager, cameraDispatcher);
|
||||
mapKeyListener = new MapKeyListener(transform, uiSettings, mapGestureDetector);
|
||||
|
||||
// compass
|
||||
compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraChangeDispatcher));
|
||||
compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher));
|
||||
compassView.injectCompassAnimationListener(createCompassAnimationListener(cameraDispatcher));
|
||||
compassView.setOnClickListener(createCompassClickListener(cameraDispatcher));
|
||||
|
||||
// LocationComponent
|
||||
mapboxMap.injectLocationComponent(new LocationComponent(mapboxMap));
|
||||
|
||||
@@ -58,31 +58,27 @@ public final class MapboxMap {
|
||||
private static final String TAG = "Mbgl-MapboxMap";
|
||||
|
||||
private final NativeMapView nativeMapView;
|
||||
|
||||
private final UiSettings uiSettings;
|
||||
private final Projection projection;
|
||||
private final Transform transform;
|
||||
private final AnnotationManager annotationManager;
|
||||
private final CameraChangeDispatcher cameraChangeDispatcher;
|
||||
|
||||
private final OnGesturesManagerInteractionListener onGesturesManagerInteractionListener;
|
||||
private final List<Style.OnStyleLoaded> styleLoadedCallbacks = new ArrayList<>();
|
||||
|
||||
private LocationComponent locationComponent;
|
||||
private AnnotationManager annotationManager;
|
||||
|
||||
@Nullable
|
||||
private MapboxMap.OnFpsChangedListener onFpsChangedListener;
|
||||
|
||||
private final List<Style.OnStyleLoaded> styleLoadedCallbacks = new ArrayList<>();
|
||||
|
||||
@Nullable
|
||||
private Style style;
|
||||
|
||||
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection,
|
||||
OnGesturesManagerInteractionListener listener, AnnotationManager annotations,
|
||||
CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.nativeMapView = map;
|
||||
this.uiSettings = ui;
|
||||
this.projection = projection;
|
||||
this.annotationManager = annotations.bind(this);
|
||||
this.transform = transform;
|
||||
this.onGesturesManagerInteractionListener = listener;
|
||||
this.cameraChangeDispatcher = cameraChangeDispatcher;
|
||||
@@ -762,7 +758,7 @@ public final class MapboxMap {
|
||||
* will be triggered.
|
||||
* </p>
|
||||
*
|
||||
* @param style The bundled style
|
||||
* @param style The bundled style
|
||||
* @param callback The callback to be invoked when the style has loaded
|
||||
* @see Style
|
||||
*/
|
||||
@@ -793,7 +789,7 @@ public final class MapboxMap {
|
||||
* and {@link MapView.OnDidFailLoadingMapListener} callback will be triggered.
|
||||
* </p>
|
||||
*
|
||||
* @param builder The style builder
|
||||
* @param builder The style builder
|
||||
* @param callback The callback to be invoked when the style has loaded
|
||||
* @see Style
|
||||
*/
|
||||
@@ -820,7 +816,7 @@ public final class MapboxMap {
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyStyleLoaded() {
|
||||
void notifyStyleLoaded() {
|
||||
if (style != null) {
|
||||
style.onDidFinishLoadingStyle();
|
||||
locationComponent.onFinishLoadingStyle();
|
||||
@@ -1814,6 +1810,10 @@ public final class MapboxMap {
|
||||
this.locationComponent = locationComponent;
|
||||
}
|
||||
|
||||
void injectAnnotationManager(AnnotationManager annotationManager) {
|
||||
this.annotationManager = annotationManager.bind(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link LocationComponent} that can be used to display user's location on the map.
|
||||
* <p>
|
||||
|
||||
@@ -603,6 +603,22 @@ public class Style {
|
||||
return styleJson;
|
||||
}
|
||||
|
||||
List<Source> getSources() {
|
||||
return sources;
|
||||
}
|
||||
|
||||
List<LayerWrapper> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
List<ImageWrapper> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
TransitionOptions getTransitionOptions() {
|
||||
return transitionOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the composed style.
|
||||
*/
|
||||
@@ -610,41 +626,28 @@ public class Style {
|
||||
return new Style(this, nativeMapView);
|
||||
}
|
||||
|
||||
private class ImageWrapper {
|
||||
private Bitmap bitmap;
|
||||
private String id;
|
||||
private boolean sdf;
|
||||
class ImageWrapper {
|
||||
Bitmap bitmap;
|
||||
String id;
|
||||
boolean sdf;
|
||||
|
||||
ImageWrapper(String id, Bitmap bitmap, boolean sdf) {
|
||||
this.id = id;
|
||||
this.bitmap = bitmap;
|
||||
this.sdf = sdf;
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isSdf() {
|
||||
return sdf;
|
||||
}
|
||||
}
|
||||
|
||||
private class LayerWrapper {
|
||||
private Layer layer;
|
||||
class LayerWrapper {
|
||||
Layer layer;
|
||||
|
||||
LayerWrapper(Layer layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
}
|
||||
|
||||
private class LayerAboveWrapper extends LayerWrapper {
|
||||
|
||||
private String aboveLayer;
|
||||
class LayerAboveWrapper extends LayerWrapper {
|
||||
String aboveLayer;
|
||||
|
||||
LayerAboveWrapper(Layer layer, String aboveLayer) {
|
||||
super(layer);
|
||||
@@ -652,9 +655,8 @@ public class Style {
|
||||
}
|
||||
}
|
||||
|
||||
private class LayerBelowWrapper extends LayerWrapper {
|
||||
|
||||
private String belowLayer;
|
||||
class LayerBelowWrapper extends LayerWrapper {
|
||||
String belowLayer;
|
||||
|
||||
LayerBelowWrapper(Layer layer, String belowLayer) {
|
||||
super(layer);
|
||||
@@ -662,9 +664,8 @@ public class Style {
|
||||
}
|
||||
}
|
||||
|
||||
private class LayerAtWrapper extends LayerWrapper {
|
||||
|
||||
private int index;
|
||||
class LayerAtWrapper extends LayerWrapper {
|
||||
int index;
|
||||
|
||||
LayerAtWrapper(Layer layer, int index) {
|
||||
super(layer);
|
||||
|
||||
Reference in New Issue
Block a user