[android] adapt LocationLayerPlugin's test suite
This commit is contained in:
committed by
Łukasz Paczos
parent
cb771f6aca
commit
465316b4ce
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
@@ -151,6 +153,22 @@ public final class LocationLayerPlugin {
|
||||
.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
|
||||
*/
|
||||
@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>
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user