From eb4a1108f8a346448d1bdf636a54981fff40a9ab Mon Sep 17 00:00:00 2001 From: cepprice Date: Mon, 5 Apr 2021 11:44:55 +0500 Subject: [PATCH] Review fixes --- .../MeasurementEditingContext.java | 29 ++++++++++++++++--- .../views/layers/geometry/GeometryWay.java | 12 ++++++-- .../layers/geometry/GeometryWayContext.java | 3 +- .../geometry/MultiProfileGeometryWay.java | 28 ++++-------------- .../MultiProfileGeometryWayContext.java | 15 ++++++---- .../MultiProfileGeometryWayDrawer.java | 12 +++----- 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index bda7c5404b..ba28e9402a 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -2,9 +2,6 @@ package net.osmand.plus.measurementtool; import android.util.Pair; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; @@ -38,12 +35,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.NEXT_SEGMENT; import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK; import static net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType.APPROXIMATE_POINTS; @@ -1112,7 +1115,25 @@ public class MeasurementEditingContext implements IRouteSettingsListener { } public boolean isInMultiProfileMode() { - return lastCalculationMode == CalculationMode.NEXT_SEGMENT; + if (lastCalculationMode == CalculationMode.NEXT_SEGMENT) { + return true; + } + Set profiles = new HashSet<>(); + List segments = new ArrayList<>(); + segments.addAll(beforeSegments); + segments.addAll(afterSegments); + for (TrkSegment segment : segments) { + if (Algorithms.isEmpty(segment.points)) { + continue; + } + for (WptPt pt : segment.points) { + if (!pt.isGap()) { + profiles.add(pt.getProfileType()); + } + } + } + lastCalculationMode = profiles.size() >= 2 ? NEXT_SEGMENT : WHOLE_TRACK; + return profiles.size() >= 2; } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java index 9489cd9620..d5f206ec90 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java @@ -11,6 +11,8 @@ import net.osmand.Location; import net.osmand.data.RotatedTileBox; import net.osmand.util.MapAlgorithms; import net.osmand.util.MapUtils; +import net.osmand.plus.views.layers.geometry.MultiProfileGeometryWay.GeometryMultiProfileWayStyle; + import java.util.ArrayList; import java.util.Collections; @@ -188,7 +190,9 @@ public abstract class GeometryWay prevStyle = style instanceof GeometryMultiProfileWayStyle ? + getStyle(i - 1, style) : style; + addLocation(tb, prevLat, prevLon, prevStyle, tx, ty, angles, distances, dist, styles); // first point } } addLocation(tb, lat, lon, style, tx, ty, angles, distances, dist, styles); @@ -360,7 +364,7 @@ public abstract class GeometryWay>> paths = new ArrayList<>(); canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY()); - calculatePath(tb, tx, ty, 0, styles, paths); + calculatePath(tb, tx, ty, getOutMargin(), styles, paths); for (Pair> pc : paths) { GeometryWayStyle style = pc.second; if (style.hasPathLine()) { @@ -377,6 +381,10 @@ public abstract class GeometryWay tx, List ty, List angles, List distances, double distToFinish, List> styles) { - if (tx.size() < 2) { - return; - } - try { - List>> pathStyles = new ArrayList<>(); - canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY()); - calculatePath(tb, tx, ty, getContext().circleSize, styles, pathStyles); - - for (int i = 0; i < pathStyles.size(); i++) { - Pair> currPathStyle = pathStyles.get(i); - if (!((GeometryMultiProfileWayStyle) currPathStyle.second).isGap) { - getDrawer().drawPathBorder(canvas, currPathStyle.first, currPathStyle.second); - getDrawer().drawPath(canvas, currPathStyle.first, currPathStyle.second); - } - } - getDrawer().drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles); - } finally { - canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY()); - } - } - public void updateRoute(RotatedTileBox tileBox, Map, RoadSegmentData> segmentData, List beforeSegments, List afterSegments) { boolean shouldUpdateRoute = tileBox.getMapDensity() != getMapDensity() || segmentDataChanged(segmentData) @@ -231,6 +208,11 @@ public class MultiProfileGeometryWay extends GeometryWay(mode.getProfileColor(night), mode.getIconRes()); } + @Override + protected float getOutMargin() { + return getContext().getAttrs().paint.getStrokeWidth() * 2; + } + @NonNull @Override public GeometryWayStyle getDefaultWayStyle() { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java index 555194ba87..d6ef3cfa72 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java @@ -7,6 +7,7 @@ import android.graphics.Color; import android.graphics.Paint; import net.osmand.AndroidUtils; +import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.views.OsmandMapLayer.RenderingLineAttributes; import net.osmand.util.Algorithms; @@ -26,6 +27,8 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { public final float circleSize; public final float pointIconSize; + private static final String pointColorHex = "#637EFB"; + private RenderingLineAttributes multiProfileAttrs; private Bitmap pointIcon; @@ -64,15 +67,10 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { paint.setColor(Color.WHITE); canvas.drawCircle(centerXY, centerXY, centerRadius, paint); - paint.setColor(Algorithms.parseColor("#637EFB")); + paint.setColor(Algorithms.parseColor(pointColorHex)); canvas.drawCircle(centerXY, centerXY, innerRadius, paint); } - @Override - protected int getArrowBitmapResId() { - return 0; - } - @NonNull public Bitmap getProfileIconBitmap(@DrawableRes int iconRes, @ColorInt int color) { String key = iconRes + "_" + color; @@ -100,4 +98,9 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { public Bitmap getPointIcon() { return pointIcon; } + + @Override + protected int getArrowBitmapResId() { + return R.drawable.ic_action_split_interval; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayDrawer.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayDrawer.java index 7bc5620d18..52fed039ac 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayDrawer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayDrawer.java @@ -19,6 +19,10 @@ public class MultiProfileGeometryWayDrawer extends GeometryWayDrawer style) { if (style instanceof GeometryMultiProfileWayStyle) { RenderingLineAttributes attrs = getContext().getAttrs(); + + attrs.paint.setColor(((GeometryMultiProfileWayStyle) style).getBorderColor()); + canvas.drawPath(path, attrs.paint); + attrs.paint2.setColor(((GeometryMultiProfileWayStyle) style).getLineColor()); canvas.drawPath(path, attrs.paint2); } @@ -42,12 +46,4 @@ public class MultiProfileGeometryWayDrawer extends GeometryWayDrawer style) { - if (style instanceof GeometryMultiProfileWayStyle) { - RenderingLineAttributes attrs = getContext().getAttrs(); - attrs.paint.setColor(((GeometryMultiProfileWayStyle) style).getBorderColor()); - canvas.drawPath(path, attrs.paint); - } - } } \ No newline at end of file