summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLangston Smith <langston.smith@mapbox.com>2019-03-05 11:05:06 -0800
committerGitHub <noreply@github.com>2019-03-05 11:05:06 -0800
commit7e4824960cfb414a3485310998d5761ac7abdef7 (patch)
treebd45eb3dea9f74729342714dfef91a740a333516
parentb29704cd1f19f03ac71ee7d308669135c6cfddcc (diff)
downloadqtlocation-mapboxgl-7e4824960cfb414a3485310998d5761ac7abdef7.tar.gz
[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
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java68
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java244
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java119
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt394
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt75
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml11
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java140
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt19
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java9
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java16
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml17
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml1
14 files changed, 984 insertions, 147 deletions
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 ddb211f8f6..aa3f95bca5 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
@@ -217,8 +217,10 @@ public final class LocationComponent {
*
* @param context the context
* @param style the proxy object for current map style. More info at {@link Style}
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style) {
activateLocationComponent(context, style,
LocationComponentOptions.createFromAttributes(context, R.style.mapbox_LocationComponent));
@@ -232,8 +234,10 @@ public final class LocationComponent {
* @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
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
boolean useDefaultLocationEngine) {
if (useDefaultLocationEngine) {
@@ -252,8 +256,10 @@ public final class LocationComponent {
* @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
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
boolean useDefaultLocationEngine,
@NonNull LocationEngineRequest locationEngineRequest) {
@@ -275,8 +281,10 @@ public final class LocationComponent {
* there should be no location engine initialized
* @param locationEngineRequest the location request
* @param options the options
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
boolean useDefaultLocationEngine,
@NonNull LocationEngineRequest locationEngineRequest,
@@ -298,8 +306,10 @@ public final class LocationComponent {
* @param context the context
* @param style the proxy object for current map style. More info at {@link Style}
* @param styleRes the LocationComponent style res
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style, @StyleRes int styleRes) {
activateLocationComponent(context, style, LocationComponentOptions.createFromAttributes(context, styleRes));
}
@@ -314,8 +324,10 @@ public final class LocationComponent {
* @param context the context
* @param style the proxy object for current map style. More info at {@link Style}
* @param options the options
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@NonNull LocationComponentOptions options) {
initialize(context, style, options);
@@ -331,8 +343,10 @@ public final class LocationComponent {
* @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 styleRes the LocationComponent style res
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine, @StyleRes int styleRes) {
activateLocationComponent(context, style, locationEngine,
@@ -348,8 +362,10 @@ public final class LocationComponent {
* @param locationEngine the engine, or null if you'd like to only force location updates
* @param locationEngineRequest the location request
* @param styleRes the LocationComponent style res
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine,
@NonNull LocationEngineRequest locationEngineRequest, @StyleRes int styleRes) {
@@ -363,8 +379,10 @@ public final class LocationComponent {
* @param context the context
* @param style the proxy object for current map style. More info at {@link Style}
* @param locationEngine the engine
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine) {
activateLocationComponent(context, style, locationEngine, R.style.mapbox_LocationComponent);
@@ -377,8 +395,10 @@ public final class LocationComponent {
* @param style the proxy object for current map style. More info at {@link Style}
* @param locationEngine the engine
* @param locationEngineRequest the location request
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine,
@NonNull LocationEngineRequest locationEngineRequest) {
@@ -392,8 +412,10 @@ public final class LocationComponent {
* @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
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine,
@NonNull LocationComponentOptions options) {
@@ -411,7 +433,9 @@ public final class LocationComponent {
* @param locationEngine the engine, or null if you'd like to only force location updates
* @param locationEngineRequest the location request
* @param options the options
+ * @deprecated use {@link LocationComponentActivationOptions.Builder} instead
*/
+ @Deprecated
public void activateLocationComponent(@NonNull Context context, @NonNull Style style,
@Nullable LocationEngine locationEngine,
@NonNull LocationEngineRequest locationEngineRequest,
@@ -423,6 +447,50 @@ 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 activationOptions a fully built {@link LocationComponentActivationOptions} object
+ */
+ public void activateLocationComponent(@NonNull LocationComponentActivationOptions
+ activationOptions) {
+ LocationComponentOptions options = activationOptions.locationComponentOptions();
+ if (options == null) {
+ int styleRes = activationOptions.styleRes();
+ if (styleRes == 0) {
+ styleRes = R.style.mapbox_LocationComponent;
+ }
+ options = LocationComponentOptions.createFromAttributes(activationOptions.context(), styleRes);
+ }
+
+ // Initialize the LocationComponent with Context, the map's `Style`, and either custom LocationComponentOptions
+ // or backup options created from default/custom attributes
+ initialize(activationOptions.context(), activationOptions.style(), options);
+
+ // Apply the LocationComponent styling
+ // TODO avoid doubling style initialization
+ applyStyle(options);
+
+ // Set the LocationEngine request if one was given to LocationComponentActivationOptions
+ LocationEngineRequest locationEngineRequest = activationOptions.locationEngineRequest();
+ if (locationEngineRequest != null) {
+ setLocationEngineRequest(locationEngineRequest);
+ }
+
+ // Set the LocationEngine if one was given to LocationComponentActivationOptions
+ LocationEngine locationEngine = activationOptions.locationEngine();
+ if (locationEngine != null) {
+ setLocationEngine(locationEngine);
+ } else {
+ if (activationOptions.useDefaultLocationEngine()) {
+ initializeLocationEngine(activationOptions.context());
+ } else {
+ setLocationEngine(null);
+ }
+ }
+ }
+
+ /**
* Manage component's visibility after activation.
*
* @param isEnabled true if the plugin should be visible and listen for location updates, false otherwise.
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
new file mode 100644
index 0000000000..3f71209d10
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptions.java
@@ -0,0 +1,244 @@
+package com.mapbox.mapboxsdk.location;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
+import com.mapbox.android.core.location.LocationEngine;
+import com.mapbox.android.core.location.LocationEngineRequest;
+import com.mapbox.mapboxsdk.maps.Style;
+
+/**
+ * A class which holds the various options for activating the Maps SDK's {@link LocationComponent} to eventually
+ * show the device location on the map.
+ */
+public class LocationComponentActivationOptions {
+
+ private final Context context;
+ private final Style style;
+ private final LocationEngine locationEngine;
+ private final LocationEngineRequest locationEngineRequest;
+ private final LocationComponentOptions locationComponentOptions;
+ private final int styleRes;
+ private final boolean useDefaultLocationEngine;
+
+ private LocationComponentActivationOptions(@NonNull Context context, @NonNull Style style,
+ @Nullable LocationEngine locationEngine,
+ @Nullable LocationEngineRequest locationEngineRequest,
+ @Nullable LocationComponentOptions locationComponentOptions,
+ int styleRes,
+ boolean useDefaultLocationEngine) {
+ this.context = context;
+ this.style = style;
+ this.locationEngine = locationEngine;
+ this.locationEngineRequest = locationEngineRequest;
+ this.locationComponentOptions = locationComponentOptions;
+ this.styleRes = styleRes;
+ this.useDefaultLocationEngine = useDefaultLocationEngine;
+ }
+
+ /**
+ * Convenience method to retrieve a {@link LocationComponentActivationOptions} object which is ready to build with
+ *
+ * @return a builder object
+ */
+ @NonNull
+ public static Builder builder(@NonNull Context context, @NonNull Style fullyLoadedMapStyle) {
+ return new LocationComponentActivationOptions.Builder(context, fullyLoadedMapStyle);
+ }
+
+ /**
+ * The application's current context
+ *
+ * @return the application's current context
+ */
+ @NonNull
+ public Context context() {
+ return context;
+ }
+
+ /**
+ * The proxy object for current map style. More info at {@link Style}
+ *
+ * @return the map's fully loaded Style object
+ */
+ @NonNull
+ public Style style() {
+ return style;
+ }
+
+ /**
+ * The {@link LocationEngine} which the {@link LocationComponent} should use
+ *
+ * @return the engine
+ */
+ @Nullable
+ public LocationEngine locationEngine() {
+ return locationEngine;
+ }
+
+ /**
+ * The location request which the {@link LocationComponent} should use
+ *
+ * @return the LocationEngineRequest object
+ */
+ @Nullable
+ public LocationEngineRequest locationEngineRequest() {
+ return locationEngineRequest;
+ }
+
+ /**
+ * A built {@link LocationComponentOptions} object, which holds the various {@link LocationComponent} styling options
+ *
+ * @return the options for styling the actual LocationComponent
+ */
+ @Nullable
+ public LocationComponentOptions locationComponentOptions() {
+ return locationComponentOptions;
+ }
+
+ /**
+ * The LocationComponent style resource (e.g. R.style.style_name)
+ *
+ * @return the style resource.
+ */
+ public int styleRes() {
+ return styleRes;
+ }
+
+ /**
+ * True if you want to initialize and use the built-in location engine or false if there should be no
+ * location engine initialized
+ *
+ * @return whether the default LocationEngine is used
+ */
+ public boolean useDefaultLocationEngine() {
+ return useDefaultLocationEngine;
+ }
+
+ /**
+ * Builder class for constructing a new instance of {@link LocationComponentActivationOptions}.
+ */
+ public static class Builder {
+ private final Context context;
+ private final Style style;
+ private LocationEngine locationEngine;
+ private LocationEngineRequest locationEngineRequest;
+ private LocationComponentOptions locationComponentOptions;
+ private int styleRes;
+
+ /**
+ * Set to true as the default in case a true/false value isn't declared via the builder's
+ * {@link LocationComponentActivationOptions#useDefaultLocationEngine()} method.
+ * <p>
+ * Please be aware that this activation boolean is ignored when a non-null
+ * {@link LocationEngine} is set via the builder's `locationEngine()` method.
+ */
+ private boolean useDefaultLocationEngine = true;
+
+ /**
+ * Constructor for the {@link LocationComponentActivationOptions} builder class.
+ * While other activation options are optional, the activation process always requires
+ * context and a fully-loaded map {@link Style} object, which is why the two are in this
+ * constructor.
+ */
+ public Builder(@NonNull Context context, @NonNull Style style) {
+ this.context = context;
+ this.style = style;
+ }
+
+ /**
+ * Deliver your own {@link LocationEngine} to the LocationComponent.
+ * <p>
+ * The true/false
+ * {@link LocationComponentActivationOptions#builder(Context, Style)#useDefaultLocationEngine}
+ * activation option is ignored when a non-null {@link LocationEngine} is set via
+ * this `locationEngine()` method.
+ *
+ * @param locationEngine a {@link LocationEngine} object
+ * @return the {@link Builder} object being constructed
+ */
+ @NonNull
+ public Builder locationEngine(@Nullable LocationEngine locationEngine) {
+ this.locationEngine = locationEngine;
+ return this;
+ }
+
+ /**
+ * @param locationEngineRequest the location request which the
+ * {@link LocationComponent} should use
+ * @return the {@link Builder} object being constructed
+ */
+ public Builder locationEngineRequest(LocationEngineRequest locationEngineRequest) {
+ this.locationEngineRequest = locationEngineRequest;
+ return this;
+ }
+
+ /**
+ * @param locationComponentOptions a built {@link LocationComponentOptions} object,
+ * which holds the various {@link LocationComponent}
+ * styling options
+ * @return the {@link Builder} object being constructed
+ */
+ public Builder locationComponentOptions(LocationComponentOptions locationComponentOptions) {
+ this.locationComponentOptions = locationComponentOptions;
+ return this;
+ }
+
+ /**
+ * @param styleRes the LocationComponent style resource (e.g. R.style.style_name)
+ * @return the {@link Builder} object being constructed
+ */
+ public Builder styleRes(int styleRes) {
+ this.styleRes = styleRes;
+ return this;
+ }
+
+ /**
+ * @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
+ * This is ignored when null is set as the parameter
+ * for {@link LocationComponentActivationOptions#builder
+ * (Context, Style)#locationEngine()}.
+ * @return the {@link Builder} object being constructed
+ */
+ public Builder useDefaultLocationEngine(boolean useDefaultLocationEngine) {
+ this.useDefaultLocationEngine = useDefaultLocationEngine;
+ return this;
+ }
+
+ /**
+ * Method which actually builds the {@link LocationComponentActivationOptions} object while
+ * taking the various options into account.
+ *
+ * @return a built {@link LocationComponentActivationOptions} object
+ */
+ public LocationComponentActivationOptions build() {
+ if (styleRes != 0 && locationComponentOptions != null) {
+ throw new IllegalArgumentException(
+ "You've provided both a style resource and a LocationComponentOptions object to the "
+ + "LocationComponentActivationOptions builder. You can't use both and "
+ + "you must choose one of the two to style the LocationComponent.");
+ }
+ if (context == null) {
+ throw new NullPointerException(
+ "Context in LocationComponentActivationOptions is null.");
+ }
+ if (style == null) {
+ throw new NullPointerException(
+ "Style in LocationComponentActivationOptions is null. Make sure the "
+ + "Style object isn't null. Wait for the map to fully load before passing "
+ + "the Style object to LocationComponentActivationOptions.");
+ }
+ if (!style.isFullyLoaded()) {
+ throw new IllegalArgumentException(
+ "Style in LocationComponentActivationOptions isn't fully loaded. Wait for the "
+ + "map to fully load before passing the Style object to "
+ + "LocationComponentActivationOptions.");
+ }
+ return new LocationComponentActivationOptions(context, style, locationEngine,
+ locationEngineRequest, locationComponentOptions, styleRes, useDefaultLocationEngine);
+ }
+ }
+} \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
new file mode 100644
index 0000000000..2660c819d4
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationComponentActivationOptionsTest.java
@@ -0,0 +1,119 @@
+package com.mapbox.mapboxsdk.location;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.support.annotation.NonNull;
+
+import com.mapbox.mapboxsdk.R;
+import com.mapbox.mapboxsdk.maps.Style;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnit;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.MockitoRule;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class LocationComponentActivationOptionsTest {
+
+ @Mock
+ private Context context;
+ @Mock
+ private TypedArray array;
+ @Mock
+ private Resources resources;
+ @Mock
+ private Style style;
+
+ @Rule
+ public MockitoRule mockitoRule = MockitoJUnit.rule();
+
+ @NonNull
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Before
+ public void setUp() throws Exception {
+ when(context.obtainStyledAttributes(R.style.mapbox_LocationComponent, R.styleable.mapbox_LocationComponent))
+ .thenReturn(array);
+ when(array.getResourceId(R.styleable.mapbox_LocationComponent_mapbox_foregroundDrawable, -1))
+ .thenReturn(R.drawable.mapbox_user_icon);
+ when(context.getResources()).thenReturn(resources);
+ }
+
+ @Test
+ public void sanity() throws Exception {
+ when(style.isFullyLoaded()).thenReturn(true);
+
+ LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
+ .accuracyAlpha(0.5f)
+ .build();
+ assertNotNull(locationComponentOptions);
+
+ LocationComponentActivationOptions locationComponentActivationOptions =
+ LocationComponentActivationOptions.builder(context, style)
+ .locationComponentOptions(locationComponentOptions)
+ .useDefaultLocationEngine(true)
+ .build();
+ assertNotNull(locationComponentActivationOptions);
+ }
+
+ @Test
+ public void includingBothStyleResAndComponentOptions_causesExceptionToBeThrown() throws Exception {
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("You've provided both a style resource and a LocationComponentOptions"
+ + " object to the LocationComponentActivationOptions builder. You can't use both and "
+ + "you must choose one of the two to style the LocationComponent.");
+
+ LocationComponentOptions locationComponentOptions = LocationComponentOptions.builder(context)
+ .accuracyAlpha(0.5f)
+ .build();
+
+ LocationComponentActivationOptions.builder(context, style)
+ .locationComponentOptions(locationComponentOptions)
+ .styleRes(R.style.mapbox_LocationComponent)
+ .build();
+ }
+
+ @Test
+ public void nullContext_causesExceptionToBeThrown() throws Exception {
+ thrown.expect(NullPointerException.class);
+ thrown.expectMessage("Context in LocationComponentActivationOptions is null.");
+
+ LocationComponentActivationOptions.builder(null, style)
+ .build();
+ }
+
+ @Test
+ public void nullStyle_causesExceptionToBeThrown() throws Exception {
+ thrown.expect(NullPointerException.class);
+ thrown.expectMessage("Style in LocationComponentActivationOptions is null. Make sure the Style object isn't null."
+ + " Wait for the map to fully load before passing the Style object to LocationComponentActivationOptions.");
+
+ LocationComponentActivationOptions.builder(context, null)
+ .build();
+ }
+
+ @Test
+ public void locationComponent_exceptionThrownWithDefaultLocationEngineButNotFullyLoadedStyle() throws Exception {
+
+ when(style.isFullyLoaded()).thenReturn(false);
+
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Style in LocationComponentActivationOptions isn't fully loaded. Wait for the "
+ + "map to fully load before passing the Style object to "
+ + "LocationComponentActivationOptions.");
+
+ LocationComponentActivationOptions.builder(context, style)
+ .build();
+ }
+} \ No newline at end of file
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 5fe4e03375..da06ba7173 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
@@ -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) {
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 199235c9ca..37b3e8b802 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
@@ -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)
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
index 22ae7f9824..a113fe1d6b 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/AndroidManifest.xml
@@ -862,6 +862,17 @@
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"
android:label="@string/activity_recyclerview">
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java
new file mode 100644
index 0000000000..927a624611
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationComponentActivationActivity.java
@@ -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();
+ }
+} \ No newline at end of file
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 d55a4f5fde..6a01d14249 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
@@ -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)
}
}
}
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 ea827dc4cd..e444c2fcfd 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
@@ -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);
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 11918669cb..28d165428d 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
@@ -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);
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 dc6bf8a8b7..5ca00e5d0f 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
@@ -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);
});
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml
new file mode 100644
index 0000000000..daae10ad03
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_location_layer_activation_builder.xml
@@ -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> \ No newline at end of file
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
index 7fdc4c1bea..14eb678795 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/descriptions.xml
@@ -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>
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
index 3345c8db4e..dc4fd89deb 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/titles.xml
@@ -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> \ No newline at end of file