Fixing bug in GPX import - we were reading the last point time too soon

This commit is contained in:
Rodrigo Damazio
2010-05-22 01:17:59 -07:00
parent 81ee6bbcf6
commit c4efcfd2db
@@ -119,7 +119,6 @@ public class GpxImport {
} else if (segmentNode.getNodeName().equals("description")) { } else if (segmentNode.getNodeName().equals("description")) {
track.setDescription(segmentNode.getFirstChild().getNodeValue()); track.setDescription(segmentNode.getFirstChild().getNodeValue());
} else if (segmentNode.getNodeName().equals("trkseg")) { } else if (segmentNode.getNodeName().equals("trkseg")) {
long pointTime = locations.get(locations.size() - 1).getTime();
if (nSegments > 0) { if (nSegments > 0) {
// Add a segment separator: // Add a segment separator:
Location location = new Location("gps"); Location location = new Location("gps");
@@ -127,6 +126,7 @@ public class GpxImport {
location.setLongitude(100.0); location.setLongitude(100.0);
location.setAltitude(0); location.setAltitude(0);
if (locations.size() > 0) { if (locations.size() > 0) {
long pointTime = locations.get(locations.size() - 1).getTime();
location.setTime(pointTime); location.setTime(pointTime);
} }
track.addLocation(location); track.addLocation(location);
@@ -217,7 +217,6 @@ public class GpxImport {
track.setStartTime(startTime); track.setStartTime(startTime);
// Calculate statistics for the imported track // Calculate statistics for the imported track
int numberOfPoints = locations.size();
TripStatistics stats = new TripStatistics(startTime); TripStatistics stats = new TripStatistics(startTime);
for (Location location : locations) { for (Location location : locations) {
if (MyTracksUtils.isValidLocation(location)) { if (MyTracksUtils.isValidLocation(location)) {
@@ -225,8 +224,9 @@ public class GpxImport {
stats.addLocation(location, location.getTime()); stats.addLocation(location, location.getTime());
} }
} }
stats.pauseAt(pointTime); long lastPointTime = locations.get(locations.size() - 1).getTime();
track.setStopTime(pointTime); stats.pauseAt(lastPointTime);
track.setStopTime(lastPointTime);
stats.fillStatisticsForTrack(track); stats.fillStatisticsForTrack(track);
} }