[android] - make style part of location component activation, add tests for non existing style and multiple style loading, revisit code comments
This commit is contained in:
@@ -75,7 +75,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val locationEngine = component.locationEngine
|
||||
@@ -96,6 +96,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
mapboxMap.style!!,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
@@ -127,6 +128,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -158,8 +160,9 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
|
||||
val style = mapboxMap.style!!
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, style,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -181,7 +184,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
// Source should be present but empty
|
||||
@@ -212,6 +215,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -223,6 +227,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(500)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also {
|
||||
it.forEach {
|
||||
assertThat(it.getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
@@ -241,6 +246,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -264,6 +270,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(false))
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val feature = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0]
|
||||
assertThat(feature.getStringProperty(PROPERTY_FOREGROUND_ICON), `is`(equalTo("custom-foreground-bitmap")))
|
||||
assertThat(feature.getStringProperty(PROPERTY_BACKGROUND_ICON), `is`(equalTo("custom-background-bitmap")))
|
||||
@@ -283,6 +290,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -298,7 +306,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.addImageFromDrawable("custom-foreground-bitmap", it)
|
||||
mapboxMap.addImageFromDrawable("custom-gps-bitmap", it)
|
||||
}
|
||||
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
}
|
||||
@@ -314,6 +322,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
@@ -325,12 +334,14 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
|
||||
component.applyStyle(LocationComponentOptions.builder(context).build())
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON) == FOREGROUND_ICON
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
@@ -349,6 +360,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController: UiController, context: Context) {
|
||||
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.gpsName("custom-gps-bitmap")
|
||||
@@ -359,12 +371,14 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val foregroundId = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON)
|
||||
assertThat(foregroundId, `is`(equalTo("custom-gps-bitmap")))
|
||||
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getStringProperty(PROPERTY_FOREGROUND_ICON) == FOREGROUND_ICON
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
@@ -382,6 +396,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
@@ -393,6 +408,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController.loopMainThreadForAtLeast(250) // engaging stale state
|
||||
|
||||
val renderCheck = {
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE)
|
||||
}
|
||||
waitForRenderResult(uiController, renderCheck, true)
|
||||
@@ -402,6 +418,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(true))
|
||||
assertThat(mapboxMap.isLayerVisible(ACCURACY_LAYER), `is`(false))
|
||||
}
|
||||
@@ -416,16 +433,19 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
|
||||
assertThat(mapboxMap.isLayerVisible(ACCURACY_LAYER), `is`(true))
|
||||
}
|
||||
@@ -443,6 +463,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
mapboxMap.style!!,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyColor(color)
|
||||
@@ -453,6 +474,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
// Check that the source property changes correctly
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.querySourceFeatures(LOCATION_SOURCE).also {
|
||||
it.forEach {
|
||||
assertThat(it.getStringProperty(PROPERTY_ACCURACY_COLOR), `is`(equalTo(rgbaColor)))
|
||||
@@ -470,11 +492,12 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
|
||||
assertThat(component.locationEngine, nullValue())
|
||||
@@ -491,7 +514,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -514,7 +537,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -540,7 +563,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
}
|
||||
@@ -554,7 +577,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
component.onStop()
|
||||
@@ -571,7 +594,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.isLocationComponentEnabled = false
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
@@ -589,7 +612,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.onStop()
|
||||
@@ -608,7 +631,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
@@ -625,12 +648,13 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE).isEmpty(), `is`(true))
|
||||
}
|
||||
}
|
||||
@@ -643,13 +667,15 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
@@ -664,7 +690,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
@@ -673,6 +699,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStart()
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
val point: Point = mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].geometry() as Point
|
||||
assertEquals(point.latitude(), location.latitude, 0.1)
|
||||
assertEquals(point.longitude(), location.longitude, 0.1)
|
||||
@@ -693,9 +720,9 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
.accuracyColor(Color.RED)
|
||||
.build()
|
||||
@@ -719,9 +746,9 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -742,8 +769,9 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
component.activateLocationComponent(context, false)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
@@ -768,7 +796,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
location.bearing = 77f
|
||||
@@ -776,11 +804,15 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
assertThat(mapboxMap.style?.getSource(LOCATION_SOURCE), notNullValue())
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
assertEquals(77.0, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING) as Double, 0.1)
|
||||
|
||||
location.bearing = 92f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY) // Waiting for the animation to finish
|
||||
mapboxMap.waitForSource(uiController, LOCATION_SOURCE)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
assertEquals(92.0, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING) as Double, 0.1)
|
||||
}
|
||||
}
|
||||
@@ -793,7 +825,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
location.bearing = 77f
|
||||
@@ -822,7 +854,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE_GPS
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -854,7 +886,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -887,7 +919,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.cameraMode = CameraMode.NONE
|
||||
@@ -906,7 +938,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val zoom = mapboxMap.cameraPosition.zoom
|
||||
@@ -925,7 +957,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(10.0)
|
||||
@@ -944,7 +976,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
@@ -964,7 +996,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
@@ -987,7 +1019,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
@@ -1007,7 +1039,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
@@ -1026,7 +1058,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1045,7 +1077,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1065,7 +1097,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
@@ -1087,7 +1119,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1107,7 +1139,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -1131,7 +1163,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
val target = LatLng(51.0, 17.0)
|
||||
assertTrue(target.distanceTo(LatLng(location)) > LocationComponentConstants.INSTANT_LOCATION_TRANSITION_THRESHOLD)
|
||||
@@ -1154,7 +1186,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
assertTrue(component.compassEngine is LocationComponentCompassEngine)
|
||||
}
|
||||
@@ -1168,7 +1200,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
val engine: CompassEngine = object : CompassEngine {
|
||||
override fun addCompassListener(compassListener: CompassListener) {
|
||||
|
||||
@@ -75,7 +75,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
@@ -94,7 +94,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -114,7 +114,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.COMPASS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -134,7 +134,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -154,7 +154,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -183,7 +183,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -207,7 +207,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -239,7 +239,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build())
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -268,10 +268,10 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build())
|
||||
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.forceLocationUpdate(location)
|
||||
}
|
||||
@@ -288,9 +288,10 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
var show = true
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.isLocationComponentEnabled = show
|
||||
show = !show
|
||||
@@ -310,7 +311,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!,false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0))
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -330,7 +331,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -364,7 +365,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
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
|
||||
import java.util.logging.Handler
|
||||
|
||||
/**
|
||||
* Resource, that's idling until the provided style is loaded.
|
||||
@@ -32,14 +32,10 @@ class StyleChangeIdlingResource : IdlingResource {
|
||||
callback?.onTransitionToIdle()
|
||||
}
|
||||
|
||||
fun waitForStyle(mapView: MapView, mapboxMap: MapboxMap, styleUrl: String) {
|
||||
fun waitForStyle(mapboxMap: MapboxMap, styleUrl: String) {
|
||||
isIdle = false
|
||||
mapView.addOnDidFinishLoadingStyleListener(object : MapView.OnDidFinishLoadingStyleListener {
|
||||
override fun onDidFinishLoadingStyle() {
|
||||
mapView.removeOnDidFinishLoadingStyleListener(this)
|
||||
setIdle()
|
||||
}
|
||||
})
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(styleUrl))
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(styleUrl)) {
|
||||
setIdle()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.mapbox.mapboxsdk.testapp.maps
|
||||
|
||||
import android.support.test.espresso.UiController
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class StyleLoadTest : BaseActivityTest() {
|
||||
|
||||
private lateinit var mapView: MapView
|
||||
|
||||
override fun getActivityClass(): Class<*> {
|
||||
return EspressoTestActivity::class.java
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun beforeTest() {
|
||||
super.beforeTest()
|
||||
mapView = (rule.activity as EspressoTestActivity).mapView
|
||||
}
|
||||
|
||||
@Test
|
||||
fun updateSourceAfterStyleLoad() {
|
||||
validateTestSetup()
|
||||
MapboxMapAction.invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val source = GeoJsonSource("id")
|
||||
val layer = SymbolLayer("id", "id")
|
||||
mapboxMap.setStyle(Style.Builder().withSource(source).withLayer(layer))
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.MAPBOX_STREETS))
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
source.setGeoJson("{}")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,14 @@ package com.mapbox.mapboxsdk.testapp.utils;
|
||||
import android.app.Activity;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.WorkerThread;
|
||||
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 {
|
||||
public class OnMapReadyIdlingResource implements IdlingResource {
|
||||
|
||||
private boolean styleLoaded;
|
||||
private MapboxMap mapboxMap;
|
||||
@@ -61,10 +56,4 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
public MapboxMap getMapboxMap() {
|
||||
return mapboxMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
|
||||
this.mapboxMap = mapboxMap;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,6 @@ class LocationFragmentActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var mapView: MapView
|
||||
private lateinit var mapboxMap: MapboxMap
|
||||
private var component: LocationComponent? = null
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
mapView = MapView(inflater.context)
|
||||
@@ -105,11 +104,11 @@ class LocationFragmentActivity : AppCompatActivity() {
|
||||
mapView.onCreate(savedInstanceState)
|
||||
mapView.getMapAsync {
|
||||
mapboxMap = it
|
||||
it.setStyle(Style.MAPBOX_STREETS) { _ ->
|
||||
component = mapboxMap.locationComponent
|
||||
component?.activateLocationComponent(activity)
|
||||
component?.isLocationComponentEnabled = true
|
||||
component?.locationEngine?.getLastLocation(this)
|
||||
it.setStyle(Style.MAPBOX_STREETS) { style ->
|
||||
val component = mapboxMap.locationComponent
|
||||
component.activateLocationComponent(activity, style)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.locationEngine?.getLastLocation(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,14 +74,14 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Utils.getNextStyle()),
|
||||
style -> activateLocationComponent());
|
||||
style -> activateLocationComponent(style));
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void activateLocationComponent() {
|
||||
private void activateLocationComponent(@NonNull Style style) {
|
||||
LocationComponent locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.onStart();
|
||||
locationComponent.activateLocationComponent(this);
|
||||
locationComponent.activateLocationComponent(this, style);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
|
||||
@@ -137,7 +137,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
.build();
|
||||
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, true,
|
||||
locationComponent.activateLocationComponent(this, style, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
|
||||
@@ -111,6 +111,7 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
style,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
|
||||
Reference in New Issue
Block a user