Extract isLocationOutdated() to OsmandMapLayer
This commit is contained in:
parent
a7c27eeb23
commit
07844c49e5
3 changed files with 25 additions and 20 deletions
|
@ -792,7 +792,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) {
|
private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) {
|
||||||
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
|
boolean enabled = !isLocationOutdated(mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation());
|
||||||
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
|
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
|
||||||
|
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
|
|
|
@ -16,11 +16,13 @@ import android.os.Build;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import net.osmand.Location;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.QuadRect;
|
import net.osmand.data.QuadRect;
|
||||||
import net.osmand.data.QuadTree;
|
import net.osmand.data.QuadTree;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
|
import net.osmand.plus.OsmAndLocationProvider;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.render.OsmandRenderer;
|
import net.osmand.plus.render.OsmandRenderer;
|
||||||
|
@ -38,6 +40,8 @@ import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
public abstract class OsmandMapLayer {
|
public abstract class OsmandMapLayer {
|
||||||
|
|
||||||
|
protected static final int UPDATES_BEFORE_CHECK_LOCATION = 20;
|
||||||
|
|
||||||
protected List<LatLon> fullObjectsLatLon;
|
protected List<LatLon> fullObjectsLatLon;
|
||||||
protected List<LatLon> smallObjectsLatLon;
|
protected List<LatLon> smallObjectsLatLon;
|
||||||
|
|
||||||
|
@ -47,6 +51,22 @@ public abstract class OsmandMapLayer {
|
||||||
TWO_POINTERS_ZOOM_OUT
|
TWO_POINTERS_ZOOM_OUT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int updatesCounter;
|
||||||
|
private boolean locationOutdated;
|
||||||
|
|
||||||
|
boolean isLocationOutdated(Location location) {
|
||||||
|
if (location != null && updatesCounter == 0) {
|
||||||
|
locationOutdated = System.currentTimeMillis() - location.getTime() >
|
||||||
|
OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON;
|
||||||
|
}
|
||||||
|
if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) {
|
||||||
|
updatesCounter = 0;
|
||||||
|
} else {
|
||||||
|
updatesCounter++;
|
||||||
|
}
|
||||||
|
return locationOutdated;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isMapGestureAllowed(MapGestureType type) {
|
public boolean isMapGestureAllowed(MapGestureType type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
||||||
public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||||
private static final Log LOG = PlatformUtil.getLog(PointLocationLayer.class);
|
private static final Log LOG = PlatformUtil.getLog(PointLocationLayer.class);
|
||||||
|
|
||||||
private static final int UPDATES_BEFORE_CHECK_LOCATION = 20;
|
|
||||||
|
|
||||||
protected final static int RADIUS = 7;
|
protected final static int RADIUS = 7;
|
||||||
|
|
||||||
|
@ -43,7 +42,6 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
||||||
private OsmAndLocationProvider locationProvider;
|
private OsmAndLocationProvider locationProvider;
|
||||||
private MapViewTrackingUtilities mapViewTrackingUtilities;
|
private MapViewTrackingUtilities mapViewTrackingUtilities;
|
||||||
private boolean nm;
|
private boolean nm;
|
||||||
private int updatesCounter;
|
|
||||||
private boolean locationOutdated;
|
private boolean locationOutdated;
|
||||||
|
|
||||||
public PointLocationLayer(MapViewTrackingUtilities mv) {
|
public PointLocationLayer(MapViewTrackingUtilities mv) {
|
||||||
|
@ -66,7 +64,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
||||||
aroundArea.setAntiAlias(true);
|
aroundArea.setAntiAlias(true);
|
||||||
|
|
||||||
locationProvider = view.getApplication().getLocationProvider();
|
locationProvider = view.getApplication().getLocationProvider();
|
||||||
updateIcons(view.getSettings().getApplicationMode(), false, isLocationOutdated());
|
updateIcons(view.getSettings().getApplicationMode(), false,
|
||||||
|
isLocationOutdated(locationProvider.getLastKnownLocation()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,21 +74,6 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
||||||
initUI();
|
initUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLocationOutdated() {
|
|
||||||
if (locationProvider.getLastKnownLocation() != null && updatesCounter == 0) {
|
|
||||||
updatesCounter++;
|
|
||||||
return System.currentTimeMillis() - locationProvider.getLastKnownLocation().getTime() >
|
|
||||||
OsmAndLocationProvider.STALE_LOCATION_TIMEOUT_FOR_ICON;
|
|
||||||
} else {
|
|
||||||
if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) {
|
|
||||||
updatesCounter = 0;
|
|
||||||
} else {
|
|
||||||
updatesCounter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return locationOutdated;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RectF getHeadingRect(int locationX, int locationY){
|
private RectF getHeadingRect(int locationX, int locationY){
|
||||||
int rad = (int) (view.getDensity() * 60);
|
int rad = (int) (view.getDensity() * 60);
|
||||||
return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad);
|
return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad);
|
||||||
|
@ -102,7 +86,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
|
||||||
}
|
}
|
||||||
// draw
|
// draw
|
||||||
boolean nm = nightMode != null && nightMode.isNightMode();
|
boolean nm = nightMode != null && nightMode.isNightMode();
|
||||||
updateIcons(view.getSettings().getApplicationMode(), nm, isLocationOutdated());
|
updateIcons(view.getSettings().getApplicationMode(), nm,
|
||||||
|
isLocationOutdated(locationProvider.getLastKnownLocation()));
|
||||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||||
if(lastKnownLocation == null || view == null){
|
if(lastKnownLocation == null || view == null){
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue