From f16b46295dd62551a05ef5f959f95e265e8d8664 Mon Sep 17 00:00:00 2001 From: cepprice Date: Sun, 21 Mar 2021 14:44:37 +0500 Subject: [PATCH 1/3] Make track arrows more visible when track line is thin --- .../views/layers/geometry/GpxGeometryWay.java | 20 ++++++-- .../geometry/GpxGeometryWayContext.java | 11 +++++ .../layers/geometry/GpxGeometryWayDrawer.java | 46 ++++++++++++++++++- 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java index 24d49df0b1..0e9b73dc82 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java @@ -2,13 +2,14 @@ package net.osmand.plus.views.layers.geometry; import android.graphics.Bitmap; -import androidx.annotation.NonNull; - +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.RotatedTileBox; import java.util.List; +import androidx.annotation.NonNull; + public class GpxGeometryWay extends GeometryWay> { private List points; @@ -76,7 +77,9 @@ public class GpxGeometryWay extends GeometryWay { - private static final double DIRECTION_ARROW_DISTANCE_MULTIPLIER = 10.0; + private static final float TRACK_WIDTH_THRESHOLD = 8f; + private static final float ARROW_DISTANCE_MULTIPLIER = 1.5f; + private static final float SPECIAL_ARROW_DISTANCE_MULTIPLIER = 10f; private Bitmap arrowBitmap; @@ -114,6 +117,9 @@ public class GpxGeometryWay extends GeometryWay { @@ -22,31 +25,70 @@ public class GpxGeometryWayDrawer extends GeometryWayDrawer style) { super(x, y, angle, style); + createCircleBitmap((GeometryArrowsStyle) style); } @Override void draw(Canvas canvas, GeometryWayContext context) { if (style instanceof GeometryArrowsStyle) { + Context ctx = style.getCtx(); GeometryArrowsStyle arrowsWayStyle = (GeometryArrowsStyle) style; Bitmap bitmap = style.getPointBitmap(); + boolean useSpecialArrow = arrowsWayStyle.useSpecialArrow(); - float newWidth = arrowsWayStyle.getTrackWidth() / 2f; + float newWidth = useSpecialArrow ? AndroidUtils.dpToPx(ctx, 12) : arrowsWayStyle.getTrackWidth() / 2f; float paintH2 = bitmap.getHeight() / 2f; float paintW2 = newWidth / 2f; Matrix matrix = getMatrix(); matrix.reset(); - matrix.postScale(newWidth / bitmap.getWidth(), 1); + float sy = useSpecialArrow ? newWidth / bitmap.getHeight() : 1; + matrix.postScale(newWidth / bitmap.getWidth(), sy); matrix.postRotate((float) angle, paintW2, paintH2); matrix.postTranslate(x - paintW2, y - paintH2); + if (useSpecialArrow) { + drawCircle(canvas, arrowsWayStyle); + } + Paint paint = context.getPaintIconCustom(); Integer pointColor = style.getPointColor(); paint.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, matrix, paint); } } + + private void drawCircle(Canvas canvas, GeometryArrowsStyle style) { + float offset = circleBitmap.getWidth() / 2f; + float angleOffset = AndroidUtils.dpToPx(style.getCtx(), 1); + double rad = Math.toRadians(angle + 90); + float x = (float) (this.x - offset - angleOffset * Math.cos(rad)); + float y = (float) (this.y - offset - angleOffset * Math.sin(rad)); + canvas.drawBitmap(circleBitmap, x, y, null); + } + + private void createCircleBitmap(GeometryArrowsStyle style) { + Context ctx = style.getCtx(); + int size = AndroidUtils.dpToPx(ctx, 16); + circleBitmap = Bitmap.createBitmap(size, size, style.getPointBitmap().getConfig()); + Paint paint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG); + paint.setStyle(Paint.Style.FILL); + + Canvas c = new Canvas(circleBitmap); + + paint.setColor(0x33000000); + Path path = new Path(); + path.addCircle(size / 2f, size / 2f, AndroidUtils.dpToPx(ctx, 8), Path.Direction.CW); + c.drawPath(path, paint); + + paint.setColor(style.getTrackColor()); + path.reset(); + path.addCircle(size / 2f, size / 2f, AndroidUtils.dpToPx(ctx, 7), Path.Direction.CW); + c.drawPath(path, paint); + } } } \ No newline at end of file From 170c70e42bc555daf3015c776123234db90086cf Mon Sep 17 00:00:00 2001 From: cepprice Date: Sun, 21 Mar 2021 20:54:58 +0500 Subject: [PATCH 2/3] Refactor to optimize memory consumption and rendering speed --- .../views/layers/geometry/GpxGeometryWay.java | 26 ++++++++++++-- .../geometry/GpxGeometryWayContext.java | 15 ++++++++ .../layers/geometry/GpxGeometryWayDrawer.java | 34 ++++--------------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java index 0e9b73dc82..c0fdf55930 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java @@ -77,18 +77,27 @@ public class GpxGeometryWay extends GeometryWay { - private static final float TRACK_WIDTH_THRESHOLD = 8f; + private static final float TRACK_WIDTH_THRESHOLD_DP = 8f; private static final float ARROW_DISTANCE_MULTIPLIER = 1.5f; private static final float SPECIAL_ARROW_DISTANCE_MULTIPLIER = 10f; + private final float TRACK_WIDTH_THRESHOLD_PIX; private Bitmap arrowBitmap; + public static final int OUTER_CIRCLE_COLOR = 0x33000000; protected int pointColor; protected int trackColor; protected float trackWidth; + private float circleAngleOffset; + private float outerCircleRadius; + private float innerCircleRadius; + GeometryArrowsStyle(GpxGeometryWayContext context, int arrowColor, int trackColor, float trackWidth) { this(context, null, arrowColor, trackColor, trackWidth); + circleAngleOffset = AndroidUtils.dpToPx(context.getCtx(), 1); + outerCircleRadius = AndroidUtils.dpToPx(context.getCtx(), 8); + innerCircleRadius = AndroidUtils.dpToPx(context.getCtx(), 7); } GeometryArrowsStyle(GpxGeometryWayContext context, Bitmap arrowBitmap, int arrowColor, int trackColor, float trackWidth) { @@ -97,6 +106,7 @@ public class GpxGeometryWay extends GeometryWay style) { super(x, y, angle, style); - createCircleBitmap((GeometryArrowsStyle) style); } @Override @@ -63,32 +59,14 @@ public class GpxGeometryWayDrawer extends GeometryWayDrawer Date: Sun, 21 Mar 2021 21:57:59 +0500 Subject: [PATCH 3/3] Don't bias arrow's position --- .../osmand/plus/views/layers/geometry/GpxGeometryWay.java | 6 ------ .../plus/views/layers/geometry/GpxGeometryWayDrawer.java | 3 --- 2 files changed, 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java index c0fdf55930..5ba26346a3 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GpxGeometryWay.java @@ -89,13 +89,11 @@ public class GpxGeometryWay extends GeometryWay