Direction arrows improvements

This commit is contained in:
Vitaliy 2020-07-29 14:09:05 +03:00
parent b469563ea1
commit 9903021d58
3 changed files with 67 additions and 12 deletions

View file

@ -130,7 +130,11 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card
Bundle arguments = getArguments(); Bundle arguments = getArguments();
if (savedInstanceState != null) { if (savedInstanceState != null) {
trackDrawInfo = new TrackDrawInfo(savedInstanceState); trackDrawInfo = new TrackDrawInfo(savedInstanceState);
if (trackDrawInfo.isCurrentRecording()) {
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
} else {
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath()); selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(trackDrawInfo.getFilePath());
}
if (!selectedGpxFile.isShowCurrentTrack()) { if (!selectedGpxFile.isShowCurrentTrack()) {
gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath())); gpxDataItem = app.getGpxDbHelper().getItem(new File(trackDrawInfo.getFilePath()));
} }

View file

@ -29,7 +29,7 @@ public class TrackDrawInfo {
private double splitInterval; private double splitInterval;
private boolean joinSegments; private boolean joinSegments;
private boolean showArrows; private boolean showArrows;
private boolean showStartFinish; private boolean showStartFinish = true;
private boolean currentRecording; private boolean currentRecording;
public TrackDrawInfo(boolean currentRecording) { public TrackDrawInfo(boolean currentRecording) {

View file

@ -1,11 +1,11 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.Paint.Cap;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff.Mode;
@ -50,6 +50,7 @@ import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.Sele
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference; import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask;
import net.osmand.plus.track.TrackDrawInfo; import net.osmand.plus.track.TrackDrawInfo;
@ -78,6 +79,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private static final Log log = PlatformUtil.getLog(GPXLayer.class); private static final Log log = PlatformUtil.getLog(GPXLayer.class);
private static final double TOUCH_RADIUS_MULTIPLIER = 1.5; private static final double TOUCH_RADIUS_MULTIPLIER = 1.5;
private static final double DIRECTION_ARROW_DISTANCE_MULTIPLIER = 10.0;
private static final float DIRECTION_ARROW_CIRCLE_MULTIPLIER = 1.5f;
private static final int DEFAULT_WIDTH_MULTIPLIER = 7; private static final int DEFAULT_WIDTH_MULTIPLIER = 7;
private static final int START_ZOOM = 7; private static final int START_ZOOM = 7;
@ -200,7 +203,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
grayColor = ContextCompat.getColor(view.getApplication(), R.color.color_favorite_gray); grayColor = ContextCompat.getColor(view.getApplication(), R.color.color_favorite_gray);
wayContext = new GeometryWayContext(view.getContext(), view.getDensity()); wayContext = new GeometryWayContext(view.getContext(), view.getDensity());
arrowBitmap = BitmapFactory.decodeResource(view.getApplication().getResources(), R.drawable.map_route_direction_arrow, null);
Paint paint = wayContext.getPaintIcon();
paint.setStrokeCap(Cap.ROUND);
arrowBitmap = RenderingIcons.getBitmapFromVectorDrawable(view.getContext(), R.drawable.mm_special_arrow_up);
} }
@Override @Override
@ -415,15 +422,21 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
if (showArrows) { if (showArrows) {
QuadRect correctedQuadRect = getCorrectedQuadRect(tileBox.getLatLonBounds()); QuadRect correctedQuadRect = getCorrectedQuadRect(tileBox.getLatLonBounds());
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
int color = selectedGpxFile.getGpxFile().getColor(cachedColor); int color = selectedGpxFile.getGpxFile().getColor(cachedColor);
if (selectedGpxFile.isShowCurrentTrack()) { if (selectedGpxFile.isShowCurrentTrack()) {
color = currentTrackColor; color = currentTrackColor;
} }
if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) { if (hasTrackDrawInfoForSelectedGpx(selectedGpxFile)) {
color = trackDrawInfo.getColor(); color = trackDrawInfo.getColor();
width = trackDrawInfo.getWidth();
}
Float trackWidth = cachedTrackWidth.get(width);
if (trackWidth == null) {
trackWidth = defaultTrackWidth;
} }
int contrastColor = UiUtilities.getContrastColor(view.getApplication(), color, false); int contrastColor = UiUtilities.getContrastColor(view.getApplication(), color, false);
GeometryWayStyle arrowsWayStyle = new GeometryArrowsWayStyle(wayContext, contrastColor); GeometryWayStyle arrowsWayStyle = new GeometryArrowsWayStyle(wayContext, arrowBitmap, contrastColor, color, trackWidth);
for (TrkSegment segment : selectedGpxFile.getPointsToDisplay()) { for (TrkSegment segment : selectedGpxFile.getPointsToDisplay()) {
List<Float> tx = new ArrayList<>(); List<Float> tx = new ArrayList<>();
List<Float> ty = new ArrayList<>(); List<Float> ty = new ArrayList<>();
@ -465,10 +478,10 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
int bottom = pixHeight + pixHeight / 4; int bottom = pixHeight + pixHeight / 4;
double zoomCoef = tb.getZoomAnimation() > 0 ? (Math.pow(2, tb.getZoomAnimation() + tb.getZoomFloatPart())) : 1f; double zoomCoef = tb.getZoomAnimation() > 0 ? (Math.pow(2, tb.getZoomAnimation() + tb.getZoomFloatPart())) : 1f;
double pxStep = arrowBitmap.getHeight() * 4f * zoomCoef; double pxStep = arrowBitmap.getHeight() * DIRECTION_ARROW_DISTANCE_MULTIPLIER * zoomCoef;
double dist = 0; double dist = 0;
List<PathPoint> arrows = new ArrayList<>(); List<ArrowPathPoint> arrows = new ArrayList<>();
for (int i = tx.size() - 2; i >= 0; i--) { for (int i = tx.size() - 2; i >= 0; i--) {
float px = tx.get(i); float px = tx.get(i);
float py = ty.get(i); float py = ty.get(i);
@ -490,7 +503,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
float iconx = (float) (px + pdx); float iconx = (float) (px + pdx);
float icony = (float) (py + pdy); float icony = (float) (py + pdy);
if (isIn(iconx, icony, left, top, right, bottom)) { if (isIn(iconx, icony, left, top, right, bottom)) {
arrows.add(new PathPoint(iconx, icony, angle, wayStyle)); arrows.add(new ArrowPathPoint(iconx, icony, angle, wayStyle));
} }
dist -= pxStep; dist -= pxStep;
percent -= pxStep / distSegment; percent -= pxStep / distSegment;
@ -502,13 +515,43 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
} }
private static class ArrowPathPoint extends PathPoint {
ArrowPathPoint(float x, float y, double angle, GeometryWayStyle style) {
super(x, y, angle, style);
}
@Override
void draw(Canvas canvas, GeometryWayContext context) {
if (style instanceof GeometryArrowsWayStyle) {
GeometryArrowsWayStyle arrowsWayStyle = (GeometryArrowsWayStyle) style;
float arrowWidth = style.getPointBitmap().getWidth();
if (arrowWidth > arrowsWayStyle.getTrackWidth()) {
Paint paint = context.getPaintIcon();
paint.setColor(arrowsWayStyle.getTrackColor());
paint.setStrokeWidth(arrowWidth * DIRECTION_ARROW_CIRCLE_MULTIPLIER);
canvas.drawPoint(x, y, paint);
}
}
super.draw(canvas, context);
}
}
private static class GeometryArrowsWayStyle extends GeometryWayStyle { private static class GeometryArrowsWayStyle extends GeometryWayStyle {
protected Integer pointColor; private Bitmap arrowBitmap;
GeometryArrowsWayStyle(GeometryWayContext context, int pointColor) { protected int pointColor;
protected int trackColor;
protected float trackWidth;
GeometryArrowsWayStyle(GeometryWayContext context, Bitmap arrowBitmap, int arrowColor, int trackColor, float trackWidth) {
super(context); super(context);
this.pointColor = pointColor; this.arrowBitmap = arrowBitmap;
this.pointColor = arrowColor;
this.trackColor = trackColor;
this.trackWidth = trackWidth;
} }
@Override @Override
@ -524,13 +567,21 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
@Override @Override
public Bitmap getPointBitmap() { public Bitmap getPointBitmap() {
return getContext().getArrowBitmap(); return arrowBitmap;
} }
@Override @Override
public Integer getPointColor() { public Integer getPointColor() {
return pointColor; return pointColor;
} }
public int getTrackColor() {
return trackColor;
}
public float getTrackWidth() {
return trackWidth;
}
} }
private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) { private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {