From fd19f2c50561eef91e0d87de2880d7dc270dea5c Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 21 Jul 2017 13:17:01 +0300 Subject: [PATCH 1/3] Extract isLocationOutdated() to OsmandMapLayer --- .../osmand/plus/views/MapControlsLayer.java | 2 +- .../net/osmand/plus/views/OsmandMapLayer.java | 20 ++++++++++++++++ .../osmand/plus/views/PointLocationLayer.java | 23 ++++--------------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 4cbd858b94..55124a1f4d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -792,7 +792,7 @@ public class MapControlsLayer extends OsmandMapLayer { } 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(); if (!enabled) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 0c2592cd07..86ad14b6ef 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -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 = 20; + protected List fullObjectsLatLon; protected List 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; } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index 00d5e77218..27487d8d24 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -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; From 71c69860dff87240797d35e175917ec4a1551402 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 21 Jul 2017 13:55:18 +0300 Subject: [PATCH 2/3] Add small fixes --- OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java | 3 ++- OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 55124a1f4d..7892aa3ea5 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -792,7 +792,8 @@ public class MapControlsLayer extends OsmandMapLayer { } private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) { - boolean enabled = !isLocationOutdated(mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation()); + boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null && + !isLocationOutdated(mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation()); boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); if (!enabled) { diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 86ad14b6ef..dc09eca433 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -40,7 +40,7 @@ import gnu.trove.list.array.TIntArrayList; public abstract class OsmandMapLayer { - protected static final int UPDATES_BEFORE_CHECK_LOCATION = 20; + protected static final int UPDATES_BEFORE_CHECK_LOCATION = 40; protected List fullObjectsLatLon; protected List smallObjectsLatLon; From a13085c06cd65fe24ac2284fd7a6f0156cd42760 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Fri, 21 Jul 2017 15:09:51 +0300 Subject: [PATCH 3/3] Fix #3674; fix text in mapillary widget --- OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java | 3 ++- OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 832784ccb8..dbb6c3cb02 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -199,7 +199,8 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc showViewAngle = routePlanningMode; // disable compass rotation in that mode } registerUnregisterSensor(location); - if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation) { + if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation && + settings.WAKE_ON_VOICE_INT.get() == 0) { mapView.getAnimatedDraggingThread().startMoving( location.getLatitude(), location.getLongitude(), zoom, rotation, false); } else { diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java index 9cfd80507e..1eb7d18913 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryPlugin.java @@ -189,7 +189,7 @@ public class MapillaryPlugin extends OsmandPlugin { private TextInfoWidget createMonitoringControl(final MapActivity map) { mapillaryControl = new TextInfoWidget(map); - mapillaryControl.setText("", map.getString(R.string.mapillary)); + mapillaryControl.setText(map.getString(R.string.mapillary), ""); mapillaryControl.setIcons(R.drawable.widget_mapillary_day, R.drawable.widget_mapillary_night); mapillaryControl.setOnClickListener(new View.OnClickListener() { @Override