From d8ddb717427df979d339412e36c0d694f325d4c5 Mon Sep 17 00:00:00 2001 From: cepprice Date: Sun, 4 Apr 2021 18:03:09 +0500 Subject: [PATCH] Fixes after review --- .../java/net/osmand/router/RouteColorize.java | 21 +++++++------- .../osmand/plus/views/layers/GPXLayer.java | 28 +++++++++++++++---- 2 files changed, 34 insertions(+), 15 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 e224e9c679..a4d5e8a597 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java @@ -1,10 +1,13 @@ package net.osmand.router; -import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXTrackAnalysis; +import net.osmand.GPXUtilities.Track; +import net.osmand.GPXUtilities.TrkSegment; +import net.osmand.GPXUtilities.WptPt; import net.osmand.PlatformUtil; import net.osmand.osm.edit.Node; import net.osmand.osm.edit.OsmMapUtils; -import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -78,7 +81,7 @@ public class RouteColorize { /** * @param type ELEVATION, SPEED, SLOPE */ - public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ColorizationType type, float maxProfileSpeed) { + public RouteColorize(int zoom, GPXFile gpxFile, GPXTrackAnalysis analysis, ColorizationType type, float maxProfileSpeed) { if (!gpxFile.hasTrkPt()) { LOG.warn("GPX file is not consist of track points"); @@ -89,12 +92,10 @@ public class RouteColorize { List lonList = new ArrayList<>(); List valList = new ArrayList<>(); - GPXUtilities.GPXTrackAnalysis analysis = Algorithms.isEmpty(gpxFile.path) ? - gpxFile.getAnalysis(System.currentTimeMillis()) : gpxFile.getAnalysis(gpxFile.modifiedTime); int wptIdx = 0; - for (GPXUtilities.Track t : gpxFile.tracks) { - for (GPXUtilities.TrkSegment ts : t.segments) { - for (GPXUtilities.WptPt p : ts.points) { + for (Track t : gpxFile.tracks) { + for (TrkSegment ts : t.segments) { + for (WptPt p : ts.points) { latList.add(p.lat); lonList.add(p.lon); if (type == ColorizationType.SPEED) { @@ -405,11 +406,11 @@ public class RouteColorize { return result; } - public static double getMinValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis) { + public static double getMinValue(ColorizationType type, GPXTrackAnalysis analysis) { return type == ColorizationType.ELEVATION ? analysis.minElevation : 0.0; } - public static double getMaxValue(ColorizationType type, GPXUtilities.GPXTrackAnalysis analysis, double minValue, double maxProfileSpeed) { + public static double getMaxValue(ColorizationType type, GPXTrackAnalysis analysis, double minValue, double maxProfileSpeed) { if (type == ColorizationType.SPEED) { return Math.max(analysis.maxSpeed, maxProfileSpeed); } else if (type == ColorizationType.ELEVATION) { diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index 5c757285ef..69266746a9 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -680,16 +680,15 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { + OsmandApplication app = view.getApplication(); GPXFile gpxFile = selectedGpxFile.getGpxFile(); List segments = selectedGpxFile.getPointsToDisplay(); GradientScaleType scaleType = getGradientScaleType(gpxFile); List colorsOfPoints = null; - boolean needCalculateColors = scaleType != null && segments.get(0).points.get(0) - .getColor(scaleType.toColorizationType()) == 0; - if (scaleType != null && currentTrack || needCalculateColors) { - RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, - scaleType.toColorizationType(), view.getApplication().getSettings().getApplicationMode().getMaxSpeed()); + if (needCalculatePointsColors(segments, scaleType)) { + RouteColorize colorize = new RouteColorize(view.getZoom(), gpxFile, selectedGpxFile.getTrackAnalysis(app), + scaleType.toColorizationType(), app.getSettings().getApplicationMode().getMaxSpeed()); colorize.setPalette(getColorizationPalette(gpxFile, scaleType)); colorsOfPoints = colorize.getResult(false); } @@ -721,6 +720,25 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM } } + private boolean needCalculatePointsColors(List segments, GradientScaleType scaleType) { + if (scaleType == null) { + return false; + } + RouteColorize.ColorizationType colorizationType = scaleType.toColorizationType(); + for (int segIdx = segments.size() - 1; segIdx >= 0; segIdx--) { + List pts = segments.get(segIdx).points; + if (!Algorithms.isEmpty(pts)) { + for (int wptIdx = pts.size() - 1; wptIdx >= 0; wptIdx--) { + WptPt pt = pts.get(wptIdx); + if (pt.getColor(colorizationType) == 0) { + return true; + } + } + } + } + return false; + } + private int setColorsToPoints(TrkSegment segment, List colors, GradientScaleType scaleType, int startIdx) { int pointsSize = segment.points.size(); RouteColorize.RouteColorizationPoint startColor = colors.get(startIdx);