From 4de1aa9193f8f646f360918f0b8dc149691af04e Mon Sep 17 00:00:00 2001 From: cepprice Date: Wed, 21 Apr 2021 23:51:15 +0500 Subject: [PATCH] Fix crash and other fixes --- .../java/net/osmand/router/RouteColorize.java | 2 +- .../net/osmand/plus/helpers/GpxUiHelper.java | 18 +++++------------- .../layers/geometry/RouteGeometryWay.java | 12 +++++------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java index 0db39d0695..ece3b01a38 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java @@ -200,7 +200,7 @@ public class RouteColorize { public int getColorByValue(double value) { if (Double.isNaN(value)) { - value = (minValue + maxValue) / 2; + value = colorizationType == ColorizationType.SLOPE ? minValue : (minValue + maxValue) / 2; } for (int i = 0; i < palette.length - 1; i++) { if (value == palette[i][VALUE_INDEX]) diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 9d6b019cc2..75d62d6f0a 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -2124,9 +2124,12 @@ public class GpxUiHelper { public static GPXFile makeGpxFromRoute(RouteCalculationResult route, OsmandApplication app) { + return makeGpxFromLocations(route.getRouteLocations(), app); + } + + public static GPXFile makeGpxFromLocations(List locations, OsmandApplication app) { double lastHeight = HEIGHT_UNDEFINED; GPXFile gpx = new GPXUtilities.GPXFile(Version.getFullVersion(app)); - List locations = route.getRouteLocations(); if (locations != null) { GPXUtilities.Track track = new GPXUtilities.Track(); GPXUtilities.TrkSegment seg = new GPXUtilities.TrkSegment(); @@ -2139,8 +2142,7 @@ public class GpxUiHelper { float h = (float) l.getAltitude(); point.ele = h; if (lastHeight == HEIGHT_UNDEFINED && seg.points.size() > 0) { - for (int i = seg.points.size() - 1; i >= 0; i--) { - GPXUtilities.WptPt pt = seg.points.get(i); + for (GPXUtilities.WptPt pt : seg.points) { if (Double.isNaN(pt.ele)) { pt.ele = h; } @@ -2152,16 +2154,6 @@ public class GpxUiHelper { } seg.points.add(point); } - if (lastHeight == HEIGHT_UNDEFINED && gpx.hasAltitude) { - int start = seg.points.size() - 1; - while (start > 0 && Double.isNaN(seg.points.get(start).ele)) { - start--; - } - double ele = seg.points.get(start).ele; - for (int i = start + 1; i < seg.points.size(); i++) { - seg.points.get(i).ele = ele; - } - } track.segments.add(seg); gpx.tracks.add(track); } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/geometry/RouteGeometryWay.java b/OsmAnd/src/net/osmand/plus/views/layers/geometry/RouteGeometryWay.java index 8d3ff947e9..a21a6ad29a 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/geometry/RouteGeometryWay.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/geometry/RouteGeometryWay.java @@ -72,7 +72,7 @@ public class RouteGeometryWay extends GeometryWay