diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java index f938edc68..dfd923776 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackEditActivity.java @@ -184,24 +184,30 @@ public class TrackEditActivity extends AbstractMyTracksActivity save.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - track.setName(name.getText().toString()); String category = activityType.getText().toString(); - if (!category.equals(track.getCategory())) { - // TODO Is there no race condition when setCalorie is called. - double calorie = CalorieUtils.calculateTrackCalorie(getApplicationContext(), track, - category); - - track.getTripStatistics().setCalorie(calorie); - TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection, - calorie); - } - track.setCategory(category); + track.setName(name.getText().toString()); track.setIcon(TrackIconUtils.getIconValue(TrackEditActivity.this, category)); track.setDescription(description.getText().toString()); track.setModifiedTime(System.currentTimeMillis()); - myTracksProviderUtils.updateTrack(track); - boolean driveSync = PreferencesUtils.getBoolean( - TrackEditActivity.this, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT); + if (!category.equals(track.getCategory())) { + track.setCategory(category); + + // If edit recording track. + if (track.getId() == PreferencesUtils.getLong(getApplicationContext(), + R.string.recording_track_id_key)) { + + // Update data without new calorie. + myTracksProviderUtils.updateTrack(track); + TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection); + } else { + CalorieUtils.updateTrackStatistics(getApplicationContext(), -1, track); + + // Update data with new calorie. + myTracksProviderUtils.updateTrack(track); + } + } + boolean driveSync = PreferencesUtils.getBoolean(TrackEditActivity.this, + R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT); if (driveSync) { PreferencesUtils.addToList(TrackEditActivity.this, R.string.drive_edited_list_key, PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId())); diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java index 5ae8e2aba..150ccb530 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/ChartFragment.java @@ -28,6 +28,7 @@ import com.google.android.apps.mytracks.content.TrackDataType; import com.google.android.apps.mytracks.content.Waypoint; 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.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.UnitConversions; @@ -453,7 +454,10 @@ public class ChartFragment extends Fragment implements TrackDataListener { double power = Double.NaN; if (tripStatisticsUpdater != null) { - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, CalorieUtils + .getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils + .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics(); if (chartByDistance) { double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM; 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 7d62b172a..7735a7e03 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 @@ -24,6 +24,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.FileUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -241,9 +242,16 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track // No more track points. Ignore the rest of the waypoints. return; } - trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, - context); - markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, context); + trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); + markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); } if (waypoint.getLocation().getTime() > trackPoint.getTime()) { trackPoint = null; @@ -546,7 +554,10 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track trackData.tripStatisticsUpdater = new TripStatisticsUpdater( location.getTime() != -1L ? location.getTime() : trackData.importTime); } - trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils + .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); trackData.bufferedLocations[trackData.numBufferedLocations] = location; trackData.numBufferedLocations++; diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java index 1444cf82d..3776779f1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/maps/SendMapsAsyncTask.java @@ -29,6 +29,7 @@ import com.google.android.apps.mytracks.io.gdata.maps.XmlMapsGDataParserFactory; import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; +import com.google.android.apps.mytracks.util.CalorieUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.common.gdata.AndroidXmlParserFactory; @@ -277,7 +278,11 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask { sentStartMarker = true; } - tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, CalorieUtils + .getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); if (i % elevationSamplingFrequency == 0) { distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance()); elevations.add(tripStatisticsUpdater.getSmoothedElevation()); diff --git a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java index 8e33cb9c6..90bbd48db 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java +++ b/MyTracks/src/com/google/android/apps/mytracks/services/TrackRecordingService.java @@ -36,6 +36,7 @@ import com.google.android.apps.mytracks.services.tasks.PeriodicTaskExecutor; import com.google.android.apps.mytracks.services.tasks.SplitPeriodicTaskFactory; 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.IntentUtils; import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.PreferencesUtils; @@ -659,9 +660,17 @@ public class TrackRecordingService extends Service { if (cursor.moveToLast()) { do { Location location = myTracksProviderUtils.createTrackPoint(cursor); - trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); if (location.getTime() > markerStartTime) { - markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); } } while (cursor.moveToPrevious()); } @@ -1001,8 +1010,13 @@ public class TrackRecordingService extends Service { try { Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId()); long trackPointId = Long.parseLong(uri.getLastPathSegment()); - trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); - markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); + trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true, + CalorieUtils.getActivityType(context, track.getId()), PreferencesUtils.getInt(context, + R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); + markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false, + CalorieUtils.getActivityType(context, + PreferencesUtils.getLong(context, R.string.recording_track_id_key)), PreferencesUtils + .getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT)); updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location)); } catch (SQLiteException e) { /* @@ -1335,32 +1349,48 @@ public class TrackRecordingService extends Service { } @Override - public void updateCalorie(double calorie) { + public void updateCalorie() { if (!canAccess()) { return; } - trackRecordingService.updateCalorie(calorie); + trackRecordingService.updateCalorie(); } } - + /** - * Updates the calorie value. - * - * @param calorie new calorie value. + * Updates the calorie of current recording track after the current + * track is edited by user. */ - public void updateCalorie(final double calorie) { + public void updateCalorie() { if (myTracksLocationManager == null || executorService == null || !myTracksLocationManager.isAllowed() || executorService.isShutdown() || executorService.isTerminated()) { return; } executorService.submit(new Runnable() { - @Override + @Override public void run() { - trackTripStatisticsUpdater.updateCalorie(calorie); + // Update track statistics. + long trackId = PreferencesUtils.getLong(getApplicationContext(), + R.string.recording_track_id_key); + Track currentTrack = myTracksProviderUtils.getTrack(trackId); + CalorieUtils.updateTrackStatistics(getApplicationContext(), -1, currentTrack); + trackTripStatisticsUpdater.updateCalorie(currentTrack.getTripStatistics().getCalorie()); + + // Update to database. + MyTracksProviderUtils.Factory.get(context).updateTrack(currentTrack); + + // Update marker statistics. + Waypoint lastWayPoint = myTracksProviderUtils.getLastWaypoint(trackId, + WaypointType.WAYPOINT); + long lastWayPoint_pointId = myTracksProviderUtils.getTrackPointId(trackId, + lastWayPoint.getLocation()); + if (lastWayPoint_pointId > 0) { + CalorieUtils.updateTrackStatistics(getApplicationContext(), lastWayPoint_pointId, + currentTrack); + } + markerTripStatisticsUpdater.updateCalorie(currentTrack.getTripStatistics().getCalorie()); } }); - - } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java index fde264308..6630d9b3c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java +++ b/MyTracks/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdater.java @@ -22,11 +22,8 @@ import static com.google.android.apps.mytracks.services.TrackRecordingService.PA import com.google.android.apps.mytracks.util.CalorieUtils; import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType; import com.google.android.apps.mytracks.util.LocationUtils; -import com.google.android.apps.mytracks.util.PreferencesUtils; -import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; -import android.content.Context; import android.location.Location; import android.util.Log; @@ -122,37 +119,21 @@ public class TripStatisticsUpdater { return stats; } - /** - * Adds a location. - * - * @param location the location - * @param minRecordingDistance the min recording distance - * @param context the context to get the weight and track category - */ - public void addLocation(Location location, int minRecordingDistance, Context context) { - int weight = PreferencesUtils.getInt(context, R.string.stats_weight_key, - PreferencesUtils.STATS_WEIGHT_DEFAULT); - addLocation( - location, - minRecordingDistance, - CalorieUtils.getActivityType(context, - PreferencesUtils.getLong(context, R.string.recording_track_id_key)), weight); - } - /** * Adds a location. TODO: This assume location has a valid time. * * @param location the location * @param minRecordingDistance the min recording distance - * @param activityType the activity type of current track - * @param weight the weight to calculate calorie + * @param isCalculateCalorie true means calculate calorie + * @param activityType the activity type of current track which is used to + * calculate calorie + * @param weight the weight to calculate calorie which is used to calculate + * calorie */ - @VisibleForTesting - void addLocation(Location location, int minRecordingDistance, ActivityType activityType, - int weight) { + public void addLocation(Location location, int minRecordingDistance, + boolean isCalculateCalorie, ActivityType activityType, int weight) { // Always update time updateTime(location.getTime()); - if (!LocationUtils.isValidLocation(location)) { // Either pause or resume marker if (location.getLatitude() == PAUSE_LATITUDE) { @@ -214,24 +195,16 @@ public class TripStatisticsUpdater { location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed()); } - // Update calorie - double calorie = CalorieUtils.getCalorie(lastMovingLocation, location, - gradeBuffer.getAverage(), weight, activityType); - currentSegment.addCalorie(calorie); - + if (isCalculateCalorie) { + // Update calorie + double calorie = CalorieUtils.getCalorie(lastMovingLocation, location, + gradeBuffer.getAverage(), weight, activityType); + currentSegment.addCalorie(calorie); + } lastLocation = location; lastMovingLocation = location; } - /** - * Updates the calorie value. - * - * @param calorie new calorie value. - */ - public void updateCalorie(double calorie) { - currentSegment.setCalorie(calorie); - } - /** * Gets the smoothed elevation over several readings. The elevation readings * is noisy so the smoothed elevation is better than the raw elevation for @@ -375,4 +348,14 @@ public class TripStatisticsUpdater { return true; } } + + /** + * Updates the calorie value; + * + * @param calorie + */ + public void updateCalorie(double calorie) { + tripStatistics.setCalorie(calorie); + currentSegment.setCalorie(0); + } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java index 4e758911b..aa18ad403 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/CalorieUtils.java @@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.util; import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.Track; -import com.google.android.apps.mytracks.stats.DoubleBuffer; import com.google.android.apps.mytracks.stats.TripStatisticsUpdater; import com.google.android.maps.mytracks.R; import com.google.common.annotations.VisibleForTesting; @@ -278,53 +277,36 @@ 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 double calculateTrackCalorie(Context context, Track track, String category) { - ActivityType activityType = getActivityType(context, category); - if (activityType == ActivityType.INVALID) { - return 0.0; - } + public static TripStatisticsUpdater updateTrackStatistics(Context context, + long startTrackPointId, Track track) { + ActivityType activityType = getActivityType(context, track.getCategory()); - double calorie = 0.0; 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); - DoubleBuffer gradeBuffer = new DoubleBuffer(TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR); - - if (points.hasNext()) { - Location start = points.next(); - - while (points.hasNext()) { - Location stop = points.next(); - double grade = updateGrade(gradeBuffer, stop.distanceTo(start), - stop.getAltitude() - start.getAltitude()); - calorie += getCalorie(start, stop, grade, PreferencesUtils.getInt(context, - R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT), activityType); - start = stop; + TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(track + .getTripStatistics().getStartTime()); + while (points.hasNext()) { + if (activityType == ActivityType.INVALID) { + tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context, + R.string.recording_distance_interval_key, + PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), false, activityType, + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); + } else { + tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context, + R.string.recording_distance_interval_key, + PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), true, activityType, + PreferencesUtils.getInt(context, R.string.stats_weight_key, + PreferencesUtils.STATS_WEIGHT_DEFAULT)); } } - return calorie; + track.setTripStatistics(tripStatisticsUpdater.getTripStatistics()); + return tripStatisticsUpdater; } - - /** - * Updates a grade reading. - * - * @param gradeBuffer - * @param distance - * @param rise - */ - private static double updateGrade(DoubleBuffer gradeBuffer, float distance, Double rise) { - double grade = 0; - if (rise > 0 && distance > 0) { - gradeBuffer.setNext(rise / distance); - grade = gradeBuffer.getAverage(); - } else { - gradeBuffer.setNext(0); - } - return grade; - } - } \ No newline at end of file diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java index a481af233..e9d7a4966 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/StatsUtils.java @@ -114,7 +114,9 @@ public class StatsUtils { * * @param activity the activity * @param tripStatistics the trip statistics - * @param trackId the id of track + * @param trackId the id of track, which is used to set calorie value. Does + * not handle the calorie If the value is + * {@link PreferencesUtils#RECORDING_TRACK_ID_DEFAULT} */ public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics, long trackId) { boolean metricUnits = PreferencesUtils.isMetricUnits(activity); @@ -181,26 +183,24 @@ public class StatsUtils { gradeElevationContainer.setVisibility(View.GONE); } - // Set calories - boolean showCalorie = PreferencesUtils.getBoolean(activity, R.string.stats_show_calorie_key, - PreferencesUtils.STATS_SHOW_CALORIE_DEFAULT); - View calorieHorizontalLine = activity.findViewById(R.id.stats_calorie_horizontal_line); - View calorieContainer = activity.findViewById(R.id.stats_calorie_container); - - if (showCalorie) { - if(trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) { - return; + if (trackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) { + // Set calories + boolean showCalorie = PreferencesUtils.getBoolean(activity, R.string.stats_show_calorie_key, + PreferencesUtils.STATS_SHOW_CALORIE_DEFAULT); + View calorieHorizontalLine = activity.findViewById(R.id.stats_calorie_horizontal_line); + View calorieContainer = activity.findViewById(R.id.stats_calorie_container); + if (showCalorie) { + calorieHorizontalLine.setVisibility(View.VISIBLE); + calorieContainer.setVisibility(View.VISIBLE); + double calories = Double.NaN; + if (tripStatistics != null) { + calories = tripStatistics.getCalorie(); + } + setCalorie(activity, R.id.stats_calorie, calories, trackId); + } else { + calorieHorizontalLine.setVisibility(View.GONE); + calorieContainer.setVisibility(View.GONE); } - calorieHorizontalLine.setVisibility(View.VISIBLE); - calorieContainer.setVisibility(View.VISIBLE); - double calories = Double.NaN; - if (tripStatistics != null) { - calories = tripStatistics.getCalorie(); - } - setCalorie(activity, R.id.stats_calorie, calories, trackId); - } else { - calorieHorizontalLine.setVisibility(View.GONE); - calorieContainer.setVisibility(View.GONE); } } diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java index afe817669..3cd98a5f1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/TrackRecordingServiceConnectionUtils.java @@ -196,16 +196,17 @@ public class TrackRecordingServiceConnectionUtils { /** * Updates the calorie of current recording track. + * + * @param trackRecordingServiceConnection */ - public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection, - double calorie) { + 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.updateCalorie(calorie); + trackRecordingService.updateCalorie(); } catch (RemoteException e) { Log.e(TAG, "Unable to update calorie", e); } catch (IllegalStateException e) { diff --git a/MyTracksLib/src/com/google/android/apps/mytracks/services/ITrackRecordingService.aidl b/MyTracksLib/src/com/google/android/apps/mytracks/services/ITrackRecordingService.aidl index ba0d72833..0ef27b480 100644 --- a/MyTracksLib/src/com/google/android/apps/mytracks/services/ITrackRecordingService.aidl +++ b/MyTracksLib/src/com/google/android/apps/mytracks/services/ITrackRecordingService.aidl @@ -108,9 +108,7 @@ interface ITrackRecordingService { int getSensorState(); /** - * Updates the calorie value. - * - * @param calorie new calorie value. + * Updates the calorie of current recording track. */ - void updateCalorie(double calorie); + void updateCalorie(); } diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java index 0aef3dc5b..c457f4758 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/stats/TripStatisticsUpdaterTest.java @@ -226,7 +226,7 @@ public class TripStatisticsUpdaterTest extends TestCase { startTime + (timeOffset + i) * TEN_SECONDS); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, - PreferencesUtils.STATS_WEIGHT_DEFAULT); + PreferencesUtils.STATS_WEIGHT_DEFAULT, true); tripStatistics = tripStatisticsUpdater.getTripStatistics(); assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime()); @@ -273,7 +273,7 @@ public class TripStatisticsUpdaterTest extends TestCase { locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, - PreferencesUtils.STATS_WEIGHT_DEFAULT); + PreferencesUtils.STATS_WEIGHT_DEFAULT, false); tripStatistics = tripStatisticsUpdater.getTripStatistics(); assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime()); @@ -311,7 +311,7 @@ public class TripStatisticsUpdaterTest extends TestCase { startTime + (timeOffset + i) * TEN_SECONDS); tripStatisticsUpdater.addLocation(location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, - PreferencesUtils.STATS_WEIGHT_DEFAULT); + PreferencesUtils.STATS_WEIGHT_DEFAULT, true); tripStatistics = tripStatisticsUpdater.getTripStatistics(); assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime()); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/PauseRecordingTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/PauseRecordingTest.java index bb8b0e6f1..3237b2c92 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/PauseRecordingTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/common/PauseRecordingTest.java @@ -76,7 +76,7 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2