diff --git a/OsmAnd/src/net/osmand/plus/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/ApplicationMode.java index d5a9ddabf5..8531912c7f 100644 --- a/OsmAnd/src/net/osmand/plus/ApplicationMode.java +++ b/OsmAnd/src/net/osmand/plus/ApplicationMode.java @@ -123,6 +123,8 @@ public class ApplicationMode { applicationMode.headingIconNight = R.drawable.map_car_location_view_angle_night; applicationMode.locationIconDay = R.drawable.map_car_location; applicationMode.locationIconNight = R.drawable.map_car_location_night; + applicationMode.locationIconDayLost = R.drawable.map_car_location_lost; + applicationMode.locationIconNightLost = R.drawable.map_car_location_lost_night; return this; } @@ -138,6 +140,8 @@ public class ApplicationMode { applicationMode.headingIconNight = R.drawable.map_bicycle_location_view_angle_night; applicationMode.locationIconDay = R.drawable.map_bicycle_location; applicationMode.locationIconNight = R.drawable.map_bicycle_location_night; + applicationMode.locationIconDayLost = R.drawable.map_bicycle_location_lost; + applicationMode.locationIconNightLost = R.drawable.map_bicycle_location_lost_night; return this; } @@ -148,6 +152,8 @@ public class ApplicationMode { applicationMode.headingIconNight = R.drawable.map_default_location_view_angle_night; applicationMode.locationIconDay = R.drawable.map_pedestrian_location; applicationMode.locationIconNight = R.drawable.map_pedestrian_location_night; + applicationMode.locationIconDayLost = R.drawable.map_pedestrian_location_lost; + applicationMode.locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; return this; } @@ -304,6 +310,14 @@ public class ApplicationMode { return locationIconNight; } + public int getResourceLocationDayLost() { + return locationIconDayLost; + } + + public int getResourceLocationNightLost() { + return locationIconNightLost; + } + public String getStringKey() { return stringKey; } @@ -364,5 +378,7 @@ public class ApplicationMode { private int headingIconNight = R.drawable.map_pedestrian_location_view_angle_night; private int locationIconDay = R.drawable.map_pedestrian_location; private int locationIconNight = R.drawable.map_pedestrian_location_night; + private int locationIconDayLost = R.drawable.map_pedestrian_location_lost; + private int locationIconNightLost = R.drawable.map_pedestrian_location_lost_night; private static StateChangedListener listener; } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 78342c607e..f0dff0fb77 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -48,7 +48,6 @@ public class OsmAndLocationProvider implements SensorEventListener { public static final String SIMULATED_PROVIDER = "OsmAnd"; - public interface OsmAndLocationListener { void updateLocation(net.osmand.Location location); } @@ -70,6 +69,12 @@ public class OsmAndLocationProvider implements SensorEventListener { private static final int GPS_DIST_REQUEST = 0; private static final int NOT_SWITCH_TO_NETWORK_WHEN_GPS_LOST_MS = 12000; + private static final long STALE_LOCATION_TIMEOUT = 1000 * 60 * 60; // 60 minutes + public static final long STALE_LOCATION_TIMEOUT_FOR_ICON = 1000 * 60 * 5; // 5 minutes + + private static final int UPDATES_BEFORE_CHECK_LOCATION = 100; + private int updatesCounter; + private long lastTimeGPSLocationFixed = 0; private boolean gpsSignalLost; private SimulationProvider simulatePosition = null; @@ -859,6 +864,16 @@ public class OsmAndLocationProvider implements SensorEventListener { } public net.osmand.Location getLastKnownLocation() { + if (location != null && updatesCounter == 0) { + if ((System.currentTimeMillis() - location.getTime()) > STALE_LOCATION_TIMEOUT) { + location = null; + } + } + if (updatesCounter == UPDATES_BEFORE_CHECK_LOCATION) { + updatesCounter = 0; + } else { + updatesCounter++; + } return location; } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index c31aae66f6..fc4a1aaaa5 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -639,8 +639,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os View compassView = view.findViewById(R.id.compass_layout); Location ll = getMyApplication().getLocationProvider().getLastKnownLocation(); boolean showCompass = currentLatLon != null && location != null; - boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20; - if (gpsFixed && showCompass) { + if (ll != null && showCompass) { updateDistanceDirection(view, location, currentLatLon, heading); compassView.setVisibility(View.VISIBLE); } else { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index b602853021..ac0cddee64 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -450,8 +450,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { View compassView = view.findViewById(R.id.compass_layout); Location ll = app.getLocationProvider().getLastKnownLocation(); boolean showCompass = location != null && listItem.getSearchResult().location != null; - boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20; - if ((gpsFixed || useMapCenter) && showCompass) { + if ((ll != null || useMapCenter) && showCompass) { updateDistanceDirection(view, listItem); compassView.setVisibility(View.VISIBLE); } else { diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index 00640f4472..00d5e77218 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -8,6 +8,7 @@ import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.PointF; import android.graphics.RectF; + import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.data.LatLon; @@ -25,6 +26,8 @@ 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; private Paint locationPaint; @@ -32,7 +35,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay private Paint aroundArea; private OsmandMapTileView view; - + private ApplicationMode appMode; private Bitmap bearingIcon; private Bitmap headingIcon; @@ -40,7 +43,9 @@ 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) { this.mapViewTrackingUtilities = mv; } @@ -53,30 +58,43 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay area = new Paint(); area.setColor(view.getResources().getColor(R.color.pos_area)); - + aroundArea = new Paint(); aroundArea.setColor(view.getResources().getColor(R.color.pos_around)); aroundArea.setStyle(Style.STROKE); aroundArea.setStrokeWidth(1); aroundArea.setAntiAlias(true); - - updateIcons(view.getSettings().getApplicationMode(), false); + locationProvider = view.getApplication().getLocationProvider(); + updateIcons(view.getSettings().getApplicationMode(), false, isLocationOutdated()); } - + @Override public void initLayer(OsmandMapTileView view) { this.view = view; 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); } - + @Override public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) { if(box.getZoom() < 3) { @@ -84,7 +102,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay } // draw boolean nm = nightMode != null && nightMode.isNightMode(); - updateIcons(view.getSettings().getApplicationMode(), nm); + updateIcons(view.getSettings().getApplicationMode(), nm, isLocationOutdated()); Location lastKnownLocation = locationProvider.getLastKnownLocation(); if(lastKnownLocation == null || view == null){ return; @@ -103,7 +121,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay final double dist = box.getDistance(0, box.getPixHeight() / 2, box.getPixWidth(), box.getPixHeight() / 2); int radius = (int) (((double) box.getPixWidth()) / dist * lastKnownLocation.getAccuracy()); - + if (radius > RADIUS * box.getDensity()) { int allowedRad = Math.min(box.getPixWidth() / 2, box.getPixHeight() / 2); canvas.drawCircle(locationX, locationY, Math.min(radius, allowedRad), area); @@ -139,16 +157,17 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay public boolean isLocationVisible(RotatedTileBox tb, Location l) { return l != null && tb.containsLatLon(l.getLatitude(), l.getLongitude()); } - + @Override public void destroyLayer() { - + } - public void updateIcons(ApplicationMode appMode, boolean nighMode) { - if (appMode != this.appMode || this.nm != nighMode) { + public void updateIcons(ApplicationMode appMode, boolean nighMode, boolean locationOutdated) { + if (appMode != this.appMode || this.nm != nighMode || this.locationOutdated != locationOutdated) { this.appMode = appMode; this.nm = nighMode; + this.locationOutdated = locationOutdated; final int resourceBearingDay = appMode.getResourceBearingDay(); final int resourceBearingNight = appMode.getResourceBearingNight(); final int resourceBearing = nighMode ? resourceBearingNight : resourceBearingDay; @@ -159,13 +178,19 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay final int resourceHeading = nighMode ? resourceHeadingNight : resourceHeadingDay; headingIcon = BitmapFactory.decodeResource(view.getResources(), resourceHeading); - final int resourceLocationDay = appMode.getResourceLocationDay(); - final int resourceLocationNight = appMode.getResourceLocationNight(); + final int resourceLocationDay; + final int resourceLocationNight; + if (locationOutdated) { + resourceLocationDay = appMode.getResourceLocationDayLost(); + resourceLocationNight = appMode.getResourceLocationNightLost(); + } else { + resourceLocationDay = appMode.getResourceLocationDay(); + resourceLocationNight = appMode.getResourceLocationNight(); + } final int resourceLocation = nighMode ? resourceLocationNight : resourceLocationDay; locationIcon = BitmapFactory.decodeResource(view.getResources(), resourceLocation); area.setColor(view.getResources().getColor(!nm ? R.color.pos_area : R.color.pos_area_night)); } - } @Override public boolean drawInScreenPixels() { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index 7304f7f524..5e46bda6b9 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -113,7 +113,7 @@ public class MapInfoWidgetsFactory { } public TextInfoWidget createRulerControl(final MapActivity map) { - final String title = "-"; + final String title = "—"; final TextInfoWidget rulerControl = new TextInfoWidget(map) { RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer(); LatLon cacheFirstTouchPoint = new LatLon(0, 0); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 79923b443f..78dc836f2f 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -55,7 +55,6 @@ public class MapMarkersWidgetsFactory { private ImageButton moreButton2nd; private LatLon loc; - private LatLon lastKnownPosition; public MapMarkersWidgetsFactory(final MapActivity map) { this.map = map; @@ -189,9 +188,8 @@ public class MapMarkersWidgetsFactory { Location l = map.getMapViewTrackingUtilities().getMyLocation(); if (l != null) { loc = new LatLon(l.getLatitude(), l.getLongitude()); - lastKnownPosition = loc; } else { - loc = lastKnownPosition; + loc = null; } }