+
+ // Moving distance
+ double movingDist = selection.getMovingDistance();
+ _movingDistanceLabel.setText(roundedNumber(movingDist) + " " + distUnitsStr);
+ // Moving average speed
+ long numMovingSecs = selection.getMovingSeconds();
+ if (numMovingSecs > 0)
+ {
+ _movingDurationLabel.setText(DisplayUtils.buildDurationString(numMovingSecs));
+ _movingSpeedLabel.setText(roundedNumber(movingDist/numMovingSecs*3600.0)
+ + " " + speedUnitsStr);
+ _movingPaceLabel.setText(
+ DisplayUtils.buildDurationString((long) (numMovingSecs/movingDist))
+ + " / " + distUnitsStr);
+ }
+ else
+ {
+ _movingDurationLabel.setText("");
+ _movingSpeedLabel.setText("");
+ _movingPaceLabel.setText("");
+ }
+
+ // Moving gradient and moving climb/descent
+ Altitude firstAlt = null, lastAlt = null;
+ Altitude veryFirstAlt = null, veryLastAlt = null;
+ AltitudeRange altRange = new AltitudeRange();
+ double movingHeightDiff = 0.0;
+ if (movingDist > 0.0)
+ {
+ for (int pNum = selection.getStart(); pNum <= selection.getEnd(); pNum++)
+ {
+ DataPoint p = _app.getTrackInfo().getTrack().getPoint(pNum);
+ if (p != null && !p.isWaypoint())
+ {
+ // If we're starting a new segment, calculate the height diff of the previous one
+ if (p.getSegmentStart())
+ {
+ if (firstAlt != null && firstAlt.isValid() && lastAlt != null && lastAlt.isValid())
+ movingHeightDiff = movingHeightDiff + lastAlt.getMetricValue() - firstAlt.getMetricValue();
+ firstAlt = null; lastAlt = null;
+ }
+ Altitude alt = p.getAltitude();
+ if (alt != null && alt.isValid())
+ {
+ if (firstAlt == null) firstAlt = alt;
+ else lastAlt = alt;
+ if (veryFirstAlt == null) veryFirstAlt = alt;
+ else veryLastAlt = alt;
+ }
+ // Keep track of climb and descent too
+ if (p.getSegmentStart())
+ altRange.ignoreValue(alt);
+ else
+ altRange.addValue(alt);
+ }
+ }
+ // deal with last segment
+ if (firstAlt != null && firstAlt.isValid() && lastAlt != null && lastAlt.isValid())
+ movingHeightDiff = movingHeightDiff + lastAlt.getMetricValue() - firstAlt.getMetricValue();
+ final double metricMovingDist = movingDist / distUnit.getMultFactorFromStd(); // convert back to metres
+ final double gradient = movingHeightDiff * 100.0 / metricMovingDist;
+ _movingGradientLabel.setText(FORMAT_ONE_DP.format(gradient) + " %");
+ }
+ if (!altRange.hasRange()) {
+ _movingGradientLabel.setText("");
+ }
+ final boolean hasAltitudes = veryFirstAlt != null && veryFirstAlt.isValid() && veryLastAlt != null && veryLastAlt.isValid();
+
+ // Total gradient
+ final double metreDist = selection.getDistance() / distUnit.getMultFactorFromStd(); // convert back to metres
+ if (hasAltitudes && metreDist > 0.0)