From 76d5d36b1ef0eb0123e3a462dc0e9e2dbf8f6e94 Mon Sep 17 00:00:00 2001 From: crimean Date: Tue, 5 Feb 2019 17:57:14 +0300 Subject: [PATCH] Fix walking line on zoom --- .../measurementtool/MeasurementToolLayer.java | 26 +++++----- .../osmand/plus/views/MapMarkersLayer.java | 22 ++++----- .../net/osmand/plus/views/OsmandMapLayer.java | 21 ++++---- .../osmand/plus/views/OsmandMapTileView.java | 4 ++ .../src/net/osmand/plus/views/RouteLayer.java | 48 +++++++++++-------- .../osmand/plus/views/RulerControlLayer.java | 19 ++++---- .../plus/views/TransportStopsLayer.java | 12 ++--- 7 files changed, 76 insertions(+), 76 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 2e8ad14410..36e6c23d5f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -24,8 +24,6 @@ import net.osmand.util.MapUtils; import java.util.ArrayList; import java.util.List; -import gnu.trove.list.array.TIntArrayList; - public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final int POINTS_TO_DRAW = 50; @@ -42,8 +40,8 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL private int marginApplyingPointIconX; private int marginApplyingPointIconY; private final Path path = new Path(); - private final TIntArrayList tx = new TIntArrayList(); - private final TIntArrayList ty = new TIntArrayList(); + private final List tx = new ArrayList<>(); + private final List ty = new ArrayList<>(); private OnMeasureDistanceToCenter measureDistanceToCenterListener; private OnSingleTapListener singleTapListener; private OnEnterMovePointModeListener enterMovePointModeListener; @@ -218,26 +216,26 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL if (before.points.size() > 0 || after.points.size() > 0) { path.reset(); - tx.reset(); - ty.reset(); + tx.clear(); + ty.clear(); if (before.points.size() > 0) { WptPt pt = before.points.get(before.points.size() - 1); - int locX = tb.getPixXFromLonNoRot(pt.lon); - int locY = tb.getPixYFromLatNoRot(pt.lat); + float locX = tb.getPixXFromLonNoRot(pt.lon); + float locY = tb.getPixYFromLatNoRot(pt.lat); tx.add(locX); ty.add(locY); - tx.add(tb.getCenterPixelX()); - ty.add(tb.getCenterPixelY()); + tx.add((float)tb.getCenterPixelX()); + ty.add((float)tb.getCenterPixelY()); } if (after.points.size() > 0) { if (before.points.size() == 0) { - tx.add(tb.getCenterPixelX()); - ty.add(tb.getCenterPixelY()); + tx.add((float)tb.getCenterPixelX()); + ty.add((float)tb.getCenterPixelY()); } WptPt pt = after.points.get(0); - int locX = tb.getPixXFromLonNoRot(pt.lon); - int locY = tb.getPixYFromLatNoRot(pt.lat); + float locX = tb.getPixXFromLonNoRot(pt.lon); + float locY = tb.getPixYFromLatNoRot(pt.lat); tx.add(locX); ty.add(locY); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 172784b2b0..bb8fec7ad8 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -49,8 +49,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import gnu.trove.list.array.TIntArrayList; - public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection, ContextMenuLayer.IMoveObjectProvider { @@ -93,8 +91,8 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private float textSize; private int verticalOffset; - private TIntArrayList tx = new TIntArrayList(); - private TIntArrayList ty = new TIntArrayList(); + private List tx = new ArrayList<>(); + private List ty = new ArrayList<>(); private Path linePath = new Path(); private LatLon fingerLocation; @@ -270,22 +268,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi boolean drawMarkerName = settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1; - int locX; - int locY; + float locX; + float locY; if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() && !MapViewTrackingUtilities.isSmallSpeedForAnimation(myLoc) && !map.getMapViewTrackingUtilities().isMovingToMyLocation()) { - locX = (int) tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude()); - locY = (int) tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude()); + locX = tileBox.getPixXFromLatLon(tileBox.getLatitude(), tileBox.getLongitude()); + locY = tileBox.getPixYFromLatLon(tileBox.getLatitude(), tileBox.getLongitude()); } else { - locX = (int) tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); - locY = (int) tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); + locX = tileBox.getPixXFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); + locY = tileBox.getPixYFromLatLon(myLoc.getLatitude(), myLoc.getLongitude()); } int[] colors = MapMarker.getColors(map); for (int i = 0; i < activeMapMarkers.size() && i < displayedWidgets; i++) { MapMarker marker = activeMapMarkers.get(i); - int markerX = (int) tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude()); - int markerY = (int) tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude()); + float markerX = tileBox.getPixXFromLatLon(marker.getLatitude(), marker.getLongitude()); + float markerY = tileBox.getPixYFromLatLon(marker.getLatitude(), marker.getLongitude()); linePath.reset(); tx.clear(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 06dec1345e..297a19ec3c 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -47,8 +47,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import gnu.trove.list.array.TIntArrayList; - public abstract class OsmandMapLayer { protected List fullObjectsLatLon; @@ -142,12 +140,11 @@ public abstract class OsmandMapLayer { } } - - protected boolean isIn(int x, int y, int lx, int ty, int rx, int by) { + protected boolean isIn(float x, float y, int lx, int ty, int rx, int by) { return x >= lx && x <= rx && y >= ty && y <= by; } - public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) { + public int calculatePath(RotatedTileBox tb, List xs, List ys, Path path) { List> paths = new ArrayList<>(); int res = calculatePath(tb, xs, ys, null, paths); if (paths.size() > 0) { @@ -440,10 +437,10 @@ public abstract class OsmandMapLayer { } } - public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, List styles, List> paths) { + public int calculatePath(RotatedTileBox tb, List xs, List ys, List styles, List> paths) { boolean segmentStarted = false; - int prevX = xs.get(0) / 100; - int prevY = ys.get(0) / 100; + float prevX = xs.get(0); + float prevY = ys.get(0); int height = tb.getPixHeight(); int width = tb.getPixWidth(); int cnt = 0; @@ -452,14 +449,14 @@ public abstract class OsmandMapLayer { Path path = new Path(); boolean prevIn = isIn(prevX, prevY, 0, 0, width, height); for (int i = 1; i < xs.size(); i++) { - int currX = xs.get(i) / 100; - int currY = ys.get(i) / 100; + float currX = xs.get(i); + float currY = ys.get(i); boolean currIn = isIn(currX, currY, 0, 0, width, height); boolean draw = false; if (prevIn && currIn) { draw = true; } else { - long intersection = MapAlgorithms.calculateIntersection(currX, currY, prevX, prevY, 0, width, height, 0); + long intersection = MapAlgorithms.calculateIntersection((int)currX, (int)currY, (int)prevX, (int)prevY, 0, width, height, 0); if (intersection != -1) { if (prevIn && (i == 1)) { cnt++; @@ -471,7 +468,7 @@ public abstract class OsmandMapLayer { draw = true; } if (i == xs.size() - 1 && !currIn) { - long inter = MapAlgorithms.calculateIntersection(prevX, prevY, currX, currY, 0, width, height, 0); + long inter = MapAlgorithms.calculateIntersection((int)prevX, (int)prevY, (int)currX, (int)currY, 0, width, height, 0); if (inter != -1) { currX = (int) (inter >> 32); currY = (int) (inter & 0xffffffff); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index bf08946e5f..d28ea4f55b 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -711,6 +711,10 @@ public class OsmandMapTileView implements IMapDownloaderCallback { return additional.fps; } + public boolean isAnimatingZoom() { + return animatedDraggingThread.isAnimatingZoom(); + } + @SuppressLint("WrongCall") public void drawOverMap(Canvas canvas, RotatedTileBox tileBox, DrawSettings drawSettings) { if (mapRenderer == null) { diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index 8d9410b76d..cb06c398e7 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -53,7 +53,6 @@ import java.util.Set; import java.util.TreeMap; import gnu.trove.list.array.TByteArrayList; -import gnu.trove.list.array.TIntArrayList; public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { @@ -563,7 +562,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } } - private void drawArrowsOverPath(Canvas canvas, RotatedTileBox tb, TIntArrayList tx, TIntArrayList ty, + private void drawArrowsOverPath(Canvas canvas, RotatedTileBox tb, List tx, List ty, List angles, List distances, double distPixToFinish, List styles) { int h = tb.getPixHeight(); int w = tb.getPixWidth(); @@ -573,9 +572,11 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont int bottom = h + h/4; boolean hasStyles = styles != null && styles.size() == tx.size(); + double zoomCoef = tb.getZoomAnimation() > 0 ? (Math.pow(2, tb.getZoomAnimation() + tb.getZoomFloatPart())) : 1f; Bitmap arrow = wayContext.getArrowBitmap(); - double pxStep = arrow.getHeight() * 4f; + int arrowHeight = arrow.getHeight(); + double pxStep = arrowHeight * 4f * zoomCoef; double dist = 0; if (distPixToFinish != 0) { dist = distPixToFinish - pxStep * ((int) (distPixToFinish / pxStep)); // dist < 1 @@ -590,23 +591,26 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont GeometryWalkWayStyle walkWayStyle = new GeometryWalkWayStyle(wayContext); Bitmap walkArrow = walkWayStyle.getPointBitmap(); + int walkArrowHeight = walkArrow.getHeight(); + double pxStepWalk = walkArrowHeight * 1.2f * zoomCoef; + double pxStepRegular = arrowHeight * 4f * zoomCoef; GeometryWayStyle prevStyle = null; for (int i = tx.size() - 2; i >= 0; i --) { GeometryWayStyle style = hasStyles ? styles.get(i) : null; - float px = tx.get(i) / 100f; - float py = ty.get(i) / 100f; - float x = tx.get(i + 1) / 100f; - float y = ty.get(i + 1) / 100f; + float px = tx.get(i); + float py = ty.get(i); + float x = tx.get(i + 1); + float y = ty.get(i + 1); double distSegment = distances.get(i + 1); double angle = angles.get(i + 1); if (distSegment == 0) { continue; } if (style != null && style.isWalkLine()) { - pxStep = walkArrow.getHeight() * 1.2f; + pxStep = pxStepWalk; } else { - pxStep = arrow.getHeight() * 4f; + pxStep = pxStepRegular; } if (style != null && !style.equals(prevStyle) && (prevStyle != null || style.hasAnchors())) { prevStyle = style; @@ -626,7 +630,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont double pdy = (y - py) * percent; float iconx = (float) (px + pdx); float icony = (float) (py + pdy); - if (isIn((int)(iconx), (int) (icony), left, top, right, bottom)) { + if (isIn(iconx, icony, left, top, right, bottom)) { arrows.add(new PathPoint(iconx, icony, angle, style)); } dist -= pxStep; @@ -645,7 +649,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont double lon = stop.getLocation().getLongitude(); float x = tb.getPixXFromLatLon(lat, lon); float y = tb.getPixYFromLatLon(lat, lon); - if (isIn((int) (x), (int) (y), left, top, right, bottom)) { + if (isIn(x, y, left, top, right, bottom)) { if (i != start && i != end) { stops.add(new PathTransportStop(x, y, style)); } @@ -657,7 +661,9 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont for (int i = arrows.size() - 1; i >= 0; i--) { PathPoint a = arrows.get(i); - a.draw(canvas, wayContext); + if (!tb.isZoomAnimated() || a.style.isWalkLine()) { + a.draw(canvas, wayContext); + } } for (int i = anchors.size() - 1; i >= 0; i--) { PathAnchor anchor = anchors.get(i); @@ -757,8 +763,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont Map styleMap = Collections.emptyMap(); // cache arrays - TIntArrayList tx = new TIntArrayList(); - TIntArrayList ty = new TIntArrayList(); + List tx = new ArrayList<>(); + List ty = new ArrayList<>(); List angles = new ArrayList<>(); List distances = new ArrayList<>(); List styles = new ArrayList<>(); @@ -903,7 +909,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont styles.clear(); } - private void addLocation(RotatedTileBox tb, Location ls, GeometryWayStyle style, TIntArrayList tx, TIntArrayList ty, + private void addLocation(RotatedTileBox tb, Location ls, GeometryWayStyle style, List tx, List ty, List angles, List distances, double dist, List styles) { float x = tb.getPixXFromLatLon(ls.getLatitude(), ls.getLongitude()); float y = tb.getPixYFromLatLon(ls.getLatitude(), ls.getLongitude()); @@ -911,8 +917,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont float py = y; int previous = tx.size() - 1; if (previous >= 0 && previous < tx.size()) { - px = tx.get(previous) / 100f; - py = ty.get(previous) / 100f; + px = tx.get(previous); + py = ty.get(previous); } double angle = 0; if (px != x || py != y) { @@ -923,8 +929,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont if(dist != 0) { distSegment = dist; } - tx.add((int) (x * 100f)); - ty.add((int) (y * 100f)); + tx.add(x); + ty.add(y); angles.add(angle); distances.add(distSegment); styles.add(style); @@ -933,7 +939,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont private RouteSimplificationGeometry routeGeometry = new RouteSimplificationGeometry(); - private void drawRouteSegment(RotatedTileBox tb, Canvas canvas, TIntArrayList tx, TIntArrayList ty, + private void drawRouteSegment(RotatedTileBox tb, Canvas canvas, List tx, List ty, List angles, List distances, double distToFinish, List styles) { if (tx.size() < 2) { return; @@ -960,7 +966,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont } attrs.customColor = 0; attrsPT.customColor = 0; - if (tb.getZoomAnimation() == 0) { + if (!view.isAnimatingZoom()) { drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles); } } finally { diff --git a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java index b55b288356..b1b232618e 100644 --- a/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RulerControlLayer.java @@ -27,8 +27,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.util.MapUtils; import java.util.ArrayList; - -import gnu.trove.list.array.TIntArrayList; +import java.util.List; public class RulerControlLayer extends OsmandMapLayer { @@ -68,8 +67,8 @@ public class RulerControlLayer extends OsmandMapLayer { private boolean touched; private boolean wasZoom; - private TIntArrayList tx = new TIntArrayList(); - private TIntArrayList ty = new TIntArrayList(); + private List tx = new ArrayList<>(); + private List ty = new ArrayList<>(); private Path linePath = new Path(); private Bitmap centerIconDay; @@ -309,15 +308,15 @@ public class RulerControlLayer extends OsmandMapLayer { private void drawDistBetweenFingerAndLocation(Canvas canvas, RotatedTileBox tb, Location currLoc, boolean night) { float x = tb.getPixXFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude()); float y = tb.getPixYFromLatLon(touchPointLatLon.getLatitude(), touchPointLatLon.getLongitude()); - int currX = (int) tb.getPixXFromLatLon(currLoc.getLatitude(), currLoc.getLongitude()); - int currY = (int) tb.getPixYFromLatLon(currLoc.getLatitude(), currLoc.getLongitude()); + float currX = tb.getPixXFromLatLon(currLoc.getLatitude(), currLoc.getLongitude()); + float currY = tb.getPixYFromLatLon(currLoc.getLatitude(), currLoc.getLongitude()); linePath.reset(); - tx.reset(); - ty.reset(); + tx.clear(); + ty.clear(); - tx.add((int) x); - ty.add((int) y); + tx.add(x); + ty.add(y); tx.add(currX); ty.add(currY); diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 402b3906fe..2da704414b 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -23,9 +23,9 @@ import net.osmand.data.TransportStop; import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Way; import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.transport.TransportStopRoute; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.transport.TransportStopType; import java.util.ArrayList; @@ -34,8 +34,6 @@ import java.util.Comparator; import java.util.List; import java.util.TreeSet; -import gnu.trove.list.array.TIntArrayList; - public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final int startZoom = 12; private static final int startZoomRoute = 10; @@ -202,12 +200,12 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa List ws = stopRoute.route.getForwardWays(); if (ws != null) { for (Way w : ws) { - TIntArrayList tx = new TIntArrayList(); - TIntArrayList ty = new TIntArrayList(); + List tx = new ArrayList<>(); + List ty = new ArrayList<>(); for (int i = 0; i < w.getNodes().size(); i++) { Node o = w.getNodes().get(i); - int x = (int) tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); - int y = (int) tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); + float x = tb.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); + float y = tb.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); tx.add(x); ty.add(y); }