From 687e5f6d814b4642e5cd623cf86fc4bc26707565 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 7 Apr 2021 10:44:04 +0500 Subject: [PATCH 1/4] Change condition of multi profile mode --- .../MeasurementEditingContext.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java index af4d599afa..2de8070b58 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementEditingContext.java @@ -2,6 +2,7 @@ package net.osmand.plus.measurementtool; import android.util.Pair; +import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; @@ -1115,16 +1116,26 @@ public class MeasurementEditingContext implements IRouteSettingsListener { } public boolean isInMultiProfileMode() { - if (lastCalculationMode == CalculationMode.NEXT_SEGMENT) { - return true; - } Set profiles = new HashSet<>(); - for (RoadSegmentData segmentData : roadSegmentData.values()) { - String profile = segmentData.getAppMode().getStringKey(); - if (!DEFAULT_APP_MODE.getStringKey().equals(profile)) { - profiles.add(profile); + List allSegments = new ArrayList<>(); + allSegments.addAll(beforeSegments); + allSegments.addAll(afterSegments); + for (TrkSegment segment : allSegments) { + List points = segment.points; + if (Algorithms.isEmpty(points)) { + continue; + } + for (int i = 0; i < points.size() / 2 + 1; i++) { + WptPt left = points.get(i); + int rightIdx = points.size() - 1 - i; + WptPt right = points.get(rightIdx); + if (!left.isGap() && i + 1 < points.size()) { + profiles.add(left.getProfileType()); + } + if (!right.isGap() && rightIdx + 1 < points.size()) { + profiles.add(right.getProfileType()); + } if (profiles.size() >= 2) { - lastCalculationMode = NEXT_SEGMENT; return true; } } From 14272afa44beb2c298099b3e8da7b4d45ec57b02 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 7 Apr 2021 11:55:59 +0500 Subject: [PATCH 2/4] Fix line visibility on high zoom --- .../views/layers/geometry/GeometryWay.java | 11 +++----- .../geometry/MultiProfileGeometryWay.java | 25 +++++++++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) 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 ab98990d36..aed7a2f315 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/GeometryWay.java @@ -4,15 +4,10 @@ import android.graphics.Canvas; import android.graphics.Path; import android.util.Pair; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - 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; @@ -20,6 +15,8 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import gnu.trove.list.array.TByteArrayList; public abstract class GeometryWay> { @@ -176,7 +173,7 @@ public abstract class GeometryWay { @@ -148,19 +149,23 @@ public class MultiProfileGeometryWay extends GeometryWay= provider.getSize()) { - return false; + double currLat = provider.getLatitude(currLocationIdx); + double currLon = provider.getLongitude(currLocationIdx); + + int nextIdx = currLocationIdx; + for (int i = nextIdx + 1; i < simplification.size(); i++) { + if (simplification.getQuick(i) == 1) { + nextIdx = i; + } } - float nextX = tileBox.getPixXFromLatLon(provider.getLatitude(currLocationIdx + 1), provider.getLongitude(currLocationIdx + 1)); - float nextY = tileBox.getPixXFromLatLon(provider.getLatitude(currLocationIdx + 1), provider.getLongitude(currLocationIdx + 1)); - return tileBox.containsPoint(nextX, nextY, getContext().circleSize); + + double nextLat = provider.getLatitude(nextIdx); + double nextLon = provider.getLongitude(nextIdx); + return Math.min(currLon, nextLon) < rightLon && Math.max(currLon, nextLon) > leftLon + && Math.min(currLat, nextLat) < topLat && Math.max(currLat, nextLat) > bottomLat; } private boolean segmentDataChanged(Map, RoadSegmentData> other) { From 077f57c830ece37ba069b854c36bb68fe346b841 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 7 Apr 2021 12:10:17 +0500 Subject: [PATCH 3/4] Fix route points --- .../views/layers/geometry/MultiProfileGeometryWay.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java index c004dc7fcd..7deff7b264 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWay.java @@ -141,9 +141,18 @@ public class MultiProfileGeometryWay extends GeometryWay points = roadSegmentData.getPoints(); + if (points.get(0).getLatitude() != start.getLatitude() && points.get(0).getLongitude() != start.getLongitude()) { + routePoints.add(new LatLon(start.lat, start.lon)); + } for (WptPt routePt : roadSegmentData.getPoints()) { routePoints.add(new LatLon(routePt.lat, routePt.lon)); } + int lastIdx = routePoints.size() - 1; + if (routePoints.get(lastIdx).getLatitude() != end.getLatitude() + && routePoints.get(lastIdx).getLongitude() != end.getLongitude()) { + routePoints.add(new LatLon(end.lat, end.lon)); + } } return routePoints; } From 482acc95f1e7455584628ee68df571dec98fcb55 Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 7 Apr 2021 13:12:37 +0500 Subject: [PATCH 4/4] Fix NPE --- .../MultiProfileGeometryWayContext.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) 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 d6ef3cfa72..0edb3bf67f 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/MultiProfileGeometryWayContext.java @@ -31,7 +31,7 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { private RenderingLineAttributes multiProfileAttrs; - private Bitmap pointIcon; + private final Bitmap pointIcon; private final Map profileIconsBitmapCache; public MultiProfileGeometryWayContext(Context ctx, UiUtilities iconsCache, float density) { @@ -41,6 +41,7 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { minIconMargin = density * 30; circleSize = density * 70; pointIconSize = density * 22f; + pointIcon = createPointIcon(); } public void updatePaints(boolean nightMode, @NonNull RenderingLineAttributes multiProfileAttrs) { @@ -48,29 +49,6 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { super.updatePaints(nightMode, multiProfileAttrs); } - @Override - protected void recreateBitmaps() { - float density = getDensity(); - float outerRadius = density * 11f; - float centerRadius = density * 10.5f; - float innerRadius = density * 6.5f; - float centerXY = pointIconSize / 2; - - pointIcon = Bitmap.createBitmap((int) pointIconSize, (int) pointIconSize, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(pointIcon); - Paint paint = new Paint(); - paint.setStyle(Paint.Style.FILL); - - paint.setColor(Color.BLACK); - canvas.drawCircle(centerXY, centerXY, outerRadius, paint); - - paint.setColor(Color.WHITE); - canvas.drawCircle(centerXY, centerXY, centerRadius, paint); - - paint.setColor(Algorithms.parseColor(pointColorHex)); - canvas.drawCircle(centerXY, centerXY, innerRadius, paint); - } - @NonNull public Bitmap getProfileIconBitmap(@DrawableRes int iconRes, @ColorInt int color) { String key = iconRes + "_" + color; @@ -94,6 +72,30 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext { return bitmap; } + private Bitmap createPointIcon() { + float density = getDensity(); + float outerRadius = density * 11f; + float centerRadius = density * 10.5f; + float innerRadius = density * 6.5f; + float centerXY = pointIconSize / 2; + + Bitmap bitmap = Bitmap.createBitmap((int) pointIconSize, (int) pointIconSize, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + Paint paint = new Paint(); + paint.setStyle(Paint.Style.FILL); + + paint.setColor(Color.BLACK); + canvas.drawCircle(centerXY, centerXY, outerRadius, paint); + + paint.setColor(Color.WHITE); + canvas.drawCircle(centerXY, centerXY, centerRadius, paint); + + paint.setColor(Algorithms.parseColor(pointColorHex)); + canvas.drawCircle(centerXY, centerXY, innerRadius, paint); + + return bitmap; + } + @NonNull public Bitmap getPointIcon() { return pointIcon;