Merge pull request #4162 from osmandapp/alex_fixes

Extract isLocationOutdated() to OsmandMapLayer
This commit is contained in:
vshcherb 2017-07-21 13:18:17 +02:00 committed by GitHub
commit bed581b245
3 changed files with 26 additions and 20 deletions

View file

@ -792,7 +792,8 @@ public class MapControlsLayer extends OsmandMapLayer {
}
private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) {
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null &&
!isLocationOutdated(mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation());
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
if (!enabled) {

View file

@ -16,11 +16,13 @@ import android.os.Build;
import android.support.annotation.NonNull;
import android.view.MotionEvent;
import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.OsmandRenderer;
@ -38,6 +40,8 @@ import gnu.trove.list.array.TIntArrayList;
public abstract class OsmandMapLayer {
protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40;
protected List<LatLon> fullObjectsLatLon;
protected List<LatLon> smallObjectsLatLon;
@ -47,6 +51,22 @@ public abstract class OsmandMapLayer {
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) {
return true;
}

View file

@ -26,7 +26,6 @@ import java.util.List;
public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
private static final Log LOG = PlatformUtil.getLog(PointLocationLayer.class);
private static final int UPDATES_BEFORE_CHECK_LOCATION = 20;
protected final static int RADIUS = 7;
@ -43,7 +42,6 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
private OsmAndLocationProvider locationProvider;
private MapViewTrackingUtilities mapViewTrackingUtilities;
private boolean nm;
private int updatesCounter;
private boolean locationOutdated;
public PointLocationLayer(MapViewTrackingUtilities mv) {
@ -66,7 +64,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
aroundArea.setAntiAlias(true);
locationProvider = view.getApplication().getLocationProvider();
updateIcons(view.getSettings().getApplicationMode(), false, isLocationOutdated());
updateIcons(view.getSettings().getApplicationMode(), false,
isLocationOutdated(locationProvider.getLastKnownLocation()));
}
@Override
@ -75,21 +74,6 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
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){
int rad = (int) (view.getDensity() * 60);
return new RectF(locationX - rad, locationY - rad, locationX + rad, locationY + rad);
@ -102,7 +86,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
}
// draw
boolean nm = nightMode != null && nightMode.isNightMode();
updateIcons(view.getSettings().getApplicationMode(), nm, isLocationOutdated());
updateIcons(view.getSettings().getApplicationMode(), nm,
isLocationOutdated(locationProvider.getLastKnownLocation()));
Location lastKnownLocation = locationProvider.getLastKnownLocation();
if(lastKnownLocation == null || view == null){
return;