summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-09-06 14:04:02 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-09-12 13:59:11 +0200
commitcaebcd08e3803f5758353fbadefc9b75093b4015 (patch)
tree5189e182b0d11c8271396a73a89ef6a892a3a009
parentd4a2123bec4289848a4a0634d2727e2d4c77f180 (diff)
downloadqtlocation-mapboxgl-caebcd08e3803f5758353fbadefc9b75093b4015.tar.gz
[android] LocationComponent - javadoc fixes, improved initialization, removed location save state
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java239
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java6
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java126
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationClickListener.java14
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentClickListener.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentLongClickListener.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationLongClickListener.java14
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationStaleListener.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/StaleStateManager.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java16
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/ZoomAnimator.java1
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/modes/RenderMode.java2
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java7
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java14
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt224
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt23
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt8
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java1
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java87
-rw-r--r--platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java1
21 files changed, 391 insertions, 423 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 c6b868f3da..0503c5e9dc 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
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.hardware.SensorManager;
import android.location.Location;
-import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresPermission;
@@ -34,15 +33,10 @@ import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION;
-import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOCATION_CAMERA_MODE;
-import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOCATION_ENABLED;
-import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOCATION_LAST_LOCATION;
-import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOCATION_OPTIONS;
-import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOCATION_RENDER_MODE;
/**
- * The Location layer plugin provides location awareness to your mobile application. Enabling this
- * plugin provides a contextual experience to your users by showing an icon representing the users
+ * The Location Component provides location awareness to your mobile application. Enabling this
+ * component provides a contextual experience to your users by showing an icon representing the users
* current location. A few different modes are offered to provide the right context to your users at
* the correct time. {@link RenderMode#NORMAL} simply shows the users location on the map
* represented as a dot. {@link RenderMode#COMPASS} mode allows you to display an arrow icon
@@ -50,32 +44,33 @@ import static com.mapbox.mapboxsdk.location.LocationComponentConstants.STATE_LOC
* {@link RenderMode#GPS} can be used in conjunction with our Navigation SDK to
* display a larger icon (customized with {@link LocationComponentOptions#gpsDrawable()}) we call the user puck.
* <p>
- * This plugin also offers the ability to set a map camera behavior for tracking the user
+ * This component also offers the ability to set a map camera behavior for tracking the user
* location. These different {@link CameraMode}s will track, stop tracking the location based on the
* mode set with {@link LocationComponent#setCameraMode(int)}.
* <p>
- * Lastly, {@link LocationComponent#setLocationComponentEnabled(boolean)} can be used
- * to disable the Location Layer but keep the instance around till the activity is destroyed.
+ * <strong>
+ * To get the component object use {@link MapboxMap#getLocationComponent()} and activate it with
+ * {@link #activateLocationComponent(Context)} or one of the overloads.
+ * Then, manage its visibility with {@link #setLocationComponentEnabled(boolean)}.
+ * </strong>
* <p>
- * Using this plugin requires you to request permission beforehand manually or using
+ * Using this component requires you to request permission beforehand manually or using
* {@link com.mapbox.android.core.permissions.PermissionsManager}. Either
* {@code ACCESS_COARSE_LOCATION} or {@code ACCESS_FINE_LOCATION} permissions can be requested and
* this plugin work as expected.
* <p>
- * When instantiating the plugin for the first time, the map's max/min zoom levels will be set to
+ * This component offers a default, built-in {@link LocationEngine} with some of the activation methods.
+ * This engine will be obtained by {@link LocationEngineProvider#obtainBestLocationEngineAvailable} which defaults
+ * to the {@link com.mapbox.android.core.location.AndroidLocationEngine}. If you'd like to utilize Google Play Services
+ * for more precise location updates, simply add the Google Play Location Services dependency in your build script.
+ * This will make the default engine the {@link com.mapbox.android.core.location.GoogleLocationEngine} instead.
+ * <p>
+ * When activating the component for the first time, the map's max/min zoom levels will be set to
* {@link LocationComponentOptions#MAX_ZOOM_DEFAULT} and {@link LocationComponentOptions#MIN_ZOOM_DEFAULT} respectively.
* You can adjust the zoom range with {@link LocationComponentOptions#maxZoom()} and
* {@link LocationComponentOptions#minZoom()}.
* <p>
- * When an activity, or a fragment, that contains the plugin is destroyed and recreated,
- * the plugin will restore its state, which is:
- * <br/>
- * - If the plugin was enabled, last location will be displayed.
- * You still need to activate the plugin, or just provide the {@link LocationEngine}.
- * <br/>
- * - {@link CameraMode} and {@link RenderMode} will be restored.
- * <br/>
- * - {@link LocationComponentOptions} will be restored.
+ * Location Component doesn't support state saving out-of-the-box.
*/
public final class LocationComponent {
private static final String TAG = "Mbgl-LocationComponent";
@@ -99,18 +94,20 @@ public final class LocationComponent {
private CameraPosition lastCameraPosition;
/**
- * Indicates that the plugin is enabled and should be displaying location if Mapbox components are available and
- * the lifecycle is in a resumed state.
+ * Indicates whether the component has been initialized.
+ */
+ private boolean isInitialized;
+
+ /**
+ * Indicates that the component is enabled and should be displaying location if Mapbox components are available and
+ * the lifecycle is in a started state.
*/
private boolean isEnabled;
/**
- * Indicated that plugin's lifecycle {@link #onStart()} method has been called or the plugin is initialized..
+ * Indicated that component's lifecycle {@link #onStart()} method has been called.
* This allows Mapbox components enter started state and display data, and adds state safety for methods like
* {@link #setLocationComponentEnabled(boolean)}
- * <p>
- * Initialized in a started state because the plugin can be instantiated after lifecycle's onStart() and
- * the developer might not register the lifecycle observer but call lifecycle methods manually instead.
*/
private boolean isComponentStarted;
@@ -123,44 +120,27 @@ public final class LocationComponent {
private StaleStateManager staleStateManager;
private final CopyOnWriteArrayList<OnLocationStaleListener> onLocationStaleListeners
= new CopyOnWriteArrayList<>();
- private final CopyOnWriteArrayList<OnLocationComponentClickListener> onLocationComponentClickListeners
+ private final CopyOnWriteArrayList<OnLocationClickListener> onLocationClickListeners
= new CopyOnWriteArrayList<>();
- private final CopyOnWriteArrayList<OnLocationComponentLongClickListener> onLocationComponentLongClickListeners
+ private final CopyOnWriteArrayList<OnLocationLongClickListener> onLocationLongClickListeners
= new CopyOnWriteArrayList<>();
private final CopyOnWriteArrayList<OnCameraTrackingChangedListener> onCameraTrackingChangedListeners
= new CopyOnWriteArrayList<>();
/**
- * Construct a LocationComponent. In order to display location,
- * the location layer has to be activated with {@link LocationComponent#activateLocationComponent(Context)},
- * or one of the overloads.
- *
- * @param mapboxMap the MapboxMap to apply the LocationComponent with
+ * Internal use.
+ * <p>
+ * To get the component object use {@link MapboxMap#getLocationComponent()}.
*/
- public LocationComponent(@NonNull Context context, @NonNull MapboxMap mapboxMap) {
+ public LocationComponent(@NonNull MapboxMap mapboxMap) {
this.mapboxMap = mapboxMap;
- options = LocationComponentOptions.createFromAttributes(context, R.style.mapbox_LocationComponent);
- initialize(context);
}
/**
- * This method will show or hide the location icon and enable or disable the camera
- * tracking the location.
- *
- * @param isEnabled true to show layers and enable camera, false otherwise
- */
- private void setLocationComponentEnabled(boolean isEnabled) {
- if (isEnabled) {
- enableLocationComponent();
- } else {
- disableLocationComponent();
- }
- }
-
- /**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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)}.
* <p>
- * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine} when enabled.
*
* @param context the context
*/
@@ -171,7 +151,8 @@ public final class LocationComponent {
}
/**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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 useDefaultLocationEngine true if you want to initialize and use the built-in location engine or false if
@@ -187,9 +168,10 @@ public final class LocationComponent {
}
/**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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)}.
* <p>
- * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine} when enabled.
*
* @param context the context
* @param styleRes the LocationComponent style res
@@ -200,9 +182,10 @@ public final class LocationComponent {
}
/**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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)}.
* <p>
- * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine}.
+ * <strong>Note</strong>: This method will initialize and use an internal {@link LocationEngine} when enabled.
* </p>
*
* @param context the context
@@ -210,13 +193,14 @@ public final class LocationComponent {
*/
@RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
public void activateLocationComponent(@NonNull Context context, @NonNull LocationComponentOptions options) {
- applyStyle(options);
+ initialize(context, options);
initializeLocationEngine(context);
- setLocationComponentEnabled(true);
+ applyStyle(options);
}
/**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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 locationEngine the engine, or null if you'd like to only force location updates
@@ -224,7 +208,8 @@ public final class LocationComponent {
*/
public void activateLocationComponent(@NonNull Context context, @Nullable LocationEngine locationEngine,
@StyleRes int styleRes) {
- activateLocationComponent(locationEngine, LocationComponentOptions.createFromAttributes(context, styleRes));
+ activateLocationComponent(context, locationEngine,
+ LocationComponentOptions.createFromAttributes(context, styleRes));
}
/**
@@ -238,23 +223,30 @@ public final class LocationComponent {
}
/**
- * This method will show the location icon and enable the camera tracking the location.
+ * 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 locationEngine the engine, or null if you'd like to only force location updates
* @param options the options
*/
- public void activateLocationComponent(@Nullable LocationEngine locationEngine,
+ public void activateLocationComponent(@NonNull Context context, @Nullable LocationEngine locationEngine,
@NonNull LocationComponentOptions options) {
+ initialize(context, options);
setLocationEngine(locationEngine);
applyStyle(options);
- setLocationComponentEnabled(true);
}
/**
- * This method will hide the location icon and disable the camera tracking the location.
+ * Manage component's visibility after activation.
+ *
+ * @param isEnabled true if the plugin should be visible and listen for location updates, false otherwise.
*/
- public void deactivateLocationComponent() {
- setLocationComponentEnabled(false);
+ public void setLocationComponentEnabled(boolean isEnabled) {
+ if (isEnabled) {
+ enableLocationComponent();
+ } else {
+ disableLocationComponent();
+ }
}
/**
@@ -288,8 +280,7 @@ public final class LocationComponent {
}
/**
- * Provides the current camera mode being used to track
- * the location or compass updates.
+ * Provides the current camera mode being used to track the location or compass updates.
*
* @return the current camera mode
*/
@@ -335,7 +326,7 @@ public final class LocationComponent {
}
/**
- * Apply a new LocationLayerController style with a style resource.
+ * Apply a new component style with a style resource.
*
* @param styleRes a XML style overriding some or all the options
*/
@@ -344,7 +335,7 @@ public final class LocationComponent {
}
/**
- * Apply a new LocationLayerController style with location layer options.
+ * Apply a new component style with location component options.
*
* @param options to update the current style
*/
@@ -486,10 +477,10 @@ public final class LocationComponent {
/**
* Set the location engine to update the current user location.
* <p>
- * If {@code null} is passed in, all updates will occur through the
+ * If {@code null} is passed in, all updates will have to occur through the
* {@link LocationComponent#forceLocationUpdate(Location)} method.
*
- * @param locationEngine a {@link LocationEngine} this plugin should use to handle updates
+ * @param locationEngine a {@link LocationEngine} this component should use to handle updates
*/
public void setLocationEngine(@Nullable LocationEngine locationEngine) {
if (this.locationEngine != null) {
@@ -513,9 +504,9 @@ public final class LocationComponent {
}
/**
- * Returns the current {@link LocationEngine} being used for updating the user location layer.
+ * Returns the current {@link LocationEngine} being used for updating the user location.
*
- * @return the {@link LocationEngine} being used to update the user location layer
+ * @return the {@link LocationEngine} being used to update the user location
*/
@Nullable
public LocationEngine getLocationEngine() {
@@ -544,7 +535,7 @@ public final class LocationComponent {
}
/**
- * Get the last know location of the location layer plugin.
+ * Get the last know location of the location component.
*
* @return the last known location
*/
@@ -559,7 +550,7 @@ public final class LocationComponent {
}
/**
- * Return the last known {@link CompassEngine} accuracy status of the location layer plugin.
+ * Return the last known {@link CompassEngine} accuracy status of the location component.
* <p>
* The last known accuracy of the compass sensor, one of SensorManager.SENSOR_STATUS_*
*
@@ -591,13 +582,13 @@ public final class LocationComponent {
}
/**
- * Adds a listener that gets invoked when the user clicks the location layer.
+ * Adds a listener that gets invoked when the user clicks the displayed location.
*
- * @param listener The location layer click listener that is invoked when the
- * location layer is clicked
+ * @param listener The location click listener that is invoked when the
+ * location is clicked
*/
- public void addOnLocationClickListener(@NonNull OnLocationComponentClickListener listener) {
- onLocationComponentClickListeners.add(listener);
+ public void addOnLocationClickListener(@NonNull OnLocationClickListener listener) {
+ onLocationClickListeners.add(listener);
}
/**
@@ -605,18 +596,18 @@ public final class LocationComponent {
*
* @param listener to be removed
*/
- public void removeOnLocationClickListener(@NonNull OnLocationComponentClickListener listener) {
- onLocationComponentClickListeners.remove(listener);
+ public void removeOnLocationClickListener(@NonNull OnLocationClickListener listener) {
+ onLocationClickListeners.remove(listener);
}
/**
- * Adds a listener that gets invoked when the user long clicks the location layer.
+ * Adds a listener that gets invoked when the user long clicks the displayed location.
*
- * @param listener The location layer click listener that is invoked when the
- * location layer is clicked
+ * @param listener The location click listener that is invoked when the
+ * location is clicked
*/
- public void addOnLocationLongClickListener(@NonNull OnLocationComponentLongClickListener listener) {
- onLocationComponentLongClickListeners.add(listener);
+ public void addOnLocationLongClickListener(@NonNull OnLocationLongClickListener listener) {
+ onLocationLongClickListeners.add(listener);
}
/**
@@ -624,8 +615,8 @@ public final class LocationComponent {
*
* @param listener to be removed
*/
- public void removeOnLocationLongClickListener(@NonNull OnLocationComponentLongClickListener listener) {
- onLocationComponentLongClickListeners.remove(listener);
+ public void removeOnLocationLongClickListener(@NonNull OnLocationLongClickListener listener) {
+ onLocationLongClickListeners.remove(listener);
}
/**
@@ -686,28 +677,6 @@ public final class LocationComponent {
/**
* Internal use.
*/
- public void onSaveInstanceState(@NonNull Bundle outState) {
- outState.putBoolean(STATE_LOCATION_ENABLED, isEnabled);
- outState.putParcelable(STATE_LOCATION_OPTIONS, options);
- outState.putInt(STATE_LOCATION_RENDER_MODE, locationLayerController.getRenderMode());
- outState.putInt(STATE_LOCATION_CAMERA_MODE, locationCameraController.getCameraMode());
- outState.putParcelable(STATE_LOCATION_LAST_LOCATION, lastLocation);
- }
-
- /**
- * Internal use.
- */
- public void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
- updateLocation(savedInstanceState.getParcelable(STATE_LOCATION_LAST_LOCATION), true);
- setCameraMode(savedInstanceState.getInt(STATE_LOCATION_CAMERA_MODE));
- setRenderMode(savedInstanceState.getInt(STATE_LOCATION_RENDER_MODE));
- applyStyle(savedInstanceState.getParcelable(STATE_LOCATION_OPTIONS));
- setLocationComponentEnabled(savedInstanceState.getBoolean(STATE_LOCATION_ENABLED));
- }
-
- /**
- * Internal use.
- */
public void onDestroy() {
if (locationEngine != null && usingInternalLocationEngine) {
locationEngine.deactivate();
@@ -725,23 +694,23 @@ public final class LocationComponent {
* Internal use.
*/
public void onFinishLoadingStyle() {
- locationLayerController.initializeComponents(options);
- locationCameraController.initializeOptions(options);
+ if (isInitialized) {
+ locationLayerController.initializeComponents(options);
+ locationCameraController.initializeOptions(options);
+ }
onLocationLayerStart();
}
@SuppressLint("MissingPermission")
private void onLocationLayerStart() {
- if (!isComponentStarted) {
+ if (!isInitialized || !isComponentStarted) {
return;
}
if (!isLayerReady) {
isLayerReady = true;
- if (mapboxMap != null) {
- mapboxMap.addOnCameraMoveListener(onCameraMoveListener);
- mapboxMap.addOnCameraIdleListener(onCameraIdleListener);
- }
+ mapboxMap.addOnCameraMoveListener(onCameraMoveListener);
+ mapboxMap.addOnCameraIdleListener(onCameraIdleListener);
if (options.enableStaleState()) {
staleStateManager.onStart();
}
@@ -762,7 +731,7 @@ public final class LocationComponent {
}
private void onLocationLayerStop() {
- if (!isLayerReady || !isComponentStarted) {
+ if (!isInitialized || !isLayerReady || !isComponentStarted) {
return;
}
@@ -777,13 +746,17 @@ public final class LocationComponent {
}
locationEngine.removeLocationEngineListener(locationEngineListener);
}
- if (mapboxMap != null) {
- mapboxMap.removeOnCameraMoveListener(onCameraMoveListener);
- mapboxMap.removeOnCameraIdleListener(onCameraIdleListener);
- }
+ mapboxMap.removeOnCameraMoveListener(onCameraMoveListener);
+ mapboxMap.removeOnCameraIdleListener(onCameraIdleListener);
}
- private void initialize(@NonNull Context context) {
+ private void initialize(@NonNull Context context, @NonNull LocationComponentOptions options) {
+ if (isInitialized) {
+ return;
+ }
+ isInitialized = true;
+ this.options = options;
+
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
mapboxMap.addOnMapClickListener(onMapClickListener);
@@ -810,6 +783,8 @@ public final class LocationComponent {
setRenderMode(RenderMode.NORMAL);
setCameraMode(CameraMode.NONE);
+
+ onLocationLayerStart();
}
private void initializeLocationEngine(@NonNull Context context) {
@@ -936,8 +911,8 @@ public final class LocationComponent {
private OnMapClickListener onMapClickListener = new OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
- if (!onLocationComponentClickListeners.isEmpty() && locationLayerController.onMapClick(point)) {
- for (OnLocationComponentClickListener listener : onLocationComponentClickListeners) {
+ if (!onLocationClickListeners.isEmpty() && locationLayerController.onMapClick(point)) {
+ for (OnLocationClickListener listener : onLocationClickListeners) {
listener.onLocationComponentClick();
}
}
@@ -947,8 +922,8 @@ public final class LocationComponent {
private MapboxMap.OnMapLongClickListener onMapLongClickListener = new MapboxMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(@NonNull LatLng point) {
- if (!onLocationComponentLongClickListeners.isEmpty() && locationLayerController.onMapClick(point)) {
- for (OnLocationComponentLongClickListener listener : onLocationComponentLongClickListeners) {
+ if (!onLocationLongClickListeners.isEmpty() && locationLayerController.onMapClick(point)) {
+ for (OnLocationLongClickListener listener : onLocationLongClickListeners) {
listener.onLocationComponentLongClick();
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java
index 854170d617..40aae5bb6f 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java
@@ -5,12 +5,6 @@ package com.mapbox.mapboxsdk.location;
*/
final class LocationComponentConstants {
- static final String STATE_LOCATION_ENABLED = "mapbox_location_locationEnabled";
- static final String STATE_LOCATION_OPTIONS = "mapbox_location_options";
- static final String STATE_LOCATION_LAST_LOCATION = "mapbox_location_lastLocation";
- static final String STATE_LOCATION_RENDER_MODE = "mapbox_location_renderMode";
- static final String STATE_LOCATION_CAMERA_MODE = "mapbox_location_cameraMode";
-
// Controls the compass update rate in milliseconds
static final int COMPASS_UPDATE_RATE_MS = 500;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
index fcca4764d4..584d214f6e 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java
@@ -19,11 +19,11 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import java.util.Arrays;
/**
- * This class exposes options for the Location Layer Plugin. The options can be set by defining a
+ * This class exposes options for the Location Component. The options can be set by defining a
* style in your apps style.xml file and passing in directly into the {@link LocationComponent}
* class. Alternatively, if properties need to be changed at runtime depending on a specific state,
* you can build an instance of this class, setting the values you desire, and then passing it into
- * either the {@link LocationComponent} constructor (if it isn't initialized yet) or
+ * either the {@link LocationComponent} activation method (if it isn't initialized yet) or
* {@link LocationComponent#applyStyle(LocationComponentOptions)}.
* <p>
* When the {@link #createFromAttributes(Context, int)} methods called, any attributes not found
@@ -35,7 +35,7 @@ import java.util.Arrays;
* get the currently used options object using {@link LocationComponent#getLocationComponentOptions()}
* and it's {@code toBuilder} method to modify a single entry while also maintaining the other
* settings. Once your modifications have been made, you'll need to pass it back into the location
- * layer plugin using {@link LocationComponent#applyStyle(LocationComponentOptions)}.
+ * component using {@link LocationComponent#applyStyle(LocationComponentOptions)}.
*/
public class LocationComponentOptions implements Parcelable {
@@ -72,7 +72,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* The default value which is used when the stale state is enabled
*/
- private static final long STALE_STATE_DELAY_MS = 30000;
+ private static final long STALE_STATE_DELAY_MS = 30_000L;
private float accuracyAlpha;
private int accuracyColor;
@@ -175,7 +175,7 @@ public class LocationComponentOptions implements Parcelable {
}
/**
- * Construct a new Location Layer Options class using the attributes found within a style
+ * Construct a new Location Component Options class using the attributes found within a style
* resource. It's important to note that you only need to define the attributes you plan to
* change and can safely ignore the other attributes which will be set to their default value.
*
@@ -300,8 +300,7 @@ public class LocationComponentOptions implements Parcelable {
* with all the values set matching the values in this instance. This allows you to modify a
* single attribute and then rebuild the object.
*
- * @return the Location Layer builder which contains the values defined in this current instance
- * as defaults.
+ * @return the builder which contains the values defined in this current instance as defaults.
*/
public Builder toBuilder() {
return new Builder(this);
@@ -313,8 +312,7 @@ public class LocationComponentOptions implements Parcelable {
* attributes while leaving the rest alone and maintaining their default behavior.
*
* @param context your activities context used to acquire the style resource
- * @return the Location Layer builder which contains the default values defined by the style
- * resource
+ * @return the builder which contains the default values defined by the style resource
*/
public static Builder builder(Context context) {
return LocationComponentOptions.createFromAttributes(context,
@@ -326,7 +324,7 @@ public class LocationComponentOptions implements Parcelable {
* completely transparent and 1 means the view is completely opaque.
*
* @return the opacity of the accuracy view
- * @attr ref R.styleable#LocationLayer_accuracyAlpha
+ * @attr ref R.styleable#LocationComponent_accuracyAlpha
*/
public float accuracyAlpha() {
return accuracyAlpha;
@@ -336,7 +334,7 @@ public class LocationComponentOptions implements Parcelable {
* Solid color to use as the accuracy view color property.
*
* @return the color of the accuracy view
- * @attr ref R.styleable#LocationLayer_accuracyColor
+ * @attr ref R.styleable#LocationComponent_accuracyColor
*/
@ColorInt
public int accuracyColor() {
@@ -347,7 +345,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the drawable used for the stale background icon.
*
* @return the drawable resource ID
- * @attr ref R.styleable#LocationLayer_backgroundDrawableStale
+ * @attr ref R.styleable#LocationComponent_backgroundDrawableStale
*/
@DrawableRes
public int backgroundDrawableStale() {
@@ -357,7 +355,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_foregroundDrawableStale.
+ * component, will use this image in place of the provided or default mapbox_foregroundDrawableStale.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -374,7 +372,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the drawable used for the stale foreground icon.
*
* @return the drawable resource ID
- * @attr ref R.styleable#LocationLayer_foregroundDrawableStale
+ * @attr ref R.styleable#LocationComponent_foregroundDrawableStale
*/
@DrawableRes
public int foregroundDrawableStale() {
@@ -384,7 +382,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_foregroundDrawableStale.
+ * component, will used this image in place of the provided or default mapbox_foregroundDrawableStale.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -401,7 +399,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the drawable used for the navigation state icon.
*
* @return the drawable resource ID
- * @attr ref R.styleable#LocationLayer_gpsDrawable
+ * @attr ref R.styleable#LocationComponent_gpsDrawable
*/
@DrawableRes
public int gpsDrawable() {
@@ -411,7 +409,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_gpsDrawable.
+ * component, will used this image in place of the provided or default mapbox_gpsDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -425,11 +423,10 @@ public class LocationComponentOptions implements Parcelable {
}
/**
- * Supply a Drawable that is to be rendered on top of all of the content in the Location Layer
- * Plugin layer stack.
+ * Supply a Drawable that is to be rendered on top of all of the content in the Location LayerComponent layer stack.
*
* @return the drawable resource used for the foreground layer
- * @attr ref R.styleable#LocationLayer_foregroundDrawable
+ * @attr ref R.styleable#LocationComponent_foregroundDrawable
*/
@DrawableRes
public int foregroundDrawable() {
@@ -439,7 +436,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_foregroundDrawable.
+ * component, will used this image in place of the provided or default mapbox_foregroundDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -456,7 +453,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the drawable used for the background state icon.
*
* @return the drawable resource ID
- * @attr ref R.styleable#LocationLayer_backgroundDrawable
+ * @attr ref R.styleable#LocationComponent_backgroundDrawable
*/
@DrawableRes
public int backgroundDrawable() {
@@ -466,7 +463,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_backgroundDrawable.
+ * component, will used this image in place of the provided or default mapbox_backgroundDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -483,7 +480,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the drawable used for the bearing icon.
*
* @return the drawable resource ID
- * @attr ref R.styleable#LocationLayer_bearingDrawable
+ * @attr ref R.styleable#LocationComponent_bearingDrawable
*/
@DrawableRes
public int bearingDrawable() {
@@ -493,7 +490,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_bearingDrawable.
+ * component, will used this image in place of the provided or default mapbox_bearingDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -510,7 +507,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the bearing icon color as an integer.
*
* @return the color integer resource
- * @attr ref R.styleable#LocationLayer_bearingTintColor
+ * @attr ref R.styleable#LocationComponent_bearingTintColor
*/
@ColorInt
@Nullable
@@ -522,7 +519,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the foreground color as an integer.
*
* @return the color integer resource
- * @attr ref R.styleable#LocationLayer_foregroundTintColor
+ * @attr ref R.styleable#LocationComponent_foregroundTintColor
*/
@ColorInt
@Nullable
@@ -534,7 +531,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the background color as an integer.
*
* @return the color integer resource
- * @attr ref R.styleable#LocationLayer_backgroundTintColor
+ * @attr ref R.styleable#LocationComponent_backgroundTintColor
*/
@ColorInt
@Nullable
@@ -546,7 +543,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the foreground stale color as an integer.
*
* @return the color integer resource
- * @attr ref R.styleable#LocationLayer_foregroundStaleTintColor
+ * @attr ref R.styleable#LocationComponent_foregroundStaleTintColor
*/
@ColorInt
@Nullable
@@ -558,7 +555,7 @@ public class LocationComponentOptions implements Parcelable {
* Defines the background stale color as an integer.
*
* @return the color integer resource
- * @attr ref R.styleable#LocationLayer_backgroundStaleTintColor
+ * @attr ref R.styleable#LocationComponent_backgroundStaleTintColor
*/
@ColorInt
@Nullable
@@ -569,8 +566,8 @@ public class LocationComponentOptions implements Parcelable {
/**
* Sets the base elevation of this view, in pixels.
*
- * @return the elevation currently set for the location layer icon
- * @attr ref R.styleable#LocationLayer_elevation
+ * @return the elevation currently set for the location component icon
+ * @attr ref R.styleable#LocationComponent_elevation
*/
@Dimension
public float elevation() {
@@ -582,7 +579,7 @@ public class LocationComponentOptions implements Parcelable {
* displayed on the map hasn't been updated in a specific amount of time.
*
* @return whether the stale state mode is enabled or not
- * @attr ref R.styleable#LocationLayer_enableStaleState
+ * @attr ref R.styleable#LocationComponent_enableStaleState
*/
public boolean enableStaleState() {
return enableStaleState;
@@ -593,9 +590,9 @@ public class LocationComponentOptions implements Parcelable {
* location update comes in and using this defined time, if an update hasn't occured by the end,
* the location is considered stale.
*
- * @return the duration in milliseconds which it should take before the location layer is
+ * @return the duration in milliseconds which it should take before the location is
* considered stale
- * @attr ref R.styleable#LocationLayer_staleStateDelay
+ * @attr ref R.styleable#LocationComponent_staleStateDelay
*/
public long staleStateTimeout() {
return staleStateTimeout;
@@ -694,9 +691,9 @@ public class LocationComponentOptions implements Parcelable {
}
/**
- * Gets the id of the layer to add the location layer above to.
+ * Gets the id of the layer to add the location component above to.
*
- * @return layerBelow the id of the layer to add the location layer above to
+ * @return layerBelow the id of the layer to add the location component above to
*/
public String layerBelow() {
return layerBelow;
@@ -1099,7 +1096,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param accuracyAlpha the opacity of the accuracy view
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_accuracyAlpha
+ * @attr ref R.styleable#LocationComponent_accuracyAlpha
*/
public LocationComponentOptions.Builder accuracyAlpha(float accuracyAlpha) {
this.accuracyAlpha = accuracyAlpha;
@@ -1111,7 +1108,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param accuracyColor the color of the accuracy view
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_accuracyColor
+ * @attr ref R.styleable#LocationComponent_accuracyColor
*/
public LocationComponentOptions.Builder accuracyColor(int accuracyColor) {
this.accuracyColor = accuracyColor;
@@ -1123,7 +1120,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param backgroundDrawableStale the drawable resource ID
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_backgroundDrawableStale
+ * @attr ref R.styleable#LocationComponent_backgroundDrawableStale
*/
public LocationComponentOptions.Builder backgroundDrawableStale(int backgroundDrawableStale) {
this.backgroundDrawableStale = backgroundDrawableStale;
@@ -1133,7 +1130,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_backgroundDrawableStale.
+ * component, will used this image in place of the provided or default mapbox_backgroundDrawableStale.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1152,7 +1149,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param foregroundDrawableStale the drawable resource ID
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_foregroundDrawableStale
+ * @attr ref R.styleable#LocationComponent_foregroundDrawableStale
*/
public LocationComponentOptions.Builder foregroundDrawableStale(int foregroundDrawableStale) {
this.foregroundDrawableStale = foregroundDrawableStale;
@@ -1162,7 +1159,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_foregroundDrawableStale.
+ * component, will used this image in place of the provided or default mapbox_foregroundDrawableStale.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1181,7 +1178,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param gpsDrawable the drawable resource ID
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_gpsDrawable
+ * @attr ref R.styleable#LocationComponent_gpsDrawable
*/
public LocationComponentOptions.Builder gpsDrawable(int gpsDrawable) {
this.gpsDrawable = gpsDrawable;
@@ -1191,7 +1188,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_gpsDrawable.
+ * component, will used this image in place of the provided or default mapbox_gpsDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1206,12 +1203,11 @@ public class LocationComponentOptions implements Parcelable {
}
/**
- * Supply a Drawable that is to be rendered on top of all of the content in the Location Layer
- * Plugin layer stack.
+ * Supply a Drawable that is to be rendered on top of all of the content in the Location Component layer stack.
*
* @param foregroundDrawable the drawable resource used for the foreground layer
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_foregroundDrawable
+ * @attr ref R.styleable#LocationComponent_foregroundDrawable
*/
public LocationComponentOptions.Builder foregroundDrawable(int foregroundDrawable) {
this.foregroundDrawable = foregroundDrawable;
@@ -1221,7 +1217,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_foregroundDrawable.
+ * component, will used this image in place of the provided or default mapbox_foregroundDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1240,7 +1236,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param backgroundDrawable the drawable resource ID
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_backgroundDrawable
+ * @attr ref R.styleable#LocationComponent_backgroundDrawable
*/
public LocationComponentOptions.Builder backgroundDrawable(int backgroundDrawable) {
this.backgroundDrawable = backgroundDrawable;
@@ -1250,7 +1246,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_backgroundDrawable.
+ * component, will used this image in place of the provided or default mapbox_backgroundDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1269,7 +1265,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param bearingDrawable the drawable resource ID
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_bearingDrawable
+ * @attr ref R.styleable#LocationComponent_bearingDrawable
*/
public LocationComponentOptions.Builder bearingDrawable(int bearingDrawable) {
this.bearingDrawable = bearingDrawable;
@@ -1279,7 +1275,7 @@ public class LocationComponentOptions implements Parcelable {
/**
* Given a String image name, identical to one used in
* the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the
- * plugin, will used this image in place of the provided or default mapbox_bearingDrawable.
+ * component, will used this image in place of the provided or default mapbox_bearingDrawable.
* <p>
* A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded
* with certain styles. Note, this will fail if the provided icon name is not provided by the loaded map style.
@@ -1298,7 +1294,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param bearingTintColor the color integer resource
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_bearingTintColor
+ * @attr ref R.styleable#LocationComponent_bearingTintColor
*/
public LocationComponentOptions.Builder bearingTintColor(@Nullable Integer bearingTintColor) {
this.bearingTintColor = bearingTintColor;
@@ -1310,7 +1306,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param foregroundTintColor the color integer resource
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_foregroundTintColor
+ * @attr ref R.styleable#LocationComponent_foregroundTintColor
*/
public LocationComponentOptions.Builder foregroundTintColor(@Nullable Integer foregroundTintColor) {
this.foregroundTintColor = foregroundTintColor;
@@ -1322,7 +1318,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param backgroundTintColor the color integer resource
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_backgroundTintColor
+ * @attr ref R.styleable#LocationComponent_backgroundTintColor
*/
public LocationComponentOptions.Builder backgroundTintColor(@Nullable Integer backgroundTintColor) {
this.backgroundTintColor = backgroundTintColor;
@@ -1334,7 +1330,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param foregroundStaleTintColor the color integer resource
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_foregroundStaleTintColor
+ * @attr ref R.styleable#LocationComponent_foregroundStaleTintColor
*/
public LocationComponentOptions.Builder foregroundStaleTintColor(@Nullable Integer foregroundStaleTintColor) {
this.foregroundStaleTintColor = foregroundStaleTintColor;
@@ -1346,7 +1342,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param backgroundStaleTintColor the color integer resource
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_backgroundStaleTintColor
+ * @attr ref R.styleable#LocationComponent_backgroundStaleTintColor
*/
public LocationComponentOptions.Builder backgroundStaleTintColor(@Nullable Integer backgroundStaleTintColor) {
this.backgroundStaleTintColor = backgroundStaleTintColor;
@@ -1356,9 +1352,9 @@ public class LocationComponentOptions implements Parcelable {
/**
* Sets the base elevation of this view, in pixels.
*
- * @param elevation the elevation currently set for the location layer icon
+ * @param elevation the elevation currently set for the location icon
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_elevation
+ * @attr ref R.styleable#LocationComponent_elevation
*/
public LocationComponentOptions.Builder elevation(float elevation) {
this.elevation = elevation;
@@ -1371,7 +1367,7 @@ public class LocationComponentOptions implements Parcelable {
*
* @param enabled whether the stale state mode is enabled or not
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_enableStaleState
+ * @attr ref R.styleable#LocationComponent_enableStaleState
*/
public LocationComponentOptions.Builder enableStaleState(boolean enabled) {
this.enableStaleState = enabled;
@@ -1383,10 +1379,10 @@ public class LocationComponentOptions implements Parcelable {
* new location update comes in and using this defined time, if an update hasn't occurred by the
* end, the location is considered stale.
*
- * @param timeout the duration in milliseconds which it should take before the location layer is
+ * @param timeout the duration in milliseconds which it should take before the location is
* considered stale
* @return this builder for chaining options together
- * @attr ref R.styleable#LocationLayer_staleStateTimeout
+ * @attr ref R.styleable#LocationComponent_staleStateTimeout
*/
public LocationComponentOptions.Builder staleStateTimeout(long timeout) {
this.staleStateTimeout = timeout;
@@ -1506,9 +1502,9 @@ public class LocationComponentOptions implements Parcelable {
}
/**
- * Sets the layer id to set the location layer plugin below to.
+ * Sets the layer id to set the location component below to.
*
- * @param layerBelow the id to set the location layer plugin below to.
+ * @param layerBelow the id to set the location component below to.
*/
public LocationComponentOptions.Builder layerBelow(String layerBelow) {
this.layerBelow = layerBelow;
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationClickListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationClickListener.java
new file mode 100644
index 0000000000..fdd2aeb811
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationClickListener.java
@@ -0,0 +1,14 @@
+package com.mapbox.mapboxsdk.location;
+
+/**
+ * The Location Component exposes an API for listening to when the user clicks on the location
+ * layer icon visible on the map. When this event occurs, the {@link #onLocationComponentClick()} method
+ * gets invoked.
+ */
+public interface OnLocationClickListener {
+
+ /**
+ * Called whenever user clicks on the location layer drawn on the map.
+ */
+ void onLocationComponentClick();
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentClickListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentClickListener.java
deleted file mode 100644
index c592ae3a25..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentClickListener.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.mapbox.mapboxsdk.location;
-
-/**
- * The Location Layer Plugin exposes an API for listening to when the user clicks on the location
- * layer icon visible on the map. when this event occurs, the {@link #onLocationComponentClick()} method
- * gets invoked.
- */
-public interface OnLocationComponentClickListener {
-
- void onLocationComponentClick();
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentLongClickListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentLongClickListener.java
deleted file mode 100644
index dc63e48a58..0000000000
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationComponentLongClickListener.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.mapbox.mapboxsdk.location;
-
-/**
- * The Location Layer Plugin exposes an API for listening to when the user long clicks on the location
- * layer icon visible on the map. when this event occurs, the {@link #onLocationComponentLongClick()} method
- * gets invoked.
- */
-public interface OnLocationComponentLongClickListener {
-
- void onLocationComponentLongClick();
-}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationLongClickListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationLongClickListener.java
new file mode 100644
index 0000000000..0c34614f3e
--- /dev/null
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationLongClickListener.java
@@ -0,0 +1,14 @@
+package com.mapbox.mapboxsdk.location;
+
+/**
+ * The Location Component exposes an API for listening to when the user long clicks on the location
+ * layer icon visible on the map. when this event occurs, the {@link #onLocationComponentLongClick()} method
+ * gets invoked.
+ */
+public interface OnLocationLongClickListener {
+
+ /**
+ * Called whenever user long clicks on the location layer drawn on the map.
+ */
+ void onLocationComponentLongClick();
+}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationStaleListener.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationStaleListener.java
index d42eddf277..6bbe7f34b3 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationStaleListener.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/OnLocationStaleListener.java
@@ -9,5 +9,9 @@ package com.mapbox.mapboxsdk.location;
*/
public interface OnLocationStaleListener {
+ /**
+ * Called when the stale state changes.
+ * @param isStale true if location is stale, false otherwise
+ */
void onStaleStateChange(boolean isStale);
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/StaleStateManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/StaleStateManager.java
index c2d50610fa..c8f6ed58b9 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/StaleStateManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/StaleStateManager.java
@@ -3,9 +3,9 @@ package com.mapbox.mapboxsdk.location;
import android.os.Handler;
/**
- * Class controls the location layer stale state when the {@link android.location.Location} hasn't
+ * Class controls the location stale state when the {@link android.location.Location} hasn't
* been updated in 'x' amount of time. {@link LocationComponentOptions#staleStateTimeout()} can be used to
- * control the amount of time before the locations considered stale.
+ * control the amount of time before the location's considered stale.
* {@link LocationComponentOptions#enableStaleState()} is available for disabling this behaviour.
*/
class StaleStateManager {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
index aa01c914dd..ff0a9ce193 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/Utils.java
@@ -23,20 +23,20 @@ public final class Utils {
}
/**
- * Util for finding the shortest path from the current icon rotated degree to the new degree.
+ * Util for finding the shortest path from the current rotated degree to the new degree.
*
- * @param magneticHeading the new position of the rotation
- * @param previousMagneticHeading the current position of the rotation
+ * @param heading the new position of the rotation
+ * @param previousHeading the current position of the rotation
* @return the shortest degree of rotation possible
*/
- public static float shortestRotation(float magneticHeading, float previousMagneticHeading) {
- double diff = previousMagneticHeading - magneticHeading;
+ public static float shortestRotation(float heading, float previousHeading) {
+ double diff = previousHeading - heading;
if (diff > 180.0f) {
- magneticHeading += 360.0f;
+ heading += 360.0f;
} else if (diff < -180.0f) {
- magneticHeading -= 360.f;
+ heading -= 360.f;
}
- return magneticHeading;
+ return heading;
}
static Bitmap getBitmapFromDrawable(Drawable drawable) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/ZoomAnimator.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/ZoomAnimator.java
index 204a1457dc..323b51fa88 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/ZoomAnimator.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/ZoomAnimator.java
@@ -25,5 +25,4 @@ class ZoomAnimator extends MapboxCameraAnimatorAdapter {
listener.onNewZoomValue((Float) animation.getAnimatedValue());
}
}
-
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/modes/RenderMode.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/modes/RenderMode.java
index 0f7fa24008..3d20313dfe 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/modes/RenderMode.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/modes/RenderMode.java
@@ -19,7 +19,7 @@ public final class RenderMode {
/**
* One of these constants should be used with {@link LocationComponent#setRenderMode(int)}.
- * mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing
+ * Mode can be switched at anytime by calling the {@code setLocationLayerMode} method passing
* in the new mode you'd like the location layer to be in.
*/
@IntDef( {COMPASS, GPS, NORMAL})
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
index 60cf9bb31d..73495f78e7 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java
@@ -200,7 +200,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
compassView.setOnClickListener(createCompassClickListener(cameraChangeDispatcher));
// LocationComponent
- mapboxMap.injectLocationComponent(new LocationComponent(context, mapboxMap));
+ mapboxMap.injectLocationComponent(new LocationComponent(mapboxMap));
// inject widgets with MapboxMap
attrView.setOnClickListener(new AttributionClickListener(context, mapboxMap));
@@ -1224,7 +1224,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
@Override
public void onMapChanged(@MapChange int change) {
- if (change == WILL_START_LOADING_MAP) {
+ if (change == WILL_START_LOADING_MAP && !initialLoad) {
mapboxMap.onStartLoadingMap();
} else if (change == DID_FINISH_LOADING_STYLE) {
if (initialLoad) {
@@ -1232,8 +1232,9 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
mapboxMap.onPreMapReady();
onMapReady();
mapboxMap.onPostMapReady();
+ } else {
+ mapboxMap.onFinishLoadingStyle();
}
- mapboxMap.onFinishLoadingStyle();
} else if (change == DID_FINISH_RENDERING_FRAME || change == DID_FINISH_RENDERING_FRAME_FULLY_RENDERED) {
mapboxMap.onUpdateFullyRendered();
} else if (change == REGION_IS_CHANGING || change == REGION_DID_CHANGE || change == DID_FINISH_LOADING_MAP) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
index 688b90eb8e..c1392be731 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java
@@ -42,8 +42,8 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
-import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.location.LocationComponent;
+import com.mapbox.mapboxsdk.log.Logger;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.Layer;
import com.mapbox.mapboxsdk.style.light.Light;
@@ -132,7 +132,6 @@ public final class MapboxMap {
outState.putBoolean(MapboxConstants.STATE_DEBUG_ACTIVE, nativeMapView.getDebug());
outState.putString(MapboxConstants.STATE_STYLE_URL, nativeMapView.getStyleUrl());
uiSettings.onSaveInstanceState(outState);
- locationComponent.onSaveInstanceState(outState);
}
/**
@@ -157,7 +156,6 @@ public final class MapboxMap {
if (!TextUtils.isEmpty(styleUrl)) {
nativeMapView.setStyleUrl(savedInstanceState.getString(MapboxConstants.STATE_STYLE_URL));
}
- locationComponent.onRestoreInstanceState(savedInstanceState);
}
/**
@@ -2319,8 +2317,14 @@ public final class MapboxMap {
}
/**
- * Returns an object that can be used to display user's location on the Map.
- * @return the location layer
+ * Returns the {@link LocationComponent} that can be used to display user's location on the map.
+ * <p>
+ * Use {@link LocationComponent#activateLocationComponent(Context)} or any overload to activate the component,
+ * then, enable it with {@link LocationComponent#setLocationComponentEnabled(boolean)}.
+ * <p>
+ * You can customize the location icon and more with {@link com.mapbox.mapboxsdk.location.LocationComponentOptions}.
+ *
+ * @return the Location Component
*/
@NonNull
public LocationComponent getLocationComponent() {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
index 6541abb748..1d4c4af149 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt
@@ -19,7 +19,6 @@ import com.mapbox.geojson.Point
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
import com.mapbox.mapboxsdk.constants.Style
import com.mapbox.mapboxsdk.geometry.LatLng
-import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.location.LocationComponentConstants.*
import com.mapbox.mapboxsdk.location.modes.CameraMode
import com.mapbox.mapboxsdk.location.modes.RenderMode
@@ -28,6 +27,7 @@ import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAPBOX_H
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_CONNECTION_DELAY
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.MAP_RENDER_DELAY
import com.mapbox.mapboxsdk.location.utils.MapboxTestingUtils.Companion.pushSourceUpdates
+import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest
import com.mapbox.mapboxsdk.testapp.activity.SingleActivity
import com.mapbox.mapboxsdk.utils.ColorUtils
@@ -70,8 +70,9 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context)
+ component.isLocationComponentEnabled = true
val locationEngine = component.locationEngine
assertThat(locationEngine, notNullValue())
@@ -89,7 +90,7 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(
context,
LocationComponentOptions.builder(context)
@@ -98,6 +99,7 @@ class LocationComponentTest : BaseActivityTest() {
.accuracyAlpha(.5f)
.accuracyColor(Color.BLUE)
.build())
+ component.isLocationComponentEnabled = true
val locationEngine = component.locationEngine
val componentOptions = component.locationComponentOptions
@@ -120,8 +122,9 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(
+ context,
null,
LocationComponentOptions.builder(context)
.staleStateTimeout(200)
@@ -129,6 +132,7 @@ class LocationComponentTest : BaseActivityTest() {
.accuracyAlpha(.5f)
.accuracyColor(Color.BLUE)
.build())
+ component.isLocationComponentEnabled = true
val locationEngine = component.locationEngine
val componentOptions = component.locationComponentOptions
@@ -150,9 +154,10 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
mapboxMap.setStyle(Style.LIGHT)
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -173,8 +178,9 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
// Source should be present but empty
val mapView = (rule.activity as SingleActivity).mapView
@@ -202,12 +208,13 @@ class LocationComponentTest : BaseActivityTest() {
validateTestSetup()
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.staleStateTimeout(200)
.enableStaleState(false)
.build())
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -229,7 +236,7 @@ class LocationComponentTest : BaseActivityTest() {
fun locationComponentOptions_loadsForegroundBitmapFromNameOption() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.foregroundName("custom-foreground-bitmap")
@@ -238,6 +245,7 @@ class LocationComponentTest : BaseActivityTest() {
.backgroundStaleName("custom-background-stale-bitmap")
.bearingName("custom-bearing-bitmap")
.build())
+ component.isLocationComponentEnabled = true
val foregroundDrawable = ContextCompat.getDrawable(context, R.drawable.ic_media_play)
foregroundDrawable?.let {
@@ -268,12 +276,13 @@ class LocationComponentTest : BaseActivityTest() {
fun locationComponentOptions_loadsGpsNameWithGpsRenderMode() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.foregroundName("custom-foreground-bitmap")
.gpsName("custom-gps-bitmap")
.build())
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
component.forceLocationUpdate(location)
@@ -296,12 +305,13 @@ class LocationComponentTest : BaseActivityTest() {
fun locationComponentOptions_customIconNameRevertsToDefault() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.foregroundName("custom-foreground-bitmap")
.gpsName("custom-gps-bitmap")
.build())
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
component.forceLocationUpdate(location)
@@ -325,12 +335,13 @@ class LocationComponentTest : BaseActivityTest() {
fun locationComponentOptions_customGpsIconNameChangeBackWithMode() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.gpsName("custom-gps-bitmap")
.build())
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
component.forceLocationUpdate(location)
@@ -354,11 +365,12 @@ class LocationComponentTest : BaseActivityTest() {
fun stillStaleAfterResuming() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.staleStateTimeout(200)
.build())
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -382,8 +394,9 @@ class LocationComponentTest : BaseActivityTest() {
fun stillNotStaleAfterResuming() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
assertThat(mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getBooleanProperty(PROPERTY_LOCATION_STALE), `is`(false))
@@ -406,11 +419,12 @@ class LocationComponentTest : BaseActivityTest() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context,
LocationComponentOptions.builder(context)
.accuracyColor(color)
.build())
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -431,8 +445,9 @@ class LocationComponentTest : BaseActivityTest() {
fun forceLocationUpdate_doesMoveLocationLayerIconToCorrectPosition() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -450,8 +465,9 @@ class LocationComponentTest : BaseActivityTest() {
fun disablingComponentHidesPuck() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -459,7 +475,7 @@ class LocationComponentTest : BaseActivityTest() {
assertEquals(point.latitude(), location.latitude, 0.1)
assertEquals(point.longitude(), location.longitude, 0.1)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = false
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
assertThat(mapboxMap.queryRenderedFeatures(location, FOREGROUND_LAYER).isEmpty(), `is`(true))
}
@@ -471,15 +487,16 @@ class LocationComponentTest : BaseActivityTest() {
fun disablingComponentAndChangingStyleAllowsToEnableAgain() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = false
mapboxMap.setStyle(Style.LIGHT)
- component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
assertThat(mapboxMap.isLayerVisible(FOREGROUND_LAYER), `is`(true))
}
@@ -491,12 +508,13 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_isDisabledOnStart() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
assertThat(component.isLocationComponentEnabled, `is`(false))
component.onStop()
component.onStart()
assertThat(component.isLocationComponentEnabled, `is`(false))
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
assertThat(component.isLocationComponentEnabled, `is`(true))
}
}
@@ -507,8 +525,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_keepsEnabledWhenStoppedAndStarted() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
assertThat(component.isLocationComponentEnabled, `is`(true))
component.onStop()
component.onStart()
@@ -522,9 +541,10 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_keepsDisabledWhenStoppedAndStarted() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = true
+ component.isLocationComponentEnabled = false
assertThat(component.isLocationComponentEnabled, `is`(false))
component.onStop()
component.onStart()
@@ -538,8 +558,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_ableToChangeStyleAfterResuming() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.onStop()
component.onStart()
@@ -555,8 +576,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_interruptedDuringStyleChange() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
mapboxMap.setStyle(Style.DARK)
component.onStop()
component.onStart()
@@ -570,8 +592,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_forceLocationUpdateAfterStopped() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.onStop()
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -586,8 +609,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_acceptAndReuseLocationUpdatesBeforeLayerStarted() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.onStop()
component.forceLocationUpdate(location)
component.onStart()
@@ -605,8 +629,9 @@ class LocationComponentTest : BaseActivityTest() {
fun lifecycle_lifecycleChangeRightAfterStyleReload() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.setStyle(Style.LIGHT)
component.onStop()
@@ -632,8 +657,9 @@ class LocationComponentTest : BaseActivityTest() {
fun mapChange_settingComponentStyle() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
val options = LocationComponentOptions.builder(context)
.accuracyColor(Color.RED)
@@ -656,8 +682,9 @@ class LocationComponentTest : BaseActivityTest() {
fun mapChange_forcingLocation() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
pushSourceUpdates(styleChangeIdlingResource) {
@@ -677,9 +704,10 @@ class LocationComponentTest : BaseActivityTest() {
fun mapChange_settingMapStyleBeforeComponentCreation() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
val options = LocationComponentOptions.builder(context)
.accuracyColor(Color.RED)
@@ -701,8 +729,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_layerBearingCorrect() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
location.bearing = 77f
component.forceLocationUpdate(location)
@@ -723,8 +752,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_cameraLatLngBearingCorrect() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING_GPS
location.bearing = 77f
component.forceLocationUpdate(location)
@@ -751,8 +781,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_cameraBearingCorrect() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.NONE_GPS
val latitude = mapboxMap.cameraPosition.target.latitude
val longitude = mapboxMap.cameraPosition.target.longitude
@@ -782,8 +813,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_cameraNoneCorrect() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.NONE
val latitude = mapboxMap.cameraPosition.target.latitude
val longitude = mapboxMap.cameraPosition.target.longitude
@@ -814,8 +846,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_focalPointAdjustment() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.cameraMode = CameraMode.NONE
component.forceLocationUpdate(location)
@@ -832,8 +865,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_dontZoomWhileNotTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.NONE
val zoom = mapboxMap.cameraPosition.zoom
component.zoomWhileTracking(10.0)
@@ -850,8 +884,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_zoomWhileTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.zoomWhileTracking(10.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION)
@@ -868,8 +903,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_zoomWhileTrackingCanceledOnModeChange() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.zoomWhileTracking(15.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
@@ -887,8 +923,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_dontZoomWhileStopped() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
@@ -910,8 +947,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_cancelZoomWhileTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.zoomWhileTracking(15.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_ZOOM_ANIM_DURATION / 2)
@@ -929,8 +967,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_dontTiltWhileNotTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.NONE
val tilt = mapboxMap.cameraPosition.tilt
component.tiltWhileTracking(30.0)
@@ -947,8 +986,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_tiltWhileTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.tiltWhileTracking(30.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION)
@@ -965,8 +1005,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_tiltWhileTrackingCanceledOnModeChange() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.tiltWhileTracking(30.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
@@ -984,8 +1025,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_dontTiltWhileStopped() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
val tilt = mapboxMap.cameraPosition.tilt
@@ -1005,8 +1047,9 @@ class LocationComponentTest : BaseActivityTest() {
fun animators_cancelTiltWhileTracking() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING
component.tiltWhileTracking(30.0)
uiController.loopMainThreadForAtLeast(DEFAULT_TRACKING_TILT_ANIM_DURATION / 2)
@@ -1024,14 +1067,15 @@ class LocationComponentTest : BaseActivityTest() {
fun cameraPositionAdjustedToTrackingModeWhenComponentEnabled() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.cameraMode = CameraMode.TRACKING_GPS
component.forceLocationUpdate(location)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = false
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(LatLng(51.0, 17.0)))
mapboxMap.moveCamera(CameraUpdateFactory.bearingTo(90.0))
- component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
assertEquals(location.bearing.toDouble(), mapboxMap.cameraPosition.bearing, 0.1)
@@ -1047,8 +1091,9 @@ class LocationComponentTest : BaseActivityTest() {
fun compassEngine_onComponentInitializedDefaultIsProvided() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
assertTrue(component.compassEngine is LocationComponentCompassEngine)
}
}
@@ -1060,8 +1105,9 @@ class LocationComponentTest : BaseActivityTest() {
fun compassEngine_changesWhenNewProvided() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
+ uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
val engine: CompassEngine = object : CompassEngine {
override fun addCompassListener(compassListener: CompassListener) {
}
@@ -1094,84 +1140,12 @@ class LocationComponentTest : BaseActivityTest() {
}
@Test
- fun savedState_bundleCreationDeactivated() {
- val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
- override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
- val bundle = Bundle()
- component.onSaveInstanceState(bundle)
- assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled))
- assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions)))
- assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(equalTo(component.renderMode)))
- assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(equalTo(component.cameraMode)))
- assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation)))
- }
- }
-
- executeComponentTest(componentAction)
- }
-
- @Test
- fun savedState_bundleCreationActivated() {
- val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
- override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
- val options = LocationComponentOptions.builder(context)
- .accuracyColor(Color.RED)
- .build()
- component.activateLocationComponent(null, options)
- component.cameraMode = CameraMode.TRACKING
- component.renderMode = RenderMode.GPS
- component.forceLocationUpdate(location)
- mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
-
- val bundle = Bundle()
- component.onSaveInstanceState(bundle)
- assertThat(bundle.getBoolean(STATE_LOCATION_ENABLED), `is`(component.isLocationComponentEnabled))
- assertThat(bundle.getParcelable(STATE_LOCATION_OPTIONS), `is`(equalTo(component.locationComponentOptions)))
- assertThat(bundle.getInt(STATE_LOCATION_RENDER_MODE), `is`(component.renderMode))
- assertThat(bundle.getInt(STATE_LOCATION_CAMERA_MODE), `is`(component.cameraMode))
- assertThat(bundle.getParcelable(STATE_LOCATION_LAST_LOCATION), `is`(equalTo(component.lastKnownLocation)))
- }
- }
-
- executeComponentTest(componentAction)
- }
-
- @Test
- fun savedState_componentRecreated() {
- val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
- override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
- uiController: UiController, context: Context) {
- val options = LocationComponentOptions.builder(context)
- .accuracyColor(Color.RED)
- .build()
-
- val bundle = Bundle()
- bundle.putBoolean(STATE_LOCATION_ENABLED, true)
- bundle.putParcelable(STATE_LOCATION_OPTIONS, options)
- bundle.putInt(STATE_LOCATION_RENDER_MODE, RenderMode.GPS)
- bundle.putInt(STATE_LOCATION_CAMERA_MODE, CameraMode.TRACKING)
- bundle.putParcelable(STATE_LOCATION_LAST_LOCATION, location)
-
- component.onRestoreInstanceState(bundle)
- assertThat(component.isLocationComponentEnabled, `is`(true))
- assertThat(component.locationComponentOptions, `is`(equalTo(options)))
- assertThat(component.renderMode, `is`(RenderMode.GPS))
- assertThat(component.cameraMode, `is`(CameraMode.TRACKING))
- assertThat(component.lastKnownLocation, `is`(equalTo(location)))
- }
- }
-
- executeComponentTest(componentAction)
- }
-
- @Test
fun defaultLocationEngine_deactivatedWhenDestroyed() {
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context)
+ component.isLocationComponentEnabled = true
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
assertThat(component.locationEngine?.isConnected, `is`(true))
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
index c50d1817fd..92f4d770fe 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationLayerControllerTest.kt
@@ -76,6 +76,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
assertThat(mapboxMap.getSource(LOCATION_SOURCE), notNullValue())
@@ -94,6 +95,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -113,6 +115,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.COMPASS
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -132,6 +135,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.GPS
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -151,9 +155,10 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = false
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true)
component.renderMode = RenderMode.GPS
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
@@ -173,10 +178,11 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
- component.deactivateLocationComponent()
+ component.isLocationComponentEnabled = false
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER, shouldDisappear = true)
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
@@ -197,6 +203,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.renderMode = RenderMode.NORMAL
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -228,6 +235,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(100).build())
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -252,6 +260,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.applyStyle(LocationComponentOptions.builder(context).staleStateTimeout(1).build())
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
pushSourceUpdates(styleChangeIdlingResource) {
@@ -272,12 +281,9 @@ class LocationLayerControllerTest : BaseActivityTest() {
uiController: UiController, context: Context) {
styleChangeIdlingResource.waitForStyle((rule.activity as SingleActivity).mapView, mapboxMap, MAPBOX_HEAVY_STYLE)
var show = true
+ component.activateLocationComponent(context, false)
pushSourceUpdates(styleChangeIdlingResource) {
- if (show) {
- component.activateLocationComponent(context, false)
- } else {
- component.deactivateLocationComponent()
- }
+ component.isLocationComponentEnabled = show
show = !show
}
@@ -296,6 +302,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0))
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
@@ -315,6 +322,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
component.forceLocationUpdate(location)
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
mapboxMap.easeCamera(CameraUpdateFactory.newLatLngZoom(LatLng(location), 16.0), 300)
@@ -334,6 +342,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
uiController: UiController, context: Context) {
component.activateLocationComponent(context, false)
+ component.isLocationComponentEnabled = true
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
component.forceLocationUpdate(location)
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt
index ad80a3333e..75fae82cf2 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt
@@ -21,14 +21,8 @@ class LocationComponentAction(private val mapboxMap: MapboxMap,
}
override fun perform(uiController: UiController, view: View) {
- val component = mapboxMap.locationComponent
-
- while (mapboxMap.getSource("mapbox-location-source") == null) {
- uiController.loopMainThreadForAtLeast(MapboxTestingUtils.MAP_RENDER_DELAY)
- }
-
onPerformLocationComponentAction.onLocationComponentAction(
- component,
+ mapboxMap.locationComponent,
mapboxMap,
uiController,
view.context)
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt
index 974dc5c571..035ad67e12 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationFragmentActivity.kt
@@ -102,6 +102,7 @@ class LocationFragmentActivity : AppCompatActivity() {
mapboxMap = it
component = mapboxMap.locationComponent
component?.activateLocationComponent(activity)
+ component?.isLocationComponentEnabled = true
component?.locationEngine?.addLocationEngineListener(this)
}
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
index 6fa514e28b..e53604fdd4 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationMapChangeActivity.java
@@ -84,6 +84,7 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
private void activateLocationComponent() {
LocationComponent locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this);
+ locationComponent.setLocationComponentEnabled(true);
locationComponent.setRenderMode(RenderMode.COMPASS);
}
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
index 72bd91108a..86feb00dec 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/LocationModesActivity.java
@@ -22,13 +22,13 @@ import com.mapbox.android.core.permissions.PermissionsListener;
import com.mapbox.android.core.permissions.PermissionsManager;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
+import com.mapbox.mapboxsdk.location.OnLocationClickListener;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
import com.mapbox.mapboxsdk.location.LocationComponent;
import com.mapbox.mapboxsdk.location.OnCameraTrackingChangedListener;
-import com.mapbox.mapboxsdk.location.OnLocationComponentClickListener;
import com.mapbox.mapboxsdk.location.modes.CameraMode;
import com.mapbox.mapboxsdk.location.modes.RenderMode;
import com.mapbox.mapboxsdk.testapp.R;
@@ -37,7 +37,7 @@ import java.util.ArrayList;
import java.util.List;
public class LocationModesActivity extends AppCompatActivity implements OnMapReadyCallback,
- LocationEngineListener, OnLocationComponentClickListener, OnCameraTrackingChangedListener {
+ LocationEngineListener, OnLocationClickListener, OnCameraTrackingChangedListener {
private MapView mapView;
private Button locationModeBtn;
@@ -50,7 +50,17 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
private MapboxMap mapboxMap;
private boolean customStyle;
- private Bundle savedInstanceState;
+ private static final String SAVED_STATE_CAMERA = "saved_state_camera";
+ private static final String SAVED_STATE_RENDER = "saved_state_render";
+ private static final String SAVED_STATE_LOCATION = "saved_state_location";
+
+ @CameraMode.Mode
+ private int cameraMode = CameraMode.TRACKING;
+
+ @RenderMode.Mode
+ private int renderMode = RenderMode.NORMAL;
+
+ private Location lastLocation;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -81,6 +91,13 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
}
});
+
+ if (savedInstanceState != null) {
+ cameraMode = savedInstanceState.getInt(SAVED_STATE_CAMERA);
+ renderMode = savedInstanceState.getInt(SAVED_STATE_RENDER);
+ lastLocation = savedInstanceState.getParcelable(SAVED_STATE_LOCATION);
+ }
+
mapView.onCreate(savedInstanceState);
if (PermissionsManager.areLocationPermissionsGranted(this)) {
@@ -104,8 +121,6 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
});
permissionsManager.requestLocationPermissions(this);
}
-
- this.savedInstanceState = savedInstanceState;
}
@Override
@@ -125,11 +140,26 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
locationEngine.addLocationEngineListener(this);
locationEngine.activate();
+ int[] padding;
+ if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
+ padding = new int[] {0, 750, 0, 0};
+ } else {
+ padding = new int[] {0, 250, 0, 0};
+ }
+
+ LocationComponentOptions options = LocationComponentOptions.builder(this)
+ .padding(padding)
+ .layerBelow("waterway-label")
+ .build();
+
locationComponent = mapboxMap.getLocationComponent();
+ locationComponent.activateLocationComponent(this, locationEngine, options);
+ locationComponent.setLocationComponentEnabled(true);
locationComponent.addOnLocationClickListener(this);
locationComponent.addOnCameraTrackingChangedListener(this);
-
- activateLocationComponent();
+ locationComponent.setCameraMode(cameraMode);
+ setRendererMode(renderMode);
+ locationComponent.forceLocationUpdate(lastLocation);
}
@Override
@@ -153,10 +183,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
toggleMapStyle();
return true;
} else if (id == R.id.action_component_disable) {
- locationComponent.deactivateLocationComponent();
+ locationComponent.setLocationComponentEnabled(false);
return true;
} else if (id == R.id.action_component_enabled) {
- activateLocationComponent();
+ locationComponent.setLocationComponentEnabled(true);
return true;
} else if (id == R.id.action_gestures_management_disabled) {
disableGesturesManagement();
@@ -169,35 +199,6 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
return super.onOptionsItemSelected(item);
}
- private void activateLocationComponent() {
- if (locationComponent != null) {
- int[] padding;
- if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
- padding = new int[] {0, 750, 0, 0};
- } else {
- padding = new int[] {0, 250, 0, 0};
- }
-
- if (savedInstanceState == null) {
- LocationComponentOptions options = LocationComponentOptions.builder(this)
- .padding(padding)
- .layerBelow("waterway-label")
- .build();
-
- locationComponent.activateLocationComponent(locationEngine, options);
- } else {
- LocationComponentOptions options = locationComponent
- .getLocationComponentOptions()
- .toBuilder()
- .padding(padding)
- .build();
-
- locationComponent.setLocationEngine(locationEngine);
- locationComponent.applyStyle(options);
- }
- }
- }
-
private void toggleStyle() {
customStyle = !customStyle;
locationComponent.applyStyle(
@@ -265,10 +266,16 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
}
}
+ @SuppressLint("MissingPermission")
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
+ outState.putInt(SAVED_STATE_CAMERA, cameraMode);
+ outState.putInt(SAVED_STATE_RENDER, renderMode);
+ if (locationComponent != null) {
+ outState.putParcelable(SAVED_STATE_LOCATION, locationComponent.getLastKnownLocation());
+ }
}
@Override
@@ -299,7 +306,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
@Override
public void onLocationComponentClick() {
- Toast.makeText(this, "OnlocationComponentClick", Toast.LENGTH_LONG).show();
+ Toast.makeText(this, "OnLocationComponentClick", Toast.LENGTH_LONG).show();
}
private void showModeListDialog() {
@@ -328,6 +335,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
}
private void setRendererMode(@RenderMode.Mode int mode) {
+ renderMode = mode;
locationComponent.setRenderMode(mode);
if (mode == RenderMode.NORMAL) {
locationModeBtn.setText("Normal");
@@ -392,6 +400,7 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
@Override
public void onCameraTrackingChanged(int currentMode) {
+ this.cameraMode = currentMode;
if (currentMode == CameraMode.NONE) {
locationTrackingBtn.setText("None");
} else if (currentMode == CameraMode.TRACKING) {
diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
index 5750e97d63..2651137273 100644
--- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
+++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/location/ManualLocationUpdatesActivity.java
@@ -120,6 +120,7 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements
locationEngine.activate();
locationComponent = mapboxMap.getLocationComponent();
locationComponent.activateLocationComponent(this, locationEngine);
+ locationComponent.setLocationComponentEnabled(true);
locationComponent.setRenderMode(RenderMode.COMPASS);
}