mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 13:26:50 +01:00
add UUID to to GPX with opentracks namespace
ensure that GPX has trackpoints improve GPX track name if null
This commit is contained in:
parent
894102e45a
commit
198040c935
@ -88,9 +88,11 @@ public class ActivitySummariesGpsFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gpxParser != null) {
|
if (gpxParser != null) {
|
||||||
|
if (gpxParser.getPoints().toArray().length > 0) {
|
||||||
drawTrack(canvas, gpxParser.getPoints());
|
drawTrack(canvas, gpxParser.getPoints());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
private void drawTrack(Canvas canvas, List<GPSCoordinate> trackPoints) {
|
private void drawTrack(Canvas canvas, List<GPSCoordinate> trackPoints) {
|
||||||
|
@ -19,6 +19,9 @@ package nodomain.freeyourgadget.gadgetbridge.export;
|
|||||||
|
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlSerializer;
|
import org.xmlpull.v1.XmlSerializer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -29,9 +32,8 @@ import java.math.RoundingMode;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
|
||||||
@ -45,6 +47,10 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
private static final String NS_TRACKPOINT_EXTENSION = "gpxtpx";
|
private static final String NS_TRACKPOINT_EXTENSION = "gpxtpx";
|
||||||
private static final String NS_TRACKPOINT_EXTENSION_URI = "http://www.garmin.com/xmlschemas/TrackPointExtension/v1";
|
private static final String NS_TRACKPOINT_EXTENSION_URI = "http://www.garmin.com/xmlschemas/TrackPointExtension/v1";
|
||||||
private static final String NS_XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
|
private static final String NS_XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
|
||||||
|
private static final String TOPOGRAFIX_NAMESPACE_XSD = "http://www.topografix.com/GPX/1/1/gpx.xsd";
|
||||||
|
private static final String OPENTRACKS_PREFIX = "opentracks";
|
||||||
|
private static final String OPENTRACKS_NAMESPACE_URI = "http://opentracksapp.com/xmlschemas/v1";
|
||||||
|
private static final String OPENTRACKS_NAMESPACE_XSD = "http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd";
|
||||||
|
|
||||||
private String creator;
|
private String creator;
|
||||||
private boolean includeHeartRate = true;
|
private boolean includeHeartRate = true;
|
||||||
@ -66,11 +72,14 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
ser.setPrefix("xsi", NS_XSI_URI);
|
ser.setPrefix("xsi", NS_XSI_URI);
|
||||||
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
ser.setPrefix(NS_TRACKPOINT_EXTENSION, NS_TRACKPOINT_EXTENSION_URI);
|
||||||
ser.setPrefix(NS_GPX_PREFIX, NS_GPX_URI);
|
ser.setPrefix(NS_GPX_PREFIX, NS_GPX_URI);
|
||||||
|
ser.setPrefix(OPENTRACKS_PREFIX, OPENTRACKS_NAMESPACE_URI);
|
||||||
|
|
||||||
ser.startTag(NS_GPX_URI, "gpx");
|
ser.startTag(NS_GPX_URI, "gpx");
|
||||||
ser.attribute(null, "version", "1.1");
|
ser.attribute(null, "version", "1.1");
|
||||||
ser.attribute(null, "creator", getCreator());
|
ser.attribute(null, "creator", getCreator());
|
||||||
ser.attribute(NS_XSI_URI, "schemaLocation", NS_GPX_URI + " " + "http://www.topografix.com/GPX/1/1/gpx.xsd");
|
ser.attribute(NS_XSI_URI, "schemaLocation", NS_GPX_URI + " "
|
||||||
|
+ TOPOGRAFIX_NAMESPACE_XSD + " "
|
||||||
|
+ OPENTRACKS_NAMESPACE_URI + " " + OPENTRACKS_NAMESPACE_XSD);
|
||||||
|
|
||||||
exportMetadata(ser, track);
|
exportMetadata(ser, track);
|
||||||
exportTrack(ser, track);
|
exportTrack(ser, track);
|
||||||
@ -99,7 +108,12 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException, GPXTrackEmptyException {
|
private void exportTrack(XmlSerializer ser, ActivityTrack track) throws IOException, GPXTrackEmptyException {
|
||||||
|
String uuid = UUID.randomUUID().toString();
|
||||||
ser.startTag(NS_GPX_URI, "trk");
|
ser.startTag(NS_GPX_URI, "trk");
|
||||||
|
ser.startTag(NS_GPX_URI, "extensions");
|
||||||
|
ser.startTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid").text(uuid).endTag(NS_GPX_URI, OPENTRACKS_PREFIX + ":trackid");
|
||||||
|
ser.endTag(NS_GPX_URI, "extensions");
|
||||||
|
|
||||||
ser.startTag(NS_GPX_URI, "trkseg");
|
ser.startTag(NS_GPX_URI, "trkseg");
|
||||||
|
|
||||||
List<ActivityPoint> trackPoints = track.getTrackPoints();
|
List<ActivityPoint> trackPoints = track.getTrackPoints();
|
||||||
|
@ -70,7 +70,7 @@ public class HuamiActivityDetailsParser {
|
|||||||
this.activityTrack = new ActivityTrack();
|
this.activityTrack = new ActivityTrack();
|
||||||
activityTrack.setUser(summary.getUser());
|
activityTrack.setUser(summary.getUser());
|
||||||
activityTrack.setDevice(summary.getDevice());
|
activityTrack.setDevice(summary.getDevice());
|
||||||
activityTrack.setName(summary.getName() + "-" + summary.getId());
|
activityTrack.setName(createActivityName(summary));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActivityTrack parse(byte[] bytes) throws GBException {
|
public ActivityTrack parse(byte[] bytes) throws GBException {
|
||||||
@ -295,4 +295,14 @@ public class HuamiActivityDetailsParser {
|
|||||||
LOG.debug("got packet type 8 (swimming?): " + GB.hexdump(bytes, offset, 6));
|
LOG.debug("got packet type 8 (swimming?): " + GB.hexdump(bytes, offset, 6));
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String createActivityName(BaseActivitySummary summary) {
|
||||||
|
String name = summary.getName();
|
||||||
|
String nameText = "";
|
||||||
|
Long id = summary.getId();
|
||||||
|
if (name != null) {
|
||||||
|
nameText = name + " - ";
|
||||||
|
}
|
||||||
|
return nameText + id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
import org.xmlpull.v1.XmlPullParser;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
import org.xmlpull.v1.XmlPullParserFactory;
|
import org.xmlpull.v1.XmlPullParserFactory;
|
||||||
@ -28,8 +30,9 @@ import java.util.List;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
|
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
|
||||||
|
|
||||||
public class GpxParser {
|
public class GpxParser {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(GpxParser.class);
|
||||||
private XmlPullParser parser;
|
private XmlPullParser parser;
|
||||||
private List<GPSCoordinate> points;
|
private List<GPSCoordinate> points = new ArrayList<>();
|
||||||
private int eventType;
|
private int eventType;
|
||||||
|
|
||||||
public GpxParser(InputStream stream) {
|
public GpxParser(InputStream stream) {
|
||||||
@ -52,13 +55,15 @@ public class GpxParser {
|
|||||||
|
|
||||||
private void parseGpx() throws XmlPullParserException, IOException {
|
private void parseGpx() throws XmlPullParserException, IOException {
|
||||||
eventType = parser.getEventType();
|
eventType = parser.getEventType();
|
||||||
|
|
||||||
while (eventType != XmlPullParser.END_DOCUMENT) {
|
while (eventType != XmlPullParser.END_DOCUMENT) {
|
||||||
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("trkpt"))
|
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("trkpt")) {
|
||||||
points.add(parsePoint(parser));
|
points.add(parsePoint(parser));
|
||||||
else
|
} else {
|
||||||
eventType = parser.next();
|
eventType = parser.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private double parseElevation(XmlPullParser parser) throws XmlPullParserException, IOException {
|
private double parseElevation(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||||
String eleString = "";
|
String eleString = "";
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="Gadgetbridge Test" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:opentracks="http://opentracksapp.com/xmlschemas/v1" version="1.1" creator="Gadgetbridge Test" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://opentracksapp.com/xmlschemas/v1 http://opentracksapp.com/xmlschemas/OpenTracks_v1.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<name>Test Track</name>
|
<name>Test Track</name>
|
||||||
<author>
|
<author>
|
||||||
<name>Test User</name>
|
<name>Test User</name>
|
||||||
</author>
|
</author>
|
||||||
<time>2020-10-25T14:44:45+01:00</time>
|
<time>2021-01-16T23:27:34+01:00</time>
|
||||||
</metadata>
|
</metadata>
|
||||||
<trk>
|
<trk>
|
||||||
|
<extensions>
|
||||||
|
<opentracks:trackid>0555e104-e8ea-4e10-b3e9-8b58abae257f</opentracks:trackid>
|
||||||
|
</extensions>
|
||||||
<trkseg>
|
<trkseg>
|
||||||
<trkpt lon="-68.200293" lat="44.152462">
|
<trkpt lon="-68.200293" lat="44.152462">
|
||||||
<ele>40.000000</ele>
|
<ele>40.000000</ele>
|
||||||
|
Loading…
Reference in New Issue
Block a user