merge branch

This commit is contained in:
Jimmy Shih
2013-11-20 10:44:32 -08:00
@@ -763,11 +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 (PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT.equals(track.getCategory())) { // If not paused, add the last location
// Category not set, use activity_recognition_type_key value 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);
@@ -789,14 +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)));
double calorie = CalorieUtils.getTrackCalorie(this, track, -1L); myTracksProviderUtils.updateTrack(track);
track.getTripStatistics().setCalorie(calorie); CalorieUtils.updateTrackCalorie(context, track);
} }
} }
} }
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
} }
endRecording(true, trackId); endRecording(true, trackId);
} }
@@ -1036,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);
} }