forked from upstream-mirrors/OpenTracks
Localize dates. Use DateFormat.getDateInstance for
user visible dates.
This commit is contained in:
@@ -32,7 +32,7 @@ import android.os.RemoteException;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@@ -44,8 +44,7 @@ import java.util.TimerTask;
|
|||||||
*/
|
*/
|
||||||
public class SensorStateActivity extends Activity {
|
public class SensorStateActivity extends Activity {
|
||||||
|
|
||||||
private static final SimpleDateFormat TIMESTAMP_FORMAT =
|
private static final DateFormat TIMESTAMP_FORMAT = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||||
new SimpleDateFormat("HH:mm:ss");
|
|
||||||
private static final long REFRESH_PERIOD_MS = 250;
|
private static final long REFRESH_PERIOD_MS = 250;
|
||||||
|
|
||||||
private final StatsUtilities utils;
|
private final StatsUtilities utils;
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import android.util.Log;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -47,8 +47,8 @@ import java.util.Date;
|
|||||||
public class BackupActivityHelper {
|
public class BackupActivityHelper {
|
||||||
|
|
||||||
// Since the user sees this format, we use the local timezone
|
// Since the user sees this format, we use the local timezone
|
||||||
private static final SimpleDateFormat DISPLAY_BACKUP_FORMAT =
|
private static final DateFormat DISPLAY_BACKUP_FORMAT = DateFormat.getDateTimeInstance(
|
||||||
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
DateFormat.SHORT, DateFormat.SHORT);
|
||||||
|
|
||||||
private static final Comparator<Date> REVERSE_DATE_ORDER =
|
private static final Comparator<Date> REVERSE_DATE_ORDER =
|
||||||
new Comparator<Date>() {
|
new Comparator<Date>() {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import com.google.wireless.gdata.parser.ParseException;
|
|||||||
import com.google.wireless.gdata2.client.AuthenticationException;
|
import com.google.wireless.gdata2.client.AuthenticationException;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.format.DateFormat;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -45,6 +44,7 @@ import java.io.OutputStream;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ public class DocsHelper {
|
|||||||
DocsTagBuilder tagBuilder = new DocsTagBuilder(metricUnits)
|
DocsTagBuilder tagBuilder = new DocsTagBuilder(metricUnits)
|
||||||
.append("name", track.getName())
|
.append("name", track.getName())
|
||||||
.append("description", track.getDescription())
|
.append("description", track.getDescription())
|
||||||
.append("date", getDisplayDate(context, stats.getStartTime()))
|
.append("date", getDisplayDate(stats.getStartTime()))
|
||||||
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
|
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
|
||||||
stats.getTotalTime()))
|
stats.getTotalTime()))
|
||||||
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
|
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
|
||||||
@@ -331,17 +331,15 @@ public class DocsHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the display string for a time based on the phone's setting.
|
* Gets the display string for a time.
|
||||||
*
|
*
|
||||||
* @param context the context to obtain the phone's setting.
|
|
||||||
* @param time the time
|
* @param time the time
|
||||||
* @return the display string of the time
|
* @return the display string of the time
|
||||||
*/
|
*/
|
||||||
protected String getDisplayDate(Context context, long time) {
|
private String getDisplayDate(long time) {
|
||||||
java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
|
DateFormat format = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
|
|
||||||
Date startTime = new Date(time);
|
Date startTime = new Date(time);
|
||||||
String dateString = dateFormat.format(startTime) + " " + timeFormat.format(startTime);
|
String dateString = format.format(startTime);
|
||||||
return dateString;
|
return dateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ import java.text.NumberFormat;
|
|||||||
*/
|
*/
|
||||||
class DocsTagBuilder {
|
class DocsTagBuilder {
|
||||||
|
|
||||||
private static final NumberFormat LARGE_UNIT_FORMAT = NumberFormat.getIntegerInstance();
|
private static final NumberFormat LARGE_UNIT_FORMAT = NumberFormat.getNumberInstance();
|
||||||
private static final NumberFormat SMALL_UNIT_FORMAT = NumberFormat.getNumberInstance();
|
private static final NumberFormat SMALL_UNIT_FORMAT = NumberFormat.getIntegerInstance();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SMALL_UNIT_FORMAT.setMaximumFractionDigits(2);
|
LARGE_UNIT_FORMAT.setMaximumFractionDigits(2);
|
||||||
SMALL_UNIT_FORMAT.setMinimumFractionDigits(2);
|
LARGE_UNIT_FORMAT.setMinimumFractionDigits(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean metricUnits;
|
protected final boolean metricUnits;
|
||||||
|
|||||||
@@ -18,15 +18,14 @@ package com.google.android.apps.mytracks.io.file;
|
|||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
||||||
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports a track as a CSV file, according to RFC 4180.
|
* Exports a track as a CSV file, according to RFC 4180.
|
||||||
@@ -46,13 +45,10 @@ import java.util.TimeZone;
|
|||||||
*/
|
*/
|
||||||
public class CsvTrackWriter implements TrackFormatWriter {
|
public class CsvTrackWriter implements TrackFormatWriter {
|
||||||
|
|
||||||
static final NumberFormat SHORT_FORMAT = NumberFormat.getInstance();
|
private static final NumberFormat SHORT_FORMAT = NumberFormat.getInstance();
|
||||||
static final SimpleDateFormat TIMESTAMP_FORMAT =
|
|
||||||
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SHORT_FORMAT.setMaximumFractionDigits(4);
|
SHORT_FORMAT.setMaximumFractionDigits(4);
|
||||||
TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int segmentIdx = 0;
|
private int segmentIdx = 0;
|
||||||
@@ -93,7 +89,7 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeLocation(Location location) {
|
public void writeLocation(Location location) {
|
||||||
String timeStr = TIMESTAMP_FORMAT.format(new Date(location.getTime()));
|
String timeStr = FileUtils.FILE_TIMESTAMP_FORMAT.format(new Date(location.getTime()));
|
||||||
writeCommaSeparatedLine("P",
|
writeCommaSeparatedLine("P",
|
||||||
timeStr,
|
timeStr,
|
||||||
Double.toString(location.getLatitude()),
|
Double.toString(location.getLatitude()),
|
||||||
@@ -109,7 +105,7 @@ public class CsvTrackWriter implements TrackFormatWriter {
|
|||||||
@Override
|
@Override
|
||||||
public void writeWaypoint(Waypoint waypoint) {
|
public void writeWaypoint(Waypoint waypoint) {
|
||||||
Location location = waypoint.getLocation();
|
Location location = waypoint.getLocation();
|
||||||
String timeStr = TIMESTAMP_FORMAT.format(new Date(location.getTime()));
|
String timeStr = FileUtils.FILE_TIMESTAMP_FORMAT.format(new Date(location.getTime()));
|
||||||
writeCommaSeparatedLine("WAYPOINT",
|
writeCommaSeparatedLine("WAYPOINT",
|
||||||
timeStr,
|
timeStr,
|
||||||
Double.toString(location.getLatitude()),
|
Double.toString(location.getLatitude()),
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.io.file;
|
|||||||
import com.google.android.apps.mytracks.content.Track;
|
import com.google.android.apps.mytracks.content.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
||||||
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
@@ -27,10 +28,8 @@ import java.io.OutputStream;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log of one track.
|
* Log of one track.
|
||||||
@@ -38,11 +37,8 @@ import java.util.TimeZone;
|
|||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class GpxTrackWriter implements TrackFormatWriter {
|
public class GpxTrackWriter implements TrackFormatWriter {
|
||||||
private static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
|
||||||
|
|
||||||
private final NumberFormat elevationFormatter;
|
private final NumberFormat elevationFormatter;
|
||||||
private final NumberFormat coordinateFormatter;
|
private final NumberFormat coordinateFormatter;
|
||||||
private final SimpleDateFormat timestampFormatter;
|
|
||||||
private PrintWriter pw = null;
|
private PrintWriter pw = null;
|
||||||
private Track track;
|
private Track track;
|
||||||
|
|
||||||
@@ -57,9 +53,6 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
coordinateFormatter.setMaximumFractionDigits(5);
|
coordinateFormatter.setMaximumFractionDigits(5);
|
||||||
coordinateFormatter.setMaximumIntegerDigits(3);
|
coordinateFormatter.setMaximumIntegerDigits(3);
|
||||||
coordinateFormatter.setGroupingUsed(false);
|
coordinateFormatter.setGroupingUsed(false);
|
||||||
|
|
||||||
timestampFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
|
|
||||||
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatLocation(Location l) {
|
private String formatLocation(Location l) {
|
||||||
@@ -144,7 +137,7 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
pw.println("<trkpt " + formatLocation(l) + ">");
|
pw.println("<trkpt " + formatLocation(l) + ">");
|
||||||
Date d = new Date(l.getTime());
|
Date d = new Date(l.getTime());
|
||||||
pw.println("<ele>" + elevationFormatter.format(l.getAltitude()) + "</ele>");
|
pw.println("<ele>" + elevationFormatter.format(l.getAltitude()) + "</ele>");
|
||||||
pw.println("<time>" + timestampFormatter.format(d) + "</time>");
|
pw.println("<time>" + FileUtils.FILE_TIMESTAMP_FORMAT.format(d) + "</time>");
|
||||||
pw.println("</trkpt>");
|
pw.println("</trkpt>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,7 +157,7 @@ public class GpxTrackWriter implements TrackFormatWriter {
|
|||||||
if (l != null) {
|
if (l != null) {
|
||||||
pw.println("<wpt " + formatLocation(l) + ">");
|
pw.println("<wpt " + formatLocation(l) + ">");
|
||||||
pw.println("<ele>" + elevationFormatter.format(l.getAltitude()) + "</ele>");
|
pw.println("<ele>" + elevationFormatter.format(l.getAltitude()) + "</ele>");
|
||||||
pw.println("<time>" + timestampFormatter.format(l.getTime()) + "</time>");
|
pw.println("<time>" + FileUtils.FILE_TIMESTAMP_FORMAT.format(l.getTime()) + "</time>");
|
||||||
pw.println("<name>" + StringUtils.stringAsCData(waypoint.getName())
|
pw.println("<name>" + StringUtils.stringAsCData(waypoint.getName())
|
||||||
+ "</name>");
|
+ "</name>");
|
||||||
pw.println("<desc>"
|
pw.println("<desc>"
|
||||||
|
|||||||
@@ -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.Track;
|
||||||
import com.google.android.apps.mytracks.content.Waypoint;
|
import com.google.android.apps.mytracks.content.Waypoint;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
import com.google.android.apps.mytracks.io.file.TrackWriterFactory.TrackFileFormat;
|
||||||
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
import com.google.android.apps.mytracks.util.SystemUtils;
|
import com.google.android.apps.mytracks.util.SystemUtils;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -30,10 +31,8 @@ import android.os.Build;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write out a a track in the Garmin training center database, tcx format.
|
* Write out a a track in the Garmin training center database, tcx format.
|
||||||
@@ -44,10 +43,9 @@ import java.util.TimeZone;
|
|||||||
* Garmin Training Center 3.5.3.
|
* Garmin Training Center 3.5.3.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Dominik Ršttsches
|
* @author Dominik Rttsches
|
||||||
*/
|
*/
|
||||||
public class TcxTrackWriter implements TrackFormatWriter {
|
public class TcxTrackWriter implements TrackFormatWriter {
|
||||||
protected static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
|
||||||
|
|
||||||
// These are the only sports allowed by the TCX v2 specification for fields
|
// These are the only sports allowed by the TCX v2 specification for fields
|
||||||
// of type Sport_t.
|
// of type Sport_t.
|
||||||
@@ -59,7 +57,6 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
private static final String TCX_TYPE_RELEASE = "Release";
|
private static final String TCX_TYPE_RELEASE = "Release";
|
||||||
private static final String TCX_TYPE_INTERNAL = "Internal";
|
private static final String TCX_TYPE_INTERNAL = "Internal";
|
||||||
|
|
||||||
private final SimpleDateFormat timestampFormatter;
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
private PrintWriter pw = null;
|
private PrintWriter pw = null;
|
||||||
@@ -70,9 +67,6 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
|
|
||||||
public TcxTrackWriter(Context context) {
|
public TcxTrackWriter(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
|
||||||
timestampFormatter = new SimpleDateFormat(TIMESTAMP_FORMAT);
|
|
||||||
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("hiding")
|
@SuppressWarnings("hiding")
|
||||||
@@ -117,7 +111,7 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String startTime = timestampFormatter.format(track.getStatistics().getStartTime());
|
String startTime = FileUtils.FILE_TIMESTAMP_FORMAT.format(track.getStatistics().getStartTime());
|
||||||
|
|
||||||
pw.println(" <Activities>");
|
pw.println(" <Activities>");
|
||||||
pw.format(" <Activity Sport=\"%s\">\n", categoryToTcxSport(track.getCategory()));
|
pw.format(" <Activity Sport=\"%s\">\n", categoryToTcxSport(track.getCategory()));
|
||||||
@@ -150,7 +144,7 @@ public class TcxTrackWriter implements TrackFormatWriter {
|
|||||||
}
|
}
|
||||||
pw.println(" <Trackpoint>");
|
pw.println(" <Trackpoint>");
|
||||||
Date d = new Date(location.getTime());
|
Date d = new Date(location.getTime());
|
||||||
pw.println(" <Time>" + timestampFormatter.format(d) + "</Time>");
|
pw.println(" <Time>" + FileUtils.FILE_TIMESTAMP_FORMAT.format(d) + "</Time>");
|
||||||
pw.println(" <Position>");
|
pw.println(" <Position>");
|
||||||
|
|
||||||
pw.print(" <LatitudeDegrees>");
|
pw.print(" <LatitudeDegrees>");
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import com.google.android.maps.mytracks.R;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,8 +30,6 @@ import java.util.Date;
|
|||||||
* @author Matthew Simmons
|
* @author Matthew Simmons
|
||||||
*/
|
*/
|
||||||
class DefaultTrackNameFactory {
|
class DefaultTrackNameFactory {
|
||||||
private static final String TIMESTAMP_DATE_FORMAT = "yyyy-MM-dd HH:mm";
|
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
DefaultTrackNameFactory(Context context) {
|
DefaultTrackNameFactory(Context context) {
|
||||||
@@ -48,7 +46,7 @@ class DefaultTrackNameFactory {
|
|||||||
*/
|
*/
|
||||||
String newTrackName(long trackId, long startTime) {
|
String newTrackName(long trackId, long startTime) {
|
||||||
if (useTimestampTrackName()) {
|
if (useTimestampTrackName()) {
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat(TIMESTAMP_DATE_FORMAT);
|
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
return formatter.format(new Date(startTime));
|
return formatter.format(new Date(startTime));
|
||||||
} else {
|
} else {
|
||||||
return String.format(context.getString(R.string.track_name_format), trackId);
|
return String.format(context.getString(R.string.track_name_format), trackId);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ import com.google.android.apps.mytracks.Constants;
|
|||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,6 +41,16 @@ public class FileUtils {
|
|||||||
private static final Pattern PROHIBITED_CHAR_PATTERN =
|
private static final Pattern PROHIBITED_CHAR_PATTERN =
|
||||||
Pattern.compile("[^ A-Za-z0-9_.()-]+");
|
Pattern.compile("[^ A-Za-z0-9_.()-]+");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timestamp format in UTC time zone.
|
||||||
|
*/
|
||||||
|
public static final SimpleDateFormat FILE_TIMESTAMP_FORMAT =
|
||||||
|
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||||
|
|
||||||
|
static {
|
||||||
|
FILE_TIMESTAMP_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a path inside the My Tracks directory in the SD card.
|
* Builds a path inside the My Tracks directory in the SD card.
|
||||||
*
|
*
|
||||||
|
|||||||
+4
-13
@@ -40,7 +40,8 @@ import junit.framework.TestCase;
|
|||||||
*/
|
*/
|
||||||
public class DocsHelper_AddTrackRowTest extends TestCase {
|
public class DocsHelper_AddTrackRowTest extends TestCase {
|
||||||
private static final long TIME = 1288721514000L;
|
private static final long TIME = 1288721514000L;
|
||||||
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
private static final DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(
|
||||||
|
DateFormat.SHORT, DateFormat.SHORT);
|
||||||
|
|
||||||
private static class StringWritingDocsHelper extends DocsHelper {
|
private static class StringWritingDocsHelper extends DocsHelper {
|
||||||
String writtenSheetUri = null;
|
String writtenSheetUri = null;
|
||||||
@@ -55,12 +56,7 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddTrackRow_imperial() throws Exception {
|
public void testAddTrackRow_imperial() throws Exception {
|
||||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper() {
|
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||||
@Override
|
|
||||||
protected String getDisplayDate(Context context, long time) {
|
|
||||||
return DATE_FORMAT.format(new Date(TIME));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
addTrackRow(docsHelper, false);
|
addTrackRow(docsHelper, false);
|
||||||
|
|
||||||
String expectedData =
|
String expectedData =
|
||||||
@@ -94,12 +90,7 @@ public class DocsHelper_AddTrackRowTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testAddTrackRow_metric() throws Exception {
|
public void testAddTrackRow_metric() throws Exception {
|
||||||
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper() {
|
StringWritingDocsHelper docsHelper = new StringWritingDocsHelper();
|
||||||
@Override
|
|
||||||
protected String getDisplayDate(Context context, long time) {
|
|
||||||
return DATE_FORMAT.format(new Date(TIME));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
addTrackRow(docsHelper, true);
|
addTrackRow(docsHelper, true);
|
||||||
|
|
||||||
// The imperial test verifies that the tags come out in the proper order,
|
// The imperial test verifies that the tags come out in the proper order,
|
||||||
|
|||||||
@@ -3,13 +3,9 @@ package com.google.android.apps.mytracks.io.file;
|
|||||||
|
|
||||||
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
import com.google.android.apps.mytracks.content.MyTracksLocation;
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
import com.google.android.apps.mytracks.io.file.TcxTrackWriter;
|
import com.google.android.apps.mytracks.util.FileUtils;
|
||||||
import com.google.android.apps.mytracks.io.file.TrackFormatWriter;
|
|
||||||
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
@@ -20,15 +16,6 @@ import org.w3c.dom.Element;
|
|||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
||||||
private DateFormat timestampFormatter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
timestampFormatter = new SimpleDateFormat(TcxTrackWriter.TIMESTAMP_FORMAT);
|
|
||||||
timestampFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testXmlOutput() throws Exception {
|
public void testXmlOutput() throws Exception {
|
||||||
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
TrackFormatWriter writer = new TcxTrackWriter(getContext());
|
||||||
@@ -72,7 +59,7 @@ public class TcxTrackWriterTest extends TrackFormatWriterTest {
|
|||||||
assertEquals(Double.toString(loc.getLongitude()),
|
assertEquals(Double.toString(loc.getLongitude()),
|
||||||
getChildTextValue(posTag, "LongitudeDegrees"));
|
getChildTextValue(posTag, "LongitudeDegrees"));
|
||||||
|
|
||||||
assertEquals(timestampFormatter.format(loc.getTime()),
|
assertEquals(FileUtils.FILE_TIMESTAMP_FORMAT.format(loc.getTime()),
|
||||||
getChildTextValue(tag, "Time"));
|
getChildTextValue(tag, "Time"));
|
||||||
assertEquals(Double.toString(loc.getAltitude()),
|
assertEquals(Double.toString(loc.getAltitude()),
|
||||||
getChildTextValue(tag, "AltitudeMeters"));
|
getChildTextValue(tag, "AltitudeMeters"));
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ package com.google.android.apps.mytracks.services;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.test.AndroidTestCase;
|
import android.test.AndroidTestCase;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +52,7 @@ public class DefaultTrackNameFactoryTest extends AndroidTestCase {
|
|||||||
DefaultTrackNameFactory factory =
|
DefaultTrackNameFactory factory =
|
||||||
new MockDefaultTrackNameFactory(getContext(), true);
|
new MockDefaultTrackNameFactory(getContext(), true);
|
||||||
|
|
||||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
|
||||||
assertEquals(formatter.format(new Date(TIMESTAMP)),
|
assertEquals(formatter.format(new Date(TIMESTAMP)),
|
||||||
factory.newTrackName(1, TIMESTAMP));
|
factory.newTrackName(1, TIMESTAMP));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user