From a4930eea6caa56a787bb5c9eb2ce0b0dca1695e7 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Thu, 3 Aug 2023 19:21:05 +0200 Subject: [PATCH] Idle: TrackRecordingManager creates IDLE TrackPoints (import/export GPX/KML). Fixes of #1187. --- .../de/dennisguse/opentracks/data/models/TrackPoint.java | 2 ++ .../opentracks/io/file/exporter/GPXTrackExporter.java | 3 +++ .../opentracks/io/file/exporter/KMLTrackExporter.java | 8 +++++++- .../opentracks/io/file/importer/KmlTrackImporter.java | 4 ++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java index 775bcf141d..a9c64045c7 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java @@ -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; diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java index a2354f8614..0d5fa2bcf6 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/GPXTrackExporter.java @@ -171,6 +171,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()); } diff --git a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java index 3de5f615a7..c0c26a3e92 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/exporter/KMLTrackExporter.java @@ -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; @@ -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 -> diff --git a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java index 9dce6b4070..572bec9146 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/importer/KmlTrackImporter.java @@ -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)));