diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-09-03 21:51:43 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-09-12 13:59:11 +0200 |
commit | 465316b4cef4b0d4630d855a789f5b6acef2084e (patch) | |
tree | c101b9386531ed47463127f4ae0ecba7d5ea6621 /platform/android/MapboxGLAndroidSDK/src/main/java/com | |
parent | cb771f6aca2ef3cd0d1bf686139e18ce7cc0e233 (diff) | |
download | qtlocation-mapboxgl-465316b4cef4b0d4630d855a789f5b6acef2084e.tar.gz |
[android] adapt LocationLayerPlugin's test suite
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com')
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); + } + } + } } |