forked from upstream-mirrors/OpenTracks
@@ -96,16 +96,7 @@ public class TestDataUtil {
|
|||||||
return new TrackData(track, trackPoints, markers);
|
return new TrackData(track, trackPoints, markers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class TrackData {
|
public record TrackData(Track track, List<TrackPoint> trackPoints, List<Marker> markers) {
|
||||||
public final Track track;
|
|
||||||
public final List<TrackPoint> trackPoints;
|
|
||||||
public final List<Marker> markers;
|
|
||||||
|
|
||||||
public TrackData(Track track, List<TrackPoint> trackPoints, List<Marker> markers) {
|
|
||||||
this.track = track;
|
|
||||||
this.trackPoints = trackPoints;
|
|
||||||
this.markers = markers;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -424,7 +424,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
Marker.Id markerId = new Marker.Id(System.currentTimeMillis());
|
Marker.Id markerId = new Marker.Id(System.currentTimeMillis());
|
||||||
marker.setId(markerId);
|
marker.setId(markerId);
|
||||||
ContentValues contentValues = contentProviderUtils.createContentValues(marker);
|
ContentValues contentValues = contentProviderUtils.createContentValues(marker);
|
||||||
assertEquals(markerId.getId(), contentValues.get(MarkerColumns._ID));
|
assertEquals(markerId.id(), contentValues.get(MarkerColumns._ID));
|
||||||
assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(MarkerColumns.LONGITUDE));
|
assertEquals((int) (TestDataUtil.INITIAL_LONGITUDE * 1000000), contentValues.get(MarkerColumns.LONGITUDE));
|
||||||
assertEquals(TEST_DESC, contentValues.get(MarkerColumns.DESCRIPTION));
|
assertEquals(TEST_DESC, contentValues.get(MarkerColumns.DESCRIPTION));
|
||||||
}
|
}
|
||||||
@@ -458,7 +458,7 @@ public class CustomContentProviderUtilsTest {
|
|||||||
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
|
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
|
||||||
|
|
||||||
Marker marker = contentProviderUtils.createMarker(cursorMock);
|
Marker marker = contentProviderUtils.createMarker(cursorMock);
|
||||||
assertEquals(id, marker.getId().getId());
|
assertEquals(id, marker.getId().id());
|
||||||
assertEquals(name, marker.getName());
|
assertEquals(name, marker.getName());
|
||||||
assertEquals(trackId, marker.getTrackId().getId());
|
assertEquals(trackId, marker.getTrackId().getId());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class BluetoothUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void parseHeartRate_uint8() {
|
public void parseHeartRate_uint8() {
|
||||||
// given
|
// given
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.HEARTRATE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.HEARTRATE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x02, 0x3C});
|
characteristic.setValue(new byte[]{0x02, 0x3C});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -34,7 +34,7 @@ public class BluetoothUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void parseHeartRate_uint16() {
|
public void parseHeartRate_uint16() {
|
||||||
// given
|
// given
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.HEARTRATE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.HEARTRATE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x01, 0x01, 0x01});
|
characteristic.setValue(new byte[]{0x01, 0x01, 0x01});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -47,7 +47,7 @@ public class BluetoothUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
public void parseEnvironmentalSensing_Pa() {
|
public void parseEnvironmentalSensing_Pa() {
|
||||||
// given
|
// given
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.BAROMETRIC_PRESSURE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.BAROMETRIC_PRESSURE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{(byte) 0xB2, (byte) 0x48, (byte) 0x0F, (byte) 0x00});
|
characteristic.setValue(new byte[]{(byte) 0xB2, (byte) 0x48, (byte) 0x0F, (byte) 0x00});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -59,7 +59,7 @@ public class BluetoothUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingSpeedCadence_crankOnly() {
|
public void parseCyclingSpeedCadence_crankOnly() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x02, (byte) 0xC8, 0x00, 0x00, 0x00, 0x06, (byte) 0x99});
|
characteristic.setValue(new byte[]{0x02, (byte) 0xC8, 0x00, 0x00, 0x00, 0x06, (byte) 0x99});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -72,7 +72,7 @@ public class BluetoothUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingSpeedCadence_wheelOnly() {
|
public void parseCyclingSpeedCadence_wheelOnly() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x01, (byte) 0xFF, (byte) 0xFF, 0, 1, 0x45, (byte) 0x99});
|
characteristic.setValue(new byte[]{0x01, (byte) 0xFF, (byte) 0xFF, 0, 1, 0x45, (byte) 0x99});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -85,7 +85,7 @@ public class BluetoothUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingSpeedCadence_crankWheel() {
|
public void parseCyclingSpeedCadence_crankWheel() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_SPEED_CADENCE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x03, (byte) 0xC8, 0x00, 0x00, 0x01, 0x06, (byte) 0x99, (byte) 0xE1, 0x00, 0x45, (byte) 0x99});
|
characteristic.setValue(new byte[]{0x03, (byte) 0xC8, 0x00, 0x00, 0x01, 0x06, (byte) 0x99, (byte) 0xE1, 0x00, 0x45, (byte) 0x99});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@@ -98,34 +98,34 @@ public class BluetoothUtilsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingPower_power() {
|
public void parseCyclingPower_power() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_POWER.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_POWER.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0, 0, 40, 0});
|
characteristic.setValue(new byte[]{0, 0, 40, 0});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SensorDataCyclingPower.Data powerCadence = BluetoothUtils.parseCyclingPower("", "", characteristic);
|
SensorDataCyclingPower.Data powerCadence = BluetoothUtils.parseCyclingPower("", "", characteristic);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(40, powerCadence.getPower().getValue().getW(), 0.01);
|
assertEquals(40, powerCadence.power().getValue().getW(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseCyclingPower_power_with_cadence() {
|
public void parseCyclingPower_power_with_cadence() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_POWER.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.CYCLING_POWER.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{0x2C, 0x00, 0x00, 0x00, (byte) 0x9F, 0x00, 0x0C, 0x00, (byte) 0xE5, 0x42});
|
characteristic.setValue(new byte[]{0x2C, 0x00, 0x00, 0x00, (byte) 0x9F, 0x00, 0x0C, 0x00, (byte) 0xE5, 0x42});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SensorDataCyclingPower.Data powerCadence = BluetoothUtils.parseCyclingPower("", "", characteristic);
|
SensorDataCyclingPower.Data powerCadence = BluetoothUtils.parseCyclingPower("", "", characteristic);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertEquals(0, powerCadence.getPower().getValue().getW(), 0.01);
|
assertEquals(0, powerCadence.power().getValue().getW(), 0.01);
|
||||||
|
|
||||||
assertEquals(12, powerCadence.getCadence().getCrankRevolutionsCount());
|
assertEquals(12, powerCadence.cadence().getCrankRevolutionsCount());
|
||||||
assertEquals(17125, powerCadence.getCadence().getCrankRevolutionsTime());
|
assertEquals(17125, powerCadence.cadence().getCrankRevolutionsTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseRunningSpeedAndCadence_with_distance() {
|
public void parseRunningSpeedAndCadence_with_distance() {
|
||||||
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.RUNNING_SPEED_CADENCE.getServiceUUID(), 0, 0);
|
BluetoothGattCharacteristic characteristic = new BluetoothGattCharacteristic(BluetoothUtils.RUNNING_SPEED_CADENCE.serviceUUID(), 0, 0);
|
||||||
characteristic.setValue(new byte[]{2, 0, 5, 80, (byte) 0xFF, (byte) 0xFF, 0, 1});
|
characteristic.setValue(new byte[]{2, 0, 5, 80, (byte) 0xFF, (byte) 0xFF, 0, 1});
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class PressureSensorUtilsTest {
|
|||||||
if (altitudeChange != null) {
|
if (altitudeChange != null) {
|
||||||
altitudeGain_m += altitudeChange.getAltitudeGain_m();
|
altitudeGain_m += altitudeChange.getAltitudeGain_m();
|
||||||
altitudeLoss += altitudeChange.getAltitudeLoss_m();
|
altitudeLoss += altitudeChange.getAltitudeLoss_m();
|
||||||
lastUsedPressureValue = altitudeChange.getCurrentSensorValue();
|
lastUsedPressureValue = altitudeChange.currentSensorValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class TrackStatisticsUpdaterTest {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
TrackStatisticsUpdater subject = new TrackStatisticsUpdater();
|
||||||
data.trackPoints.forEach(subject::addTrackPoint);
|
data.trackPoints().forEach(subject::addTrackPoint);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
TrackStatistics statistics = subject.getTrackStatistics();
|
TrackStatistics statistics = subject.getTrackStatistics();
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ public class ContentProviderUtils {
|
|||||||
public void deleteMarker(Context context, Marker.Id markerId) {
|
public void deleteMarker(Context context, Marker.Id markerId) {
|
||||||
final Marker marker = getMarker(markerId);
|
final Marker marker = getMarker(markerId);
|
||||||
deleteMarkerPhoto(context, marker);
|
deleteMarkerPhoto(context, marker);
|
||||||
contentResolver.delete(MarkerColumns.CONTENT_URI, MarkerColumns._ID + "=?", new String[]{Long.toString(markerId.getId())});
|
contentResolver.delete(MarkerColumns.CONTENT_URI, MarkerColumns._ID + "=?", new String[]{Long.toString(markerId.id())});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -422,7 +422,7 @@ public class ContentProviderUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Marker getMarker(@NonNull Marker.Id markerId) {
|
public Marker getMarker(@NonNull Marker.Id markerId) {
|
||||||
try (Cursor cursor = getMarkerCursor(null, MarkerColumns._ID + "=?", new String[]{Long.toString(markerId.getId())}, MarkerColumns._ID, 1)) {
|
try (Cursor cursor = getMarkerCursor(null, MarkerColumns._ID + "=?", new String[]{Long.toString(markerId.id())}, MarkerColumns._ID, 1)) {
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
return createMarker(cursor);
|
return createMarker(cursor);
|
||||||
}
|
}
|
||||||
@@ -442,7 +442,7 @@ public class ContentProviderUtils {
|
|||||||
String[] selectionArgs;
|
String[] selectionArgs;
|
||||||
if (minMarkerId != null) {
|
if (minMarkerId != null) {
|
||||||
selection = MarkerColumns.TRACKID + "=? AND " + MarkerColumns._ID + ">=?";
|
selection = MarkerColumns.TRACKID + "=? AND " + MarkerColumns._ID + ">=?";
|
||||||
selectionArgs = new String[]{Long.toString(trackId.getId()), Long.toString(minMarkerId.getId())};
|
selectionArgs = new String[]{Long.toString(trackId.getId()), Long.toString(minMarkerId.id())};
|
||||||
} else {
|
} else {
|
||||||
selection = MarkerColumns.TRACKID + "=?";
|
selection = MarkerColumns.TRACKID + "=?";
|
||||||
selectionArgs = new String[]{Long.toString(trackId.getId())};
|
selectionArgs = new String[]{Long.toString(trackId.getId())};
|
||||||
@@ -495,7 +495,7 @@ public class ContentProviderUtils {
|
|||||||
if (!updateMarker.hasPhoto()) {
|
if (!updateMarker.hasPhoto()) {
|
||||||
deleteMarkerPhoto(context, savedMarker);
|
deleteMarkerPhoto(context, savedMarker);
|
||||||
}
|
}
|
||||||
int rows = contentResolver.update(MarkerColumns.CONTENT_URI, createContentValues(updateMarker), MarkerColumns._ID + "=?", new String[]{Long.toString(updateMarker.getId().getId())});
|
int rows = contentResolver.update(MarkerColumns.CONTENT_URI, createContentValues(updateMarker), MarkerColumns._ID + "=?", new String[]{Long.toString(updateMarker.getId().id())});
|
||||||
return rows == 1;
|
return rows == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,7 +503,7 @@ public class ContentProviderUtils {
|
|||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
|
|
||||||
if (marker.getId() != null) {
|
if (marker.getId() != null) {
|
||||||
values.put(MarkerColumns._ID, marker.getId().getId());
|
values.put(MarkerColumns._ID, marker.getId().id());
|
||||||
}
|
}
|
||||||
values.put(MarkerColumns.NAME, marker.getName());
|
values.put(MarkerColumns.NAME, marker.getName());
|
||||||
values.put(MarkerColumns.DESCRIPTION, marker.getDescription());
|
values.put(MarkerColumns.DESCRIPTION, marker.getDescription());
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package de.dennisguse.opentracks.data.models;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class AtmosphericPressure {
|
public record AtmosphericPressure(float value) {
|
||||||
|
|
||||||
public static AtmosphericPressure ofPA(float value_Pa) {
|
public static AtmosphericPressure ofPA(float value_Pa) {
|
||||||
return new AtmosphericPressure(value_Pa * 100);
|
return new AtmosphericPressure(value_Pa * 100);
|
||||||
@@ -12,12 +12,6 @@ public class AtmosphericPressure {
|
|||||||
return new AtmosphericPressure(value_hPa);
|
return new AtmosphericPressure(value_hPa);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final float value;
|
|
||||||
|
|
||||||
private AtmosphericPressure(float value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPA() {
|
public float getPA() {
|
||||||
return value * 100;
|
return value * 100;
|
||||||
}
|
}
|
||||||
@@ -25,24 +19,4 @@ public class AtmosphericPressure {
|
|||||||
public float getHPA() {
|
public float getHPA() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
AtmosphericPressure that = (AtmosphericPressure) o;
|
|
||||||
return Float.compare(that.value, value) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "AtmosphericPressure{" +
|
|
||||||
"value=" + value +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,8 @@
|
|||||||
package de.dennisguse.opentracks.data.models;
|
package de.dennisguse.opentracks.data.models;
|
||||||
|
|
||||||
public class BatteryLevel {
|
public record BatteryLevel(int percentage) {
|
||||||
|
|
||||||
public static BatteryLevel of(int percentage) {
|
public static BatteryLevel of(int percentage) {
|
||||||
return new BatteryLevel(percentage);
|
return new BatteryLevel(percentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int percentage;
|
|
||||||
|
|
||||||
private BatteryLevel(int percentage) {
|
|
||||||
this.percentage = percentage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPercentage() {
|
|
||||||
return percentage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import androidx.annotation.NonNull;
|
|||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Cadence {
|
public record Cadence(float value_rpm) {
|
||||||
|
|
||||||
public static Cadence of(float value, Duration duration) {
|
public static Cadence of(float value, Duration duration) {
|
||||||
if (duration.isZero()) {
|
if (duration.isZero()) {
|
||||||
@@ -23,34 +23,7 @@ public class Cadence {
|
|||||||
return of(0.0f);
|
return of(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final float value_rpm;
|
|
||||||
|
|
||||||
private Cadence(float value) {
|
|
||||||
this.value_rpm = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getRPM() {
|
public float getRPM() {
|
||||||
return value_rpm;
|
return value_rpm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Cadence cadence = (Cadence) o;
|
|
||||||
return Float.compare(cadence.value_rpm, value_rpm) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value_rpm);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Cadence{" +
|
|
||||||
"value=" + value_rpm + " rpm" +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.settings.UnitSystem;
|
import de.dennisguse.opentracks.settings.UnitSystem;
|
||||||
|
|
||||||
public class Distance {
|
public record Distance(double distance_m) {
|
||||||
|
|
||||||
public static Distance of(double distance_m) {
|
public static Distance of(double distance_m) {
|
||||||
return new Distance(distance_m);
|
return new Distance(distance_m);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Distance of(Double distance_m) {
|
public static Distance of(Double distance_m) {
|
||||||
if (distance_m == null) {
|
if (distance_m == null) {
|
||||||
return Distance.of(Double.NaN);
|
return Distance.of(Double.NaN);
|
||||||
@@ -20,11 +19,9 @@ public class Distance {
|
|||||||
return Distance.of((double) distance_m);
|
return Distance.of((double) distance_m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Distance of(String distance_m) {
|
public static Distance of(String distance_m) {
|
||||||
return of(Float.parseFloat(distance_m));
|
return of(Float.parseFloat(distance_m));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Distance ofOrNull(Double distance_m) {
|
public static Distance ofOrNull(Double distance_m) {
|
||||||
if (distance_m == null) {
|
if (distance_m == null) {
|
||||||
@@ -65,12 +62,6 @@ public class Distance {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private final double distance_m;
|
|
||||||
|
|
||||||
private Distance(double distance_m) {
|
|
||||||
this.distance_m = distance_m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Distance plus(@NonNull Distance distance) {
|
public Distance plus(@NonNull Distance distance) {
|
||||||
return new Distance(distance_m + distance.distance_m);
|
return new Distance(distance_m + distance.distance_m);
|
||||||
}
|
}
|
||||||
@@ -142,27 +133,6 @@ public class Distance {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Distance distance = (Distance) o;
|
|
||||||
return Double.compare(distance.distance_m, distance_m) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(distance_m);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Distance{" +
|
|
||||||
"distance_m=" + distance_m +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
// multiplication factors for conversion
|
// multiplication factors for conversion
|
||||||
private static final double KM_TO_M = 1000.0;
|
private static final double KM_TO_M = 1000.0;
|
||||||
private static final double M_TO_KM = 1 / KM_TO_M;
|
private static final double M_TO_KM = 1 / KM_TO_M;
|
||||||
|
|||||||
@@ -4,40 +4,13 @@ import androidx.annotation.NonNull;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class HeartRate {
|
public record HeartRate(float value) {
|
||||||
|
|
||||||
public static HeartRate of(float value) {
|
public static HeartRate of(float value) {
|
||||||
return new HeartRate(value);
|
return new HeartRate(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final float value;
|
|
||||||
|
|
||||||
private HeartRate(float value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getBPM() {
|
public float getBPM() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
HeartRate heartRate = (HeartRate) o;
|
|
||||||
return Float.compare(heartRate.value, value) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "HeartRate{" +
|
|
||||||
"value=" + value + " bpm" +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
|
|
||||||
@@ -267,31 +266,7 @@ public final class Marker {
|
|||||||
return photoUrl != null && !"".equals(photoUrl);
|
return photoUrl != null && !"".equals(photoUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Id implements Parcelable {
|
public record Id(long id) implements Parcelable {
|
||||||
|
|
||||||
private final long id;
|
|
||||||
|
|
||||||
public Id(long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TOOD Limit visibility to TrackRecordingService / ContentProvider
|
|
||||||
public long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Id id1 = (Id) o;
|
|
||||||
return id == id1.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
@@ -309,7 +284,7 @@ public final class Marker {
|
|||||||
parcel.writeLong(id);
|
parcel.writeLong(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Parcelable.Creator<Id> CREATOR = new Parcelable.Creator<>() {
|
public static final Creator<Id> CREATOR = new Creator<>() {
|
||||||
public Id createFromParcel(Parcel in) {
|
public Id createFromParcel(Parcel in) {
|
||||||
return new Id(in.readLong());
|
return new Id(in.readLong());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,40 +4,13 @@ import androidx.annotation.NonNull;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class Power {
|
public record Power(float value) {
|
||||||
|
|
||||||
public static Power of(float value) {
|
public static Power of(float value) {
|
||||||
return new Power(value);
|
return new Power(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final float value;
|
|
||||||
|
|
||||||
private Power(float value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getW() {
|
public float getW() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Power power = (Power) o;
|
|
||||||
return Float.compare(power.value, value) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Power{" +
|
|
||||||
"value=" + value + " W" +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.util.Objects;
|
|||||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.settings.UnitSystem;
|
import de.dennisguse.opentracks.settings.UnitSystem;
|
||||||
|
|
||||||
public class Speed {
|
public record Speed(double speed_mps) {
|
||||||
|
|
||||||
public static Speed of(Distance distance, Duration duration) {
|
public static Speed of(Distance distance, Duration duration) {
|
||||||
if (duration.isZero()) {
|
if (duration.isZero()) {
|
||||||
@@ -47,12 +47,6 @@ public class Speed {
|
|||||||
return Speed.of(Math.abs(speed1.speed_mps - speed2.speed_mps));
|
return Speed.of(Math.abs(speed1.speed_mps - speed2.speed_mps));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final double speed_mps;
|
|
||||||
|
|
||||||
private Speed(double speed_mps) {
|
|
||||||
this.speed_mps = speed_mps;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Speed mul(double factor) {
|
public Speed mul(double factor) {
|
||||||
return new Speed(factor * speed_mps);
|
return new Speed(factor * speed_mps);
|
||||||
}
|
}
|
||||||
@@ -121,25 +115,4 @@ public class Speed {
|
|||||||
case NAUTICAL_IMPERIAL -> toKnots();
|
case NAUTICAL_IMPERIAL -> toKnots();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Speed speed = (Speed) o;
|
|
||||||
return Double.compare(speed.speed_mps, speed_mps) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(speed_mps);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Speed{" +
|
|
||||||
"speed_mps=" + speed_mps +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,6 +141,6 @@ public class KmzTrackExporter implements TrackExporter {
|
|||||||
public static String buildKmzImageFilePath(Marker marker) {
|
public static String buildKmzImageFilePath(Marker marker) {
|
||||||
String ext = FileUtils.getExtension(marker.getPhotoUrl());
|
String ext = FileUtils.getExtension(marker.getPhotoUrl());
|
||||||
ext = ext == null ? "" : "." + ext;
|
ext = ext == null ? "" : "." + ext;
|
||||||
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(marker.getId().getId() + ext);
|
return KMZ_IMAGES_DIR + File.separatorChar + FileUtils.sanitizeFileName(marker.getId().id() + ext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,8 @@ public class StopRecording extends AbstractAPIActivity {
|
|||||||
protected void execute(TrackRecordingService service) {
|
protected void execute(TrackRecordingService service) {
|
||||||
RecordingData recordingData = service.getRecordingDataObservable().getValue();
|
RecordingData recordingData = service.getRecordingDataObservable().getValue();
|
||||||
Track.Id trackId = null;
|
Track.Id trackId = null;
|
||||||
if (recordingData != null && recordingData.getTrack() != null) {
|
if (recordingData != null && recordingData.track() != null) {
|
||||||
trackId = recordingData.getTrack().getId();
|
trackId = recordingData.track().getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|||||||
+4
-4
@@ -77,7 +77,7 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
|||||||
BluetoothGattService gattService = null;
|
BluetoothGattService gattService = null;
|
||||||
ServiceMeasurementUUID serviceMeasurement = null;
|
ServiceMeasurementUUID serviceMeasurement = null;
|
||||||
for (ServiceMeasurementUUID s : serviceMeasurementUUIDs) {
|
for (ServiceMeasurementUUID s : serviceMeasurementUUIDs) {
|
||||||
gattService = gatt.getService(s.getServiceUUID());
|
gattService = gatt.getService(s.serviceUUID());
|
||||||
if (gattService != null) {
|
if (gattService != null) {
|
||||||
serviceMeasurement = s;
|
serviceMeasurement = s;
|
||||||
break;
|
break;
|
||||||
@@ -89,9 +89,9 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(serviceMeasurement.getMeasurementUUID());
|
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(serviceMeasurement.measurementUUID());
|
||||||
if (characteristic == null) {
|
if (characteristic == null) {
|
||||||
Log.e(TAG, "Could not get BluetoothCharacteristic for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement.getServiceUUID() + " characteristicUUID=" + serviceMeasurement.getMeasurementUUID());
|
Log.e(TAG, "Could not get BluetoothCharacteristic for address=" + gatt.getDevice().getAddress() + " serviceUUID=" + serviceMeasurement.serviceUUID() + " characteristicUUID=" + serviceMeasurement.measurementUUID());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gatt.setCharacteristicNotification(characteristic, true);
|
gatt.setCharacteristicNotification(characteristic, true);
|
||||||
@@ -113,7 +113,7 @@ public abstract class AbstractBluetoothConnectionManager<DataType> {
|
|||||||
UUID serviceUUID = characteristic.getService().getUuid();
|
UUID serviceUUID = characteristic.getService().getUuid();
|
||||||
Log.d(TAG, "Received data from " + gatt.getDevice().getAddress() + " with service " + serviceUUID + " and characteristics " + characteristic.getUuid());
|
Log.d(TAG, "Received data from " + gatt.getDevice().getAddress() + " with service " + serviceUUID + " and characteristics " + characteristic.getUuid());
|
||||||
Optional<ServiceMeasurementUUID> serviceMeasurementUUID = serviceMeasurementUUIDs.stream()
|
Optional<ServiceMeasurementUUID> serviceMeasurementUUID = serviceMeasurementUUIDs.stream()
|
||||||
.filter(s -> s.getServiceUUID().equals(characteristic.getService().getUuid())).findFirst();
|
.filter(s -> s.serviceUUID().equals(characteristic.getService().getUuid())).findFirst();
|
||||||
if (serviceMeasurementUUID.isEmpty()) {
|
if (serviceMeasurementUUID.isEmpty()) {
|
||||||
Log.e(TAG, "Unknown service UUID; not supported?");
|
Log.e(TAG, "Unknown service UUID; not supported?");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class AltitudeSumManager implements SensorConnector {
|
|||||||
|
|
||||||
altitudeLoss_m += altitudeChange.getAltitudeLoss_m();
|
altitudeLoss_m += altitudeChange.getAltitudeLoss_m();
|
||||||
|
|
||||||
lastAcceptedSensorValue = altitudeChange.getCurrentSensorValue();
|
lastAcceptedSensorValue = altitudeChange.currentSensorValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
lastSeenSensorValue = currentSensorValue;
|
lastSeenSensorValue = currentSensorValue;
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ public class BluetoothConnectionManagerCyclingCadence extends AbstractBluetoothC
|
|||||||
if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_POWER)) {
|
if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_POWER)) {
|
||||||
SensorDataCyclingPower.Data data = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
SensorDataCyclingPower.Data data = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
||||||
if (data!= null) {
|
if (data!= null) {
|
||||||
return data.getCadence();
|
return data.cadence();
|
||||||
}
|
}
|
||||||
} else if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_SPEED_CADENCE)) {
|
} else if (serviceMeasurementUUID.equals(BluetoothUtils.CYCLING_SPEED_CADENCE)) {
|
||||||
SensorDataCyclingCadenceAndDistanceSpeed cadenceAndSpeed = BluetoothUtils.parseCyclingCrankAndWheel(address, sensorName, characteristic);
|
SensorDataCyclingCadenceAndDistanceSpeed cadenceAndSpeed = BluetoothUtils.parseCyclingCrankAndWheel(address, sensorName, characteristic);
|
||||||
|
|||||||
+1
-1
@@ -22,6 +22,6 @@ public class BluetoothConnectionManagerCyclingPower extends AbstractBluetoothCon
|
|||||||
protected SensorDataCyclingPower parsePayload(@NonNull ServiceMeasurementUUID serviceMeasurementUUID, String sensorName, String address, BluetoothGattCharacteristic characteristic) {
|
protected SensorDataCyclingPower parsePayload(@NonNull ServiceMeasurementUUID serviceMeasurementUUID, String sensorName, String address, BluetoothGattCharacteristic characteristic) {
|
||||||
SensorDataCyclingPower.Data cyclingPower = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
SensorDataCyclingPower.Data cyclingPower = BluetoothUtils.parseCyclingPower(address, sensorName, characteristic);
|
||||||
|
|
||||||
return cyclingPower != null ? cyclingPower.getPower() : null;
|
return cyclingPower != null ? cyclingPower.power() : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ public class BluetoothUtils {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Used for device discovery in preferences
|
// Used for device discovery in preferences
|
||||||
public static final List<ServiceMeasurementUUID> HEART_RATE_SUPPORTING_DEVICES = Collections.unmodifiableList(Arrays.asList(
|
public static final List<ServiceMeasurementUUID> HEART_RATE_SUPPORTING_DEVICES = List.of(
|
||||||
HEARTRATE,
|
HEARTRATE,
|
||||||
//Devices that support HEART_RATE_SERVICE_UUID, but do not announce HEART_RATE_SERVICE_UUID in there BLE announcement messages (during device discovery).
|
//Devices that support HEART_RATE_SERVICE_UUID, but do not announce HEART_RATE_SERVICE_UUID in there BLE announcement messages (during device discovery).
|
||||||
new ServiceMeasurementUUID(
|
new ServiceMeasurementUUID(
|
||||||
UUID.fromString("0000fee0-0000-1000-8000-00805f9b34fb"), //Miband3
|
UUID.fromString("0000fee0-0000-1000-8000-00805f9b34fb"), //Miband3
|
||||||
HEARTRATE.getMeasurementUUID()
|
HEARTRATE.measurementUUID()
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final UUID ENVIRONMENTAL_SENSING_SERVICE = new UUID(0x181A00001000L, 0x800000805f9b34fbL);
|
private static final UUID ENVIRONMENTAL_SENSING_SERVICE = new UUID(0x181A00001000L, 0x800000805f9b34fbL);
|
||||||
|
|||||||
@@ -18,24 +18,7 @@ public class PressureSensorUtils {
|
|||||||
private PressureSensorUtils() {
|
private PressureSensorUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class AltitudeChange {
|
public record AltitudeChange(AtmosphericPressure currentSensorValue, float altitudeChange_m) {
|
||||||
|
|
||||||
private final AtmosphericPressure currentSensorValue;
|
|
||||||
|
|
||||||
private final float altitudeChange_m;
|
|
||||||
|
|
||||||
public AltitudeChange(AtmosphericPressure currentSensorValue, float altitudeChange_m) {
|
|
||||||
this.currentSensorValue = currentSensorValue;
|
|
||||||
this.altitudeChange_m = altitudeChange_m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AtmosphericPressure getCurrentSensorValue() {
|
|
||||||
return currentSensorValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getAltitudeChange_m() {
|
|
||||||
return altitudeChange_m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getAltitudeGain_m() {
|
public float getAltitudeGain_m() {
|
||||||
return altitudeChange_m > 0 ? altitudeChange_m : 0;
|
return altitudeChange_m > 0 ? altitudeChange_m : 0;
|
||||||
@@ -67,7 +50,7 @@ public class PressureSensorUtils {
|
|||||||
|
|
||||||
// Limit altitudeC change by ALTITUDE_CHANGE_DIFF and computes pressure value accordingly.
|
// Limit altitudeC change by ALTITUDE_CHANGE_DIFF and computes pressure value accordingly.
|
||||||
AltitudeChange altitudeChange = new AltitudeChange(currentSensorValue, altitudeChange_m);
|
AltitudeChange altitudeChange = new AltitudeChange(currentSensorValue, altitudeChange_m);
|
||||||
if (altitudeChange.getAltitudeChange_m() > 0) {
|
if (altitudeChange.altitudeChange_m() > 0) {
|
||||||
return new AltitudeChange(getBarometricPressure(lastSensorValue_m + ALTITUDE_CHANGE_DIFF_M), ALTITUDE_CHANGE_DIFF_M);
|
return new AltitudeChange(getBarometricPressure(lastSensorValue_m + ALTITUDE_CHANGE_DIFF_M), ALTITUDE_CHANGE_DIFF_M);
|
||||||
} else {
|
} else {
|
||||||
return new AltitudeChange(getBarometricPressure(lastSensorValue_m - ALTITUDE_CHANGE_DIFF_M), -1 * ALTITUDE_CHANGE_DIFF_M);
|
return new AltitudeChange(getBarometricPressure(lastSensorValue_m - ALTITUDE_CHANGE_DIFF_M), -1 * ALTITUDE_CHANGE_DIFF_M);
|
||||||
|
|||||||
@@ -5,43 +5,5 @@ import androidx.annotation.NonNull;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ServiceMeasurementUUID {
|
public record ServiceMeasurementUUID(UUID serviceUUID, UUID measurementUUID) {
|
||||||
|
|
||||||
private final UUID serviceUUID;
|
|
||||||
private final UUID measurementUUID;
|
|
||||||
|
|
||||||
public ServiceMeasurementUUID(UUID serviceUUID, UUID measurementUUID) {
|
|
||||||
this.serviceUUID = serviceUUID;
|
|
||||||
this.measurementUUID = measurementUUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getServiceUUID() {
|
|
||||||
return serviceUUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UUID getMeasurementUUID() {
|
|
||||||
return measurementUUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "ServiceMeasurementUUID{" +
|
|
||||||
"serviceUUID=" + serviceUUID +
|
|
||||||
", measurementUUID=" + measurementUUID +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
ServiceMeasurementUUID that = (ServiceMeasurementUUID) o;
|
|
||||||
return Objects.equals(serviceUUID, that.serviceUUID) && Objects.equals(measurementUUID, that.measurementUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(serviceUUID, measurementUUID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-24
@@ -28,30 +28,19 @@ public class SensorDataCyclingPower extends SensorData<Power> {
|
|||||||
return super.toString() + " data=" + value;
|
return super.toString() + " data=" + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Data {
|
public record Data(SensorDataCyclingPower power, SensorDataCyclingCadence cadence) {
|
||||||
private final SensorDataCyclingPower power;
|
public Data(SensorDataCyclingPower power, @Nullable SensorDataCyclingCadence cadence) {
|
||||||
private final SensorDataCyclingCadence cadence;
|
this.power = power;
|
||||||
|
this.cadence = cadence;
|
||||||
|
}
|
||||||
|
|
||||||
public Data(SensorDataCyclingPower power, @Nullable SensorDataCyclingCadence cadence) {
|
@NonNull
|
||||||
this.power = power;
|
@Override
|
||||||
this.cadence = cadence;
|
public String toString() {
|
||||||
|
return "Data{" +
|
||||||
|
"power=" + power +
|
||||||
|
", cadence=" + cadence +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensorDataCyclingPower getPower() {
|
|
||||||
return power;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SensorDataCyclingCadence getCadence() {
|
|
||||||
return cadence;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Data{" +
|
|
||||||
"power=" + power +
|
|
||||||
", cadence=" + cadence +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
|
|||||||
Distance overallDistance = null;
|
Distance overallDistance = null;
|
||||||
if (previous != null && previous.hasTotalDistance()) {
|
if (previous != null && previous.hasTotalDistance()) {
|
||||||
overallDistance = this.totalDistance.minus(previous.totalDistance);
|
overallDistance = this.totalDistance.minus(previous.totalDistance);
|
||||||
if (previous.hasValue() && previous.getValue().getDistance() != null) {
|
if (previous.hasValue() && previous.getValue().distance() != null) {
|
||||||
overallDistance = overallDistance.plus(previous.getValue().getDistance());
|
overallDistance = overallDistance.plus(previous.getValue().distance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,41 +84,6 @@ public final class SensorDataRunning extends SensorData<SensorDataRunning.Data>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Data {
|
public record Data(Speed speed, Cadence cadence, @Nullable Distance distance) {}
|
||||||
private final Speed speed;
|
|
||||||
private final Cadence cadence;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final Distance distance;
|
|
||||||
|
|
||||||
public Data(Speed speed, Cadence cadence, @Nullable Distance distance) {
|
|
||||||
this.speed = speed;
|
|
||||||
this.cadence = cadence;
|
|
||||||
this.distance = distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Speed getSpeed() {
|
|
||||||
return speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Cadence getCadence() {
|
|
||||||
return cadence;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Distance getDistance() {
|
|
||||||
return distance;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Data{" +
|
|
||||||
"speed=" + speed +
|
|
||||||
", cadence=" + cadence +
|
|
||||||
", distance=" + distance +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public final class SensorDataSet {
|
|||||||
return new Pair<>(cyclingDistanceSpeed.getValue().getSpeed(), cyclingDistanceSpeed.getSensorNameOrAddress());
|
return new Pair<>(cyclingDistanceSpeed.getValue().getSpeed(), cyclingDistanceSpeed.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().getSpeed() != null) {
|
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue() && runningDistanceSpeedCadence.getValue().speed() != null) {
|
||||||
return new Pair<>(runningDistanceSpeedCadence.getSpeed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
|
return new Pair<>(runningDistanceSpeedCadence.getSpeed(), runningDistanceSpeedCadence.getSensorNameOrAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) {
|
if (runningDistanceSpeedCadence != null && runningDistanceSpeedCadence.hasValue()) {
|
||||||
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue().getDistance());
|
trackPoint.setSensorDistance(runningDistanceSpeedCadence.getValue().distance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,26 +9,10 @@ import de.dennisguse.opentracks.data.models.TrackPoint;
|
|||||||
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
|
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
|
||||||
import de.dennisguse.opentracks.stats.TrackStatistics;
|
import de.dennisguse.opentracks.stats.TrackStatistics;
|
||||||
|
|
||||||
public class RecordingData {
|
/**
|
||||||
|
* {@link Track} and {@link TrackPoint} must be immutable (i.e., their content does not change).
|
||||||
private final Track track;
|
*/
|
||||||
|
public record RecordingData(Track track, TrackPoint latestTrackPoint, SensorDataSet sensorDataSet) {
|
||||||
private final TrackPoint latestTrackPoint;
|
|
||||||
|
|
||||||
private final SensorDataSet sensorDataSet;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Track} and {@link TrackPoint} must be immutable (i.e., their content does not change).
|
|
||||||
*/
|
|
||||||
public RecordingData(Track track, TrackPoint lastTrackPoint, SensorDataSet sensorDataSet) {
|
|
||||||
this.track = track;
|
|
||||||
this.latestTrackPoint = lastTrackPoint;
|
|
||||||
this.sensorDataSet = sensorDataSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Track getTrack() {
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTrackCategory() {
|
public String getTrackCategory() {
|
||||||
if (track == null) {
|
if (track == null) {
|
||||||
@@ -45,35 +29,4 @@ public class RecordingData {
|
|||||||
|
|
||||||
return track.getTrackStatistics();
|
return track.getTrackStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackPoint getLatestTrackPoint() {
|
|
||||||
return latestTrackPoint;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SensorDataSet getSensorDataSet() {
|
|
||||||
return sensorDataSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
RecordingData that = (RecordingData) o;
|
|
||||||
return Objects.equals(track, that.track) && Objects.equals(latestTrackPoint, that.latestTrackPoint) && Objects.equals(sensorDataSet, that.sensorDataSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(track, latestTrackPoint, sensorDataSet);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "RecordingData{" +
|
|
||||||
"track=" + track +
|
|
||||||
", latestTrackPoint=" + latestTrackPoint +
|
|
||||||
", sensorDataSet=" + sensorDataSet +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.data.models.Track;
|
import de.dennisguse.opentracks.data.models.Track;
|
||||||
|
|
||||||
public class RecordingStatus {
|
public record RecordingStatus(Track.Id trackId) {
|
||||||
private final Track.Id trackId;
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
RecordingStatus(Track.Id trackId) {
|
|
||||||
this.trackId = trackId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Track.Id getTrackId() {
|
public Track.Id getTrackId() {
|
||||||
return trackId;
|
return trackId;
|
||||||
@@ -34,25 +28,4 @@ public class RecordingStatus {
|
|||||||
public RecordingStatus stop() {
|
public RecordingStatus stop() {
|
||||||
return TrackRecordingService.STATUS_DEFAULT;
|
return TrackRecordingService.STATUS_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "RecordingStatus{" +
|
|
||||||
"trackId=" + trackId +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
RecordingStatus that = (RecordingStatus) o;
|
|
||||||
return Objects.equals(trackId, that.trackId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(trackId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -134,7 +134,7 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {
|
|||||||
final Bundle b = new Bundle(1);
|
final Bundle b = new Bundle(1);
|
||||||
b.putString(ARG_KEY, preferenceKey);
|
b.putString(ARG_KEY, preferenceKey);
|
||||||
b.putParcelableArrayList(ARG_BLE_SERVICE_UUIDS, new ArrayList<>(sensorUUIDs.stream()
|
b.putParcelableArrayList(ARG_BLE_SERVICE_UUIDS, new ArrayList<>(sensorUUIDs.stream()
|
||||||
.map(ServiceMeasurementUUID::getServiceUUID)
|
.map(ServiceMeasurementUUID::serviceUUID)
|
||||||
.map(ParcelUuid::new)
|
.map(ParcelUuid::new)
|
||||||
.collect(Collectors.toList())));
|
.collect(Collectors.toList())));
|
||||||
fragment.setArguments(b);
|
fragment.setArguments(b);
|
||||||
|
|||||||
@@ -90,11 +90,11 @@ public class ShareUtils {
|
|||||||
for (Marker.Id markerId : markerIds) {
|
for (Marker.Id markerId : markerIds) {
|
||||||
Marker marker = contentProviderUtils.getMarker(markerId);
|
Marker marker = contentProviderUtils.getMarker(markerId);
|
||||||
if (marker == null) {
|
if (marker == null) {
|
||||||
Log.e(TAG, "MarkerId " + markerId.getId() + " could not be resolved.");
|
Log.e(TAG, "MarkerId " + markerId.id() + " could not be resolved.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (marker.getPhotoURI() == null) {
|
if (marker.getPhotoURI() == null) {
|
||||||
Log.e(TAG, "MarkerId " + markerId.getId() + " has no picture.");
|
Log.e(TAG, "MarkerId " + markerId.id() + " has no picture.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
|
|
||||||
if (itemId == R.id.list_context_menu_edit) {
|
if (itemId == R.id.list_context_menu_edit) {
|
||||||
if (markerIds.length == 1) {
|
if (markerIds.length == 1) {
|
||||||
resourceCursorAdapter.markerInvalid(markerIds[0].getId());
|
resourceCursorAdapter.markerInvalid(markerIds[0].id());
|
||||||
Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
||||||
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerIds[0]);
|
.putExtra(MarkerEditActivity.EXTRA_MARKER_ID, markerIds[0]);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import androidx.annotation.VisibleForTesting;
|
|||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.data.models.Altitude;
|
import de.dennisguse.opentracks.data.models.Altitude;
|
||||||
@@ -144,42 +143,14 @@ public class EGM2008Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static class Indices {
|
record Indices(int latitudeIndex, int longitudeIndex) {
|
||||||
final int latitudeIndex;
|
|
||||||
final int longitudeIndex;
|
|
||||||
|
|
||||||
Indices(int latitudeIndex, int longitudeIndex) {
|
|
||||||
this.latitudeIndex = latitudeIndex;
|
|
||||||
this.longitudeIndex = longitudeIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
Indices offset(int latitudeOffset, int longitudeOffset) {
|
Indices offset(int latitudeOffset, int longitudeOffset) {
|
||||||
return new Indices(latitudeIndex + latitudeOffset, longitudeIndex + longitudeOffset);
|
return new Indices(latitudeIndex + latitudeOffset, longitudeIndex + longitudeOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getAbsoluteIndex() {
|
int getAbsoluteIndex() {
|
||||||
return latitudeIndex * LATITUDE_CORRECTION + longitudeIndex;
|
return latitudeIndex * LATITUDE_CORRECTION + longitudeIndex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
Indices indices = (Indices) o;
|
|
||||||
return latitudeIndex == indices.latitudeIndex &&
|
|
||||||
longitudeIndex == indices.longitudeIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(latitudeIndex, longitudeIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Indices{" +
|
|
||||||
"latitudeIndex=" + latitudeIndex +
|
|
||||||
", longitudeIndex=" + longitudeIndex +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,8 +82,8 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
|
|||||||
|
|
||||||
Pair<String, String> valueAndUnit;
|
Pair<String, String> valueAndUnit;
|
||||||
|
|
||||||
SensorDataSet sensorDataSet = data.getSensorDataSet();
|
SensorDataSet sensorDataSet = data.sensorDataSet();
|
||||||
final TrackPoint latestTrackPoint = data.getLatestTrackPoint();
|
final TrackPoint latestTrackPoint = data.latestTrackPoint();
|
||||||
if (sensorDataSet != null && sensorDataSet.getSpeed() != null) {
|
if (sensorDataSet != null && sensorDataSet.getSpeed() != null) {
|
||||||
valueAndUnit = localSpeedFormatter.getSpeedParts(sensorDataSet.getSpeed().first);
|
valueAndUnit = localSpeedFormatter.getSpeedParts(sensorDataSet.getSpeed().first);
|
||||||
getBinding().statsDescriptionMain.setText(sensorDataSet.getSpeed().second);
|
getBinding().statsDescriptionMain.setText(sensorDataSet.getSpeed().second);
|
||||||
@@ -220,7 +220,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
||||||
TrackPoint latestTrackPoint = data.getLatestTrackPoint();
|
TrackPoint latestTrackPoint = data.latestTrackPoint();
|
||||||
Float altitude = latestTrackPoint != null && latestTrackPoint.hasAltitude() ? (float) latestTrackPoint.getAltitude().toM() : null;
|
Float altitude = latestTrackPoint != null && latestTrackPoint.hasAltitude() ? (float) latestTrackPoint.getAltitude().toM() : null;
|
||||||
String altitudeReference = latestTrackPoint != null && latestTrackPoint.hasAltitude() ? getContext().getString(latestTrackPoint.getAltitude().getLabelId()) : null;
|
String altitudeReference = latestTrackPoint != null && latestTrackPoint.hasAltitude() ? getContext().getString(latestTrackPoint.getAltitude().getLabelId()) : null;
|
||||||
Pair<String, String> valueAndUnit = StringUtils.getAltitudeParts(getContext(), altitude, unitSystem);
|
Pair<String, String> valueAndUnit = StringUtils.getAltitudeParts(getContext(), altitude, unitSystem);
|
||||||
@@ -262,7 +262,7 @@ public abstract class GenericStatisticsViewHolder extends StatisticViewHolder<St
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
||||||
TrackPoint latestTrackPoint = data.getLatestTrackPoint();
|
TrackPoint latestTrackPoint = data.latestTrackPoint();
|
||||||
String value;
|
String value;
|
||||||
if (latestTrackPoint != null && latestTrackPoint.hasLocation()) {
|
if (latestTrackPoint != null && latestTrackPoint.hasLocation()) {
|
||||||
value = StringUtils.formatCoordinate(getContext(), latestTrackPoint.getLatitude(), latestTrackPoint.getLongitude());
|
value = StringUtils.formatCoordinate(getContext(), latestTrackPoint.getLatitude(), latestTrackPoint.getLongitude());
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public abstract class SensorStatisticsViewHolder extends StatisticViewHolder<Sta
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
||||||
SensorDataSet sensorDataSet = data.getSensorDataSet();
|
SensorDataSet sensorDataSet = data.sensorDataSet();
|
||||||
String sensorName = getContext().getString(R.string.value_unknown);
|
String sensorName = getContext().getString(R.string.value_unknown);
|
||||||
|
|
||||||
Pair<String, String> valueAndUnit;
|
Pair<String, String> valueAndUnit;
|
||||||
@@ -64,7 +64,7 @@ public abstract class SensorStatisticsViewHolder extends StatisticViewHolder<Sta
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
||||||
SensorDataSet sensorDataSet = data.getSensorDataSet();
|
SensorDataSet sensorDataSet = data.sensorDataSet();
|
||||||
String sensorName = getContext().getString(R.string.value_unknown);
|
String sensorName = getContext().getString(R.string.value_unknown);
|
||||||
|
|
||||||
Pair<String, String> valueAndUnit;
|
Pair<String, String> valueAndUnit;
|
||||||
@@ -87,7 +87,7 @@ public abstract class SensorStatisticsViewHolder extends StatisticViewHolder<Sta
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
public void onChanged(UnitSystem unitSystem, RecordingData data) {
|
||||||
SensorDataSet sensorDataSet = data.getSensorDataSet();
|
SensorDataSet sensorDataSet = data.sensorDataSet();
|
||||||
String sensorName = getContext().getString(R.string.value_unknown);
|
String sensorName = getContext().getString(R.string.value_unknown);
|
||||||
|
|
||||||
Pair<String, String> valueAndUnit;
|
Pair<String, String> valueAndUnit;
|
||||||
|
|||||||
Reference in New Issue
Block a user