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 d1d797950..9a76ed653 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 @@ -21,6 +21,7 @@ import com.google.android.apps.mytracks.content.Sensor.SensorDataSet; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat; +import com.google.android.apps.mytracks.lib.R; import com.google.android.apps.mytracks.util.FileUtils; import com.google.android.apps.mytracks.util.SystemUtils; @@ -47,6 +48,25 @@ import java.util.Locale; */ public class TcxTrackWriter implements TrackFormatWriter { + // "Biking" related string IDs + private static final int TCX_SPORT_BIKING_IDS[] = { + R.string.activity_type_cycling, + R.string.activity_type_dirt_bike, + R.string.activity_type_mountain_biking, + R.string.activity_type_road_biking, + R.string.activity_type_track_cycling, + }; + + // "Running" related string IDs + private static final int TCX_SPORT_RUNNING_IDS[] = { + R.string.activity_type_running, + R.string.activity_type_speed_walking, + R.string.activity_type_street_running, + R.string.activity_type_track_running, + R.string.activity_type_trail_running, + R.string.activity_type_walking, + }; + // These are the only sports allowed by the TCX v2 specification for fields // of type Sport_t. private static final String TCX_SPORT_BIKING = "Biking"; @@ -172,7 +192,7 @@ public class TcxTrackWriter implements TrackFormatWriter { pw.print(""); pw.println(""); } - + boolean cadenceAvailable = sensorData.hasCadence() && sensorData.getCadence().getState() == Sensor.SensorState.SENDING && sensorData.getCadence().hasValue(); @@ -191,7 +211,7 @@ public class TcxTrackWriter implements TrackFormatWriter { boolean powerAvailable = sensorData.hasPower() && sensorData.getPower().getState() == Sensor.SensorState.SENDING && sensorData.getPower().hasValue(); - + if(powerAvailable || (!sportIsCycling && cadenceAvailable)) { pw.print(" "); pw.print(""); @@ -203,7 +223,7 @@ public class TcxTrackWriter implements TrackFormatWriter { pw.print(Math.min(254, sensorData.getCadence().getValue())); pw.print(""); } - + if (powerAvailable) { pw.print(""); pw.print(sensorData.getPower().getValue()); @@ -237,7 +257,7 @@ public class TcxTrackWriter implements TrackFormatWriter { // TCX schema. pw.println("0"); pw.println("0"); - + writeVersion(); pw.println(""); @@ -275,25 +295,25 @@ 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. + // 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 + // 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); @@ -302,6 +322,20 @@ public class TcxTrackWriter implements TrackFormatWriter { private String categoryToTcxSport(String category) { category = category.trim(); + + // category is possibly localized here, so compare it to localized string resources + for (int i : TCX_SPORT_RUNNING_IDS) { + if (category.equalsIgnoreCase(context.getResources().getString(i))) { + return TCX_SPORT_RUNNING; + } + } + for (int i : TCX_SPORT_BIKING_IDS) { + if (category.equalsIgnoreCase(context.getResources().getString(i))) { + return TCX_SPORT_BIKING; + } + } + + // for tracks without localized activity type if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) { return TCX_SPORT_RUNNING; } else if (category.equalsIgnoreCase(TCX_SPORT_BIKING)) {