mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-04 21:12:29 +02:00
GPX export fixes (#1060)
This commit is contained in:
parent
8f6d287592
commit
1b9b5f821e
@ -31,6 +31,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
|
|
||||||
private String creator;
|
private String creator;
|
||||||
private boolean includeHeartRate = true;
|
private boolean includeHeartRate = true;
|
||||||
|
private boolean includeHeartRateByTime = true;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
@ -46,6 +47,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
ser.setOutput(new FileOutputStream(targetFile), encoding);
|
ser.setOutput(new FileOutputStream(targetFile), encoding);
|
||||||
ser.startDocument(encoding, Boolean.TRUE);
|
ser.startDocument(encoding, Boolean.TRUE);
|
||||||
ser.setPrefix("xsi", NS_XSI_URI);
|
ser.setPrefix("xsi", NS_XSI_URI);
|
||||||
|
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
||||||
ser.setPrefix(NS_DEFAULT_PREFIX, NS_DEFAULT);
|
ser.setPrefix(NS_DEFAULT_PREFIX, NS_DEFAULT);
|
||||||
|
|
||||||
ser.startTag(NS_DEFAULT, "gpx");
|
ser.startTag(NS_DEFAULT, "gpx");
|
||||||
@ -88,7 +90,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
String source = getSource(track);
|
String source = getSource(track);
|
||||||
boolean atLeastOnePointExported = false;
|
boolean atLeastOnePointExported = false;
|
||||||
for (ActivityPoint point : trackPoints) {
|
for (ActivityPoint point : trackPoints) {
|
||||||
atLeastOnePointExported = exportTrackPoint(ser, point, source) | atLeastOnePointExported ;
|
atLeastOnePointExported = exportTrackPoint(ser, point, source, trackPoints) | atLeastOnePointExported ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!atLeastOnePointExported) {
|
if(!atLeastOnePointExported) {
|
||||||
@ -103,7 +105,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
return track.getDevice().getName();
|
return track.getDevice().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source) throws IOException {
|
private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source, List<ActivityPoint> trackPoints) throws IOException {
|
||||||
GPSCoordinate location = point.getLocation();
|
GPSCoordinate location = point.getLocation();
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return false; // skip invalid points, that just contain hr data, for example
|
return false; // skip invalid points, that just contain hr data, for example
|
||||||
@ -117,29 +119,53 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
if (description != null) {
|
if (description != null) {
|
||||||
ser.startTag(NS_DEFAULT, "desc").text(description).endTag(NS_DEFAULT, "desc");
|
ser.startTag(NS_DEFAULT, "desc").text(description).endTag(NS_DEFAULT, "desc");
|
||||||
}
|
}
|
||||||
ser.startTag(NS_DEFAULT, "src").text(source).endTag(NS_DEFAULT, "src");
|
//ser.startTag(NS_DEFAULT, "src").text(source).endTag(NS_DEFAULT, "src");
|
||||||
|
|
||||||
exportTrackpointExtensions(ser, point);
|
exportTrackpointExtensions(ser, point, trackPoints);
|
||||||
|
|
||||||
ser.endTag(NS_DEFAULT, "trkpt");
|
ser.endTag(NS_DEFAULT, "trkpt");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void exportTrackpointExtensions(XmlSerializer ser, ActivityPoint point) throws IOException {
|
private void exportTrackpointExtensions(XmlSerializer ser, ActivityPoint point, List<ActivityPoint> trackPoints) throws IOException {
|
||||||
if (!includeHeartRate) {
|
if (!includeHeartRate) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hr = point.getHeartRate();
|
int hr = point.getHeartRate();
|
||||||
if (!HeartRateUtils.isValidHeartRateValue(hr)) {
|
if (!HeartRateUtils.isValidHeartRateValue(hr)) {
|
||||||
|
if(!includeHeartRateByTime) { return; }
|
||||||
|
|
||||||
|
Date time = point.getTime();
|
||||||
|
ActivityPoint closestPointItem = null;
|
||||||
|
long lowestDifference = Long.MAX_VALUE;
|
||||||
|
for (ActivityPoint pointItem : trackPoints) {
|
||||||
|
int hrItem = pointItem.getHeartRate();
|
||||||
|
if(HeartRateUtils.isValidHeartRateValue(hrItem)) {
|
||||||
|
Date timeItem = pointItem.getTime();
|
||||||
|
if (timeItem.after(time) || timeItem.equals(time)) continue;
|
||||||
|
long difference = time.getTime() - timeItem.getTime();
|
||||||
|
if (difference < lowestDifference) {
|
||||||
|
lowestDifference = difference;
|
||||||
|
closestPointItem = pointItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(closestPointItem != null) {
|
||||||
|
hr = closestPointItem.getHeartRate();
|
||||||
|
if (!HeartRateUtils.isValidHeartRateValue(hr)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ser.startTag(NS_DEFAULT, "extensions");
|
ser.startTag(NS_DEFAULT, "extensions");
|
||||||
|
|
||||||
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
||||||
|
ser.startTag(NS_TRACKPOINT_EXTENSION_URI, "TrackPointExtension");
|
||||||
ser.startTag(NS_TRACKPOINT_EXTENSION_URI, "hr").text(String.valueOf(hr)).endTag(NS_TRACKPOINT_EXTENSION_URI, "hr");
|
ser.startTag(NS_TRACKPOINT_EXTENSION_URI, "hr").text(String.valueOf(hr)).endTag(NS_TRACKPOINT_EXTENSION_URI, "hr");
|
||||||
|
ser.endTag(NS_TRACKPOINT_EXTENSION_URI, "TrackPointExtension");
|
||||||
ser.endTag(NS_DEFAULT, "extensions");
|
ser.endTag(NS_DEFAULT, "extensions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,11 +173,11 @@ public class ActivityDetailsParser {
|
|||||||
|
|
||||||
private ActivityPoint getActivityPointFor(long timeOffsetSeconds) {
|
private ActivityPoint getActivityPointFor(long timeOffsetSeconds) {
|
||||||
Date time = makeAbsolute(timeOffsetSeconds);
|
Date time = makeAbsolute(timeOffsetSeconds);
|
||||||
// if (lastActivityPoint != null) {
|
if (lastActivityPoint != null) {
|
||||||
// if (lastActivityPoint.getTime().equals(time)) {
|
if (lastActivityPoint.getTime().equals(time)) {
|
||||||
// return lastActivityPoint;
|
return lastActivityPoint;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
return new ActivityPoint(time);
|
return new ActivityPoint(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|||||||
|
|
||||||
public class DateTimeUtils {
|
public class DateTimeUtils {
|
||||||
private static SimpleDateFormat DAY_STORAGE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
private static SimpleDateFormat DAY_STORAGE_FORMAT = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||||
public static SimpleDateFormat ISO_8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssXXX", Locale.US);
|
public static SimpleDateFormat ISO_8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX", Locale.US);
|
||||||
|
|
||||||
public static String formatDateTime(Date date) {
|
public static String formatDateTime(Date date) {
|
||||||
return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_YEAR);
|
return DateUtils.formatDateTime(GBApplication.getContext(), date.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_YEAR);
|
||||||
|
Loading…
Reference in New Issue
Block a user