summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java4
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java26
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateManager.java34
3 files changed, 46 insertions, 18 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java
index 0e7ce37a07..67cd26d9cc 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayer.java
@@ -346,10 +346,6 @@ final class LocationLayer implements PluginAnimator.OnLayerAnimationsValuesChang
}
void setLocationsStale(boolean isStale) {
- // If options has stale state disabled, just return here.
- if (!options.enableStaleState()) {
- return;
- }
locationFeature.addBooleanProperty(PROPERTY_LOCATION_STALE, isStale);
refreshSource();
if (renderMode != RenderMode.GPS) {
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
index 988f01dce8..45a13ed58b 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java
@@ -114,7 +114,9 @@ public final class LocationLayerPlugin {
= new CopyOnWriteArrayList<>();
/**
- * Construct a LocationLayerPlugin
+ * Construct a LocationLayerPlugin. In order to display location,
+ * the location layer has to be activated with {@link LocationLayerPlugin#activateLocationLayerPlugin(Context)},
+ * or one of the overloads.
*
* @param mapboxMap the MapboxMap to apply the LocationLayerPlugin with
*/
@@ -156,6 +158,22 @@ public final class LocationLayerPlugin {
* <p>
* <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
*
+ * @param context the context
+ */
+ @RequiresPermission(anyOf = {ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION})
+ public void activateLocationLayerPlugin(@NonNull Context context, boolean useDefaultLocationEngine) {
+ if (useDefaultLocationEngine) {
+ activateLocationLayerPlugin(context, R.style.mapbox_LocationLayer);
+ } else {
+ activateLocationLayerPlugin(context, null, R.style.mapbox_LocationLayer);
+ }
+ }
+
+ /**
+ * This method will show the location icon and enable the camera tracking the location.
+ * <p>
+ * <strong>Note</strong>: This constructor will initialize and use an internal {@link LocationEngine}.
+ *
* @param context the context
* @param styleRes the LocationLayerPlugin style res
*/
@@ -312,9 +330,7 @@ public final class LocationLayerPlugin {
public void applyStyle(LocationLayerOptions options) {
this.options = options;
locationLayer.applyStyle(options);
- if (!options.enableStaleState()) {
- staleStateManager.onStop();
- }
+ staleStateManager.setEnabled(options.enableStaleState());
staleStateManager.setDelayTime(options.staleStateTimeout());
updateMapWithOptions(options);
}
@@ -740,7 +756,7 @@ public final class LocationLayerPlugin {
SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
compassEngine = new LocationLayerCompassEngine(windowManager, sensorManager);
compassEngine.addCompassListener(compassListener);
- staleStateManager = new StaleStateManager(onLocationStaleListener, options.staleStateTimeout());
+ staleStateManager = new StaleStateManager(onLocationStaleListener, options);
updateMapWithOptions(options);
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateManager.java
index 5c180b5c47..9b6afd2d93 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateManager.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/StaleStateManager.java
@@ -10,35 +10,42 @@ import android.os.Handler;
*/
class StaleStateManager {
+ private boolean isEnabled;
private final OnLocationStaleListener innerOnLocationStaleListeners;
private final Handler handler;
private boolean isStale = true;
private long delayTime;
- StaleStateManager(OnLocationStaleListener innerListener, long delayTime) {
+ StaleStateManager(OnLocationStaleListener innerListener, LocationLayerOptions options) {
innerOnLocationStaleListeners = innerListener;
- this.delayTime = delayTime;
handler = new Handler();
- innerOnLocationStaleListeners.onStaleStateChange(true);
+ isEnabled = options.enableStaleState();
+ delayTime = options.staleStateTimeout();
}
private Runnable staleStateRunnable = new Runnable() {
@Override
public void run() {
- isStale = true;
- innerOnLocationStaleListeners.onStaleStateChange(true);
+ setState(true);
}
};
+ void setEnabled(boolean enabled) {
+ if (enabled) {
+ setState(isStale);
+ } else if (isEnabled) {
+ onStop();
+ innerOnLocationStaleListeners.onStaleStateChange(false);
+ }
+ isEnabled = enabled;
+ }
+
boolean isStale() {
return isStale;
}
void updateLatestLocationTime() {
- if (isStale) {
- isStale = false;
- innerOnLocationStaleListeners.onStaleStateChange(false);
- }
+ setState(false);
postTheCallback();
}
@@ -61,4 +68,13 @@ class StaleStateManager {
handler.removeCallbacksAndMessages(null);
handler.postDelayed(staleStateRunnable, delayTime);
}
+
+ private void setState(boolean stale) {
+ if (stale != isStale) {
+ isStale = stale;
+ if (isEnabled) {
+ innerOnLocationStaleListeners.onStaleStateChange(stale);
+ }
+ }
+ }
}