forked from upstream-mirrors/OpenTracks
Added opentracks:gain and opentracks:loss information in GPX files. Fixes #555.
This commit is contained in:
@@ -17,6 +17,7 @@ public class TestDataUtil {
|
|||||||
public static final double INITIAL_LONGITUDE = -57.0;
|
public static final double INITIAL_LONGITUDE = -57.0;
|
||||||
public static final double ALTITUDE_INTERVAL = 2.5;
|
public static final double ALTITUDE_INTERVAL = 2.5;
|
||||||
public static final float ELEVATION_GAIN = 3;
|
public static final float ELEVATION_GAIN = 3;
|
||||||
|
public static final float ELEVATION_LOSS = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a track without any trackPoints.
|
* Create a track without any trackPoints.
|
||||||
@@ -72,6 +73,7 @@ public class TestDataUtil {
|
|||||||
trackPoint.setCyclingCadence_rpm(300f + i);
|
trackPoint.setCyclingCadence_rpm(300f + i);
|
||||||
trackPoint.setPower(400f + i);
|
trackPoint.setPower(400f + i);
|
||||||
trackPoint.setElevationGain(ELEVATION_GAIN);
|
trackPoint.setElevationGain(ELEVATION_GAIN);
|
||||||
|
trackPoint.setElevationLoss(ELEVATION_LOSS);
|
||||||
return trackPoint;
|
return trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -135,7 +135,7 @@ public class ExportImportTest {
|
|||||||
assertMarkers();
|
assertMarkers();
|
||||||
|
|
||||||
// 3. trackpoints
|
// 3. trackpoints
|
||||||
assertTrackpoints(false, false, false, false);
|
assertTrackpoints(false, false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -170,7 +170,7 @@ public class ExportImportTest {
|
|||||||
assertMarkers();
|
assertMarkers();
|
||||||
|
|
||||||
// 3. trackpoints
|
// 3. trackpoints
|
||||||
assertTrackpoints(true, true, true, true);
|
assertTrackpoints(true, true, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -263,7 +263,7 @@ public class ExportImportTest {
|
|||||||
assertMarkers();
|
assertMarkers();
|
||||||
|
|
||||||
// 3. trackpoints
|
// 3. trackpoints
|
||||||
assertTrackpoints(false, true, true, false);
|
assertTrackpoints(false, true, true, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@@ -310,7 +310,7 @@ public class ExportImportTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertTrackpoints(boolean verifyPower, boolean verifyHeartrate, boolean verifyCadence, boolean verifyElevationGain) {
|
private void assertTrackpoints(boolean verifyPower, boolean verifyHeartrate, boolean verifyCadence, boolean verifyElevationGain, boolean verifyElevationLoss) {
|
||||||
List<TrackPoint> importedTrackPoints = contentProviderUtils.getTrackPoints(importTrackId);
|
List<TrackPoint> importedTrackPoints = contentProviderUtils.getTrackPoints(importTrackId);
|
||||||
assertEquals(trackPoints.size(), importedTrackPoints.size());
|
assertEquals(trackPoints.size(), importedTrackPoints.size());
|
||||||
|
|
||||||
@@ -339,6 +339,9 @@ public class ExportImportTest {
|
|||||||
if (verifyElevationGain) {
|
if (verifyElevationGain) {
|
||||||
assertEquals(trackPoint.getElevationGain(), importedTrackPoint.getElevationGain(), 0.01);
|
assertEquals(trackPoint.getElevationGain(), importedTrackPoint.getElevationGain(), 0.01);
|
||||||
}
|
}
|
||||||
|
if (verifyElevationLoss) {
|
||||||
|
assertEquals(trackPoint.getElevationLoss(), importedTrackPoint.getElevationLoss(), 0.01);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,10 +197,9 @@ public class GpxTrackWriter implements TrackWriter {
|
|||||||
|
|
||||||
printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(trackPoint.getTime()) + "</time>");
|
printWriter.println("<time>" + StringUtils.formatDateTimeIso8601(trackPoint.getTime()) + "</time>");
|
||||||
|
|
||||||
if (trackPoint.hasSpeed() || trackPoint.hasHeartRate() || trackPoint.hasCyclingCadence()) {
|
if (trackPoint.hasSpeed() || trackPoint.hasHeartRate() || trackPoint.hasCyclingCadence() || trackPoint.hasElevationGain() || trackPoint.hasElevationLoss()) {
|
||||||
printWriter.println("<extensions><gpxtpx:TrackPointExtension>");
|
printWriter.println("<extensions><gpxtpx:TrackPointExtension>");
|
||||||
|
|
||||||
|
|
||||||
if (trackPoint.hasSpeed()) {
|
if (trackPoint.hasSpeed()) {
|
||||||
printWriter.println("<gpxtpx:speed>" + SPEED_FORMAT.format(trackPoint.getSpeed()) + "</gpxtpx:speed>");
|
printWriter.println("<gpxtpx:speed>" + SPEED_FORMAT.format(trackPoint.getSpeed()) + "</gpxtpx:speed>");
|
||||||
}
|
}
|
||||||
@@ -213,6 +212,14 @@ public class GpxTrackWriter implements TrackWriter {
|
|||||||
printWriter.println("<gpxtpx:cad>" + HEARTRATE_FORMAT.format(trackPoint.getCyclingCadence_rpm()) + "</gpxtpx:cad>");
|
printWriter.println("<gpxtpx:cad>" + HEARTRATE_FORMAT.format(trackPoint.getCyclingCadence_rpm()) + "</gpxtpx:cad>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (trackPoint.hasElevationGain()) {
|
||||||
|
printWriter.println("<opentracks:gain>" + ELEVATION_FORMAT.format(trackPoint.getElevationGain()) + "</opentracks:gain>");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trackPoint.hasElevationLoss()) {
|
||||||
|
printWriter.println("<opentracks:loss>" + ELEVATION_FORMAT.format(trackPoint.getElevationLoss()) + "</opentracks:loss>");
|
||||||
|
}
|
||||||
|
|
||||||
printWriter.println("</gpxtpx:TrackPointExtension></extensions>");
|
printWriter.println("</gpxtpx:TrackPointExtension></extensions>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+17
@@ -86,6 +86,8 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
protected String markerType;
|
protected String markerType;
|
||||||
protected String photoUrl;
|
protected String photoUrl;
|
||||||
protected String uuid;
|
protected String uuid;
|
||||||
|
protected String gain;
|
||||||
|
protected String loss;
|
||||||
|
|
||||||
// The current track data
|
// The current track data
|
||||||
private TrackData trackData;
|
private TrackData trackData;
|
||||||
@@ -467,6 +469,21 @@ abstract class AbstractFileTrackImporter extends DefaultHandler implements Track
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gain != null) {
|
||||||
|
try {
|
||||||
|
trackPoint.setElevationGain(Float.parseFloat(gain));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SAXException(createErrorMessage(String.format(Locale.US, "Unable to parse elevation gain: %s", gain)), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (loss != null) {
|
||||||
|
try {
|
||||||
|
trackPoint.setElevationLoss(Float.parseFloat(loss));
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SAXException(createErrorMessage(String.format(Locale.US, "Unable to parse elevation loss: %s", loss)), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return trackPoint;
|
return trackPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
private static final String TAG_EXTENSION_HEARTRATE = "gpxtpx:hr";
|
private static final String TAG_EXTENSION_HEARTRATE = "gpxtpx:hr";
|
||||||
private static final String TAG_EXTENSION_CADENCE = "gpxtpx:cad";
|
private static final String TAG_EXTENSION_CADENCE = "gpxtpx:cad";
|
||||||
|
|
||||||
|
private static final String TAG_EXTENSION_GAIN = "opentracks:gain";
|
||||||
|
private static final String TAG_EXTENSION_LOSS = "opentracks:loss";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@@ -151,6 +154,16 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
uuid = content.trim();
|
uuid = content.trim();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TAG_EXTENSION_GAIN:
|
||||||
|
if (content != null) {
|
||||||
|
gain = content.trim();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TAG_EXTENSION_LOSS:
|
||||||
|
if (content != null) {
|
||||||
|
loss = content.trim();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset element content
|
// Reset element content
|
||||||
@@ -176,6 +189,8 @@ public class GpxFileTrackImporter extends AbstractFileTrackImporter {
|
|||||||
altitude = null;
|
altitude = null;
|
||||||
time = null;
|
time = null;
|
||||||
speed = null;
|
speed = null;
|
||||||
|
gain = null;
|
||||||
|
loss = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user