diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java index 20f0bb209..dabf6344b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/AbstractFileTrackImporter.java @@ -25,6 +25,7 @@ import com.google.android.apps.mytracks.content.Waypoint.WaypointType; import com.google.android.apps.mytracks.services.TrackRecordingService; import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; +import com.google.android.apps.mytracks.util.CalorieUtils; import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.LocationUtils; @@ -107,6 +108,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track private final long importTrackId; private final MyTracksProviderUtils myTracksProviderUtils; private final int recordingDistanceInterval; + private final double weight; private final List trackIds; private final List waypoints; @@ -144,6 +146,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track this.recordingDistanceInterval = PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT); + this.weight = PreferencesUtils.getFloat( + context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT); trackIds = new ArrayList(); waypoints = new ArrayList(); } @@ -220,7 +224,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater( track.getTripStatistics().getStartTime()); LocationIterator locationIterator = null; - + ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory()); + try { locationIterator = myTracksProviderUtils.getTrackPointLocationIterator( track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); @@ -242,8 +247,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track location = locationIterator.next(); trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false, ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); - markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); + markerTripStatisticsUpdater.addLocation( + location, recordingDistanceInterval, true, activityType, weight); } if (waypoint.getLocation().getTime() > location.getTime()) { location = null; @@ -548,8 +553,9 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track trackData.tripStatisticsUpdater = new TripStatisticsUpdater( location.getTime() != -1L ? location.getTime() : trackData.importTime); } - trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, - ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); + ActivityType activityType = CalorieUtils.getActivityType(context, category); + trackData.tripStatisticsUpdater.addLocation( + location, recordingDistanceInterval, true, activityType, weight); trackData.bufferedLocations[trackData.numBufferedLocations] = location; trackData.numBufferedLocations++; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/GpxFileTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/GpxFileTrackImporter.java index ea7e49a1a..2c56a1a11 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/GpxFileTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/GpxFileTrackImporter.java @@ -156,6 +156,7 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter { name = null; description = null; category = null; + photoUrl = null; latitude = attributes.getValue(ATTRIBUTE_LAT); longitude = attributes.getValue(ATTRIBUTE_LON); altitude = null; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmlFileTrackImporter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmlFileTrackImporter.java index d518214f5..f0dd5cf98 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmlFileTrackImporter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/importer/KmlFileTrackImporter.java @@ -91,6 +91,11 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter { public void startElement(String uri, String localName, String tag, Attributes attributes) throws SAXException { if (tag.equals(TAG_PLACEMARK) || tag.equals(TAG_PHOTO_OVERLAY)) { + /* + * Note that a track is contained in a Placemark, calling onWaypointStart + * will clear various track variables like name, category, and + * description. + */ onWaypointStart(); } else if (tag.equals(TAG_GX_MULTI_TRACK)) { trackStarted = true; @@ -110,6 +115,10 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter { if (tag.equals(TAG_KML)) { onFileEnd(); } else if (tag.equals(TAG_PLACEMARK) || tag.equals(TAG_PHOTO_OVERLAY)) { + /* + * Note that a track is contained in a Placemark, calling onWaypointend is + * save since waypointType is not set for a track. + */ onWaypointEnd(); } else if (localName.equals(TAG_COORDINATES)) { onWaypointLocationEnd(); @@ -159,12 +168,12 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter { name = null; description = null; category = null; + photoUrl = null; latitude = null; longitude = null; altitude = null; time = null; waypointType = null; - photoUrl = null; } /**