Skip to content

Commit

Permalink
Idle: TrackRecordingManager creates IDLE TrackPoints (import/export G…
Browse files Browse the repository at this point in the history
…PX/KML).

Fixes of #1187.
  • Loading branch information
dennisguse committed Aug 3, 2023
1 parent d8ae9a1 commit 3a1f26c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
*/
public class TrackPoint {

public static final Speed IDLE_SPEED = Speed.of(0);

private static final Duration MAX_LOCATION_AGE = Duration.ofMinutes(1);

private TrackPoint.Id id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ private void writeTrackPoints(Track track) throws InterruptedException {
sensorPoints.add(trackPoint);
}
}
case IDLE -> {
// Not supported as IDLE-TrackPoints have no location.
}
default ->
throw new RuntimeException("Exporting this TrackPoint type is not implemented: " + trackPoint.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import de.dennisguse.opentracks.data.ContentProviderUtils;
import de.dennisguse.opentracks.data.TrackPointIterator;
import de.dennisguse.opentracks.data.models.Marker;
import de.dennisguse.opentracks.data.models.Speed;
import de.dennisguse.opentracks.data.models.Track;
import de.dennisguse.opentracks.data.models.TrackPoint;
import de.dennisguse.opentracks.ui.markers.MarkerUtils;
Expand Down Expand Up @@ -177,12 +178,17 @@ private void writeLocations(Track track) throws InterruptedException {
writeCloseSegment();
wroteSegment = false;
}
case TRACKPOINT -> {
case TRACKPOINT, IDLE -> {
if (!wroteSegment) {
// Might happen for older data (pre v3.15.0)
writeOpenSegment();
wroteSegment = true;
}

if (trackPoint.getType() == TrackPoint.Type.IDLE) {
// TODO Should we do this while loading the TrackPoints?
trackPoint.setSpeed(Speed.of(0));
}
writeTrackPoint(track.getZoneOffset(), trackPoint);
}
default ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ private void onTrackSegmentEnd() {

if (i < sensorSpeedList.size() && sensorSpeedList.get(i) != null) {
trackPoint.setSpeed(Speed.of(sensorSpeedList.get(i)));

if (TrackPoint.IDLE_SPEED.lessThan(trackPoint.getSpeed())) {
trackPoint.setType(TrackPoint.Type.IDLE);
}
}
if (i < sensorDistanceList.size() && sensorDistanceList.get(i) != null) {
trackPoint.setSensorDistance(Distance.of(sensorDistanceList.get(i)));
Expand Down

0 comments on commit 3a1f26c

Please sign in to comment.