Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

[android] Adding new variation of LocationComponent#activateLocationComponent #13909

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public LocationComponent(@NonNull MapboxMap mapboxMap) {

@VisibleForTesting
LocationComponent(@NonNull MapboxMap mapboxMap,
@NonNull LocationEngineCallback<LocationEngineResult> currentlistener,
@NonNull LocationEngineCallback<LocationEngineResult> currentListener,
@NonNull LocationEngineCallback<LocationEngineResult> lastListener,
@NonNull LocationLayerController locationLayerController,
@NonNull LocationCameraController locationCameraController,
Expand All @@ -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;
Expand Down Expand Up @@ -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)}.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,29 @@ 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)
Assert.assertEquals(locationEngineRequest, locationComponent.locationEngineRequest)
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)
Expand Down