[android] - decouple style loading from OnMapReady
This commit is contained in:
@@ -57,6 +57,11 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
initLocation
|
||||
}
|
||||
|
||||
override fun validateTestSetup() {
|
||||
super.validateTestSetup()
|
||||
assertThat(mapboxMap.getStyle(), notNullValue())
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun beforeTest() {
|
||||
super.beforeTest()
|
||||
@@ -152,7 +157,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -231,6 +237,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsForegroundBitmapFromNameOption() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -272,6 +279,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsGpsNameWithGpsRenderMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -302,6 +310,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customIconNameRevertsToDefault() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -335,6 +344,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customGpsIconNameChangeBackWithMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -368,6 +378,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -402,6 +413,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillNotStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -424,6 +436,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_accuracyRingWithColor() {
|
||||
validateTestSetup()
|
||||
val color = Color.parseColor("#4A90E2")
|
||||
val rgbaColor = ColorUtils.colorToRgbaString(color)
|
||||
|
||||
@@ -454,6 +467,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun forceLocationUpdate_doesMoveLocationLayerIconToCorrectPosition() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -474,6 +488,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentHidesPuck() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -496,6 +511,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentAndChangingStyleAllowsToEnableAgain() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -505,7 +521,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -517,6 +533,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_isDisabledOnStart() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -534,6 +551,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsEnabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -550,6 +568,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsDisabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -567,6 +586,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_ableToChangeStyleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -576,7 +596,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
}
|
||||
}
|
||||
@@ -585,12 +605,13 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_interruptedDuringStyleChange() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
@@ -601,6 +622,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_forceLocationUpdateAfterStopped() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -618,6 +640,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_acceptAndReuseLocationUpdatesBeforeLayerStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -638,13 +661,14 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_lifecycleChangeRightAfterStyleReload() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.onStop()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.onStart()
|
||||
@@ -666,6 +690,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingComponentStyle() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -691,6 +716,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_forcingLocation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -713,6 +739,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingMapStyleBeforeComponentCreation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -738,6 +765,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun animators_layerBearingCorrect() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -747,6 +775,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
assertThat(mapboxMap.style?.getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertEquals(77.0, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING) as Double, 0.1)
|
||||
|
||||
location.bearing = 92f
|
||||
|
||||
@@ -79,7 +79,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.getStyle().getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertThat(mapboxMap.getStyle()!!.getSource(LOCATION_SOURCE), notNullValue())
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -212,7 +212,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -220,7 +220,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
|
||||
// Check that the Source has been re-added to the new map style
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle()!!.getSourceAs(LOCATION_SOURCE)
|
||||
assertThat(source, notNullValue())
|
||||
|
||||
// Check that all layers visibilities are set to visible
|
||||
@@ -253,7 +253,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.style.layers.Property
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
|
||||
fun MapboxMap.querySourceFeatures(sourceId: String): List<Feature> {
|
||||
return this.style.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
return this.style!!.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
}
|
||||
|
||||
fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<Feature> {
|
||||
@@ -25,7 +25,7 @@ fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<F
|
||||
}
|
||||
|
||||
fun MapboxMap.isLayerVisible(layerId: String): Boolean {
|
||||
return this.style.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForSource(uiController: UiController, sourceId: String) {
|
||||
@@ -99,7 +99,7 @@ class MapboxTestingUtils {
|
||||
|
||||
fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
|
||||
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
|
||||
this.style.addImage(string, bitmapFromDrawable)
|
||||
this.style!!.addImage(string, bitmapFromDrawable)
|
||||
}
|
||||
|
||||
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.location.utils
|
||||
import android.support.test.espresso.IdlingResource
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
|
||||
/**
|
||||
* Resource, that's idling until the provided style is loaded.
|
||||
@@ -39,6 +40,6 @@ class StyleChangeIdlingResource : IdlingResource {
|
||||
setIdle()
|
||||
}
|
||||
})
|
||||
mapboxMap.setStyleUrl(styleUrl)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(styleUrl))
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
@@ -67,9 +68,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDuration = 600;
|
||||
mapboxMap.setTransitionDuration(transitionDuration);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(transitionDuration, 0));
|
||||
assertEquals(
|
||||
"TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0
|
||||
"TransitionDuration should match",
|
||||
transitionDuration,
|
||||
mapboxMap.getStyle().getTransition().getDuration(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
@@ -79,9 +83,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDelay = 50;
|
||||
mapboxMap.setTransitionDelay(transitionDelay);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(600, transitionDelay));
|
||||
assertEquals(
|
||||
"TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0
|
||||
"TransitionDelay should match",
|
||||
transitionDelay,
|
||||
mapboxMap.getStyle().getTransition().getDelay(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style
|
||||
|
||||
import android.support.test.espresso.UiController
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
import com.mapbox.geojson.Point
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
|
||||
import org.junit.Test
|
||||
|
||||
class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
|
||||
override fun getActivityClass(): Class<*> = SimpleMapActivity::class.java
|
||||
|
||||
@Test
|
||||
fun sourceUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
source.setGeoJson(
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(1.0, 1.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun layerUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
val layer = SymbolLayer("test", "source-id")
|
||||
style.addLayer(layer)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -58,6 +59,7 @@ public class RenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRender() {
|
||||
onView(withId(android.R.id.content)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun sourceNotLeakingThreadsTest() {
|
||||
validateTestSetup()
|
||||
waitAction(4000)
|
||||
@@ -39,9 +40,9 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsShutdownWhenSourceRemovedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer(ID_GRID_LAYER)
|
||||
mapboxMap.style!!.removeLayer(ID_GRID_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("There should be no threads running when the source is removed.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
@@ -55,12 +56,12 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsRestartedWhenSourceReAddedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
mapboxMap.getStyle().addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.getStyle().addLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.style!!.addLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
|
||||
@@ -242,7 +242,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression3 = eq(literal("Łukasz"), literal("lukasz"), collator(literal(false), eq(literal(2),
|
||||
literal(1))));
|
||||
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
Layer layer = new CircleLayer("layer", "source")
|
||||
.withProperties(circleColor(
|
||||
switchCase(
|
||||
@@ -282,7 +283,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
@@ -304,7 +306,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
@@ -326,7 +329,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
@@ -355,7 +359,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
@@ -386,7 +391,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
@@ -477,7 +483,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().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.getStyle().addLayer(layer);
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ public class ImageTest extends BaseActivityTest {
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
|
||||
Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
mapboxMap.removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getImage(IMAGE_ID));
|
||||
mapboxMap.getStyle().removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getStyle().getImage(IMAGE_ID));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,9 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
// Test inserting with invalid above-id
|
||||
try {
|
||||
mapboxMap.getStyle().addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man");
|
||||
mapboxMap.getStyle().addLayerAbove(
|
||||
new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man"
|
||||
);
|
||||
fail("Should have thrown exception");
|
||||
} catch (CannotAddLayerException ex) {
|
||||
// Yeah
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.test.espresso.UiController;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
@@ -37,8 +38,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
@@ -55,7 +56,7 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
|
||||
// fake activity stop/start
|
||||
MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
|
||||
@@ -65,8 +66,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl());
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyle().getUrl());
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
@@ -10,12 +10,14 @@ import android.support.test.espresso.IdlingResource;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
|
||||
|
||||
private boolean styleLoaded;
|
||||
private MapboxMap mapboxMap;
|
||||
private IdlingResource.ResourceCallback resourceCallback;
|
||||
|
||||
@@ -25,11 +27,22 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
handler.post(() -> {
|
||||
MapView mapView = activity.findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.getMapAsync(OnMapReadyIdlingResource.this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
styleLoaded = true;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
});
|
||||
mapView.getMapAsync(this::initMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap(MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName();
|
||||
@@ -37,7 +50,7 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
|
||||
@Override
|
||||
public boolean isIdleNow() {
|
||||
return mapboxMap != null;
|
||||
return styleLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,8 +66,5 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
|
||||
this.mapboxMap = mapboxMap;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user