Update calorie when activity recognition api sets the track category

This commit is contained in:
Jimmy Shih
2013-11-19 14:19:11 -08:00
parent 2571247829
commit 5ecb41adc2
@@ -763,9 +763,17 @@ public class TrackRecordingService extends Service {
// Update database // Update database
Track track = myTracksProviderUtils.getTrack(trackId); Track track = myTracksProviderUtils.getTrack(trackId);
if (track != null && !paused) { if (track != null) {
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
// If not paused, add the last location
if (!paused) {
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
}
// Update the recording track time
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
if (track.getCategory().equals(PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT)) {
int activityRecognitionType = PreferencesUtils.getInt(this, int activityRecognitionType = PreferencesUtils.getInt(this,
R.string.activity_recognition_type_key, R.string.activity_recognition_type_key,
PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT); PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT);
@@ -787,11 +795,12 @@ public class TrackRecordingService extends Service {
if (iconValue != null) { if (iconValue != null) {
track.setIcon(iconValue); track.setIcon(iconValue);
track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue))); track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue)));
myTracksProviderUtils.updateTrack(track);
CalorieUtils.updateTrackCalorie(context, track);
}
} }
} }
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
} }
endRecording(true, trackId); endRecording(true, trackId);
} }
@@ -1031,15 +1040,23 @@ public class TrackRecordingService extends Service {
sendTrackBroadcast(R.string.track_update_broadcast_action, track.getId()); sendTrackBroadcast(R.string.track_update_broadcast_action, track.getId());
} }
/**
* Updates the recording track time. Also updates the startId and the stopId.
* Increase the number of points if it is a new and valid track point.
*
* @param track the track
* @param lastTrackPointId the last track point id
* @param increaseNumberOfPoints true to increase the number of points
*/
private void updateRecordingTrack( private void updateRecordingTrack(
Track track, long trackPointId, boolean isTrackPointNewAndValid) { Track track, long lastTrackPointId, boolean increaseNumberOfPoints) {
if (trackPointId >= 0) { if (lastTrackPointId >= 0) {
if (track.getStartId() < 0) { if (track.getStartId() < 0) {
track.setStartId(trackPointId); track.setStartId(lastTrackPointId);
} }
track.setStopId(trackPointId); track.setStopId(lastTrackPointId);
} }
if (isTrackPointNewAndValid) { if (increaseNumberOfPoints) {
track.setNumberOfPoints(track.getNumberOfPoints() + 1); track.setNumberOfPoints(track.getNumberOfPoints() + 1);
} }