[android] Adding builder pattern for LocationComponent activation (#13941)
* initial additions of activation builder * [android] refactoring LocationComponentActivationOptions based on code review * [android] initial addition of LocationComponentActivationOptionsTest unit tests * [android] more refactoring based on code review * [android] refactoring test app location examples * [android] espresso test refactor with LocationComponentActivationOptions usage * [android] locationComponent builder instrumentation test tweaks and log removal * [android] method and docs refactoring based @lukaspaczos 's review * [android] locationEngine setting logic refactor * [android] add null locationEngine to stillStaleAfterResuming test * added .locationEngine(null) to other tests * [android] javadocs, method, and test adjustments based on @lukaspaczos review * [android] test tweaks based on Lukasz review
This commit is contained in:
@@ -52,6 +52,9 @@ class LocationComponentTest : EspressoTest() {
|
||||
initLocation
|
||||
}
|
||||
|
||||
private lateinit var locationComponentActivationOptions: LocationComponentActivationOptions
|
||||
|
||||
|
||||
override fun validateTestSetup() {
|
||||
super.validateTestSetup()
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
@@ -70,7 +73,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val locationEngine = component.locationEngine
|
||||
@@ -89,15 +95,21 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
style,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.accuracyAlpha(.5f)
|
||||
.accuracyColor(Color.BLUE)
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.accuracyAlpha(.5f)
|
||||
.accuracyColor(Color.BLUE)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val locationEngine = component.locationEngine
|
||||
@@ -121,16 +133,22 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(
|
||||
context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.accuracyAlpha(.5f)
|
||||
.accuracyColor(Color.BLUE)
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.locationEngine(null)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.accuracyAlpha(.5f)
|
||||
.accuracyColor(Color.BLUE)
|
||||
.build()
|
||||
)
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val locationEngine = component.locationEngine
|
||||
@@ -148,14 +166,18 @@ class LocationComponentTest : EspressoTest() {
|
||||
executeComponentTest(componentAction)
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException::class)
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
fun settingMapStyleImmediatelyBeforeLoadingComponent_throwsInvalidStyle() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +190,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
// Source should be present but empty
|
||||
@@ -198,13 +224,19 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.build())
|
||||
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.enableStaleState(false)
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -228,16 +260,21 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.backgroundName("custom-background-bitmap")
|
||||
.foregroundStaleName("custom-foreground-stale-bitmap")
|
||||
.backgroundStaleName("custom-background-stale-bitmap")
|
||||
.bearingName("custom-bearing-bitmap")
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.backgroundName("custom-background-bitmap")
|
||||
.foregroundStaleName("custom-foreground-stale-bitmap")
|
||||
.backgroundStaleName("custom-background-stale-bitmap")
|
||||
.bearingName("custom-bearing-bitmap")
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_media_play)
|
||||
@@ -271,13 +308,18 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
@@ -303,13 +345,17 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.foregroundName("custom-foreground-bitmap")
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
@@ -335,12 +381,16 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.gpsName("custom-gps-bitmap")
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.renderMode = RenderMode.GPS
|
||||
@@ -366,12 +416,17 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.staleStateTimeout(200)
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -398,7 +453,12 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -425,12 +485,17 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context,
|
||||
style,
|
||||
null,
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyColor(color)
|
||||
.build())
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.locationComponentOptions(
|
||||
LocationComponentOptions.builder(context)
|
||||
.accuracyColor(color)
|
||||
.build())
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -453,7 +518,12 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -473,7 +543,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -496,7 +570,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
component.isLocationComponentEnabled = false
|
||||
@@ -520,7 +598,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
}
|
||||
@@ -534,7 +616,12 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
assertThat(component.isLocationComponentEnabled, `is`(true))
|
||||
component.onStop()
|
||||
@@ -551,7 +638,11 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(
|
||||
LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.isLocationComponentEnabled = false
|
||||
assertThat(component.isLocationComponentEnabled, `is`(false))
|
||||
@@ -569,7 +660,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.onStop()
|
||||
@@ -588,7 +682,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
@@ -605,7 +702,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -623,7 +723,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.onStop()
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -644,7 +747,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
@@ -672,7 +778,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
@@ -680,7 +789,7 @@ class LocationComponentTest : EspressoTest() {
|
||||
.build()
|
||||
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.applyStyle(options)
|
||||
component.applyStyle(options)
|
||||
}
|
||||
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -698,12 +807,15 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.forceLocationUpdate(location)
|
||||
component.forceLocationUpdate(location)
|
||||
}
|
||||
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -723,7 +835,12 @@ class LocationComponentTest : EspressoTest() {
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
|
||||
locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(context, mapboxMap.style!!)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build()
|
||||
component.activateLocationComponent(locationComponentActivationOptions)
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
val options = LocationComponentOptions.builder(context)
|
||||
@@ -731,8 +848,8 @@ class LocationComponentTest : EspressoTest() {
|
||||
.build()
|
||||
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.forceLocationUpdate(location)
|
||||
component.applyStyle(options)
|
||||
component.forceLocationUpdate(location)
|
||||
component.applyStyle(options)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -748,7 +865,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
location.bearing = 77f
|
||||
@@ -773,7 +893,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
location.bearing = 77f
|
||||
@@ -806,7 +929,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE_GPS
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -842,7 +968,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val latitude = mapboxMap.cameraPosition.target.latitude
|
||||
@@ -879,7 +1008,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.cameraMode = CameraMode.NONE
|
||||
@@ -898,7 +1030,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val zoom = mapboxMap.cameraPosition.zoom
|
||||
@@ -918,7 +1053,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(10.0)
|
||||
@@ -938,7 +1076,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
@@ -959,7 +1100,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
@@ -983,7 +1127,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.zoomWhileTracking(15.0)
|
||||
@@ -1004,7 +1151,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
@@ -1024,7 +1174,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1044,7 +1197,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1065,7 +1221,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
val tilt = mapboxMap.cameraPosition.tilt
|
||||
@@ -1088,7 +1247,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING
|
||||
component.tiltWhileTracking(30.0)
|
||||
@@ -1108,7 +1270,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.TRACKING_GPS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -1133,7 +1298,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.cameraMode = CameraMode.NONE
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -1159,7 +1327,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
assertTrue(component.compassEngine is LocationComponentCompassEngine)
|
||||
}
|
||||
@@ -1173,7 +1344,10 @@ class LocationComponentTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
val engine: CompassEngine = object : CompassEngine {
|
||||
override fun addCompassListener(compassListener: CompassListener) {
|
||||
|
||||
@@ -69,7 +69,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -89,7 +92,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -110,7 +116,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.COMPASS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -131,7 +140,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.GPS
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -152,7 +164,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
component.isLocationComponentEnabled = false
|
||||
@@ -174,7 +189,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -197,7 +215,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -226,7 +247,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build())
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -249,7 +273,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
@@ -276,7 +303,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build())
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
@@ -299,7 +329,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
styleChangeIdlingResource.waitForStyle(mapboxMap, MAPBOX_HEAVY_STYLE)
|
||||
uiController.loopMainThreadForAtLeast(100)
|
||||
var show = true
|
||||
component.activateLocationComponent(context, mapboxMap.style!!, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, mapboxMap.style!!)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
pushSourceUpdates(styleChangeIdlingResource) {
|
||||
component.isLocationComponentEnabled = show
|
||||
show = !show
|
||||
@@ -319,7 +352,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0))
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -339,7 +375,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
|
||||
@@ -369,7 +408,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
|
||||
@@ -397,7 +439,10 @@ class LocationLayerControllerTest : EspressoTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
style: Style, uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, style, false)
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(context, style)
|
||||
.useDefaultLocationEngine(false)
|
||||
.build())
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
TestingAsyncUtils.waitForLayer(uiController, idlingResource.mapView)
|
||||
|
||||
@@ -861,6 +861,17 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.location.LocationComponentActivationActivity"
|
||||
android:description="@string/description_location_activation_builder"
|
||||
android:label="@string/activity_location_activation_builder">
|
||||
<meta-data
|
||||
android:name="@string/category"
|
||||
android:value="@string/category_location" />
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activity.maplayout.RecyclerViewActivity"
|
||||
android:description="@string/description_recyclerview"
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.location;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
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 java.util.List;
|
||||
|
||||
public class LocationComponentActivationActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_location_layer_activation_builder);
|
||||
|
||||
mapView = findViewById(R.id.mapView);
|
||||
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
mapView.getMapAsync(this);
|
||||
} else {
|
||||
permissionsManager = new PermissionsManager(new PermissionsListener() {
|
||||
@Override
|
||||
public void onExplanationNeeded(List<String> permissionsToExplain) {
|
||||
Toast.makeText(LocationComponentActivationActivity.this, "You need to accept location permissions.",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionResult(boolean granted) {
|
||||
if (granted) {
|
||||
mapView.getMapAsync(LocationComponentActivationActivity.this);
|
||||
} else {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
permissionsManager.requestLocationPermissions(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
permissionsManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.DARK,
|
||||
style -> activateLocationComponent(style));
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void activateLocationComponent(@NonNull Style style) {
|
||||
LocationComponent locationComponent = mapboxMap.getLocationComponent();
|
||||
|
||||
LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(this)
|
||||
.elevation(5)
|
||||
.accuracyAlpha(.6f)
|
||||
.accuracyColor(Color.GREEN)
|
||||
.foregroundDrawable(R.drawable.mapbox_logo_helmet)
|
||||
.build();
|
||||
|
||||
LocationComponentActivationOptions locationComponentActivationOptions = LocationComponentActivationOptions
|
||||
.builder(this, style)
|
||||
.locationComponentOptions(locationComponentOptions)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build();
|
||||
|
||||
locationComponent.activateLocationComponent(locationComponentActivationOptions);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.NORMAL);
|
||||
locationComponent.setCameraMode(CameraMode.TRACKING);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package com.mapbox.mapboxsdk.testapp.activity.location
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Fragment
|
||||
import android.location.Location
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.LayoutInflater
|
||||
@@ -10,21 +9,18 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import com.mapbox.android.core.location.LocationEngine
|
||||
import com.mapbox.android.core.location.LocationEngineCallback
|
||||
import com.mapbox.android.core.location.LocationEngineProvider
|
||||
import com.mapbox.android.core.location.LocationEngineResult
|
||||
import com.mapbox.android.core.permissions.PermissionsListener
|
||||
import com.mapbox.android.core.permissions.PermissionsManager
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_location_layer_fragment.*
|
||||
import java.lang.Exception
|
||||
|
||||
class LocationFragmentActivity : AppCompatActivity() {
|
||||
private lateinit var permissionsManager: PermissionsManager
|
||||
@@ -105,10 +101,15 @@ class LocationFragmentActivity : AppCompatActivity() {
|
||||
mapView.getMapAsync {
|
||||
mapboxMap = it
|
||||
it.setStyle(Style.MAPBOX_STREETS) { style ->
|
||||
val component = mapboxMap.locationComponent
|
||||
component.activateLocationComponent(activity, style)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.locationEngine?.getLastLocation(this)
|
||||
val component = mapboxMap.locationComponent
|
||||
|
||||
component.activateLocationComponent(LocationComponentActivationOptions
|
||||
.builder(activity, style)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build())
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
component.locationEngine?.getLastLocation(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.Toast;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
@@ -80,7 +81,13 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
@SuppressLint("MissingPermission")
|
||||
private void activateLocationComponent(@NonNull Style style) {
|
||||
LocationComponent locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, style);
|
||||
|
||||
locationComponent.activateLocationComponent(
|
||||
LocationComponentActivationOptions
|
||||
.builder(this, style)
|
||||
.useDefaultLocationEngine(true)
|
||||
.build());
|
||||
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
|
||||
import com.mapbox.mapboxsdk.location.OnLocationCameraTransitionListener;
|
||||
@@ -126,12 +127,16 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, style, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build()
|
||||
);
|
||||
locationComponent.activateLocationComponent(
|
||||
LocationComponentActivationOptions
|
||||
.builder(this, style)
|
||||
.useDefaultLocationEngine(true)
|
||||
.locationEngineRequest(new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build())
|
||||
.build());
|
||||
|
||||
toggleStyle();
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.addOnLocationClickListener(this);
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineProvider;
|
||||
import com.mapbox.android.core.location.LocationEngineRequest;
|
||||
@@ -13,6 +14,7 @@ import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentActivationOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
@@ -109,14 +111,16 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS), style -> {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
style,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
LocationComponentActivationOptions
|
||||
.builder(this, style)
|
||||
.locationEngine(locationEngine)
|
||||
.locationEngineRequest(new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build())
|
||||
.build());
|
||||
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginBottom="0dp"
|
||||
app:mapbox_uiAttribution="false"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
@@ -75,6 +75,7 @@
|
||||
<string name="description_location_modes">Showcases location render and tracking modes</string>
|
||||
<string name="description_location_fragment">Uses LocationComponent in a Fragment</string>
|
||||
<string name="description_location_manual">Force location updates and don\'t rely on the engine</string>
|
||||
<string name="description_location_activation_builder">Use LocationComponentActivationOptions to set options</string>
|
||||
<string name="description_recyclerview">Show a MapView as a recyclerView item</string>
|
||||
<string name="description_nested_viewpager">Show a MapView inside a viewpager inside a recyclerView</string>
|
||||
</resources>
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
<string name="activity_location_modes">Location Modes Activity</string>
|
||||
<string name="activity_location_fragment">Location Fragment</string>
|
||||
<string name="activity_location_manual">Manual Location updates</string>
|
||||
<string name="activity_location_activation_builder">Build Location Activation</string>
|
||||
<string name="activity_recyclerview">RecyclerView</string>
|
||||
<string name="activity_nested_viewpager">Nested ViewPager</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user