From adad814929934c53ef59f7961c7f1e717f807b2b Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 3 Apr 2017 15:40:21 +0300 Subject: [PATCH] Fix floating my position --- .../plus/base/MapViewTrackingUtilities.java | 16 ++++++++++++-- .../plus/views/AnimateDraggingMapThread.java | 21 +++++++++++++++---- .../osmand/plus/views/PointLocationLayer.java | 3 ++- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 6963551b3c..7ee00edd23 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -52,6 +52,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc private Location myLocation; private Float heading; private boolean drivingRegionUpdated = false; + private boolean movingToMyLocation = false; public MapViewTrackingUtilities(OsmandApplication app){ this.app = app; @@ -145,6 +146,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc this.contextMenu = contextMenu; } + public boolean isMovingToMyLocation() { + return movingToMyLocation; + } + @Override public void updateLocation(Location location) { myLocation = location; @@ -194,7 +199,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc showViewAngle = routePlanningMode; // disable compass rotation in that mode } registerUnregisterSensor(location); - if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation) { + if (settings.ANIMATE_MY_LOCATION.get() && !smallSpeedForAnimation && !movingToMyLocation) { mapView.getAnimatedDraggingThread().startMoving( location.getLatitude(), location.getLongitude(), zoom, rotation, false); } else { @@ -333,7 +338,14 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc net.osmand.Location lastKnownLocation = locationProvider.getLastKnownLocation(); AnimateDraggingMapThread thread = mapView.getAnimatedDraggingThread(); int fZoom = mapView.getZoom() < 15 ? 15 : mapView.getZoom(); - thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), fZoom, false); + movingToMyLocation = true; + thread.startMoving(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), + fZoom, false, new Runnable() { + @Override + public void run() { + movingToMyLocation = false; + } + }); } mapView.refreshMap(); } diff --git a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java index 5a98cf3231..bbfc2dd9be 100644 --- a/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java +++ b/OsmAnd/src/net/osmand/plus/views/AnimateDraggingMapThread.java @@ -170,13 +170,18 @@ public class AnimateDraggingMapThread { } if (!stopped){ - animatingMoveInThread(mMoveX, mMoveY, NAV_ANIMATION_TIME, notifyListener); + animatingMoveInThread(mMoveX, mMoveY, NAV_ANIMATION_TIME, notifyListener, null); } } }); } - public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener){ + public void startMoving(final double finalLat, final double finalLon, final int endZoom, final boolean notifyListener) { + startMoving(finalLat, finalLon, endZoom, notifyListener, null); + } + + public void startMoving(final double finalLat, final double finalLon, final int endZoom, + final boolean notifyListener, final Runnable finishAminationCallback) { stopAnimatingSync(); final RotatedTileBox rb = tileView.getCurrentRotatedTileBox().copy(); double startLat = rb.getLatitude(); @@ -219,7 +224,7 @@ public class AnimateDraggingMapThread { } if(!stopped){ - animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener); + animatingMoveInThread(mMoveX, mMoveY, animationTime, notifyListener, finishAminationCallback); } if(!stopped){ tileView.setLatLonAnimate(finalLat, finalLon, notifyListener); @@ -262,7 +267,7 @@ public class AnimateDraggingMapThread { } private void animatingMoveInThread(float moveX, float moveY, float animationTime, - boolean notify){ + boolean notify, final Runnable finishAnimationCallback){ AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator(); float cX = 0; @@ -286,6 +291,14 @@ public class AnimateDraggingMapThread { stopped = true; } } + if (finishAnimationCallback != null) { + tileView.getApplication().runInUIThread(new Runnable() { + @Override + public void run() { + finishAnimationCallback.run(); + } + }); + } } private void animatingZoomInThread(int zoomStart, double zoomFloatStart, diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index 7573d0fdc2..00640f4472 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -92,7 +92,8 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay int locationX; int locationY; if (mapViewTrackingUtilities.isMapLinkedToLocation() - && !MapViewTrackingUtilities.isSmallSpeedForAnimation(lastKnownLocation)) { + && !MapViewTrackingUtilities.isSmallSpeedForAnimation(lastKnownLocation) + && !mapViewTrackingUtilities.isMovingToMyLocation()) { locationX = box.getPixXFromLonNoRot(box.getLongitude()); locationY = box.getPixYFromLatNoRot(box.getLatitude()); } else {