Fixing the fixes for localization and track importing.

Fixes issue 462
Fixes issue 559
Fixes issue 540
This commit is contained in:
Rodrigo Damazio
2011-09-11 08:16:58 -03:00
parent 79c2cf90cf
commit eb6cdd0fc0
3 changed files with 31 additions and 17 deletions
@@ -61,8 +61,8 @@ public class ImportAllTracks {
Log.i(Constants.TAG, "ImportAllTracks: Starting"); Log.i(Constants.TAG, "ImportAllTracks: Starting");
fileUtils = new FileUtils(); fileUtils = new FileUtils();
gpxPath = fileUtils.buildExternalDirectoryPath("gpx"); gpxPath = fileUtils.buildExternalDirectoryPath("gpx");
this.activity.runOnUiThread(runner);
//new Thread(runner).start(); new Thread(runner).start();
} }
private final Runnable runner = new Runnable() { private final Runnable runner = new Runnable() {
@@ -95,6 +95,15 @@ public class ImportAllTracks {
Log.i(Constants.TAG, "ImportAllTracks: Releasing wake lock."); Log.i(Constants.TAG, "ImportAllTracks: Releasing wake lock.");
} }
activity.runOnUiThread(new Thread() {
@Override
public void run() {
showDoneDialog();
}
});
}
private void showDoneDialog() {
Log.i(Constants.TAG, "ImportAllTracks: Done"); Log.i(Constants.TAG, "ImportAllTracks: Done");
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
if (gpxFileCount == 0) { if (gpxFileCount == 0) {
@@ -287,11 +287,13 @@ public class DocsHelper {
String elevationUnit = context.getString(metricUnits ? String elevationUnit = context.getString(metricUnits ?
R.string.meter : R.string.feet); R.string.meter : R.string.feet);
DateFormat trackDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
// Prepare the Post-Text we are going to send. // Prepare the Post-Text we are going to send.
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", DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT).format(new Date(stats.getStartTime()))) .append("date", trackDateFormat.format(new Date(stats.getStartTime())))
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours( .append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
stats.getTotalTime())) stats.getTotalTime()))
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours( .append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
@@ -18,36 +18,39 @@ package com.google.android.apps.mytracks.io.docs;
import com.google.android.apps.mytracks.util.StringUtils; import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.apps.mytracks.util.UnitConversions; import com.google.android.apps.mytracks.util.UnitConversions;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Locale;
/** /**
* <p>This class builds a string of XML tags used to talk to Docs using GData. * <p>This class builds a string of XML tags used to talk to Docs using GData.
* *
* <p>Sample Usage: * <p>Sample Usage:
* *
* <code> * <code>
* String tags = new DocsTagBuilder(false) * String tags = new DocsTagBuilder(false)
* .append("tagName", "tagValue") * .append("tagName", "tagValue")
* .appendLargeUnits("bigTagName", 1.0) * .appendLargeUnits("bigTagName", 1.0)
* .build(); * .build();
* </code> * </code>
* *
* <p>results in: * <p>results in:
* *
* <code> * <code>
* <gsx:tagName><![CDATA[tagValue]]></gsx:tagName> * <gsx:tagName><![CDATA[tagValue]]></gsx:tagName>
* <gsx:bigTagName><![CDATA[1.00]]></gsx:bigTagName> * <gsx:bigTagName><![CDATA[1.00]]></gsx:bigTagName>
* </code> * </code>
* *
* @author Matthew Simmons * @author Matthew Simmons
*/ */
class DocsTagBuilder { class DocsTagBuilder {
// TODO(simmonmt): These formats aren't I18N-compatible. Not everyone uses private static final DecimalFormatSymbols FORMAT_SYMBOLS =
// commas for thousands and dots for the decimal point. DecimalFormatSymbols.getInstance(Locale.ENGLISH);
private static final NumberFormat LARGE_UNIT_FORMAT = private static final NumberFormat LARGE_UNIT_FORMAT =
NumberFormat.getNumberInstance(); new DecimalFormat("#,###,###.00", FORMAT_SYMBOLS);
private static final NumberFormat SMALL_UNIT_FORMAT = private static final NumberFormat SMALL_UNIT_FORMAT =
NumberFormat.getNumberInstance(); new DecimalFormat("###,###", FORMAT_SYMBOLS);
protected final boolean metricUnits; protected final boolean metricUnits;
protected final StringBuilder stringBuilder; protected final StringBuilder stringBuilder;
@@ -58,7 +61,7 @@ class DocsTagBuilder {
*/ */
DocsTagBuilder(boolean metricUnits) { DocsTagBuilder(boolean metricUnits) {
this.metricUnits = metricUnits; this.metricUnits = metricUnits;
stringBuilder = new StringBuilder(); this.stringBuilder = new StringBuilder();
} }
/** Appends a tag containing a string value */ /** Appends a tag containing a string value */
@@ -67,13 +70,13 @@ class DocsTagBuilder {
return this; return this;
} }
/** /**
* Appends a tag containing a numeric value. The value will be formatted * Appends a tag containing a numeric value. The value will be formatted
* according to the large distance of the specified measurement system (i.e. * according to the large distance of the specified measurement system (i.e.
* kilometers or miles). * kilometers or miles).
* *
* @param name The tag name. * @param name The tag name.
* @param d The value to be formatted, in kilometers. * @param d The value to be formatted, in kilometers.
*/ */
DocsTagBuilder appendLargeUnits(String name, double d) { DocsTagBuilder appendLargeUnits(String name, double d) {
double value = metricUnits ? d : (d * UnitConversions.KM_TO_MI); double value = metricUnits ? d : (d * UnitConversions.KM_TO_MI);
@@ -85,7 +88,7 @@ class DocsTagBuilder {
* Appends a tag containing a numeric value. The value will be formatted * Appends a tag containing a numeric value. The value will be formatted
* according to the small distance of the specified measurement system (i.e. * according to the small distance of the specified measurement system (i.e.
* meters or feet). * meters or feet).
* *
* @param name The tag name. * @param name The tag name.
* @param d The value to be formatted, in meters. * @param d The value to be formatted, in meters.
*/ */