Change code style.

This commit is contained in:
youtaol
2013-10-30 17:42:24 +08:00
parent 7cc1f878b4
commit 4907dc26a0
4 changed files with 26 additions and 18 deletions
@@ -200,7 +200,7 @@ public class TrackEditActivity extends AbstractMyTracksActivity
myTracksProviderUtils.updateTrack(track); myTracksProviderUtils.updateTrack(track);
TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection); TrackRecordingServiceConnectionUtils.updateCalorie(trackRecordingServiceConnection);
} else { } else {
CalorieUtils.updateTrackStatistics(getApplicationContext(), -1, track); CalorieUtils.updateCalorie(getApplicationContext(), -1, track);
// Update data with new calorie. // Update data with new calorie.
myTracksProviderUtils.updateTrack(track); myTracksProviderUtils.updateTrack(track);
@@ -1358,13 +1358,11 @@ public class TrackRecordingService extends Service {
} }
/** /**
* Updates the calorie of current recording track after the current * Updates the calorie of current recording track after the current track is
* track is edited by user. * edited by user.
*/ */
public void updateCalorie() { public void updateCalorie() {
if (myTracksLocationManager == null || executorService == null if (executorService == null || executorService.isShutdown() || executorService.isTerminated()) {
|| !myTracksLocationManager.isAllowed() || executorService.isShutdown()
|| executorService.isTerminated()) {
return; return;
} }
executorService.submit(new Runnable() { executorService.submit(new Runnable() {
@@ -1373,23 +1371,32 @@ public class TrackRecordingService extends Service {
// Update track statistics. // Update track statistics.
long trackId = PreferencesUtils.getLong(getApplicationContext(), long trackId = PreferencesUtils.getLong(getApplicationContext(),
R.string.recording_track_id_key); R.string.recording_track_id_key);
if (trackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
return;
}
Track currentTrack = myTracksProviderUtils.getTrack(trackId); Track currentTrack = myTracksProviderUtils.getTrack(trackId);
CalorieUtils.updateTrackStatistics(getApplicationContext(), -1, currentTrack); if (currentTrack == null) {
trackTripStatisticsUpdater.updateCalorie(currentTrack.getTripStatistics().getCalorie()); return;
}
double newCalorie = CalorieUtils.updateCalorie(getApplicationContext(), -1, currentTrack);
trackTripStatisticsUpdater.updateCalorie(newCalorie);
// Update to database. // Update to database.
MyTracksProviderUtils.Factory.get(context).updateTrack(currentTrack); myTracksProviderUtils.updateTrack(currentTrack);
// Update marker statistics. // Update marker statistics.
Waypoint lastWayPoint = myTracksProviderUtils.getLastWaypoint(trackId, Waypoint lastWayPoint = myTracksProviderUtils.getLastWaypoint(trackId,
WaypointType.WAYPOINT); WaypointType.WAYPOINT);
if (lastWayPoint == null) {
return;
}
long lastWayPoint_pointId = myTracksProviderUtils.getTrackPointId(trackId, long lastWayPoint_pointId = myTracksProviderUtils.getTrackPointId(trackId,
lastWayPoint.getLocation()); lastWayPoint.getLocation());
if (lastWayPoint_pointId > 0) { if (lastWayPoint_pointId > 0) {
CalorieUtils.updateTrackStatistics(getApplicationContext(), lastWayPoint_pointId, newCalorie = CalorieUtils.updateCalorie(getApplicationContext(), lastWayPoint_pointId,
currentTrack); currentTrack);
} }
markerTripStatisticsUpdater.updateCalorie(currentTrack.getTripStatistics().getCalorie()); markerTripStatisticsUpdater.updateCalorie(newCalorie);
} }
}); });
} }
@@ -124,14 +124,14 @@ public class TripStatisticsUpdater {
* *
* @param location the location * @param location the location
* @param minRecordingDistance the min recording distance * @param minRecordingDistance the min recording distance
* @param isCalculateCalorie true means calculate calorie * @param calculateCalorie true means calculate calorie
* @param activityType the activity type of current track which is used to * @param activityType the activity type of current track which is used to
* calculate calorie * calculate calorie
* @param weight the weight to calculate calorie which is used to calculate * @param weight the weight to calculate calorie which is used to calculate
* calorie * calorie
*/ */
public void addLocation(Location location, int minRecordingDistance, public void addLocation(Location location, int minRecordingDistance,
boolean isCalculateCalorie, ActivityType activityType, int weight) { boolean calculateCalorie, ActivityType activityType, int weight) {
// Always update time // Always update time
updateTime(location.getTime()); updateTime(location.getTime());
if (!LocationUtils.isValidLocation(location)) { if (!LocationUtils.isValidLocation(location)) {
@@ -195,7 +195,7 @@ public class TripStatisticsUpdater {
location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed()); location.getTime(), location.getSpeed(), lastLocation.getTime(), lastLocation.getSpeed());
} }
if (isCalculateCalorie) { if (calculateCalorie) {
// Update calorie // Update calorie
double calorie = CalorieUtils.getCalorie(lastMovingLocation, location, double calorie = CalorieUtils.getCalorie(lastMovingLocation, location,
gradeBuffer.getAverage(), weight, activityType); gradeBuffer.getAverage(), weight, activityType);
@@ -277,10 +277,11 @@ public class CalorieUtils {
* *
* @param context the context * @param context the context
* @param track the track to calculate * @param track the track to calculate
* @param startTrackPointId the starting track point id. -1L to ignore * @param startTrackPointId the starting track point id. Make this value less
* @return the TripStatisticsUpdater of track * than 1 to calculate the entire track
* @return the calorie value of track
*/ */
public static TripStatisticsUpdater updateTrackStatistics(Context context, public static double updateCalorie(Context context,
long startTrackPointId, Track track) { long startTrackPointId, Track track) {
ActivityType activityType = getActivityType(context, track.getCategory()); ActivityType activityType = getActivityType(context, track.getCategory());
@@ -307,6 +308,6 @@ public class CalorieUtils {
} }
} }
track.setTripStatistics(tripStatisticsUpdater.getTripStatistics()); track.setTripStatistics(tripStatisticsUpdater.getTripStatistics());
return tripStatisticsUpdater; return tripStatisticsUpdater.getTripStatistics().getCalorie();
} }
} }