Code review comments

This commit is contained in:
Matthew Simmons
2011-03-16 15:59:21 -04:00
parent c943e5dd43
commit 79e2c55c34
4 changed files with 18 additions and 29 deletions
@@ -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.io.TrackWriterFactory.TrackFileFormat;
import com.google.android.apps.mytracks.util.MyTracksUtils; import com.google.android.apps.mytracks.util.MyTracksUtils;
import android.content.Context;
import android.location.Location; import android.location.Location;
import android.os.Build; import android.os.Build;
@@ -58,11 +59,14 @@ public class TcxTrackWriter implements TrackFormatWriter {
private static final String TCX_TYPE_INTERNAL = "Internal"; private static final String TCX_TYPE_INTERNAL = "Internal";
private final SimpleDateFormat timestampFormatter; private final SimpleDateFormat timestampFormatter;
private final Context context;
private PrintWriter pw = null; private PrintWriter pw = null;
private Track track; private Track track;
public TcxTrackWriter() { public TcxTrackWriter(Context context) {
this.context = context;
timestampFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT); timestampFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); 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 // 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. They've similarly constrained the PartNumber tag, so it can't go
// there either. // there either.
pw.format("<Name>My Tracks %s by Google</Name>\n", MyTracksUtils.getMyTracksVersion()); pw.format("<Name>My Tracks %s by Google</Name>\n", MyTracksUtils.getMyTracksVersion(context));
pw.println("<Build>"); pw.println("<Build>");
pw.println("<Version>"); pw.println("<Version>");
pw.format("<VersionMajor>%d</VersionMajor>\n", MyTracksUtils.getMyTracksVersionCode()); pw.format("<VersionMajor>%d</VersionMajor>\n", MyTracksUtils.getMyTracksVersionCode(context));
pw.println("<VersionMinor>0</VersionMinor>"); pw.println("<VersionMinor>0</VersionMinor>");
pw.println("</Version>"); pw.println("</Version>");
pw.format("<Type>%s</Type>\n", MyTracksUtils.isRelease() ? TCX_TYPE_RELEASE pw.format("<Type>%s</Type>\n", MyTracksUtils.isRelease(context) ? TCX_TYPE_RELEASE
: TCX_TYPE_INTERNAL); : TCX_TYPE_INTERNAL);
pw.println("</Build>"); pw.println("</Build>");
pw.format("<LangID>%s</LangID>\n", Locale.getDefault().getLanguage()); pw.format("<LangID>%s</LangID>\n", Locale.getDefault().getLanguage());
@@ -254,6 +258,7 @@ public class TcxTrackWriter implements TrackFormatWriter {
} }
private String categoryToTcxSport(String category) { private String categoryToTcxSport(String category) {
category = category.trim();
if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) { if (category.equalsIgnoreCase(TCX_SPORT_RUNNING)) {
return TCX_SPORT_RUNNING; return TCX_SPORT_RUNNING;
} else if (category.equalsIgnoreCase(TCX_SPORT_BIKING)) { } else if (category.equalsIgnoreCase(TCX_SPORT_BIKING)) {
@@ -1,12 +1,12 @@
/* /*
* Copyright 2010 Google Inc. * Copyright 2010 Google Inc.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * use this file except in compliance with the License. You may obtain a copy of
* the License at * the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -53,7 +53,7 @@ public class TrackWriterFactory {
TCX { TCX {
@Override @Override
public TrackFormatWriter newFormatWriter(Context context) { public TrackFormatWriter newFormatWriter(Context context) {
return new TcxTrackWriter(); return new TcxTrackWriter(context);
} }
}; };
@@ -15,7 +15,6 @@
*/ */
package com.google.android.apps.mytracks.util; 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.MyTracksConstants;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.stats.TripStatistics; import com.google.android.apps.mytracks.stats.TripStatistics;
@@ -264,7 +263,7 @@ public class MyTracksUtils {
return false; return false;
} }
for (Signature sig: packageInfo.signatures) { for (Signature sig : packageInfo.signatures) {
if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) { if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) {
return true; return true;
} }
@@ -273,13 +272,6 @@ public class MyTracksUtils {
return false; return false;
} }
/**
* @see isRelease(Context)
*/
public static boolean isRelease() {
return isRelease(MyTracks.getInstance());
}
/** /**
* Get the My Tracks version from the manifest. * Get the My Tracks version from the manifest.
* *
@@ -290,27 +282,19 @@ public class MyTracksUtils {
return packageInfo == null ? "" : packageInfo.versionName; 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 My Tracks version code from the manifest.
* *
* @return the version code, or an empty string in case of failure. * @return the version code, or an empty string in case of failure.
*/ */
public static int getMyTracksVersionCode() { public static int getMyTracksVersionCode(Context context) {
PackageInfo packageInfo = getPackageInfo(MyTracks.getInstance(), PackageInfo packageInfo = getPackageInfo(context, PackageManager.GET_META_DATA);
PackageManager.GET_META_DATA);
return packageInfo == null ? -1 : packageInfo.versionCode; return packageInfo == null ? -1 : packageInfo.versionCode;
} }
private static PackageInfo getPackageInfo(Context context, int flags) { private static PackageInfo getPackageInfo(Context context, int flags) {
if (context == null) { 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; return null;
} }
try { try {
@@ -29,7 +29,7 @@ public class TcxTrackWriterTest extends TrackFormatWriterTest {
} }
public void testXmlOutput() throws Exception { public void testXmlOutput() throws Exception {
TrackFormatWriter writer = new TcxTrackWriter(); TrackFormatWriter writer = new TcxTrackWriter(null);
String result = writeTrack(writer); String result = writeTrack(writer);
Document doc = parseXmlDocument(result); Document doc = parseXmlDocument(result);