mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Update stats marker calorie in TrackRecordingService
This commit is contained in:
@@ -30,12 +30,6 @@ public class Constants {
|
||||
*/
|
||||
public static final String ACCOUNT_TYPE = "com.google";
|
||||
|
||||
/**
|
||||
* Maximum number of track points that will be loaded at one time. With
|
||||
* recording frequency of 2 seconds, 20000 corresponds to 11.1 hours.
|
||||
*/
|
||||
public static final int MAX_LOADED_TRACK_POINTS = 20000;
|
||||
|
||||
/**
|
||||
* Maximum number of waypoints that will be loaded at one time.
|
||||
*/
|
||||
|
||||
+4
-4
@@ -134,16 +134,16 @@ public class FileTrackExporter implements TrackExporter {
|
||||
boolean wroteSegment = false;
|
||||
boolean isLastLocationValid = false;
|
||||
TrackWriterLocationFactory locationFactory = new TrackWriterLocationFactory();
|
||||
LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||
LocationIterator locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||
track.getId(), -1L, false, locationFactory);
|
||||
|
||||
try {
|
||||
int locationNumber = 0;
|
||||
while (iterator.hasNext()) {
|
||||
while (locationIterator.hasNext()) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
Location location = iterator.next();
|
||||
Location location = locationIterator.next();
|
||||
|
||||
setLocationTime(location, offset);
|
||||
locationNumber++;
|
||||
@@ -195,7 +195,7 @@ public class FileTrackExporter implements TrackExporter {
|
||||
trackWriter.writeEndTrack(track, null);
|
||||
}
|
||||
} finally {
|
||||
iterator.close();
|
||||
locationIterator.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProvider;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils.LocationIterator;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
@@ -60,7 +61,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
@@ -132,7 +132,8 @@ public class TrackRecordingService extends Service {
|
||||
private int recordingGpsAccuracy;
|
||||
private int autoResumeTrackTimeout;
|
||||
private long currentRecordingInterval;
|
||||
|
||||
private double weight;
|
||||
|
||||
// The following variables are set when recording:
|
||||
private TripStatisticsUpdater trackTripStatisticsUpdater;
|
||||
private TripStatisticsUpdater markerTripStatisticsUpdater;
|
||||
@@ -230,6 +231,10 @@ public class TrackRecordingService extends Service {
|
||||
R.string.auto_resume_track_timeout_key,
|
||||
PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
||||
}
|
||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.weight_key))) {
|
||||
weight = PreferencesUtils.getFloat(
|
||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -656,31 +661,26 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
markerTripStatisticsUpdater = new TripStatisticsUpdater(markerStartTime);
|
||||
|
||||
Cursor cursor = null;
|
||||
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
|
||||
|
||||
LocationIterator locationIterator = null;
|
||||
try {
|
||||
// TODO: how to handle very long track.
|
||||
cursor = myTracksProviderUtils.getTrackPointCursor(
|
||||
recordingTrackId, -1L, Constants.MAX_LOADED_TRACK_POINTS, true);
|
||||
if (cursor == null) {
|
||||
Log.e(TAG, "Cursor is null.");
|
||||
} else {
|
||||
if (cursor.moveToLast()) {
|
||||
do {
|
||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||
if (location.getTime() > markerStartTime) {
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||
}
|
||||
} while (cursor.moveToPrevious());
|
||||
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||
track.getId(), -1L, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||
while (locationIterator.hasNext()) {
|
||||
Location location = locationIterator.next();
|
||||
trackTripStatisticsUpdater.addLocation(
|
||||
location, recordingDistanceInterval, true, activityType, weight);
|
||||
if (location.getTime() > markerStartTime) {
|
||||
markerTripStatisticsUpdater.addLocation(
|
||||
location, recordingDistanceInterval, true, activityType, weight);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "RuntimeException", e);
|
||||
} finally {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
if (locationIterator != null) {
|
||||
locationIterator.close();
|
||||
}
|
||||
}
|
||||
startRecording(true);
|
||||
@@ -1011,11 +1011,11 @@ public class TrackRecordingService extends Service {
|
||||
try {
|
||||
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
||||
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, true,
|
||||
CalorieUtils.getActivityType(context, track.getCategory()), PreferencesUtils.getFloat(context,
|
||||
R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT));
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, false,
|
||||
ActivityType.INVALID, PreferencesUtils.WEIGHT_DEFAULT);
|
||||
ActivityType activityType = CalorieUtils.getActivityType(context, track.getCategory());
|
||||
trackTripStatisticsUpdater.addLocation(
|
||||
location, recordingDistanceInterval, true, activityType, weight);
|
||||
markerTripStatisticsUpdater.addLocation(
|
||||
location, recordingDistanceInterval, true, activityType, weight);
|
||||
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
|
||||
} catch (SQLiteException e) {
|
||||
/*
|
||||
|
||||
@@ -96,8 +96,6 @@ public class CalorieUtils {
|
||||
}
|
||||
|
||||
MyTracksProviderUtils myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
LocationIterator iterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||
track.getId(), startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||
TripStatisticsUpdater tripStatisticsUpdater = new TripStatisticsUpdater(
|
||||
track.getTripStatistics().getStartTime());
|
||||
int recordingDistanceInterval = PreferencesUtils.getInt(context,
|
||||
@@ -105,10 +103,19 @@ public class CalorieUtils {
|
||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
double weight = PreferencesUtils.getFloat(
|
||||
context, R.string.weight_key, PreferencesUtils.WEIGHT_DEFAULT);
|
||||
LocationIterator locationIterator = null;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
tripStatisticsUpdater.addLocation(
|
||||
iterator.next(), recordingDistanceInterval, true, activityType, weight);
|
||||
try {
|
||||
locationIterator = myTracksProviderUtils.getTrackPointLocationIterator(
|
||||
track.getId(), startTrackPointId, false, MyTracksProviderUtils.DEFAULT_LOCATION_FACTORY);
|
||||
while (locationIterator.hasNext()) {
|
||||
tripStatisticsUpdater.addLocation(
|
||||
locationIterator.next(), recordingDistanceInterval, true, activityType, weight);
|
||||
}
|
||||
} finally {
|
||||
if (locationIterator != null) {
|
||||
locationIterator.close();
|
||||
}
|
||||
}
|
||||
return tripStatisticsUpdater.getTripStatistics().getCalorie();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user