merge heads

This commit is contained in:
Jimmy Shih
2013-10-29 11:30:44 -07:00
13 changed files with 169 additions and 150 deletions
@@ -184,24 +184,30 @@ public class TrackEditActivity extends AbstractMyTracksActivity
save.setOnClickListener(new View.OnClickListener() { save.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
track.setName(name.getText().toString());
String category = activityType.getText().toString(); String category = activityType.getText().toString();
if (!category.equals(track.getCategory())) { track.setName(name.getText().toString());
// 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.setIcon(TrackIconUtils.getIconValue(TrackEditActivity.this, category)); track.setIcon(TrackIconUtils.getIconValue(TrackEditActivity.this, category));
track.setDescription(description.getText().toString()); track.setDescription(description.getText().toString());
track.setModifiedTime(System.currentTimeMillis()); track.setModifiedTime(System.currentTimeMillis());
myTracksProviderUtils.updateTrack(track); if (!category.equals(track.getCategory())) {
boolean driveSync = PreferencesUtils.getBoolean( track.setCategory(category);
TrackEditActivity.this, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT);
// 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) { if (driveSync) {
PreferencesUtils.addToList(TrackEditActivity.this, R.string.drive_edited_list_key, PreferencesUtils.addToList(TrackEditActivity.this, R.string.drive_edited_list_key,
PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId())); PreferencesUtils.DRIVE_EDITED_LIST_DEFAULT, String.valueOf(track.getId()));
@@ -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.content.Waypoint;
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.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.apps.mytracks.util.UnitConversions;
@@ -453,7 +454,10 @@ public class ChartFragment extends Fragment implements TrackDataListener {
double power = Double.NaN; double power = Double.NaN;
if (tripStatisticsUpdater != null) { 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(); TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
if (chartByDistance) { if (chartByDistance) {
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM; double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
@@ -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.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.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;
import com.google.android.apps.mytracks.util.PreferencesUtils; 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. // No more track points. Ignore the rest of the waypoints.
return; return;
} }
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval, false,
context); CalorieUtils.getActivityType(context,
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval, 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()) { if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
trackPoint = null; trackPoint = null;
@@ -546,7 +554,10 @@ 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, 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.bufferedLocations[trackData.numBufferedLocations] = location;
trackData.numBufferedLocations++; trackData.numBufferedLocations++;
@@ -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.AbstractSendAsyncTask;
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils; import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
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.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.common.gdata.AndroidXmlParserFactory; import com.google.android.common.gdata.AndroidXmlParserFactory;
@@ -277,7 +278,11 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
sentStartMarker = true; 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) { if (i % elevationSamplingFrequency == 0) {
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance()); distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
elevations.add(tripStatisticsUpdater.getSmoothedElevation()); elevations.add(tripStatisticsUpdater.getSmoothedElevation());
@@ -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.services.tasks.SplitPeriodicTaskFactory;
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.IntentUtils; import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.LocationUtils; import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.apps.mytracks.util.PreferencesUtils;
@@ -659,9 +660,17 @@ public class TrackRecordingService extends Service {
if (cursor.moveToLast()) { if (cursor.moveToLast()) {
do { do {
Location location = myTracksProviderUtils.createTrackPoint(cursor); 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) { 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()); } while (cursor.moveToPrevious());
} }
@@ -1001,8 +1010,13 @@ public class TrackRecordingService extends Service {
try { try {
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId()); Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
long trackPointId = Long.parseLong(uri.getLastPathSegment()); long trackPointId = Long.parseLong(uri.getLastPathSegment());
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true,
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, context); 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)); updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
} catch (SQLiteException e) { } catch (SQLiteException e) {
/* /*
@@ -1335,32 +1349,48 @@ public class TrackRecordingService extends Service {
} }
@Override @Override
public void updateCalorie(double calorie) { public void updateCalorie() {
if (!canAccess()) { if (!canAccess()) {
return; return;
} }
trackRecordingService.updateCalorie(calorie); trackRecordingService.updateCalorie();
} }
} }
/** /**
* Updates the calorie value. * Updates the calorie of current recording track after the current
* * track is edited by user.
* @param calorie new calorie value.
*/ */
public void updateCalorie(final double calorie) { public void updateCalorie() {
if (myTracksLocationManager == null || executorService == null if (myTracksLocationManager == null || executorService == null
|| !myTracksLocationManager.isAllowed() || executorService.isShutdown() || !myTracksLocationManager.isAllowed() || executorService.isShutdown()
|| executorService.isTerminated()) { || executorService.isTerminated()) {
return; return;
} }
executorService.submit(new Runnable() { executorService.submit(new Runnable() {
@Override @Override
public void run() { 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());
} }
}); });
} }
} }
@@ -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;
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.LocationUtils; 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 com.google.common.annotations.VisibleForTesting;
import android.content.Context;
import android.location.Location; import android.location.Location;
import android.util.Log; import android.util.Log;
@@ -122,37 +119,21 @@ public class TripStatisticsUpdater {
return stats; 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. * Adds a location. TODO: This assume location has a valid time.
* *
* @param location the location * @param location the location
* @param minRecordingDistance the min recording distance * @param minRecordingDistance the min recording distance
* @param activityType the activity type of current track * @param isCalculateCalorie true means calculate calorie
* @param weight the weight to 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 public void addLocation(Location location, int minRecordingDistance,
void addLocation(Location location, int minRecordingDistance, ActivityType activityType, boolean isCalculateCalorie, ActivityType activityType, int weight) {
int weight) {
// Always update time // Always update time
updateTime(location.getTime()); updateTime(location.getTime());
if (!LocationUtils.isValidLocation(location)) { if (!LocationUtils.isValidLocation(location)) {
// Either pause or resume marker // Either pause or resume marker
if (location.getLatitude() == PAUSE_LATITUDE) { if (location.getLatitude() == PAUSE_LATITUDE) {
@@ -214,24 +195,16 @@ public class TripStatisticsUpdater {
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed()); location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
} }
// Update calorie if (isCalculateCalorie) {
double calorie = CalorieUtils.getCalorie(lastMovingLocation, location, // Update calorie
gradeBuffer.getAverage(), weight, activityType); double calorie = CalorieUtils.getCalorie(lastMovingLocation, location,
currentSegment.addCalorie(calorie); gradeBuffer.getAverage(), weight, activityType);
currentSegment.addCalorie(calorie);
}
lastLocation = location; lastLocation = location;
lastMovingLocation = 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 * Gets the smoothed elevation over several readings. The elevation readings
* is noisy so the smoothed elevation is better than the raw elevation for * is noisy so the smoothed elevation is better than the raw elevation for
@@ -375,4 +348,14 @@ public class TripStatisticsUpdater {
return true; return true;
} }
} }
/**
* Updates the calorie value;
*
* @param calorie
*/
public void updateCalorie(double calorie) {
tripStatistics.setCalorie(calorie);
currentSegment.setCalorie(0);
}
} }
@@ -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;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator; import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
import com.google.android.apps.mytracks.content.Track; 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.apps.mytracks.stats.TripStatisticsUpdater;
import com.google.android.maps.mytracks.R; import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
@@ -278,53 +277,36 @@ public class CalorieUtils {
* *
* @param context the context * @param context the context
* @param track the track to calculate * @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) { public static TripStatisticsUpdater updateTrackStatistics(Context context,
ActivityType activityType = getActivityType(context, category); long startTrackPointId, Track track) {
if (activityType == ActivityType.INVALID) { ActivityType activityType = getActivityType(context, track.getCategory());
return 0.0;
}
double calorie = 0.0;
MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context); MyTracksProviderUtils providerUtils = MyTracksProviderUtils.Factory.get(context);
long trackId = track.getId(); long trackId = track.getId();
LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId, -1, false, LocationIterator points = providerUtils.getTrackPointLocationIterator(trackId,
MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY); startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
DoubleBuffer gradeBuffer = new DoubleBuffer(TripStatisticsUpdater.GRADE_SMOOTHING_FACTOR); TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(track
.getTripStatistics().getStartTime());
if (points.hasNext()) { while (points.hasNext()) {
Location start = points.next(); if (activityType == ActivityType.INVALID) {
tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context,
while (points.hasNext()) { R.string.recording_distance_interval_key,
Location stop = points.next(); PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT), false, activityType,
double grade = updateGrade(gradeBuffer, stop.distanceTo(start), PreferencesUtils.getInt(context, R.string.stats_weight_key,
stop.getAltitude() - start.getAltitude()); PreferencesUtils.STATS_WEIGHT_DEFAULT));
calorie += getCalorie(start, stop, grade, PreferencesUtils.getInt(context, } else {
R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT), activityType); tripStatisticsUpdater.addLocation(points.next(), PreferencesUtils.getInt(context,
start = stop; 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;
}
} }
@@ -114,7 +114,9 @@ public class StatsUtils {
* *
* @param activity the activity * @param activity the activity
* @param tripStatistics the trip statistics * @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) { public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics, long trackId) {
boolean metricUnits = PreferencesUtils.isMetricUnits(activity); boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
@@ -181,26 +183,24 @@ public class StatsUtils {
gradeElevationContainer.setVisibility(View.GONE); gradeElevationContainer.setVisibility(View.GONE);
} }
// Set calories if (trackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
boolean showCalorie = PreferencesUtils.getBoolean(activity, R.string.stats_show_calorie_key, // Set calories
PreferencesUtils.STATS_SHOW_CALORIE_DEFAULT); boolean showCalorie = PreferencesUtils.getBoolean(activity, R.string.stats_show_calorie_key,
View calorieHorizontalLine = activity.findViewById(R.id.stats_calorie_horizontal_line); PreferencesUtils.STATS_SHOW_CALORIE_DEFAULT);
View calorieContainer = activity.findViewById(R.id.stats_calorie_container); View calorieHorizontalLine = activity.findViewById(R.id.stats_calorie_horizontal_line);
View calorieContainer = activity.findViewById(R.id.stats_calorie_container);
if (showCalorie) { if (showCalorie) {
if(trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) { calorieHorizontalLine.setVisibility(View.VISIBLE);
return; 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);
} }
} }
@@ -196,16 +196,17 @@ public class TrackRecordingServiceConnectionUtils {
/** /**
* Updates the calorie of current recording track. * Updates the calorie of current recording track.
*
* @param trackRecordingServiceConnection
*/ */
public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection, public static void updateCalorie(TrackRecordingServiceConnection trackRecordingServiceConnection) {
double calorie) {
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection ITrackRecordingService trackRecordingService = trackRecordingServiceConnection
.getServiceIfBound(); .getServiceIfBound();
if (trackRecordingService == null) { if (trackRecordingService == null) {
Log.d(TAG, "Unable to update calorie, no track recording service"); Log.d(TAG, "Unable to update calorie, no track recording service");
} else { } else {
try { try {
trackRecordingService.updateCalorie(calorie); trackRecordingService.updateCalorie();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "Unable to update calorie", e); Log.e(TAG, "Unable to update calorie", e);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
@@ -108,9 +108,7 @@ interface ITrackRecordingService {
int getSensorState(); int getSensorState();
/** /**
* Updates the calorie value. * Updates the calorie of current recording track.
*
* @param calorie new calorie value.
*/ */
void updateCalorie(double calorie); void updateCalorie();
} }
@@ -226,7 +226,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
startTime + (timeOffset + i) * TEN_SECONDS); startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location, tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT); PreferencesUtils.STATS_WEIGHT_DEFAULT, true);
tripStatistics = tripStatisticsUpdater.getTripStatistics(); tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime()); 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); locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location, tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT); PreferencesUtils.STATS_WEIGHT_DEFAULT, false);
tripStatistics = tripStatisticsUpdater.getTripStatistics(); tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime()); assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
@@ -311,7 +311,7 @@ public class TripStatisticsUpdaterTest extends TestCase {
startTime + (timeOffset + i) * TEN_SECONDS); startTime + (timeOffset + i) * TEN_SECONDS);
tripStatisticsUpdater.addLocation(location, tripStatisticsUpdater.addLocation(location,
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT, ActivityType.FOOT,
PreferencesUtils.STATS_WEIGHT_DEFAULT); PreferencesUtils.STATS_WEIGHT_DEFAULT, true);
tripStatistics = tripStatisticsUpdater.getTripStatistics(); tripStatistics = tripStatisticsUpdater.getTripStatistics();
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime()); assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());
@@ -76,7 +76,7 @@ public class PauseRecordingTest extends ActivityInstrumentationTestCase2<TrackLi
* Tests the pause recording feature. Stops the recording after resume. * Tests the pause recording feature. Stops the recording after resume.
*/ */
public void testPauseRecording_stopAfterResume() { public void testPauseRecording_stopAfterResume() {
int gpsSignalNumber = 3; int gpsSignalNumber = 0;
EndToEndTestUtils.checkNotRecording(); EndToEndTestUtils.checkNotRecording();
// Start recording // Start recording
@@ -192,8 +192,7 @@ public class SettingTest extends ActivityInstrumentationTestCase2<TrackListActiv
activityMyTracks.getString(R.string.stats_elevation), 1, activityMyTracks.getString(R.string.stats_elevation), 1,
EndToEndTestUtils.NORMAL_WAIT_TIME, true)); EndToEndTestUtils.NORMAL_WAIT_TIME, true));
assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.stats_grade))); assertTrue(EndToEndTestUtils.SOLO.waitForText(activityMyTracks.getString(R.string.stats_grade)));
assertFalse(EndToEndTestUtils.SOLO.searchText(activityMyTracks assertTrue(EndToEndTestUtils.findTextView(activityMyTracks.getString(R.string.stats_latitude)) == null);
.getString(R.string.stats_latitude)));
} }
/** /**