From 1dd4b4b576ab5d22ffa512781e0d8d9e131850a0 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 28 Sep 2015 23:53:07 +0200 Subject: [PATCH] Fix #1349 --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 18 +++++++++++++----- .../net/osmand/plus/GpxSelectionHelper.java | 11 +++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index f2dcc49760..626d7161d6 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -142,16 +142,16 @@ public class GPXUtilities { public List points = new ArrayList(); public List splitByDistance(double meters) { - return split(getDistanceMetric(), meters); + return split(getDistanceMetric(), getTimeSplit(), meters); } public List splitByTime(int seconds) { - return split(getTimeSplit(), seconds); + return split(getTimeSplit(), getDistanceMetric(), seconds); } - private List split(SplitMetric metric, double metricLimit) { + private List split(SplitMetric metric, SplitMetric secondaryMetric, double metricLimit) { List splitSegments = new ArrayList(); - splitSegment(metric, metricLimit, splitSegments, this); + splitSegment(metric, secondaryMetric, metricLimit, splitSegments, this); return convert(splitSegments); } @@ -193,6 +193,7 @@ public class GPXUtilities { public int wptPoints = 0; public double metricEnd; + public double secondaryMetricEnd; public WptPt locationStart; public WptPt locationEnd; @@ -242,6 +243,7 @@ public class GPXUtilities { channelThres = channelThresMin; metricEnd += s.metricEnd; + secondaryMetricEnd += s.secondaryMetricEnd; points += numberOfPoints; for (int j = 0; j < numberOfPoints; j++) { WptPt point = s.get(j); @@ -390,6 +392,7 @@ public class GPXUtilities { double endCoeff = 0; int endPointInd; double metricEnd; + double secondaryMetricEnd; public SplitSegment(TrkSegment s) { startPointInd = 0; @@ -497,9 +500,11 @@ public class GPXUtilities { } - private static void splitSegment(SplitMetric metric, double metricLimit, List splitSegments, + private static void splitSegment(SplitMetric metric, SplitMetric secondaryMetric, + double metricLimit, List splitSegments, TrkSegment segment) { double currentMetricEnd = metricLimit; + double secondaryMetricEnd = 0; SplitSegment sp = new SplitSegment(segment, 0, 0); double total = 0; WptPt prev = null ; @@ -507,11 +512,13 @@ public class GPXUtilities { WptPt point = segment.points.get(k); if (k > 0) { double currentSegment = metric.metric(prev, point); + secondaryMetricEnd += secondaryMetric.metric(prev, point); while (total + currentSegment > currentMetricEnd) { double p = currentMetricEnd - total; double cf = (p / currentSegment); sp.setLastPoint(k - 1, cf); sp.metricEnd = currentMetricEnd; + sp.secondaryMetricEnd = secondaryMetricEnd; splitSegments.add(sp); sp = new SplitSegment(segment, k - 1, cf); @@ -525,6 +532,7 @@ public class GPXUtilities { if (segment.points.size() > 0 && !(sp.endPointInd == segment.points.size() - 1 && sp.startCoeff == 1)) { sp.metricEnd = total; + sp.secondaryMetricEnd = secondaryMetricEnd; sp.setLastPoint(segment.points.size() - 2, 1); splitSegments.add(sp); } diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 6a0bf34452..0036c70416 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -180,7 +180,9 @@ public class GpxSelectionHelper { item.group = group; if(split) { item.splitMetric = analysis.metricEnd; + item.secondarySplitMetric = analysis.secondaryMetricEnd; item.splitName = formatSplitName(analysis.metricEnd, group, app); + item.splitName += " ("+formatSecondarySplitName(analysis.secondaryMetricEnd, group, app) +") "; } item.description = GpxUiHelper.getDescription(app, analysis, true); @@ -234,6 +236,14 @@ public class GpxSelectionHelper { } } } + + private static String formatSecondarySplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) { + if (group.isSplitDistance()) { + return Algorithms.formatDuration((int) metricEnd); + } else { + return OsmAndFormatter.getFormattedDistance((float) metricEnd, app); + } + } private static String formatSplitName(double metricEnd, GpxDisplayGroup group, OsmandApplication app) { if (group.isSplitDistance()) { @@ -607,6 +617,7 @@ public class GpxSelectionHelper { public WptPt locationStart; public WptPt locationEnd; public double splitMetric = -1; + public double secondarySplitMetric = -1; public String splitName; public String name; public String description;