Add weoght parameter in TripStatisticsUpdater.addLocation() method.

This commit is contained in:
youtaol
2013-09-02 19:31:53 +08:00
parent c42abaac6b
commit ad03336916
7 changed files with 36 additions and 20 deletions
@@ -438,7 +438,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
double power = Double.NaN;
if (tripStatisticsUpdater != null) {
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
.getInt(getActivity(), R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
if (chartByDistance) {
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
@@ -247,8 +247,12 @@ abstract class AbstractImporter extends DefaultHandler {
// No more track points. Ignore the rest of the waypoints.
return;
}
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval);
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
}
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
trackPoint = null;
@@ -534,7 +538,9 @@ abstract class AbstractImporter extends DefaultHandler {
trackData.tripStatisticsUpdater = new TripStatisticsUpdater(
location.getTime() != -1L ? location.getTime() : trackData.importTime);
}
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
trackData.bufferedLocations[trackData.numBufferedLocations] = location;
trackData.numBufferedLocations++;
@@ -277,7 +277,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
sentStartMarker = true;
}
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, 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());
@@ -659,9 +659,13 @@ public class TrackRecordingService extends Service {
if (cursor.moveToLast()) {
do {
Location location = myTracksProviderUtils.createTrackPoint(cursor);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
if (location.getTime() > markerStartTime) {
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
PreferencesUtils.getInt(context, R.string.stats_weight_key,
PreferencesUtils.STATS_WEIGHT_DEFAULT));
}
} while (cursor.moveToPrevious());
}
@@ -1001,8 +1005,10 @@ public class TrackRecordingService extends Service {
try {
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
long trackPointId = Long.parseLong(uri.getLastPathSegment());
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
} catch (SQLiteException e) {
/*
@@ -142,8 +142,8 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
weightInput.setSelectAllOnFocus(true);
dialog = (new AlertDialog.Builder(this))
.setMessage(R.string.settings_stats_calorie_weight_description)
.setNegativeButton(getString(R.string.generic_cancel), null)
.setPositiveButton(getString(R.string.generic_ok),
.setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.generic_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int number) {
storeWeightValue(weightInput.getText().toString());
@@ -23,7 +23,6 @@ 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.common.annotations.VisibleForTesting;
import android.location.Location;
@@ -126,7 +125,7 @@ public class TripStatisticsUpdater {
* @param location the location
* @param minRecordingDistance the min recording distance
*/
public void addLocation(Location location, int minRecordingDistance) {
public void addLocation(Location location, int minRecordingDistance, int weight) {
// Always update time
updateTime(location.getTime());
@@ -196,7 +195,7 @@ public class TripStatisticsUpdater {
// Update calorie
double calorie = CalorieUtils.getCalorie(lastMovingLocation, location,
gradeBuffer.getAverage(), PreferencesUtils.STATS_WEIGHT_DEFAULT, ActivityType.FOOT);
gradeBuffer.getAverage(), weight, ActivityType.FOOT);
currentSegment.addCalorie(calorie);
lastLocation = location;