From ac71d8aa2af94abf140b1de74767d0b5f685d943 Mon Sep 17 00:00:00 2001 From: Dominik R?ttsches Date: Fri, 19 Aug 2011 23:01:55 +0300 Subject: [PATCH] Fixing TCX generation: - Cadence before Extensions - Adding BuildMajor and BuildMinor to Version since it seems to be required by http://connect.garmin.com - Version Values now only contain integers by splitting mytracks version code at dots, allows correct XML validation. --- .../apps/mytracks/io/file/TcxTrackWriter.java | 55 ++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/file/TcxTrackWriter.java b/MyTracks/src/com/google/android/apps/mytracks/io/file/TcxTrackWriter.java index cde67ce57..691318334 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/file/TcxTrackWriter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/file/TcxTrackWriter.java @@ -174,6 +174,14 @@ public class TcxTrackWriter implements TrackFormatWriter { pw.print(""); pw.println(""); } + // TCX Trackpoint_t contains a sequence, needs to be put before + if (sensorData.hasCadence() + && sensorData.getCadence().getState() == Sensor.SensorState.SENDING + && sensorData.getCadence().hasValue()) { + pw.print(" "); + pw.print(Math.min(254, sensorData.getCadence().getValue())); + pw.println(""); + } if (sensorData.hasPower() && sensorData.getPower().getState() == Sensor.SensorState.SENDING && sensorData.getPower().hasValue()) { @@ -184,13 +192,6 @@ public class TcxTrackWriter implements TrackFormatWriter { pw.print(""); pw.println(""); } - if (sensorData.hasCadence() - && sensorData.getCadence().getState() == Sensor.SensorState.SENDING - && sensorData.getCadence().hasValue()) { - pw.print(" "); - pw.print(Math.min(254, sensorData.getCadence().getValue())); - pw.println(""); - } } } pw.println(" "); @@ -216,11 +217,9 @@ public class TcxTrackWriter implements TrackFormatWriter { // TCX schema. pw.println("0"); pw.println("0"); + + writeVersion(); - pw.println(""); - pw.println("0"); - pw.println("0"); - pw.println(""); pw.println(""); pw.println(" "); pw.println(" "); @@ -241,15 +240,7 @@ public class TcxTrackWriter implements TrackFormatWriter { pw.println(""); - // The TCX spec for the Version tag is too strict to allow us to use our - // user-visible version number, so we use our version code instead. We - // also set the minor version to 1 if this is a development build to - // signify that this build is newer than the one associated with the - // version code given in VersionMajor. - pw.println(""); - pw.format("%s\n", SystemUtils.getMyTracksVersion(context)); - pw.format("%d\n", SystemUtils.isRelease(context) ? 0 : 1); - pw.println(""); + writeVersion(); pw.format("%s\n", SystemUtils.isRelease(context) ? TCX_TYPE_RELEASE : TCX_TYPE_INTERNAL); @@ -264,6 +255,30 @@ public class TcxTrackWriter implements TrackFormatWriter { public void writeWaypoint(Waypoint waypoint) { // TODO Write out the waypoints somewhere. } + + private void writeVersion() { + if (pw == null) { + return; + } + + // Splitting the myTracks version code into VersionMajor, VersionMinor and BuildMajor + // to fit the integer type requirement for these fields in the TCX spec. + // Putting a string like "x.x.x" into VersionMajor breaks XML validation. + // We also set the BuildMinor version to 1 if this is a development build to + // signify that this build is newer than the one associated with the + // version code given in BuildMajor. + + String[] myTracksVersionComponents = SystemUtils.getMyTracksVersion(context).split("\\."); + + pw.println(""); + pw.format("%d\n", Integer.valueOf(myTracksVersionComponents[0])); + pw.format("%d\n", Integer.valueOf(myTracksVersionComponents[1])); + // TCX schema says these are optional but http://connect.garmin.com only accepts + // the TCX file when they are present. + pw.format("%d\n", Integer.valueOf(myTracksVersionComponents[2])); + pw.format("%d\n", SystemUtils.isRelease(context) ? 0 : 1); + pw.println(""); + } private String categoryToTcxSport(String category) { category = category.trim();