If a GPX file doesn't contain timestamp, use the import

time as the track starting time.
This commit is contained in:
Jimmy Shih
2012-08-28 18:24:33 -07:00
parent 2f6e36a8bc
commit 09453d13cd
2 changed files with 14 additions and 8 deletions
@@ -102,6 +102,9 @@ public class GpxImporter extends DefaultHandler {
// True if the current track has a start time
private boolean hasStartTime;
// The import time
private long importTime;
// The current location
private Location location;
@@ -261,8 +264,9 @@ public class GpxImporter extends DefaultHandler {
private void onTrackElementEnd() {
flushPoints();
if (tripStatisticsUpdater == null) {
tripStatisticsUpdater = new TripStatisticsUpdater(-1L);
tripStatisticsUpdater.updateTime(-1L);
long now = System.currentTimeMillis();
tripStatisticsUpdater = new TripStatisticsUpdater(now);
tripStatisticsUpdater.updateTime(now);
}
track.setStopId(getLastPointId());
track.setTripStatistics(tripStatisticsUpdater.getTripStatistics());
@@ -450,11 +454,13 @@ public class GpxImporter extends DefaultHandler {
*/
private void insertPoint(Location newLocation) {
if (tripStatisticsUpdater == null) {
tripStatisticsUpdater = new TripStatisticsUpdater(newLocation.getTime());
hasStartTime = newLocation.getTime() != -1L;
importTime = System.currentTimeMillis();
tripStatisticsUpdater = new TripStatisticsUpdater(
hasStartTime ? newLocation.getTime() : importTime);
}
if (!hasStartTime) {
newLocation.setTime(-1L);
newLocation.setTime(importTime);
}
tripStatisticsUpdater.addLocation(newLocation, minRecordingDistance);
@@ -247,13 +247,11 @@ public class GpxImporterTest extends AndroidTestCase {
public void testOneTrackTwoSegmentsNoTime() throws Exception {
Capture<Track> capturedTrack = new Capture<Track>();
Location location0 = createLocation(0, -1L);
expect(myTracksProviderUtils.insertTrack((Track) AndroidMock.anyObject()))
.andReturn(TRACK_ID_0_URI);
// A flush happens before getting the start point ID
expect(myTracksProviderUtils.bulkInsertTrackPoint(
LocationsMatcher.eqLoc(location0), eq(1), eq(TRACK_ID_0))).andReturn(1);
(Location[]) AndroidMock.anyObject(), eq(1), eq(TRACK_ID_0))).andReturn(1);
expect(myTracksProviderUtils.getFirstTrackPointId(TRACK_ID_0)).andReturn(TRACK_POINT_ID_0);
// A flush happens at the end
@@ -330,7 +328,9 @@ public class GpxImporterTest extends AndroidTestCase {
private void verifyTrack(Track track, String name, String description, long time) {
assertEquals(name, track.getName());
assertEquals(description, track.getDescription());
assertEquals(time, track.getTripStatistics().getStartTime());
if (time != -1L) {
assertEquals(time, track.getTripStatistics().getStartTime());
}
assertNotSame(-1, track.getStartId());
assertNotSame(-1, track.getStopId());
}