diff options
Diffstat (limited to 'platform/android/MapboxGLAndroidSDKTestApp/src')
7 files changed, 167 insertions, 178 deletions
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt index 6541abb748..1d4c4af149 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt @@ -19,7 +19,6 @@ import com.mapbox.geojson.Point import com.mapbox.mapboxsdk.camera.CameraUpdateFactory import com.mapbox.mapboxsdk.constants.Style import com.mapbox.mapboxsdk.geometry.LatLng -import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.location.LocationComponentConstants.* import com.mapbox.mapboxsdk.location.modes.CameraMode import com.mapbox.mapboxsdk.location.modes.RenderMode @@ -28,6 +27,7 @@ import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAPBOX_H import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_CONNECTION_DELAY import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_RENDER_DELAY import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.pushSourceUpdates +import com.mapbox.mapboxsdk.maps.MapboxMap import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest import com.mapbox.mapboxsdk.testapp.activity.SingleActivity import com.mapbox.mapboxsdk.utils.ColorUtils @@ -70,8 +70,9 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context) + component.isLocationComponentEnabled = true val locationEngine = component.locationEngine assertThat(locationEngine, notNullValue()) @@ -89,7 +90,7 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent( context, LocationComponentOptions.builder(context) @@ -98,6 +99,7 @@ class LocationComponentTest : BaseActivityTest() { .accuracyAlpha(.5f) .accuracyColor(Color.BLUE) .build()) + component.isLocationComponentEnabled = true val locationEngine = component.locationEngine val componentOptions = component.locationComponentOptions @@ -120,8 +122,9 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent( + context, null, LocationComponentOptions.builder(context) .staleStateTimeout(200) @@ -129,6 +132,7 @@ class LocationComponentTest : BaseActivityTest() { .accuracyAlpha(.5f) .accuracyColor(Color.BLUE) .build()) + component.isLocationComponentEnabled = true val locationEngine = component.locationEngine val componentOptions = component.locationComponentOptions @@ -150,9 +154,10 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { mapboxMap.setStyle(Style.LIGHT) component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -173,8 +178,9 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true // Source should be present but empty val mapView = (rule.activity as SingleActivity).mapView @@ -202,12 +208,13 @@ class LocationComponentTest : BaseActivityTest() { validateTestSetup() val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .staleStateTimeout(200) .enableStaleState(false) .build()) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -229,7 +236,7 @@ class LocationComponentTest : BaseActivityTest() { fun locationComponentOptions_loadsForegroundBitmapFromNameOption() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") @@ -238,6 +245,7 @@ class LocationComponentTest : BaseActivityTest() { .backgroundStaleName("custom-background-stale-bitmap") .bearingName("custom-bearing-bitmap") .build()) + component.isLocationComponentEnabled = true val foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_media_play) foregroundDrawable?.let { @@ -268,12 +276,13 @@ class LocationComponentTest : BaseActivityTest() { fun locationComponentOptions_loadsGpsNameWithGpsRenderMode() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") .gpsName("custom-gps-bitmap") .build()) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.GPS component.forceLocationUpdate(location) @@ -296,12 +305,13 @@ class LocationComponentTest : BaseActivityTest() { fun locationComponentOptions_customIconNameRevertsToDefault() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") .gpsName("custom-gps-bitmap") .build()) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.GPS component.forceLocationUpdate(location) @@ -325,12 +335,13 @@ class LocationComponentTest : BaseActivityTest() { fun locationComponentOptions_customGpsIconNameChangeBackWithMode() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .gpsName("custom-gps-bitmap") .build()) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.GPS component.forceLocationUpdate(location) @@ -354,11 +365,12 @@ class LocationComponentTest : BaseActivityTest() { fun stillStaleAfterResuming() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .staleStateTimeout(200) .build()) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -382,8 +394,9 @@ class LocationComponentTest : BaseActivityTest() { fun stillNotStaleAfterResuming() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false)) @@ -406,11 +419,12 @@ class LocationComponentTest : BaseActivityTest() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, LocationComponentOptions.builder(context) .accuracyColor(color) .build()) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -431,8 +445,9 @@ class LocationComponentTest : BaseActivityTest() { fun forceLocationUpdate_doesMoveLocationLayerIconToCorrectPosition() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -450,8 +465,9 @@ class LocationComponentTest : BaseActivityTest() { fun disablingComponentHidesPuck() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -459,7 +475,7 @@ class LocationComponentTest : BaseActivityTest() { assertEquals(point.latitude(), location.latitude, 0.1) assertEquals(point.longitude(), location.longitude, 0.1) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = false uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true)) } @@ -471,15 +487,16 @@ class LocationComponentTest : BaseActivityTest() { fun disablingComponentAndChangingStyleAllowsToEnableAgain() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = false mapboxMap.setStyle(Style.LIGHT) - component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true)) } @@ -491,12 +508,13 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_isDisabledOnStart() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { assertThat(component.isLocationComponentEnabled, `is`(false)) component.onStop() component.onStart() assertThat(component.isLocationComponentEnabled, `is`(false)) component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true assertThat(component.isLocationComponentEnabled, `is`(true)) } } @@ -507,8 +525,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_keepsEnabledWhenStoppedAndStarted() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true assertThat(component.isLocationComponentEnabled, `is`(true)) component.onStop() component.onStart() @@ -522,9 +541,10 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_keepsDisabledWhenStoppedAndStarted() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = true + component.isLocationComponentEnabled = false assertThat(component.isLocationComponentEnabled, `is`(false)) component.onStop() component.onStart() @@ -538,8 +558,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_ableToChangeStyleAfterResuming() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.onStop() component.onStart() @@ -555,8 +576,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_interruptedDuringStyleChange() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true mapboxMap.setStyle(Style.DARK) component.onStop() component.onStart() @@ -570,8 +592,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_forceLocationUpdateAfterStopped() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.onStop() component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -586,8 +609,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_acceptAndReuseLocationUpdatesBeforeLayerStarted() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.onStop() component.forceLocationUpdate(location) component.onStart() @@ -605,8 +629,9 @@ class LocationComponentTest : BaseActivityTest() { fun lifecycle_lifecycleChangeRightAfterStyleReload() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.setStyle(Style.LIGHT) component.onStop() @@ -632,8 +657,9 @@ class LocationComponentTest : BaseActivityTest() { fun mapChange_settingComponentStyle() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE) val options = LocationComponentOptions.builder(context) .accuracyColor(Color.RED) @@ -656,8 +682,9 @@ class LocationComponentTest : BaseActivityTest() { fun mapChange_forcingLocation() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE) pushSourceUpdates(styleChangeIdlingResource) { @@ -677,9 +704,10 @@ class LocationComponentTest : BaseActivityTest() { fun mapChange_settingMapStyleBeforeComponentCreation() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE) component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true val options = LocationComponentOptions.builder(context) .accuracyColor(Color.RED) @@ -701,8 +729,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_layerBearingCorrect() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.GPS location.bearing = 77f component.forceLocationUpdate(location) @@ -723,8 +752,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_cameraLatLngBearingCorrect() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING_GPS location.bearing = 77f component.forceLocationUpdate(location) @@ -751,8 +781,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_cameraBearingCorrect() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.NONE_GPS val latitude = mapboxMap.cameraPosition.target.latitude val longitude = mapboxMap.cameraPosition.target.longitude @@ -782,8 +813,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_cameraNoneCorrect() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.NONE val latitude = mapboxMap.cameraPosition.target.latitude val longitude = mapboxMap.cameraPosition.target.longitude @@ -814,8 +846,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_focalPointAdjustment() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.cameraMode = CameraMode.NONE component.forceLocationUpdate(location) @@ -832,8 +865,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_dontZoomWhileNotTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.NONE val zoom = mapboxMap.cameraPosition.zoom component.zoomWhileTracking(10.0) @@ -850,8 +884,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_zoomWhileTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.zoomWhileTracking(10.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION) @@ -868,8 +903,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_zoomWhileTrackingCanceledOnModeChange() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.zoomWhileTracking(15.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2) @@ -887,8 +923,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_dontZoomWhileStopped() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) @@ -910,8 +947,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_cancelZoomWhileTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.zoomWhileTracking(15.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2) @@ -929,8 +967,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_dontTiltWhileNotTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.NONE val tilt = mapboxMap.cameraPosition.tilt component.tiltWhileTracking(30.0) @@ -947,8 +986,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_tiltWhileTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.tiltWhileTracking(30.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION) @@ -965,8 +1005,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_tiltWhileTrackingCanceledOnModeChange() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.tiltWhileTracking(30.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2) @@ -984,8 +1025,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_dontTiltWhileStopped() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING val tilt = mapboxMap.cameraPosition.tilt @@ -1005,8 +1047,9 @@ class LocationComponentTest : BaseActivityTest() { fun animators_cancelTiltWhileTracking() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING component.tiltWhileTracking(30.0) uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2) @@ -1024,14 +1067,15 @@ class LocationComponentTest : BaseActivityTest() { fun cameraPositionAdjustedToTrackingModeWhenComponentEnabled() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.cameraMode = CameraMode.TRACKING_GPS component.forceLocationUpdate(location) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = false mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(LatLng(51.0, 17.0))) mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(90.0)) - component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY) assertEquals(location.bearing.toDouble(), mapboxMap.cameraPosition.bearing, 0.1) @@ -1047,8 +1091,9 @@ class LocationComponentTest : BaseActivityTest() { fun compassEngine_onComponentInitializedDefaultIsProvided() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true assertTrue(component.compassEngine is LocationComponentCompassEngine) } } @@ -1060,8 +1105,9 @@ class LocationComponentTest : BaseActivityTest() { fun compassEngine_changesWhenNewProvided() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { + uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true val engine: CompassEngine = object : CompassEngine { override fun addCompassListener(compassListener: CompassListener) { } @@ -1094,84 +1140,12 @@ class LocationComponentTest : BaseActivityTest() { } @Test - fun savedState_bundleCreationDeactivated() { - val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { - override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { - val bundle = Bundle() - component.onSaveInstanceState(bundle) - assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled)) - assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions))) - assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(equalTo(component.renderMode))) - assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(equalTo(component.cameraMode))) - assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation))) - } - } - - executeComponentTest(componentAction) - } - - @Test - fun savedState_bundleCreationActivated() { - val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { - override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { - val options = LocationComponentOptions.builder(context) - .accuracyColor(Color.RED) - .build() - component.activateLocationComponent(null, options) - component.cameraMode = CameraMode.TRACKING - component.renderMode = RenderMode.GPS - component.forceLocationUpdate(location) - mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) - - val bundle = Bundle() - component.onSaveInstanceState(bundle) - assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled)) - assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions))) - assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(component.renderMode)) - assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(component.cameraMode)) - assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation))) - } - } - - executeComponentTest(componentAction) - } - - @Test - fun savedState_componentRecreated() { - val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { - override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, - uiController: UiController, context: Context) { - val options = LocationComponentOptions.builder(context) - .accuracyColor(Color.RED) - .build() - - val bundle = Bundle() - bundle.putBoolean(STATE_LOCATION_ENABLED, true) - bundle.putParcelable(STATE_LOCATION_OPTIONS, options) - bundle.putInt(STATE_LOCATION_RENDER_MODE, RenderMode.GPS) - bundle.putInt(STATE_LOCATION_CAMERA_MODE, CameraMode.TRACKING) - bundle.putParcelable(STATE_LOCATION_LAST_LOCATION, location) - - component.onRestoreInstanceState(bundle) - assertThat(component.isLocationComponentEnabled, `is`(true)) - assertThat(component.locationComponentOptions, `is`(equalTo(options))) - assertThat(component.renderMode, `is`(RenderMode.GPS)) - assertThat(component.cameraMode, `is`(CameraMode.TRACKING)) - assertThat(component.lastKnownLocation, `is`(equalTo(location))) - } - } - - executeComponentTest(componentAction) - } - - @Test fun defaultLocationEngine_deactivatedWhenDestroyed() { val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context) + component.isLocationComponentEnabled = true uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY) assertThat(component.locationEngine?.isConnected, `is`(true)) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt index c50d1817fd..92f4d770fe 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt @@ -76,6 +76,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.NORMAL uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) assertThat(mapboxMap.getSource(LOCATION_SOURCE), notNullValue()) @@ -94,6 +95,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.NORMAL component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -113,6 +115,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.COMPASS component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -132,6 +135,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.GPS component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -151,9 +155,10 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = false mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true) component.renderMode = RenderMode.GPS uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) @@ -173,10 +178,11 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.NORMAL component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) - component.deactivateLocationComponent() + component.isLocationComponentEnabled = false mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true) uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) @@ -197,6 +203,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.renderMode = RenderMode.NORMAL component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -228,6 +235,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build()) component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -252,6 +260,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build()) styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE) pushSourceUpdates(styleChangeIdlingResource) { @@ -272,12 +281,9 @@ class LocationLayerControllerTest : BaseActivityTest() { uiController: UiController, context: Context) { styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE) var show = true + component.activateLocationComponent(context, false) pushSourceUpdates(styleChangeIdlingResource) { - if (show) { - component.activateLocationComponent(context, false) - } else { - component.deactivateLocationComponent() - } + component.isLocationComponentEnabled = show show = !show } @@ -296,6 +302,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0)) component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) @@ -315,6 +322,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true component.forceLocationUpdate(location) mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER) mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0), 300) @@ -334,6 +342,7 @@ class LocationLayerControllerTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, false) + component.isLocationComponentEnabled = true uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) component.forceLocationUpdate(location) uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt index ad80a3333e..75fae82cf2 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt @@ -21,14 +21,8 @@ class LocationComponentAction(private val mapboxMap: MapboxMap, } override fun perform(uiController: UiController, view: View) { - val component = mapboxMap.locationComponent - - while (mapboxMap.getSource("mapbox-location-source") == null) { - uiController.loopMainThreadForAtLeast(MapboxTestingUtils.MAP_RENDER_DELAY) - } - onPerformLocationComponentAction.onLocationComponentAction( - component, + mapboxMap.locationComponent, mapboxMap, uiController, view.context) diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt index 974dc5c571..035ad67e12 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt @@ -102,6 +102,7 @@ class LocationFragmentActivity : AppCompatActivity() { mapboxMap = it component = mapboxMap.locationComponent component?.activateLocationComponent(activity) + component?.isLocationComponentEnabled = true component?.locationEngine?.addLocationEngineListener(this) } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java index 6fa514e28b..e53604fdd4 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java @@ -84,6 +84,7 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa private void activateLocationComponent() { LocationComponent locationComponent = mapboxMap.getLocationComponent(); locationComponent.activateLocationComponent(this); + locationComponent.setLocationComponentEnabled(true); locationComponent.setRenderMode(RenderMode.COMPASS); } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java index 72bd91108a..86feb00dec 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java @@ -22,13 +22,13 @@ import com.mapbox.android.core.permissions.PermissionsListener; import com.mapbox.android.core.permissions.PermissionsManager; import com.mapbox.mapboxsdk.camera.CameraUpdateFactory; import com.mapbox.mapboxsdk.constants.Style; +import com.mapbox.mapboxsdk.location.OnLocationClickListener; import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.location.LocationComponentOptions; import com.mapbox.mapboxsdk.location.LocationComponent; import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener; -import com.mapbox.mapboxsdk.location.OnLocationComponentClickListener; import com.mapbox.mapboxsdk.location.modes.CameraMode; import com.mapbox.mapboxsdk.location.modes.RenderMode; import com.mapbox.mapboxsdk.testapp.R; @@ -37,7 +37,7 @@ import java.util.ArrayList; import java.util.List; public class LocationModesActivity extends AppCompatActivity implements OnMapReadyCallback, - LocationEngineListener, OnLocationComponentClickListener, OnCameraTrackingChangedListener { + LocationEngineListener, OnLocationClickListener, OnCameraTrackingChangedListener { private MapView mapView; private Button locationModeBtn; @@ -50,7 +50,17 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea private MapboxMap mapboxMap; private boolean customStyle; - private Bundle savedInstanceState; + private static final String SAVED_STATE_CAMERA = "saved_state_camera"; + private static final String SAVED_STATE_RENDER = "saved_state_render"; + private static final String SAVED_STATE_LOCATION = "saved_state_location"; + + @CameraMode.Mode + private int cameraMode = CameraMode.TRACKING; + + @RenderMode.Mode + private int renderMode = RenderMode.NORMAL; + + private Location lastLocation; @Override protected void onCreate(Bundle savedInstanceState) { @@ -81,6 +91,13 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea } }); + + if (savedInstanceState != null) { + cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA); + renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER); + lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION); + } + mapView.onCreate(savedInstanceState); if (PermissionsManager.areLocationPermissionsGranted(this)) { @@ -104,8 +121,6 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea }); permissionsManager.requestLocationPermissions(this); } - - this.savedInstanceState = savedInstanceState; } @Override @@ -125,11 +140,26 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea locationEngine.addLocationEngineListener(this); locationEngine.activate(); + int[] padding; + if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { + padding = new int[] {0, 750, 0, 0}; + } else { + padding = new int[] {0, 250, 0, 0}; + } + + LocationComponentOptions options = LocationComponentOptions.builder(this) + .padding(padding) + .layerBelow("waterway-label") + .build(); + locationComponent = mapboxMap.getLocationComponent(); + locationComponent.activateLocationComponent(this, locationEngine, options); + locationComponent.setLocationComponentEnabled(true); locationComponent.addOnLocationClickListener(this); locationComponent.addOnCameraTrackingChangedListener(this); - - activateLocationComponent(); + locationComponent.setCameraMode(cameraMode); + setRendererMode(renderMode); + locationComponent.forceLocationUpdate(lastLocation); } @Override @@ -153,10 +183,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea toggleMapStyle(); return true; } else if (id == R.id.action_component_disable) { - locationComponent.deactivateLocationComponent(); + locationComponent.setLocationComponentEnabled(false); return true; } else if (id == R.id.action_component_enabled) { - activateLocationComponent(); + locationComponent.setLocationComponentEnabled(true); return true; } else if (id == R.id.action_gestures_management_disabled) { disableGesturesManagement(); @@ -169,35 +199,6 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea return super.onOptionsItemSelected(item); } - private void activateLocationComponent() { - if (locationComponent != null) { - int[] padding; - if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { - padding = new int[] {0, 750, 0, 0}; - } else { - padding = new int[] {0, 250, 0, 0}; - } - - if (savedInstanceState == null) { - LocationComponentOptions options = LocationComponentOptions.builder(this) - .padding(padding) - .layerBelow("waterway-label") - .build(); - - locationComponent.activateLocationComponent(locationEngine, options); - } else { - LocationComponentOptions options = locationComponent - .getLocationComponentOptions() - .toBuilder() - .padding(padding) - .build(); - - locationComponent.setLocationEngine(locationEngine); - locationComponent.applyStyle(options); - } - } - } - private void toggleStyle() { customStyle = !customStyle; locationComponent.applyStyle( @@ -265,10 +266,16 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea } } + @SuppressLint("MissingPermission") @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); mapView.onSaveInstanceState(outState); + outState.putInt(SAVED_STATE_CAMERA, cameraMode); + outState.putInt(SAVED_STATE_RENDER, renderMode); + if (locationComponent != null) { + outState.putParcelable(SAVED_STATE_LOCATION, locationComponent.getLastKnownLocation()); + } } @Override @@ -299,7 +306,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea @Override public void onLocationComponentClick() { - Toast.makeText(this, "OnlocationComponentClick", Toast.LENGTH_LONG).show(); + Toast.makeText(this, "OnLocationComponentClick", Toast.LENGTH_LONG).show(); } private void showModeListDialog() { @@ -328,6 +335,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea } private void setRendererMode(@RenderMode.Mode int mode) { + renderMode = mode; locationComponent.setRenderMode(mode); if (mode == RenderMode.NORMAL) { locationModeBtn.setText("Normal"); @@ -392,6 +400,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea @Override public void onCameraTrackingChanged(int currentMode) { + this.cameraMode = currentMode; if (currentMode == CameraMode.NONE) { locationTrackingBtn.setText("None"); } else if (currentMode == CameraMode.TRACKING) { diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java index 5750e97d63..2651137273 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java @@ -120,6 +120,7 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements locationEngine.activate(); locationComponent = mapboxMap.getLocationComponent(); locationComponent.activateLocationComponent(this, locationEngine); + locationComponent.setLocationComponentEnabled(true); locationComponent.setRenderMode(RenderMode.COMPASS); } |