Remove the parameter of updateCalorie method of TrackRecordingService. Re-calculate the calorie of track and last marker in TrackRecordingService.

This commit is contained in:
youtaol
2013-10-25 14:41:21 +08:00
parent c68ec5ed9a
commit c43e9047bc
10 changed files with 107 additions and 80 deletions
@@ -277,16 +277,17 @@ public class CalorieUtils {
*
* @param context the context
* @param track the track to calculate
* @param category the category of track
* @param startTrackPointId the starting track point id. -1L to ignore
* @return the TripStatisticsUpdater of track
*/
public static TripStatisticsUpdater updateTrackStatistics(Context context, Track track) {
public static TripStatisticsUpdater updateTrackStatistics(Context context,
long startTrackPointId, Track track) {
ActivityType activityType = getActivityType(context, track.getCategory());
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
long trackId = track.getId();
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false,
MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId,
startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(track
.getTripStatistics().getStartTime());
@@ -294,11 +295,15 @@ public class CalorieUtils {
if (activityType == ActivityType.INVALID) {
tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), context);
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), false, activityType,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
} else {
tripStatisticsUpdater.addLocationCalorie(points.next(), PreferencesUtils.getInt(context,
tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context,
R.string.recording_distance_interval_key,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), activityType, context);
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), true, activityType,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
}
}
track.setTripStatistics(tripStatisticsUpdater.getTripStatistics());
@@ -17,7 +17,6 @@
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.TrackEditActivity;
import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.WaypointCreationRequest;
import com.google.android.apps.mytracks.services.ITrackRecordingService;
import com.google.android.apps.mytracks.services.TrackRecordingService;
@@ -199,16 +198,15 @@ public class TrackRecordingServiceConnectionUtils {
* Updates the calorie of current recording track.
*
* @param trackRecordingServiceConnection
* @param track the current recording track
*/
public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection, Track track) {
public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection) {
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
.getServiceIfBound();
if (trackRecordingService == null) {
Log.d(TAG, "Unable to update calorie, no track recording service");
} else {
try {
trackRecordingService.updateTripStatistics(track);
trackRecordingService.updateCalorie();
} catch (RemoteException e) {
Log.e(TAG, "Unable to update calorie", e);
} catch (IllegalStateException e) {