forked from upstream-mirrors/OpenTracks
Elevation gain: make it optional as Float.
So if no sensor data is provided, it is not stored in the database and not exported.
This commit is contained in:
+16
@@ -24,6 +24,9 @@ public class ElevationSumManagerTest {
|
||||
|
||||
@Test
|
||||
public void getElevationGainLoss_downhill() {
|
||||
// given
|
||||
elevationSumManager.setConnected(true);
|
||||
|
||||
// then
|
||||
addSensorValue(elevationSumManager, new float[]{1015f, 1015.01f, 1015.02f, 1015.03f, 1015.04f, 1015.05f, 1015.06f, 1015.07f, 1015.08f, 1015.09f, 1015.10f, 1015.11f, 1015.12f, 1015.13f, 1015.14f, 1015.15f});
|
||||
|
||||
@@ -31,4 +34,17 @@ public class ElevationSumManagerTest {
|
||||
Assert.assertEquals(0f, elevationSumManager.getElevationGain_m(), 0.01);
|
||||
Assert.assertEquals(-48.0, elevationSumManager.getElevationLoss_m(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensorUnavailable() {
|
||||
// given
|
||||
elevationSumManager.setConnected(false);
|
||||
|
||||
// then
|
||||
elevationSumManager.onSensorValueChanged(999f);
|
||||
|
||||
// then
|
||||
Assert.assertNull(elevationSumManager.getElevationGain_m());
|
||||
Assert.assertNull(elevationSumManager.getElevationLoss_m());
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class TrackPoint {
|
||||
private Float heartRate_bpm = null;
|
||||
private Float cyclingCadence_rpm = null;
|
||||
private Float power = null;
|
||||
private float elevationGain = Float.NaN;
|
||||
private Float elevationGain = null;
|
||||
|
||||
public TrackPoint() {
|
||||
this.location = new Location("");
|
||||
@@ -94,14 +94,14 @@ public class TrackPoint {
|
||||
}
|
||||
|
||||
public boolean hasElevationGain() {
|
||||
return !Float.isNaN(elevationGain);
|
||||
return elevationGain != null;
|
||||
}
|
||||
|
||||
public float getElevationGain() {
|
||||
return elevationGain;
|
||||
}
|
||||
|
||||
public void setElevationGain(float elevationGain) {
|
||||
public void setElevationGain(Float elevationGain) {
|
||||
this.elevationGain = elevationGain;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import de.dennisguse.opentracks.util.PressureSensorUtils;
|
||||
@@ -37,9 +38,10 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
if (pressureSensor == null) {
|
||||
Log.w(TAG, "No pressure sensor available.");
|
||||
isConnected = false;
|
||||
} else {
|
||||
isConnected = sensorManager.registerListener(this, pressureSensor, SAMPLING_RATE);
|
||||
}
|
||||
|
||||
isConnected = sensorManager.registerListener(this, pressureSensor, SAMPLING_RATE);
|
||||
lastAcceptedPressureValue_hPa = Float.NaN;
|
||||
reset();
|
||||
}
|
||||
@@ -58,12 +60,19 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
return isConnected;
|
||||
}
|
||||
|
||||
public float getElevationGain_m() {
|
||||
return elevationGain_m;
|
||||
@VisibleForTesting
|
||||
public void setConnected(boolean isConnected) {
|
||||
this.isConnected = isConnected;
|
||||
}
|
||||
|
||||
public float getElevationLoss_m() {
|
||||
return elevationLoss_m;
|
||||
public @Nullable
|
||||
Float getElevationGain_m() {
|
||||
return isConnected ? elevationGain_m : null;
|
||||
}
|
||||
|
||||
public @Nullable
|
||||
Float getElevationLoss_m() {
|
||||
return isConnected ? elevationLoss_m : null;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
@@ -79,6 +88,10 @@ public class ElevationSumManager implements SensorEventListener {
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
if (!isConnected) {
|
||||
Log.w(TAG, "Not connected to sensor, cannot process data.");
|
||||
return;
|
||||
}
|
||||
onSensorValueChanged(event.values[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<bool name="stats_show_coordinate_default" translatable="false">false</bool>
|
||||
|
||||
<string name="stats_show_grade_elevation_key" translatable="false">statsShowGradeElevation</string>
|
||||
<bool name="stats_show_elevation_default" translatable="false">false</bool>
|
||||
<bool name="stats_show_elevation_default" translatable="false">true</bool>
|
||||
|
||||
<string name="stats_show_on_lockscreen_while_recording_key" translatable="false">trackdetail_show_on_lockscreen_while_recording</string>
|
||||
<bool name="stats_show_on_lockscreen_while_recording_default" translatable="false">false</bool>
|
||||
|
||||
Reference in New Issue
Block a user