diff --git a/MyTracks/src/com/google/android/apps/mytracks/MyTracksMap.java b/MyTracks/src/com/google/android/apps/mytracks/MyTracksMap.java index 700db0687..a34bec3ac 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/MyTracksMap.java +++ b/MyTracks/src/com/google/android/apps/mytracks/MyTracksMap.java @@ -165,11 +165,12 @@ public class MyTracksMap extends MapActivity final int idColumnIdx = cursor.getColumnIndexOrThrow(TrackPointsColumns._ID); int i = 0; - // TODO We should update the samplingFrequency. + setSamplingFrequency(selectedTrack); do { - if (i % samplingFrequency == 0) { + Location location = providerUtils.createLocation(cursor); + if (i % samplingFrequency == 0 || + MyTracksUtils.isValidLocation(location)) { lastSeenLocationId = cursor.getLong(idColumnIdx); - Location location = providerUtils.createLocation(cursor); if (location != null) { mapOverlay.addLocation(location); } @@ -199,16 +200,12 @@ public class MyTracksMap extends MapActivity return; } Cursor cursor = null; + long totalLocations = selectedTrack.getStopId() - + selectedTrack.getStartId(); + mapOverlay.clearPoints(); lastSeenLocationId = selectedTrack.getStartId(); - long totalLocations = selectedTrack.getStopId() - - selectedTrack.getStartId(); - - // Limit the number of map points readings. - samplingFrequency = - (int) (1 + - totalLocations / MyTracksConstants.TARGET_DISPLAYED_TRACK_POINTS); - Log.i(MyTracksConstants.TAG, "Sampling locations: " + samplingFrequency); + setSamplingFrequency(selectedTrack); int bufferSize = 1024; try { int points = 0; @@ -1041,4 +1038,15 @@ public class MyTracksMap extends MapActivity public void onAccuracyChanged(Sensor s, int accuracy) { // do nothing } + + private void setSamplingFrequency(Track track) { + long totalLocations = track.getStopId() - track.getStartId(); + + // Limit the number of map points readings. + samplingFrequency = + (int) (1 + + totalLocations / MyTracksConstants.TARGET_DISPLAYED_TRACK_POINTS); + Log.i(MyTracksConstants.TAG, "Sampling locations: " + samplingFrequency); + + } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/StatsActivity.java b/MyTracks/src/com/google/android/apps/mytracks/StatsActivity.java index dc69aaa40..a0deb9c4a 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/StatsActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/StatsActivity.java @@ -353,6 +353,11 @@ public class StatsActivity extends Activity } track = providerUtils.getTrack(selectedTrackId); + startTime = track.getStatistics().getStartTime(); + if(!selectedTrackIsRecording()) { + utils.setTime(R.id.total_time_register, + track.getStatistics().getTotalTime()); + } utils.setAllStats(track.getStatistics()); } diff --git a/MyTracksTest/.classpath b/MyTracksTest/.classpath index f8a6020f2..a00f8a660 100644 --- a/MyTracksTest/.classpath +++ b/MyTracksTest/.classpath @@ -1,9 +1,9 @@ - + diff --git a/MyTracksTest/.project b/MyTracksTest/.project index b913f616a..3f06cef1f 100644 --- a/MyTracksTest/.project +++ b/MyTracksTest/.project @@ -3,7 +3,7 @@ MyTracksTest - MyTracks + MyTracks-opensource diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java new file mode 100644 index 000000000..3e9913a32 --- /dev/null +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java @@ -0,0 +1,66 @@ +// Copyright 2010 Google Inc. All Rights Reserved. +package com.google.android.apps.mytracks.io; + +import android.location.Location; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.util.Date; +import java.util.List; + +/** + * Tests for the GPX track exporter. + * + * @author Rodrigo Damazio + */ +public class TcxTrackWriterTest extends TrackFormatWriterTest { + + public void testXmlOutput() throws Exception { + TrackFormatWriter writer = new TcxTrackWriter(); + String result = writeTrack(writer); + Document doc = parseXmlDocument(result); + + Element root = getChildElement(doc, "TrainingCenterDatabase"); + Element activitiesTag = getChildElement(root, "Activities"); + Element activityTag = getChildElement(activitiesTag, "Activity"); + Element lapTag = getChildElement(activityTag, "Lap"); + + List segmentTags = getChildElements(lapTag, "Track", 2); + Element segment1Tag = segmentTags.get(0); + Element segment2Tag = segmentTags.get(1); + List seg1PointTags = getChildElements(segment1Tag, "Trackpoint", 2); + List seg2PointTags = getChildElements(segment2Tag, "Trackpoint", 2); + assertTagsMatchPoints(seg1PointTags, location1, location2); + assertTagsMatchPoints(seg2PointTags, location3, location4); + } + + /** + * Asserts that the given tags describe the given points, in the same order. + */ + protected void assertTagsMatchPoints(List tags, Location... locs) { + assertEquals(locs.length, tags.size()); + for (int i = 0; i < locs.length; i++) { + Element tag = tags.get(i); + Location loc = locs[i]; + + assertTagMatchesLocation(tag, loc); + } + } + + /** + * Asserts that the given tag describes the given location. + */ + private void assertTagMatchesLocation(Element tag, Location loc) { + Element posTag = getChildElement(tag, "Position"); + assertEquals(Double.toString(loc.getLatitude()), + getChildTextValue(posTag, "LatitudeDegrees")); + assertEquals(Double.toString(loc.getLongitude()), + getChildTextValue(posTag, "LongitudeDegrees")); + assertEquals( + TcxTrackWriter.TIMESTAMP_FORMAT.format(new Date(loc.getTime())), + getChildTextValue(tag, "Time")); + assertEquals(Double.toString(loc.getAltitude()), + getChildTextValue(tag, "AltitudeMeters")); + } +}