Merge pull request #11213 from osmandapp/make_thin_track_arrow_visible
Make track arrows more visible when track line is thin
This commit is contained in:
commit
b3f87c5036
3 changed files with 77 additions and 6 deletions
|
@ -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<GpxGeometryWayContext, GeometryWayDrawer<GpxGeometryWayContext>> {
|
||||
|
||||
private List<WptPt> points;
|
||||
|
@ -76,16 +77,25 @@ public class GpxGeometryWay extends GeometryWay<GpxGeometryWayContext, GeometryW
|
|||
|
||||
public static class GeometryArrowsStyle extends GeometryWayStyle<GpxGeometryWayContext> {
|
||||
|
||||
private static final double DIRECTION_ARROW_DISTANCE_MULTIPLIER = 10.0;
|
||||
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 outerCircleRadius;
|
||||
private float innerCircleRadius;
|
||||
|
||||
GeometryArrowsStyle(GpxGeometryWayContext context, int arrowColor, int trackColor, float trackWidth) {
|
||||
this(context, null, arrowColor, trackColor, trackWidth);
|
||||
outerCircleRadius = AndroidUtils.dpToPx(context.getCtx(), 8);
|
||||
innerCircleRadius = AndroidUtils.dpToPx(context.getCtx(), 7);
|
||||
}
|
||||
|
||||
GeometryArrowsStyle(GpxGeometryWayContext context, Bitmap arrowBitmap, int arrowColor, int trackColor, float trackWidth) {
|
||||
|
@ -94,6 +104,7 @@ public class GpxGeometryWay extends GeometryWay<GpxGeometryWayContext, GeometryW
|
|||
this.pointColor = arrowColor;
|
||||
this.trackColor = trackColor;
|
||||
this.trackWidth = trackWidth;
|
||||
TRACK_WIDTH_THRESHOLD_PIX = AndroidUtils.dpToPx(context.getCtx(), TRACK_WIDTH_THRESHOLD_DP);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,6 +125,9 @@ public class GpxGeometryWay extends GeometryWay<GpxGeometryWayContext, GeometryW
|
|||
|
||||
@Override
|
||||
public Bitmap getPointBitmap() {
|
||||
if (useSpecialArrow()) {
|
||||
return getContext().getSpecialArrowBitmap();
|
||||
}
|
||||
return arrowBitmap != null ? arrowBitmap : getContext().getArrowBitmap();
|
||||
}
|
||||
|
||||
|
@ -130,9 +144,23 @@ public class GpxGeometryWay extends GeometryWay<GpxGeometryWayContext, GeometryW
|
|||
return trackWidth;
|
||||
}
|
||||
|
||||
public float getOuterCircleRadius() {
|
||||
return outerCircleRadius;
|
||||
}
|
||||
|
||||
public float getInnerCircleRadius() {
|
||||
return innerCircleRadius;
|
||||
}
|
||||
|
||||
public boolean useSpecialArrow() {
|
||||
return trackWidth <= TRACK_WIDTH_THRESHOLD_PIX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPointStepPx(double zoomCoef) {
|
||||
return getPointBitmap().getHeight() + trackWidth * 1.5f;
|
||||
return useSpecialArrow() ?
|
||||
getPointBitmap().getHeight() * SPECIAL_ARROW_DISTANCE_MULTIPLIER :
|
||||
getPointBitmap().getHeight() + trackWidth * ARROW_DISTANCE_MULTIPLIER;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,20 +1,46 @@
|
|||
package net.osmand.plus.views.layers.geometry;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Paint;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class GpxGeometryWayContext extends GeometryWayContext {
|
||||
|
||||
private Paint circlePaint;
|
||||
|
||||
private final Bitmap specialArrowBitmap;
|
||||
|
||||
public GpxGeometryWayContext(Context ctx, float density) {
|
||||
super(ctx, density);
|
||||
Paint paint = getPaintIcon();
|
||||
paint.setStrokeCap(Paint.Cap.ROUND);
|
||||
setupCirclePaint();
|
||||
specialArrowBitmap = AndroidUtils.drawableToBitmap(ContextCompat.getDrawable(ctx, R.drawable.mm_special_arrow_up));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getArrowBitmapResId() {
|
||||
return R.drawable.ic_action_direction_arrow;
|
||||
}
|
||||
|
||||
public Bitmap getSpecialArrowBitmap() {
|
||||
return specialArrowBitmap;
|
||||
}
|
||||
|
||||
public Paint getCirclePaint() {
|
||||
return circlePaint;
|
||||
}
|
||||
|
||||
private void setupCirclePaint() {
|
||||
circlePaint = new Paint();
|
||||
circlePaint.setDither(true);
|
||||
circlePaint.setAntiAlias(true);
|
||||
circlePaint.setStyle(Paint.Style.FILL);
|
||||
circlePaint.setColor(0x33000000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.views.layers.geometry;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
|
@ -7,6 +8,7 @@ import android.graphics.Paint;
|
|||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.views.layers.geometry.GpxGeometryWay.GeometryArrowsStyle;
|
||||
|
||||
public class GpxGeometryWayDrawer extends GeometryWayDrawer<GpxGeometryWayContext> {
|
||||
|
@ -29,24 +31,39 @@ public class GpxGeometryWayDrawer extends GeometryWayDrawer<GpxGeometryWayContex
|
|||
@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) {
|
||||
Paint paint = style.getContext().getCirclePaint();
|
||||
paint.setColor(GeometryArrowsStyle.OUTER_CIRCLE_COLOR);
|
||||
canvas.drawCircle(x, y, style.getOuterCircleRadius(), paint);
|
||||
paint.setColor(style.getTrackColor());
|
||||
canvas.drawCircle(x, y, style.getInnerCircleRadius(), paint);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue