merge heads

This commit is contained in:
Jimmy Shih
2012-01-04 17:17:41 -08:00
parent 8db6f5b569
commit 23ca7bd05e
12 changed files with 56 additions and 120 deletions
@@ -805,7 +805,7 @@ public class ChartView extends View {
String s =
(mode == Mode.BY_DISTANCE)
? (shortFormat ? X_SHORT_FORMAT.format(x) : X_FORMAT.format(x))
: StringUtils.formatTime((long) x);
: StringUtils.formatElapsedTime((long) x);
c.drawText(s,
getX(x),
effectiveHeight + UNIT_BORDER + topBorder,
@@ -23,6 +23,7 @@ import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection
import com.google.android.apps.mytracks.services.sensors.SensorManager;
import com.google.android.apps.mytracks.services.sensors.SensorManagerFactory;
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import com.google.protobuf.InvalidProtocolBufferException;
@@ -32,8 +33,6 @@ import android.os.RemoteException;
import android.util.Log;
import android.widget.TextView;
import java.text.DateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
@@ -44,7 +43,6 @@ import java.util.TimerTask;
*/
public class SensorStateActivity extends Activity {
private static final DateFormat TIMESTAMP_FORMAT = DateFormat.getTimeInstance(DateFormat.SHORT);
private static final long REFRESH_PERIOD_MS = 250;
private final StatsUtilities utils;
@@ -263,7 +261,7 @@ public class SensorStateActivity extends Activity {
* @param sds sensor data set
*/
private String getLastSensorTime(Sensor.SensorDataSet sds) {
return TIMESTAMP_FORMAT.format(new Date(sds.getCreationTime()));
return StringUtils.formatTime(this, sds.getCreationTime());
}
/**
@@ -153,7 +153,7 @@ public class StatsUtilities {
}
public void setTime(int id, long l) {
setText(id, StringUtils.formatTime(l));
setText(id, StringUtils.formatElapsedTime(l));
}
public void setGrade(int id, double d) {
@@ -310,7 +310,7 @@ public class TrackList extends ListActivity
TextView textView = (TextView) view;
if (columnIndex == startTimeIdx) {
long time = cursor.getLong(startTimeIdx);
textView.setText(StringUtils.formatDateTime(time));
textView.setText(StringUtils.formatDateTime(TrackList.this, time));
} else if (columnIndex == totalDistanceIdx) {
double length = cursor.getDouble(totalDistanceIdx);
String lengthUnit = null;
@@ -331,7 +331,7 @@ public class TrackList extends ListActivity
}
}
textView.setText(String.format("%s %.2f %s",
StringUtils.formatTime(cursor.getLong(totalTimeIdx)),
StringUtils.formatElapsedTime(cursor.getLong(totalTimeIdx)),
length,
lengthUnit));
} else {
@@ -269,7 +269,7 @@ public class WaypointsList extends ListActivity
if (time == 0) {
textView.setVisibility(View.GONE);
} else {
textView.setText(StringUtils.formatDateTime(time));
textView.setText(StringUtils.formatDateTime(WaypointsList.this, time));
textView.setVisibility(View.VISIBLE);
}
} else if (columnIndex == typeIdx) {
@@ -156,7 +156,7 @@ public class BackupActivityHelper {
// Make a user-visible version of the backup filenames
final String backupDateStrs[] = new String[backupDates.length];
for (int i = 0; i < backupDates.length; i++) {
backupDateStrs[i] = StringUtils.formatDateTime(backupDates[i].getTime());
backupDateStrs[i] = StringUtils.formatDateTime(activity, backupDates[i].getTime());
}
// Show a dialog for the user to pick which backup to restore
@@ -288,11 +288,9 @@ public class DocsHelper {
DocsTagBuilder tagBuilder = new DocsTagBuilder(metricUnits)
.append("name", track.getName())
.append("description", track.getDescription())
.append("date", StringUtils.formatDateTime(stats.getStartTime()))
.append("totaltime", StringUtils.formatTimeAlwaysShowingHours(
stats.getTotalTime()))
.append("movingtime", StringUtils.formatTimeAlwaysShowingHours(
stats.getMovingTime()))
.append("date", StringUtils.formatDateTime(context, stats.getStartTime()))
.append("totaltime", StringUtils.formatElapsedTime(stats.getTotalTime()))
.append("movingtime", StringUtils.formatElapsedTime(stats.getMovingTime()))
.appendLargeUnits("distance", stats.getTotalDistance() / 1000)
.append("distanceunit", distanceUnit)
.appendLargeUnits("averagespeed", stats.getAverageSpeed() * 3.6)
@@ -44,7 +44,7 @@ class DefaultTrackNameFactory {
*/
String newTrackName(long trackId, long startTime) {
if (useTimestampTrackName()) {
return StringUtils.formatDateTime(startTime);
return StringUtils.formatDateTime(context, startTime);
} else {
return String.format(context.getString(R.string.track_name_format), trackId);
}
@@ -24,6 +24,7 @@ import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.format.DateUtils;
import java.text.DateFormat;
import java.text.NumberFormat;
@@ -46,35 +47,34 @@ public class StringUtils implements DescriptionGenerator {
private final Context context;
/**
* Formats the time based on user locale.
*
* @param time time
*/
public static String formatDateTime(long time) {
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
return formatter.format(new Date(time));
}
/**
* Formats a number of milliseconds as a string.
* Formats the date and time based on user's phone date/time preferences.
*
* @param time - A period of time in milliseconds.
* @return A string of the format M:SS, MM:SS or HH:MM:SS
* @param context the context
* @param time the time in milliseconds
*/
public static String formatTime(long time) {
return formatTimeInternal(time, false);
public static String formatDateTime(Context context, long time) {
DateFormat dateFormatter = android.text.format.DateFormat.getDateFormat(context);
return dateFormatter.format(new Date(time)) + " " + formatTime(context, time);
}
/**
* Formats a number of milliseconds as a string. To be used when we need the
* hours to be shown even when it is zero, e.g. exporting data to a
* spreadsheet.
* Formats the time based on user's phone date/time preferences.
*
* @param time - A period of time in milliseconds
* @return A string of the format HH:MM:SS even if time is less than 1 hour
* @param context the context
* @param time the time in milliseconds
*/
public static String formatTimeAlwaysShowingHours(long time) {
return formatTimeInternal(time, true);
public static String formatTime(Context context, long time) {
DateFormat timeFormatter = android.text.format.DateFormat.getTimeFormat(context);
return timeFormatter.format(new Date(time));
}
/**
* Formats the elapsed timed in the form "MM:SS" or "H:MM:SS".
*
* @param time the time in milliseconds
*/
public static String formatElapsedTime(long time) {
return DateUtils.formatElapsedTime(time / 1000);
}
private static final NumberFormat SINGLE_DECIMAL_PLACE_FORMAT = NumberFormat.getNumberInstance();
@@ -182,35 +182,6 @@ public class StringUtils implements DescriptionGenerator {
return time;
}
/**
* Formats a number of milliseconds as a string.
*
* @param time - A period of time in milliseconds
* @param alwaysShowHours - Whether to display 00 hours if time is less than 1
* hour
* @return A string of the format HH:MM:SS
*/
private static String formatTimeInternal(long time, boolean alwaysShowHours) {
int[] parts = getTimeParts(time);
StringBuilder builder = new StringBuilder();
if (parts[2] > 0 || alwaysShowHours) {
builder.append(parts[2]);
builder.append(':');
if (parts[1] <= 9) {
builder.append("0");
}
}
builder.append(parts[1]);
builder.append(':');
if (parts[0] <= 9) {
builder.append("0");
}
builder.append(parts[0]);
return builder.toString();
}
/**
* Gets the time as an array of parts.
*/
@@ -328,11 +299,11 @@ public class StringUtils implements DescriptionGenerator {
// Line 3
context.getString(R.string.stat_total_time),
StringUtils.formatTime(trackStats.getTotalTime()),
StringUtils.formatElapsedTime(trackStats.getTotalTime()),
// Line 4
context.getString(R.string.stat_moving_time),
StringUtils.formatTime(trackStats.getMovingTime()),
StringUtils.formatElapsedTime(trackStats.getMovingTime()),
// Line 5
averageSpeed, averageMovingSpeed, maxSpeed,
@@ -360,7 +331,7 @@ public class StringUtils implements DescriptionGenerator {
// Line 11
context.getString(R.string.send_google_recorded),
StringUtils.formatDateTime(trackStats.getStartTime()),
StringUtils.formatDateTime(context, trackStats.getStartTime()),
// Line 12
context.getString(R.string.track_detail_activity_type_hint), category,
@@ -470,9 +441,9 @@ public class StringUtils implements DescriptionGenerator {
distanceInKm, context.getString(R.string.unit_kilometer),
distanceInMiles, context.getString(R.string.unit_mile),
context.getString(R.string.stat_total_time),
StringUtils.formatTime(stats.getTotalTime()),
StringUtils.formatElapsedTime(stats.getTotalTime()),
context.getString(R.string.stat_moving_time),
StringUtils.formatTime(stats.getMovingTime()),
StringUtils.formatElapsedTime(stats.getMovingTime()),
context.getString(R.string.stat_average_speed),
averageSpeedInKmh, context.getString(R.string.unit_kilometer_per_hour),
averageSpeedInMph, context.getString(R.string.unit_mile_per_hour),
@@ -224,7 +224,7 @@ public class TrackWidgetProvider
StringUtils.formatSingleDecimalPlace(displayDistance) + " " + this.distanceLabel;
// convert ms to minutes
String time = StringUtils.formatTime(stats.getMovingTime());
String time = StringUtils.formatElapsedTime(stats.getMovingTime());
String speed = unknown;
if (!Double.isNaN(stats.getAverageMovingSpeed())) {
// Convert m/s to km/h
@@ -236,7 +236,7 @@ public class TrackWidgetProvider
speed = StringUtils.formatSingleDecimalPlace(displaySpeed) + " " + this.speedLabel;
} else {
long displayPace = (long) (3600000.0 / displaySpeed);
speed = StringUtils.formatTime(displayPace) + " " + paceLabel;
speed = StringUtils.formatElapsedTime(displayPace) + " " + paceLabel;
}
}