From e7aa6f20d4fddc33be6d7fa6fa3812cce8c52e54 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Fri, 28 Feb 2025 22:41:28 +0100 Subject: [PATCH] Cleanup: use Position and cleanup TrackPoint. --- .../opentracks/chart/TrackStubUtils.java | 21 +- .../opentracks/content/data/TestDataUtil.java | 19 +- .../content/data/TestSensorDataUtil.java | 21 +- .../data/CustomContentProviderUtilsTest.java | 18 +- .../opentracks/data/model/TrackPointTest.java | 27 ++- .../io/file/importer/ExportImportTest.java | 154 ++++++------ .../file/importer/GPXTrackImporterTest.java | 129 +++++----- .../file/importer/KMLTrackImporterTest.java | 140 ++++++----- .../opentracks/sensors/GpsStatusTest.java | 18 +- .../TrackRecordingServiceRecordingTest.java | 224 ++++++++++-------- .../stats/TrackStatisticsUpdaterTest.java | 63 +++-- .../opentracks/data/models/TrackPoint.java | 64 +---- .../io/file/importer/GpxTrackImporter.java | 6 +- .../io/file/importer/KmlTrackImporter.java | 43 ++-- .../opentracks/sensors/GpsManager.java | 2 +- .../SettingsCustomLayoutEditAdapter.java | 2 +- .../ui/markers/MarkerEditActivity.java | 3 +- 17 files changed, 526 insertions(+), 428 deletions(-) diff --git a/src/androidTest/java/de/dennisguse/opentracks/chart/TrackStubUtils.java b/src/androidTest/java/de/dennisguse/opentracks/chart/TrackStubUtils.java index 7ae4bb9d6..2f8973f8a 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/chart/TrackStubUtils.java +++ b/src/androidTest/java/de/dennisguse/opentracks/chart/TrackStubUtils.java @@ -18,7 +18,9 @@ package de.dennisguse.opentracks.chart; import java.time.Instant; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -27,6 +29,7 @@ import de.dennisguse.opentracks.data.models.TrackPoint; * * @author Youtao Liu */ +//TODO Move to ChartPointTest class TrackStubUtils { public static final double INITIAL_ALTITUDE = 22; @@ -52,12 +55,16 @@ class TrackStubUtils { * @return a SensorDataSetLocation stub. */ private static TrackPoint createDefaultTrackPoint(double latitude, double longitude, double altitude) { - return new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(INITIAL_TIME)) - .setLatitude(latitude) - .setLongitude(longitude) - .setAltitude(altitude) - .setHorizontalAccuracy(INITIAL_ACCURACY) - .setSpeed(INITIAL_SPEED) - .setBearing(INITIAL_BEARING); + return new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.ofEpochMilli(INITIAL_TIME), + latitude, + longitude, + INITIAL_ACCURACY, + Altitude.WGS84.of(altitude), + INITIAL_ACCURACY, + INITIAL_BEARING, + INITIAL_SPEED + )); } } diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java index e8231a479..e6c9e8343 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestDataUtil.java @@ -13,8 +13,10 @@ import java.util.List; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.TrackPointIterator; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Marker; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -109,12 +111,17 @@ public class TestDataUtil { } public static TrackPoint createTrackPoint(int i) { - TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(i)); - trackPoint.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0); - trackPoint.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0); - trackPoint.setHorizontalAccuracy(Distance.of(i / 100.0f)); - trackPoint.setAltitude(i * ALTITUDE_INTERVAL); - trackPoint.setSpeed(Speed.of(5f + (i / 10f))); + TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.ofEpochSecond(i), + INITIAL_LATITUDE + (double) i / 10000.0, + INITIAL_LONGITUDE - (double) i / 10000.0, + Distance.of(i / 100.0f), + Altitude.WGS84.of(i * ALTITUDE_INTERVAL), + null, + null, + Speed.of(5f + (i / 10f)) + )); trackPoint.setHeartRate(100f + i % 80); trackPoint.setCadence(300f + i); diff --git a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestSensorDataUtil.java b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestSensorDataUtil.java index fc7ca69d8..563ae4f36 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/content/data/TestSensorDataUtil.java +++ b/src/androidTest/java/de/dennisguse/opentracks/content/data/TestSensorDataUtil.java @@ -5,7 +5,9 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -16,10 +18,20 @@ public class TestSensorDataUtil { public void add(Instant time, Float hr, Float cadence, Float power, TrackPoint.Type type) { sensorDataList.add(new TestSensorDataUtil.SensorData(time, hr, cadence, power, type)); - TrackPoint tp = new TrackPoint(type, time); int i = trackPointList.size() + 1; - tp.setLatitude(TestDataUtil.INITIAL_LATITUDE + (double) i / 10000.0); - tp.setLongitude(TestDataUtil.INITIAL_LONGITUDE - (double) i / 10000.0); + + TrackPoint tp = new TrackPoint(type, + new Position( + time, + TestDataUtil.INITIAL_LATITUDE + (double) i / 10000.0, + TestDataUtil.INITIAL_LONGITUDE - (double) i / 10000.0, + Distance.of(1f), + Altitude.WGS84.of(1f), + null, + null, + Speed.of(5f + (i / 10f)) + ) + ); if (hr != null) { tp.setHeartRate(hr); } @@ -29,9 +41,6 @@ public class TestSensorDataUtil { if (power != null) { tp.setPower(power); } - tp.setHorizontalAccuracy(Distance.of(1f)); - tp.setAltitude(1f); - tp.setSpeed(Speed.of(5f + (i / 10f))); tp.setAltitudeGain(3f); tp.setAltitudeLoss(3f); trackPointList.add(tp); diff --git a/src/androidTest/java/de/dennisguse/opentracks/data/CustomContentProviderUtilsTest.java b/src/androidTest/java/de/dennisguse/opentracks/data/CustomContentProviderUtilsTest.java index b5bfe6ba3..d7c7bb1ea 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/data/CustomContentProviderUtilsTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/data/CustomContentProviderUtilsTest.java @@ -51,9 +51,11 @@ import java.util.stream.Collectors; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.content.data.TestSensorDataUtil; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.Marker; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -135,12 +137,16 @@ public class CustomContentProviderUtilsTest { List trackPoints = new ArrayList<>(numPoints); for (int i = 0; i < numPoints; ++i) { - TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(i)) - .setLatitude(37.0 + (double) i / 10000.0) - .setLongitude(57.0 - (double) i / 10000.0) - .setHorizontalAccuracy(Distance.of(i / 100.0f)) - .setAltitude(i * 2.5); - trackPoints.add(trackPoint); + trackPoints.add(new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.ofEpochMilli(i), + 37.0 + (double) i / 10000.0, + 57.0 - (double) i / 10000.0, + Distance.of(i / 100.0f), + Altitude.WGS84.of(i * 2.5), + null, + null, + null))); } contentProviderUtils.bulkInsertTrackPoint(trackPoints, id); diff --git a/src/androidTest/java/de/dennisguse/opentracks/data/model/TrackPointTest.java b/src/androidTest/java/de/dennisguse/opentracks/data/model/TrackPointTest.java index 1885114a5..e7ba22aec 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/data/model/TrackPointTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/data/model/TrackPointTest.java @@ -7,19 +7,34 @@ import org.junit.Test; import java.time.Instant; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.TrackPoint; public class TrackPointTest { @Test public void distanceToPrevious() { - TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(0)) - .setLatitude(0) - .setLongitude(0.0001); + TrackPoint tp1 = new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.ofEpochMilli(0), + 0d, + 0.0001, + null, + null, + null, + null, + null)); - TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochMilli(1)) - .setLatitude(0) - .setLongitude(0.0002); + TrackPoint tp2 = new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.ofEpochMilli(1), + 0d, + 0.0002, + null, + null, + null, + null, + null)); // without sensor distance assertEquals(11.13, tp2.distanceToPrevious(tp1).toM(), 0.01); diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java index e2e578f26..08d85917f 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/ExportImportTest.java @@ -49,11 +49,13 @@ import de.dennisguse.opentracks.TimezoneRule; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.AltitudeGainLoss; import de.dennisguse.opentracks.data.models.Cadence; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.HeartRate; import de.dennisguse.opentracks.data.models.Marker; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Power; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; @@ -224,15 +226,17 @@ public class ExportImportTest { List actual = TestDataUtil.getTrackPoints(contentProviderUtils, trackId); new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:02:02Z")), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:03Z")) - .setLatitude(3) - .setLongitude(14) - .setAltitude(10) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:02:03Z"), + 3d, 14d, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) .setAltitudeLoss(1f) - .setAltitudeGain(1f) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:04Z")) + .setAltitudeGain(1f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + Instant.parse("2020-02-02T02:02:04Z")) .setSensorDistance(Distance.of(10)) .setSpeed(Speed.of(15)) .setHeartRate(HeartRate.of(66)) @@ -244,47 +248,49 @@ public class ExportImportTest { .setHeartRate(HeartRate.of(68)) .setCadence(3) .setPower(50), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:17Z")) - .setLatitude(3) - .setLongitude(14.001) - .setAltitude(10) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:02:17Z"), + 3d, 14.001, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(5))) .setSensorDistance(Distance.of(2)) - .setSpeed(Speed.of(5)) .setAltitudeLoss(0f) .setAltitudeGain(0f) - .setHorizontalAccuracy(Distance.of(10)) .setHeartRate(HeartRate.of(69)) .setCadence(3) .setPower(50), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:02:18Z")), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2020-02-02T02:03:20Z")), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:21Z")) - .setLatitude(3) - .setLongitude(14.002) - .setAltitude(10) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:03:21Z"), + 3d, 14.002d, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) .setAltitudeLoss(0f) - .setAltitudeGain(0f) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:22Z")) - .setLatitude(3) - .setLongitude(16) - .setAltitude(10) - .setSpeed(Speed.of(15)) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position(Instant.parse("2020-02-02T02:03:22Z"), + 3d, 16d, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) .setAltitudeLoss(0f) - .setAltitudeGain(0f) - .setHorizontalAccuracy(Distance.of(10)), + .setAltitudeGain(0f), new TrackPoint(TrackPoint.Type.IDLE, Instant.parse("2020-02-02T02:03:30Z")) .setAltitudeLoss(0f) .setAltitudeGain(0f), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:50Z")) - .setLatitude(3) - .setLongitude(16.001) - .setAltitude(10) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:03:50Z"), + 3d, 16.001, Distance.of(10), + Altitude.WGS84.of(10), null, + null, Speed.of(15))) .setAltitudeLoss(0f) - .setAltitudeGain(0f) - .setHorizontalAccuracy(Distance.of(10)), + .setAltitudeGain(0f), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2020-02-02T02:04:00Z")) ), actual); } @@ -397,50 +403,56 @@ public class ExportImportTest { .setDelta(0.05); // speed is not fully List actual = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); a.assertEquals(List.of( - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:02:03Z")) - .setLatitude(3) - .setLongitude(14) - .setAltitude(10) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2020-02-02T02:02:03Z"), + 3d, 14d, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) .setAltitudeLoss(1f) - .setAltitudeGain(1f) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:02:17Z")) - .setLatitude(3) - .setLongitude(14.001) - .setAltitude(10) - .setSpeed(Speed.of(5)) + .setAltitudeGain(1f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:02:17Z"), + 3d, 14.001, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(5))) .setAltitudeLoss(1f) .setAltitudeGain(1f) .setSensorDistance(Distance.of(12)) .setHeartRate(69) .setPower(50f) - .setCadence(3f) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:21Z")) - .setLatitude(3) - .setLongitude(14.002) - .setAltitude(10) + .setCadence(3f), + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2020-02-02T02:03:21Z"), + 3d, 14.002, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) + .setAltitudeLoss(0f) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2020-02-02T02:03:22Z"), + 3d, 16d, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(15))) + .setAltitudeLoss(0f) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-02-02T02:03:50Z"), + 3d, 16.001, Distance.of(10), + Altitude.WGS84.of(10), null, + null, + Speed.of(10))) .setAltitudeLoss(0f) .setAltitudeGain(0f) .setSpeed(Speed.of(15)) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-02-02T02:03:22Z")) - .setLatitude(3) - .setLongitude(16) - .setAltitude(10) - .setAltitudeLoss(0f) - .setAltitudeGain(0f) - .setSpeed(Speed.of(15)) - .setHorizontalAccuracy(Distance.of(10)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-02-02T02:03:50Z")) - .setLatitude(3) - .setLongitude(16.001) - .setAltitude(10) - .setAltitudeLoss(0f) - .setAltitudeGain(0f) - .setSpeed(Speed.of(15)) - .setHorizontalAccuracy(Distance.of(10)) ), actual); // 3. trackstatistics @@ -597,7 +609,7 @@ public class ExportImportTest { Mockito.when(barometer.hasReceivedData()).thenReturn(true); Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); sensorDataSet.add(barometer); - } else { + } else { sensorDataSet.add(new AggregatorBarometer("test", null)); } } diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXTrackImporterTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXTrackImporterTest.java index 6d7fcc15d..87991dccc 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXTrackImporterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/GPXTrackImporterTest.java @@ -15,21 +15,20 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.Instant; import java.util.List; -import java.util.stream.Collectors; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -95,28 +94,37 @@ public class GPXTrackImporterTest { // first segment TrackPointAssert a = new TrackPointAssert(); a.assertEquals(List.of( - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-01-07T21:51:59.179Z")) - .setLatitude(3) - .setLongitude(14) - .setAltitude(10), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:00.653Z")) - .setLatitude(3) - .setLongitude(14.001) - .setAltitude(10) - .setSpeed(Speed.of(75.4192)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:01.010Z")) - .setLatitude(3) - .setLongitude(14.002) - .setAltitude(10) - .setSpeed(Speed.of(311.3948)), + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2021-01-07T21:51:59.179Z"), + 3d, 14d, null, + Altitude.WGS84.of(10), null, + null, + null)), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-01-07T21:52:00.653Z"), + 3d, 14.001, null, + Altitude.WGS84.of(10), null, + null, + Speed.of(75.4192))), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-01-07T21:52:01.010Z"), + 3d, 14.002, null, + Altitude.WGS84.of(10), null, + null, Speed.of(311.3948))), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-01-07T21:52:02.658Z")), // created resume trackpoint with time of next valid trackpoint new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-01-07T21:52:03.873Z")), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-01-07T21:52:04.103Z")) - .setLatitude(3) - .setLongitude(14.003) - .setAltitude(10) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-01-07T21:52:04.103Z"), + 3d, 14.003, null, + Altitude.WGS84.of(10), null, + null, + null)) ), importedTrackPoints); } @@ -151,20 +159,27 @@ public class GPXTrackImporterTest { TrackPointAssert a = new TrackPointAssert(); a.assertEquals(List.of( - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-09-07T22:10:19Z")) - .setLatitude(30.14185982) - .setLongitude(-40.3863038) - .setAltitude(-5), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:11:07Z")) - .setLatitude(30.14184657) - .setLongitude(-40.38670089) - .setAltitude(-5) - .setSpeed(Speed.of(0.7976524233818054)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:12:00Z")) - .setLatitude(30.14185982) - .setLongitude(-40.3863038) - .setAltitude(-5) - .setSpeed(Speed.of(0.7224021553993225)) + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2021-09-07T22:10:19Z"), + 30.14185982, -40.3863038, null, + Altitude.WGS84.of(-5), null, + null, + null)), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-09-07T22:11:07Z"), + 30.14184657, -40.38670089, null, + Altitude.WGS84.of(-5), null, + null, + Speed.of(0.7976524233818054))), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-09-07T22:12:00Z"), + 30.14185982, -40.3863038, null, + Altitude.WGS84.of(-5), null, + null, + Speed.of(0.7224021553993225))) ), importedTrackPoints); } @@ -199,22 +214,27 @@ public class GPXTrackImporterTest { TrackPointAssert a = new TrackPointAssert(); a.assertEquals(List.of( - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2021-09-07T22:10:19Z")) - .setLatitude(30.14185982) - .setLongitude(-40.3863038) - .setAltitude(-5) - .setSpeed(Speed.of(5)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:11:07Z")) - .setLatitude(30.14184657) - .setLongitude(-40.38670089) - .setAltitude(-5) - .setSpeed(Speed.of(0.7976524233818054)) - .setSpeed(Speed.of(4)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-09-07T22:12:00Z")) - .setLatitude(30.14185982) - .setLongitude(-40.3863038) - .setAltitude(-5) - .setSpeed(Speed.of(3)) + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2021-09-07T22:10:19Z"), + 30.14185982, -40.3863038, null, + Altitude.WGS84.of(-5), null, + null, + Speed.of(5))), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-09-07T22:11:07Z"), + 30.14184657, -40.38670089, null, + Altitude.WGS84.of(-5), null, + null, + Speed.of(4))), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-09-07T22:12:00Z"), + 30.14185982, -40.3863038, null, + Altitude.WGS84.of(-5), null, + null, + Speed.of(3))) ), importedTrackPoints); } @@ -237,11 +257,6 @@ public class GPXTrackImporterTest { trackExporter.writeTrack(List.of(importedTrack), outputStream); // then - String expected = new BufferedReader( - new InputStreamReader(inputStreamExpected, StandardCharsets.UTF_8)) - .lines() - .collect(Collectors.joining("\n")) + "\n"; - - assertEquals(expected, outputStream.toString()); //TODO inputStream.readAllBytes() ? + assertEquals(new String(inputStreamExpected.readAllBytes(), StandardCharsets.UTF_8), outputStream.toString()); } } \ No newline at end of file diff --git a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLTrackImporterTest.java b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLTrackImporterTest.java index 427e37bbe..a8229c944 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLTrackImporterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/io/file/importer/KMLTrackImporterTest.java @@ -23,7 +23,9 @@ import java.util.List; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.ActivityType; +import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -81,23 +83,30 @@ public class KMLTrackImporterTest { // 3. trackpoints List importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); - TrackPointAssert a = new TrackPointAssert(); - a.assertEquals(List.of( + new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:21.767Z")), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.042Z")) - .setLatitude(3) - .setLongitude(14) - .setAltitude(10), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.192Z")) - .setLatitude(3) - .setLongitude(14.001) - .setAltitude(10) - .setSpeed(Speed.of(741.1196)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:22.318Z")) - .setLatitude(3) - .setLongitude(14.002) - .setAltitude(10) - .setSpeed(Speed.of(882.2853)), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-05-29T18:06:22.042Z"), + 3d, 14d, null, + Altitude.WGS84.of(10), null, + null, + null)), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-05-29T18:06:22.192Z"), + 3d, 14.001, null, + Altitude.WGS84.of(10), null, + null, + Speed.of(741.1196) + )), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2021-05-29T18:06:22.318Z"), + 3d, 14.002, null, + Altitude.WGS84.of(10), null, + null, + Speed.of(882.2853))), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse("2021-05-29T18:06:22.512Z")) ), importedTrackPoints); } @@ -131,12 +140,13 @@ public class KMLTrackImporterTest { // 3. trackpoints List importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); - TrackPointAssert a = new TrackPointAssert(); - a.assertEquals(List.of( - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2021-05-29T18:06:21.767Z")) - .setLatitude(3) - .setLongitude(14) - .setAltitude(10), + new TrackPointAssert().assertEquals(List.of( + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position(Instant.parse("2021-05-29T18:06:21.767Z"), + 3d, 14d, null, + Altitude.WGS84.of(10), null, + null, + null)), new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse("2021-05-29T18:06:22.042Z")) ), importedTrackPoints); } @@ -171,47 +181,57 @@ public class KMLTrackImporterTest { // 3. trackpoints List importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId); - TrackPointAssert a = new TrackPointAssert(); - a.assertEquals(List.of( + new TrackPointAssert().assertEquals(List.of( // first 3 trackpoints - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-11-28T17:06:22.401Z")) - .setLatitude(12.340097) - .setLongitude(1.234156) - .setAltitude(469.286376953125) - .setAltitudeGain(0f) - .setSpeed(Speed.of(0.539)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:25.448Z")) - .setLatitude(12.340036) - .setLongitude(1.23415) - .setAltitude(439.1626281738281) - .setAltitudeGain(0f) - .setSpeed(Speed.of(0.1577)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:47.888Z")) - .setLatitude(12.340057) - .setLongitude(1.23405) - .setAltitude(421.8070983886719) - .setAltitudeGain(0f) - .setSpeed(Speed.of(0)), - + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2020-11-28T17:06:22.401Z"), + 12.340097, 1.234156, null, + Altitude.WGS84.of(469.286376953125), null, + null, + Speed.of(0.539))) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-11-28T17:06:25.448Z"), + 12.340036, 1.23415, null, + Altitude.WGS84.of(439.1626281738281), null, + null, + Speed.of(0.1577))) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-11-28T17:06:47.888Z"), + 12.340057, 1.23405, null, + Altitude.WGS84.of(421.8070983886719), null, + null, + Speed.of(0))) + .setAltitudeGain(0f), // created resume trackpoint with time of next valid trackpoint - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse("2020-11-28T17:06:55.861Z")) - .setLatitude(12.340057) - .setLongitude(1.23405) - .setAltitude(419.93902587890625) + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse("2020-11-28T17:06:55.861Z"), + 12.340057, 1.23405, null, + Altitude.WGS84.of(419.93902587890625), null, + null, + Speed.of(0))) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-11-28T17:06:56.905Z"), + 12.340057, 1.23405, null, + Altitude.WGS84.of(419.9036560058594), null, + null, + Speed.of(0))) + .setAltitudeGain(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse("2020-11-28T17:07:20.870Z"), + 12.340082, 1.234046, null, + Altitude.WGS84.of(417.99432373046875), null, + null, + Speed.of(0))) .setAltitudeGain(0f) - .setSpeed(Speed.of(0)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:06:56.905Z")) - .setLatitude(12.340057) - .setLongitude(1.23405) - .setAltitude(419.9036560058594) - .setAltitudeGain(0f) - .setSpeed(Speed.of(0)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse("2020-11-28T17:07:20.870Z")) - .setLatitude(12.340082) - .setLongitude(1.234046) - .setAltitude(417.99432373046875) - .setAltitudeGain(0f) - .setSpeed(Speed.of(0)) ), importedTrackPoints); } diff --git a/src/androidTest/java/de/dennisguse/opentracks/sensors/GpsStatusTest.java b/src/androidTest/java/de/dennisguse/opentracks/sensors/GpsStatusTest.java index 6d1bf14d8..741b70afc 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/sensors/GpsStatusTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/sensors/GpsStatusTest.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.List; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.TrackPoint; @RunWith(AndroidJUnit4.class) @@ -44,6 +45,7 @@ public class GpsStatusTest { private final static Location ok = new Location("gps"); static { + badFix.setAccuracy(50); ok.setAccuracy(10); @@ -80,16 +82,16 @@ public class GpsStatusTest { // when / then subject.start(); - subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD), statusList); - subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList); - subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX), statusList); - subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_BAD, GPS_SIGNAL_FIX, GPS_SIGNAL_BAD), statusList); } @@ -104,13 +106,13 @@ public class GpsStatusTest { // when / then subject.start(); - subject.onNewTrackPoint(new TrackPoint(ok, Instant.now().minusMillis(1000))); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now().minusMillis(1000)))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList); subject.determineGpsStatusByTime(Instant.now()); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList); - subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_FIX), statusList); } @@ -131,13 +133,13 @@ public class GpsStatusTest { Thread.sleep(100); assertEquals(List.of(GPS_ENABLED), statusList); - subject.onNewTrackPoint(new TrackPoint(ok, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(ok, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX), statusList); Thread.sleep(100); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST), statusList); - subject.onNewTrackPoint(new TrackPoint(badFix, Instant.now())); + subject.onNewTrackPoint(new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(badFix, Instant.now()))); assertEquals(List.of(GPS_ENABLED, GPS_SIGNAL_FIX, GPS_SIGNAL_LOST, GPS_SIGNAL_BAD), statusList); Thread.sleep(100); diff --git a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java index 6125cb7c9..e6402a3c8 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/services/TrackRecordingServiceRecordingTest.java @@ -19,7 +19,6 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.Mockito; import java.time.Duration; import java.time.Instant; @@ -34,6 +33,7 @@ import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.AltitudeGainLoss; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.HeartRate; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -95,11 +95,9 @@ public class TrackRecordingServiceRecordingTest { @MediumTest @Test public void recording_startStop() { - // given TrackPointCreator trackPointCreator = service.getTrackPointCreator(); - // when String startTime = "2020-02-02T02:02:02Z"; trackPointCreator.setClock(startTime); @@ -140,7 +138,6 @@ public class TrackRecordingServiceRecordingTest { @MediumTest @Test public void recording_startIdle() throws InterruptedException { - // given TrackPointCreator trackPointCreator = service.getTrackPointCreator(); String startTime = "2020-02-02T02:02:02Z"; @@ -159,16 +156,20 @@ public class TrackRecordingServiceRecordingTest { // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps2)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps2), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))), new TrackPoint(TrackPoint.Type.IDLE, Instant.parse(idleTime)) ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); } @@ -244,8 +245,7 @@ public class TrackRecordingServiceRecordingTest { assertFalse(service.isRecording()); List trackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, trackId); - TrackPointAssert a = new TrackPointAssert(); - a.assertEquals(List.of( + new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(starTime)), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(pauseTime)) .setAltitudeGain(0f) @@ -264,7 +264,6 @@ public class TrackRecordingServiceRecordingTest { Track.Id trackId = service.startNewTrack(); mockAltitudeChange(trackPointCreator, 0); - String stopTime = "2020-02-02T02:02:03Z"; trackPointCreator.setClock(stopTime); service.endCurrentTrack(); @@ -275,7 +274,6 @@ public class TrackRecordingServiceRecordingTest { service.resumeTrack(trackId); mockAltitudeChange(trackPointCreator, 0); - // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), @@ -374,25 +372,31 @@ public class TrackRecordingServiceRecordingTest { new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps2)) - .setLatitude(45.0001) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps2), + 45.001, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) - .setLatitude(45.0001) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps3), + 45.001, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) @@ -411,7 +415,6 @@ public class TrackRecordingServiceRecordingTest { Track.Id trackId = service.startNewTrack(); mockAltitudeChange(trackPointCreator, 0); - // when String gps1 = "2020-02-02T02:02:03Z"; TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 1, 15); @@ -434,7 +437,6 @@ public class TrackRecordingServiceRecordingTest { // then assertEquals(gps1Statistics, contentProviderUtils.getTrack(trackId).getTrackStatistics()); - // when String stopTime = "2020-02-02T02:02:12Z"; trackPointCreator.setClock(stopTime); @@ -446,25 +448,31 @@ public class TrackRecordingServiceRecordingTest { new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) - .setLatitude(45.00002) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps3), + 45.00002, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), - new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) - .setLatitude(45.00002) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, + new Position( + Instant.parse(stopTime), + 45.00002, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f) ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); @@ -501,20 +509,24 @@ public class TrackRecordingServiceRecordingTest { // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) - .setAltitudeLoss(0f) - .setSpeed(Speed.of(15)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) + .setAltitudeLoss(0f), + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps3), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) - .setAltitudeLoss(0f) - .setSpeed(Speed.of(15)), + .setAltitudeLoss(0f), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) .setAltitudeGain(0f) .setAltitudeLoss(0f) @@ -531,7 +543,6 @@ public class TrackRecordingServiceRecordingTest { Track.Id trackId = service.startNewTrack(); mockAltitudeChange(trackPointCreator, 0); - // when String gps1 = "2020-02-02T02:02:03Z"; TrackRecordingServiceTestUtils.sendGPSLocation(trackPointCreator, gps1, 45.0, 35.0, 100, 15); @@ -605,18 +616,22 @@ public class TrackRecordingServiceRecordingTest { // then new TrackPointAssert().assertEquals(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.parse(startTime)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), - new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, Instant.parse(gps2)) - .setLatitude(45.1) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(15)) + new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC, + new Position( + Instant.parse(gps2), + 45.1, 35d, Distance.of(1), + null, null, + null, + Speed.of(15))) .setAltitudeGain(0f) .setAltitudeLoss(0f), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) @@ -695,42 +710,55 @@ public class TrackRecordingServiceRecordingTest { new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor2)) //First moving TrackPoint: store as the time might be interesting. .setSpeed(Speed.of(5)) .setSensorDistance(Distance.of(2)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps1)) - .setLatitude(45) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(5)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps1), + 45d, 35d, Distance.of(1), + null, null, + null, + Speed.of(5))) .setSensorDistance(Distance.of(0)), new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(sensor3)) .setSpeed(Speed.of(5)) .setSensorDistance(Distance.of(10)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps3)) - .setLatitude(45.001) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(5)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps3), + 45.001, 35d, Distance.of(1), + null, null, + null, + Speed.of(5))) .setSensorDistance(Distance.of(4.0)), - new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.parse(gps4)) - .setLatitude(45.001) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSpeed(Speed.of(5)) + new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + Instant.parse(gps4), + 45.001, 35d, Distance.of(1), + null, null, + null, + Speed.of(5))) .setSensorDistance(Distance.of(0)), - new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.parse(stopTime)) - .setLatitude(45.001) - .setLongitude(35) - .setHorizontalAccuracy(Distance.of(1)) - .setSensorDistance(Distance.of(11)) - .setSpeed(Speed.of(0)) //Sensor data is now outdated, but we do not fall back to GPS. + new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, + new Position( + Instant.parse(stopTime), + 45.001, 35d, Distance.of(1), + null, null, + null, + Speed.of(0))) //Sensor data is now outdated, but we do not fall back to GPS. .setSensorDistance(Distance.of(0)) ), TestDataUtil.getTrackPoints(contentProviderUtils, trackId)); } private void mockAltitudeChange(TrackPointCreator trackPointCreator, float altitudeGain) { - AggregatorBarometer barometer = Mockito.mock(AggregatorBarometer.class); - Mockito.when(barometer.hasReceivedData()).thenReturn(true); - Mockito.when(barometer.getAggregatedValue(Mockito.any())).thenReturn(new AltitudeGainLoss(altitudeGain, altitudeGain)); + trackPointCreator.getSensorManager().sensorDataSet.barometer = new AggregatorBarometer("", "") { + @Override + public boolean hasReceivedData() { + return true; + } - trackPointCreator.getSensorManager().sensorDataSet.barometer = barometer; + @Override + public AltitudeGainLoss getAggregatedValue(Instant now) { + return new AltitudeGainLoss(altitudeGain, altitudeGain); + } + }; } } diff --git a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java index b52dcefbf..02b3885da 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java @@ -17,6 +17,7 @@ import java.util.List; import de.dennisguse.opentracks.content.data.TestDataUtil; import de.dennisguse.opentracks.data.models.Altitude; import de.dennisguse.opentracks.data.models.Distance; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -104,8 +105,8 @@ public class TrackStatisticsUpdaterTest { TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); - TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); - TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); + TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); + TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); tp3.setSpeed(Speed.of(5f)); // when @@ -123,11 +124,11 @@ public class TrackStatisticsUpdaterTest { TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); - TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); + TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); tp2.setSpeed(Speed.of(5f)); - TrackPoint tp3 = new TrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); + TrackPoint tp3 = createTrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); tp3.setSpeed(Speed.of(5f)); - TrackPoint tp4 = new TrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); + TrackPoint tp4 = createTrackPoint(0.001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); tp4.setSpeed(Speed.of(5f)); tp4.setSensorDistance(Distance.of(5f)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); @@ -155,12 +156,12 @@ public class TrackStatisticsUpdaterTest { TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); - TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); + TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); tp2.setSpeed(Speed.of(5f)); - TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); + TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); tp3.setSensorDistance(Distance.of(5f)); tp3.setSpeed(Speed.of(5f)); - TrackPoint tp4 = new TrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); + TrackPoint tp4 = createTrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); tp4.setSpeed(Speed.of(5f)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); @@ -187,9 +188,9 @@ public class TrackStatisticsUpdaterTest { subject.addTrackPoints(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) .setSpeed(Speed.of(2f)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) .setSpeed(Speed.of(2f)), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(4)) )); @@ -198,9 +199,9 @@ public class TrackStatisticsUpdaterTest { // when subject.addTrackPoints(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(5)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(6)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(6)) .setSpeed(Speed.of(1f)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(7)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(7)) .setSpeed(Speed.of(1f)), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(8)) )); @@ -216,9 +217,9 @@ public class TrackStatisticsUpdaterTest { // when subject.addTrackPoints(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) .setSpeed(Speed.of(2f)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) .setSpeed(Speed.of(2f)), new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)), @@ -226,8 +227,8 @@ public class TrackStatisticsUpdaterTest { .setHeartRate(50), new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45)) .setHeartRate(50), - new TrackPoint(0, 1, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)), - new TrackPoint(0, 2, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)), + createTrackPoint(0, 1, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)), + createTrackPoint(0, 2, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)) )); @@ -243,9 +244,9 @@ public class TrackStatisticsUpdaterTest { // when subject.addTrackPoints(List.of( new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(1)) .setSensorDistance(Distance.of(10)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(2)) .setSensorDistance(Distance.of(10)), new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30)) @@ -254,9 +255,9 @@ public class TrackStatisticsUpdaterTest { .setHeartRate(50), new TrackPoint(TrackPoint.Type.TRACKPOINT, Instant.ofEpochSecond(45)) .setHeartRate(50), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(50)) .setSensorDistance(Distance.of(10)), - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(55)) .setSensorDistance(Distance.of(10)), new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochSecond(60)) @@ -274,7 +275,7 @@ public class TrackStatisticsUpdaterTest { // when subject.addTrackPoint(new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochSecond(0))); subject.addTrackPoint( - new TrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10)) + createTrackPoint(0, 0, Altitude.WGS84.of(0), Instant.ofEpochSecond(10)) .setSensorDistance(Distance.of(10))); subject.addTrackPoint(new TrackPoint(TrackPoint.Type.IDLE, Instant.ofEpochSecond(30))); @@ -330,11 +331,11 @@ public class TrackStatisticsUpdaterTest { TrackStatisticsUpdater subject = new TrackStatisticsUpdater(); TrackPoint tp1 = new TrackPoint(TrackPoint.Type.SEGMENT_START_MANUAL, Instant.ofEpochMilli(1000)); - TrackPoint tp2 = new TrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); + TrackPoint tp2 = createTrackPoint(0, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(2000)); tp2.setSpeed(Speed.of(5f)); - TrackPoint tp3 = new TrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); + TrackPoint tp3 = createTrackPoint(0.00001, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(3000)); tp3.setSpeed(Speed.of(5f)); - TrackPoint tp4 = new TrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); + TrackPoint tp4 = createTrackPoint(0.0005, 0, Altitude.WGS84.of(5.0), Instant.ofEpochMilli(4000)); tp4.setSpeed(Speed.of(5f)); TrackPoint tp5 = new TrackPoint(TrackPoint.Type.SEGMENT_END_MANUAL, Instant.ofEpochMilli(5000)); @@ -352,4 +353,18 @@ public class TrackStatisticsUpdaterTest { assertEquals(55.287, subject.getTrackStatistics().getTotalDistance().toM(), 0.01); assertEquals(55.287, copy.getTrackStatistics().getTotalDistance().toM(), 0.01); } + + public TrackPoint createTrackPoint(double latitude, double longitude, Altitude altitude, Instant time) { + return new TrackPoint(TrackPoint.Type.TRACKPOINT, + new Position( + time, + latitude, + longitude, + null, + altitude, + null, + null, + null + )); + } } \ No newline at end of file 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 f75c8475f..c3b2bf150 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/TrackPoint.java @@ -23,7 +23,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; -import java.time.Duration; import java.time.Instant; import java.util.Optional; @@ -31,13 +30,11 @@ import java.util.Optional; * Sensor and/or location information for a specific point in time. *

* Time is created using the {@link de.dennisguse.opentracks.services.handlers.MonotonicClock}, because system time jump backwards. - * GPS time is ignored as for non-GPS events, we could not create timestamps. + * GPS time is ignored as for non-GPS events, we could not create GPS-based timestamps. */ //TODO Should be a record (with final properties) public class TrackPoint { - private static final Duration MAX_LOCATION_AGE = Duration.ofMinutes(1); - @Nullable private TrackPoint.Id id; @@ -98,40 +95,11 @@ public class TrackPoint { //TODO Refactor constructors public TrackPoint(@NonNull Type type, @NonNull Instant time) { - this.type = type; - this.position = Position.of(time); + this(null, type, Position.of(time)); } - @Deprecated - public TrackPoint(@NonNull Location location, @NonNull Instant time) { - this.type = Type.TRACKPOINT; - this.position = Position.of(location, time); - } - - public TrackPoint(@NonNull Position position) { - this(null, Type.TRACKPOINT, position); - } - - public TrackPoint(@NonNull Type type, @NonNull Location location, @NonNull Instant time) { - this.type = type; - this.position = Position.of(location, time); - } - - //TODO Remove; only used for TrackStatisticUpdaterTest - @Deprecated - @VisibleForTesting - public TrackPoint(double latitude, double longitude, Altitude altitude, Instant time) { - this.type = Type.TRACKPOINT; - this.position = new Position( - time, - latitude, - longitude, - null, - altitude, - null, - null, - null - ); + public TrackPoint(@NonNull Type type, @NonNull Position position) { + this(null, type, position); } public static TrackPoint createSegmentStartManualWithTime(Instant time) { @@ -147,6 +115,7 @@ public class TrackPoint { return type; } + @Deprecated //Should not be needed. public TrackPoint setType(@NonNull Type type) { this.type = type; return this; @@ -186,29 +155,12 @@ public class TrackPoint { return position.latitude(); } - @Deprecated - public TrackPoint setLatitude(double latitude) { - this.position = position.withCoordinates(latitude, getLongitude()); - return this; - } - //TODO Should be double @Deprecated //Use getPosition() public Double getLongitude() { return position.longitude(); } - @Deprecated - public TrackPoint setLongitude(double longitude) { - setCoordinates(getLatitude(), longitude); - return this; - } - - public TrackPoint setCoordinates(double latitude, double longitude) { - this.position = this.position.withCoordinates(latitude, longitude); - return this; - } - @NonNull public Position getPosition() { return position; @@ -233,6 +185,7 @@ public class TrackPoint { return altitudeGain_m; } + @Deprecated public TrackPoint setAltitudeGain(Float altitudeGain_m) { this.altitudeGain_m = altitudeGain_m; return this; @@ -246,6 +199,7 @@ public class TrackPoint { return altitudeLoss_m; } + @Deprecated public TrackPoint setAltitudeLoss(Float altitudeLoss_m) { this.altitudeLoss_m = altitudeLoss_m; return this; @@ -264,12 +218,14 @@ public class TrackPoint { return position.altitude(); } + @Deprecated @VisibleForTesting public TrackPoint setAltitude(double altitude_m) { setAltitude(Altitude.WGS84.of(altitude_m)); return this; } + @Deprecated public TrackPoint setAltitude(Altitude altitude) { position = position.with(altitude); return this; @@ -283,6 +239,7 @@ public class TrackPoint { return position.speed(); } + @Deprecated public TrackPoint setSpeed(Speed speed) { this.position = position.with(speed); return this; @@ -309,6 +266,7 @@ public class TrackPoint { return position.horizontalAccuracy(); } + @Deprecated public TrackPoint setHorizontalAccuracy(Distance horizontalAccuracy) { this.position = this.position.withHorizontalAccuracy(horizontalAccuracy); return this; diff --git a/src/main/java/de/dennisguse/opentracks/io/file/importer/GpxTrackImporter.java b/src/main/java/de/dennisguse/opentracks/io/file/importer/GpxTrackImporter.java index 1dc10bace..4acc5b09a 100644 --- a/src/main/java/de/dennisguse/opentracks/io/file/importer/GpxTrackImporter.java +++ b/src/main/java/de/dennisguse/opentracks/io/file/importer/GpxTrackImporter.java @@ -331,7 +331,9 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac } } - TrackPoint trackPoint = new TrackPoint(new Position( + TrackPoint trackPoint = new TrackPoint( + TrackPoint.Type.TRACKPOINT, + new Position( parsedTime.toInstant(), latitudeParsed, longitudeParsed, @@ -430,7 +432,7 @@ public class GpxTrackImporter extends DefaultHandler implements XMLImporter.Trac TrackPoint trackPoint = createTrackPoint(); if (!trackPoint.hasLocation()) { - Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.getLocation()); + Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.getPosition()); return; } Marker marker = new Marker(null, trackPoint); 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 0767a32aa..ac1c4afed 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 @@ -35,6 +35,7 @@ import java.util.Locale; import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Marker; +import de.dennisguse.opentracks.data.models.Position; import de.dennisguse.opentracks.data.models.Speed; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; @@ -94,7 +95,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac private ZoneOffset zoneOffset; private final ArrayList whenList = new ArrayList<>(); - private final ArrayList locationList = new ArrayList<>(); + private final ArrayList positionList = new ArrayList<>(); private String dataType; @@ -255,13 +256,14 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac return; } - Location location = createLocation(longitude, latitude, altitude); - if (location == null) { - Log.w(TAG, "Marker with invalid coordinates ignored: " + location); + Position position = createPosition(latitude, longitude, altitude); + if (position == null) { + Log.w(TAG, "Marker with invalid coordinates ignored: " + latitude + " " + longitude); return; } + position = position.with(whenList.get(0)); - Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, location, whenList.get(0))); //TODO Creating marker without need + Marker marker = new Marker(null, new TrackPoint(TrackPoint.Type.TRACKPOINT, position)); //TODO Creating marker without need marker.setName(name != null ? name : ""); marker.setDescription(description != null ? description : ""); marker.setCategory(activityTypeLocalized != null ? activityTypeLocalized : ""); @@ -288,7 +290,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac } private void onTrackSegmentStart() { - locationList.clear(); + positionList.clear(); whenList.clear(); trackpointTypeList.clear(); @@ -304,24 +306,23 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac } private void onTrackSegmentEnd() { - if (locationList.size() != whenList.size()) { + if (positionList.size() != whenList.size()) { throw new ImportParserException(" and should have the same count."); } // Close a track segment by inserting the segment locations - for (int i = 0; i < locationList.size(); i++) { + for (int i = 0; i < positionList.size(); i++) { Instant time = whenList.get(i); - Location location = locationList.get(i); + Position position = positionList.get(i); TrackPoint trackPoint; - if (location == null) { - trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, time); + if (position == null) { + trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(time)); } else { - trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, location, time); + trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, position.with(time)); } if (i < trackpointTypeList.size() && trackpointTypeList.get(i) != null) { - TrackPoint.Type type = TrackPoint.Type.valueOf(trackpointTypeList.get(i)); trackPoint.setType(type); } @@ -363,7 +364,7 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac } else { type = TrackPoint.Type.SEGMENT_START_AUTOMATIC; } - } else if (i == locationList.size() - 1 && !trackPoint.wasCreatedManually()) { + } else if (i == positionList.size() - 1 && !trackPoint.wasCreatedManually()) { //last type = TrackPoint.Type.SEGMENT_END_MANUAL; } @@ -381,18 +382,16 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac altitude = parts.length == 3 ? parts[2] : null; } - locationList.add(createLocation(longitude, latitude, altitude)); + positionList.add(createPosition(latitude, longitude, altitude)); longitude = null; latitude = null; altitude = null; } - private Location createLocation(String longitude, String latitude, String altitude) { - Location location = null; - if (longitude != null || latitude != null) { - location = new Location("import"); - + private Position createPosition(String latitude, String longitude, String altitude) { + if (longitude != null && latitude != null) { + Location location = new Location("import"); try { location.setLatitude(Double.parseDouble(latitude)); location.setLongitude(Double.parseDouble(longitude)); @@ -407,8 +406,10 @@ public class KmlTrackImporter extends DefaultHandler implements XMLImporter.Trac throw new ParsingException(createErrorMessage(String.format(Locale.US, "Unable to parse altitude: %s", altitude)), e); } } + return Position.of(location, null); } - return location; + + return null; } private void onExtendedDataValueEnd() throws SAXException { diff --git a/src/main/java/de/dennisguse/opentracks/sensors/GpsManager.java b/src/main/java/de/dennisguse/opentracks/sensors/GpsManager.java index 543c9f1f2..692a15b3e 100644 --- a/src/main/java/de/dennisguse/opentracks/sensors/GpsManager.java +++ b/src/main/java/de/dennisguse/opentracks/sensors/GpsManager.java @@ -124,7 +124,7 @@ public class GpsManager implements SensorConnector, LocationListenerCompat, GpsS @Override public void onLocationChanged(@NonNull Location location) { // Send each update to the status; please note that this TrackPoint is not stored. - TrackPoint trackPoint = new TrackPoint(location, trackPointCreator.createNow()); + TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(location, trackPointCreator.createNow())); gpsStatusManager.onNewTrackPoint(trackPoint); if (!trackPoint.getPosition().hasValidLocation()) { diff --git a/src/main/java/de/dennisguse/opentracks/ui/customRecordingLayout/SettingsCustomLayoutEditAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/customRecordingLayout/SettingsCustomLayoutEditAdapter.java index d943208a6..a5d1275f1 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/customRecordingLayout/SettingsCustomLayoutEditAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/customRecordingLayout/SettingsCustomLayoutEditAdapter.java @@ -61,7 +61,7 @@ public class SettingsCustomLayoutEditAdapter extends RecyclerView.Adapter createNewMarker() { - TrackPoint trackPoint = new TrackPoint(location, Instant.now()); + TrackPoint trackPoint = new TrackPoint(TrackPoint.Type.TRACKPOINT, Position.of(location, Instant.now())); return viewModel.createNewMarker(trackId, trackPoint); }