During import, make sure track calorie and waypoint calorie are set correctly

This commit is contained in:
Jimmy Shih
2013-11-18 16:16:15 -08:00
parent f5f0c56043
commit f5d8ca8dd2
3 changed files with 22 additions and 6 deletions
@@ -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.services.TrackRecordingService;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; 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.CalorieUtils.ActivityType;
import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.FileUtils;
import com.google.android.apps.mytracks.util.LocationUtils; 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 long importTrackId;
private final MyTracksProviderUtils myTracksProviderUtils; private final MyTracksProviderUtils myTracksProviderUtils;
private final int recordingDistanceInterval; private final int recordingDistanceInterval;
private final double weight;
private final List<Long> trackIds; private final List<Long> trackIds;
private final List<Waypoint> waypoints; private final List<Waypoint> waypoints;
@@ -144,6 +146,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
this.recordingDistanceInterval = PreferencesUtils.getInt(context, this.recordingDistanceInterval = PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key, R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT); PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
this.weight = PreferencesUtils.getFloat(
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
trackIds = new ArrayList<Long>(); trackIds = new ArrayList<Long>();
waypoints = new ArrayList<Waypoint>(); waypoints = new ArrayList<Waypoint>();
} }
@@ -220,6 +224,7 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater( TripStatisticsUpdater markerTripStatisticsUpdater = new TripStatisticsUpdater(
track.getTripStatistics().getStartTime()); track.getTripStatistics().getStartTime());
LocationIterator locationIterator = null; LocationIterator locationIterator = null;
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
try { try {
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator( locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
@@ -242,8 +247,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
location = locationIterator.next(); location = locationIterator.next();
trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false, trackTripStatisticstrackUpdater.addLocation(location, recordingDistanceInterval, false,
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, markerTripStatisticsUpdater.addLocation(
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); location, recordingDistanceInterval, true, activityType, weight);
} }
if (waypoint.getLocation().getTime() > location.getTime()) { if (waypoint.getLocation().getTime() > location.getTime()) {
location = null; location = null;
@@ -548,8 +553,9 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
trackData.tripStatisticsUpdater = new TripStatisticsUpdater( trackData.tripStatisticsUpdater = new TripStatisticsUpdater(
location.getTime() != -1L ? location.getTime() : trackData.importTime); location.getTime() != -1L ? location.getTime() : trackData.importTime);
} }
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, ActivityType activityType = CalorieUtils.getActivityType(context, category);
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT); trackData.tripStatisticsUpdater.addLocation(
location, recordingDistanceInterval, true, activityType, weight);
trackData.bufferedLocations[trackData.numBufferedLocations] = location; trackData.bufferedLocations[trackData.numBufferedLocations] = location;
trackData.numBufferedLocations++; trackData.numBufferedLocations++;
@@ -156,6 +156,7 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
name = null; name = null;
description = null; description = null;
category = null; category = null;
photoUrl = null;
latitude = attributes.getValue(ATTRIBUTE_LAT); latitude = attributes.getValue(ATTRIBUTE_LAT);
longitude = attributes.getValue(ATTRIBUTE_LON); longitude = attributes.getValue(ATTRIBUTE_LON);
altitude = null; altitude = null;
@@ -91,6 +91,11 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
public void startElement(String uri, String localName, String tag, Attributes attributes) public void startElement(String uri, String localName, String tag, Attributes attributes)
throws SAXException { throws SAXException {
if (tag.equals(TAG_PLACEMARK) || tag.equals(TAG_PHOTO_OVERLAY)) { 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(); onWaypointStart();
} else if (tag.equals(TAG_GX_MULTI_TRACK)) { } else if (tag.equals(TAG_GX_MULTI_TRACK)) {
trackStarted = true; trackStarted = true;
@@ -110,6 +115,10 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
if (tag.equals(TAG_KML)) { if (tag.equals(TAG_KML)) {
onFileEnd(); onFileEnd();
} else if (tag.equals(TAG_PLACEMARK) || tag.equals(TAG_PHOTO_OVERLAY)) { } 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(); onWaypointEnd();
} else if (localName.equals(TAG_COORDINATES)) { } else if (localName.equals(TAG_COORDINATES)) {
onWaypointLocationEnd(); onWaypointLocationEnd();
@@ -159,12 +168,12 @@ public class KmlFileTrackImporter extends AbstractFileTrackImporter {
name = null; name = null;
description = null; description = null;
category = null; category = null;
photoUrl = null;
latitude = null; latitude = null;
longitude = null; longitude = null;
altitude = null; altitude = null;
time = null; time = null;
waypointType = null; waypointType = null;
photoUrl = null;
} }
/** /**