mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Code review comments
This commit is contained in:
@@ -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("<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("<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("</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);
|
||||
pw.println("</Build>");
|
||||
pw.format("<LangID>%s</LangID>\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)) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user