From a2b49e9d22ad9c5bfb6a2ec05dc996be7c9449ea Mon Sep 17 00:00:00 2001 From: Langston Smith Date: Thu, 31 Jan 2019 07:20:25 -0800 Subject: [PATCH] [android] Adding new variation of LocationComponent#activateLocationComponent (#13829) * [android] added new activateLocationComponent method * [android] added new test for the new way to activate the LocationComponent * [android] tweak to test after lukasz review * [android] adding tests to assert LocationEngine status --- .../mapboxsdk/location/LocationComponent.java | 24 +++++++++++++++++++ .../location/LocationComponentTest.kt | 14 +++++++++++ 2 files changed, 38 insertions(+) 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 f27af0a51..ddb211f8f 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 @@ -265,6 +265,30 @@ public final class LocationComponent { } } + /** + * 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 locationEngineRequest the location request + * @param options the options + */ + @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION}) + public void activateLocationComponent(@NonNull Context context, @NonNull Style style, + boolean useDefaultLocationEngine, + @NonNull LocationEngineRequest locationEngineRequest, + @NonNull LocationComponentOptions options) { + setLocationEngineRequest(locationEngineRequest); + 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)}. 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 cf513068a..0f316fa48 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 @@ -97,6 +97,20 @@ class LocationComponentTest { Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest) } + @Test + fun activateWithDefaultLocationEngineRequestAndOptionsTestDefaultLocationEngine() { + locationComponent.activateLocationComponent(context, mockk(), true, locationEngineRequest, locationComponentOptions) + Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest) + Assert.assertNotNull(locationComponent.locationEngine) + } + + @Test + fun activateWithDefaultLocationEngineRequestAndOptionsTestCustomLocationEngine() { + locationComponent.activateLocationComponent(context, mockk(), false, locationEngineRequest, locationComponentOptions) + Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest) + Assert.assertNull(locationComponent.locationEngine) + } + @Test fun locationUpdatesWhenEnabledDisableTest() { locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)