diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/TcxTrackWriter.java b/MyTracks/src/com/google/android/apps/mytracks/io/TcxTrackWriter.java index 1140dba89..ef7931896 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/TcxTrackWriter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/TcxTrackWriter.java @@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.content.Waypoint; import com.google.android.apps.mytracks.io.TrackWriterFactory.TrackFileFormat; import com.google.android.apps.mytracks.util.MyTracksUtils; +import android.content.Context; import android.location.Location; import android.os.Build; @@ -58,11 +59,14 @@ public class TcxTrackWriter implements TrackFormatWriter { private static final String TCX_TYPE_INTERNAL = "Internal"; private final SimpleDateFormat timestampFormatter; + private final Context context; private PrintWriter pw = null; private Track track; - public TcxTrackWriter() { + public TcxTrackWriter(Context context) { + this.context = context; + timestampFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT); timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); } @@ -232,14 +236,14 @@ public class TcxTrackWriter implements TrackFormatWriter { // it. The TCX schema tightly defined the Version tag, so we can't put it // there. They've similarly constrained the PartNumber tag, so it can't go // there either. - pw.format("My Tracks %s by Google\n", MyTracksUtils.getMyTracksVersion()); + pw.format("My Tracks %s by Google\n", MyTracksUtils.getMyTracksVersion(context)); pw.println(""); pw.println(""); - pw.format("%d\n", MyTracksUtils.getMyTracksVersionCode()); + pw.format("%d\n", MyTracksUtils.getMyTracksVersionCode(context)); pw.println("0"); pw.println(""); - pw.format("%s\n", MyTracksUtils.isRelease() ? TCX_TYPE_RELEASE + pw.format("%s\n", MyTracksUtils.isRelease(context) ? TCX_TYPE_RELEASE : TCX_TYPE_INTERNAL); pw.println(""); pw.format("%s\n", Locale.getDefault().getLanguage()); @@ -254,6 +258,7 @@ public class TcxTrackWriter implements TrackFormatWriter { } private String categoryToTcxSport(String category) { + category = category.trim(); if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) { return TCX_SPORT_RUNNING; } else if (category.equalsIgnoreCase(TCX_SPORT_BIKING)) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/TrackWriterFactory.java b/MyTracks/src/com/google/android/apps/mytracks/io/TrackWriterFactory.java index 55261f8a5..785454b0b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/TrackWriterFactory.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/TrackWriterFactory.java @@ -1,12 +1,12 @@ /* * Copyright 2010 Google Inc. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -53,7 +53,7 @@ public class TrackWriterFactory { TCX { @Override public TrackFormatWriter newFormatWriter(Context context) { - return new TcxTrackWriter(); + return new TcxTrackWriter(context); } }; diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/MyTracksUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/MyTracksUtils.java index 1170726be..8e1c6e22b 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/MyTracksUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/MyTracksUtils.java @@ -15,7 +15,6 @@ */ package com.google.android.apps.mytracks.util; -import com.google.android.apps.mytracks.MyTracks; import com.google.android.apps.mytracks.MyTracksConstants; import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.stats.TripStatistics; @@ -264,7 +263,7 @@ public class MyTracksUtils { return false; } - for (Signature sig: packageInfo.signatures) { + for (Signature sig : packageInfo.signatures) { if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) { return true; } @@ -273,13 +272,6 @@ public class MyTracksUtils { return false; } - /** - * @see isRelease(Context) - */ - public static boolean isRelease() { - return isRelease(MyTracks.getInstance()); - } - /** * Get the My Tracks version from the manifest. * @@ -290,27 +282,19 @@ public class MyTracksUtils { return packageInfo == null ? "" : packageInfo.versionName; } - /** - * @see getMyTracksVersion(Context) - */ - public static String getMyTracksVersion() { - return getMyTracksVersion(MyTracks.getInstance()); - } - /** * Return the My Tracks version code from the manifest. * * @return the version code, or an empty string in case of failure. */ - public static int getMyTracksVersionCode() { - PackageInfo packageInfo = getPackageInfo(MyTracks.getInstance(), - PackageManager.GET_META_DATA); + public static int getMyTracksVersionCode(Context context) { + PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_META_DATA); return packageInfo == null ? -1 : packageInfo.versionCode; } private static PackageInfo getPackageInfo(Context context, int flags) { if (context == null) { - Log.w(MyTracksConstants.TAG, "No context found when attempting to get version"); + Log.w(MyTracksConstants.TAG, "No context found when attempting to get PackageInfo"); return null; } try { diff --git a/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java b/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java index aacdf1146..874b7ebfa 100644 --- a/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java +++ b/MyTracksTest/src/com/google/android/apps/mytracks/io/TcxTrackWriterTest.java @@ -29,7 +29,7 @@ public class TcxTrackWriterTest extends TrackFormatWriterTest { } public void testXmlOutput() throws Exception { - TrackFormatWriter writer = new TcxTrackWriter(); + TrackFormatWriter writer = new TcxTrackWriter(null); String result = writeTrack(writer); Document doc = parseXmlDocument(result);