diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index ddb211f8f60..a8cc9b1783b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -189,7 +189,7 @@ public LocationComponent(@NonNull MapboxMap mapboxMap) { @VisibleForTesting LocationComponent(@NonNull MapboxMap mapboxMap, - @NonNull LocationEngineCallback currentlistener, + @NonNull LocationEngineCallback currentListener, @NonNull LocationEngineCallback lastListener, @NonNull LocationLayerController locationLayerController, @NonNull LocationCameraController locationCameraController, @@ -198,7 +198,7 @@ public LocationComponent(@NonNull MapboxMap mapboxMap) { @NonNull CompassEngine compassEngine, @NonNull InternalLocationEngineProvider internalLocationEngineProvider) { this.mapboxMap = mapboxMap; - this.currentLocationEngineListener = currentlistener; + this.currentLocationEngineListener = currentListener; this.lastLocationEngineListener = lastListener; this.locationLayerController = locationLayerController; this.locationCameraController = locationCameraController; @@ -243,6 +243,27 @@ public void activateLocationComponent(@NonNull Context context, @NonNull Style s } } + /** + * This method initializes the component and needs to be called before any other operations are performed. + * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. + * + * @param context the context + * @param style the proxy object for current map style. More info at {@link Style} + * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if + * there should be no location engine initialized + * @param options the options for customizing the LocationComponent + */ + @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + public void activateLocationComponent(@NonNull Context context, @NonNull Style style, + boolean useDefaultLocationEngine, + @NonNull LocationComponentOptions options) { + if (useDefaultLocationEngine) { + activateLocationComponent(context, style, options); + } else { + activateLocationComponent(context, style, null, options); + } + } + /** * This method initializes the component and needs to be called before any other operations are performed. * Afterwards, you can manage component's visibility by {@link #setLocationComponentEnabled(boolean)}. @@ -274,7 +295,7 @@ public void activateLocationComponent(@NonNull Context context, @NonNull Style s * @param useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if * there should be no location engine initialized * @param locationEngineRequest the location request - * @param options the options + * @param options the options for customizing the LocationComponent */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @@ -313,7 +334,7 @@ public void activateLocationComponent(@NonNull Context context, @NonNull Style s * * @param context the context * @param style the proxy object for current map style. More info at {@link Style} - * @param options the options + * @param options the options for customizing the LocationComponent */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @@ -391,7 +412,7 @@ public void activateLocationComponent(@NonNull Context context, @NonNull Style s * * @param locationEngine the engine, or null if you'd like to only force location updates * @param style the proxy object for current map style. More info at {@link Style} - * @param options the options + * @param options the options for customizing the LocationComponent */ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @@ -410,7 +431,7 @@ public void activateLocationComponent(@NonNull Context context, @NonNull Style s * @param style the proxy object for current map style. More info at {@link Style} * @param locationEngine the engine, or null if you'd like to only force location updates * @param locationEngineRequest the location request - * @param options the options + * @param options the options for customizing the LocationComponent */ public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @Nullable LocationEngine locationEngine, diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt index 0f316fa4835..1928f692e17 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt @@ -104,6 +104,14 @@ class LocationComponentTest { Assert.assertNotNull(locationComponent.locationEngine) } + @Test + fun activateWithDefaultLocationEngineAndOptionsTestDefaultLocationEngine() { + locationComponent.activateLocationComponent(context, mockk(), true, locationComponentOptions) + Assert.assertNotNull(locationComponent.locationComponentOptions) + Assert.assertEquals(locationComponentOptions.foregroundName(), locationComponent.locationComponentOptions.foregroundName()) + Assert.assertEquals(locationComponentOptions.accuracyColor(), locationComponent.locationComponentOptions.accuracyColor()) + } + @Test fun activateWithDefaultLocationEngineRequestAndOptionsTestCustomLocationEngine() { locationComponent.activateLocationComponent(context, mockk(), false, locationEngineRequest, locationComponentOptions) @@ -111,6 +119,14 @@ class LocationComponentTest { Assert.assertNull(locationComponent.locationEngine) } + @Test + fun activateWithDefaultLocationEngineAndOptionsTestCustomLocationEngine() { + locationComponent.activateLocationComponent(context, mockk(), false, locationComponentOptions) + Assert.assertNotNull(locationComponent.locationComponentOptions) + Assert.assertEquals(locationComponentOptions.foregroundName(), locationComponent.locationComponentOptions.foregroundName()) + Assert.assertEquals(locationComponentOptions.accuracyColor(), locationComponent.locationComponentOptions.accuracyColor()) + } + @Test fun locationUpdatesWhenEnabledDisableTest() { locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)