forked from upstream-mirrors/OpenTracks
merge heads
This commit is contained in:
@@ -81,7 +81,7 @@ public class StringUtils {
|
||||
*/
|
||||
public static String formatElapsedTime(long time) {
|
||||
/*
|
||||
* Temporary workaround for DateUtils.formatElapsedTime(time / 1000). In API
|
||||
* Temporary workaround for DateUtils.formatElapsedTime(time * MS_TO_S). In API
|
||||
* level 17, it returns strings like "1:0:00" instead of "1:00:00", which
|
||||
* breaks several unit tests.
|
||||
*/
|
||||
@@ -91,7 +91,7 @@ public class StringUtils {
|
||||
long hours = 0;
|
||||
long minutes = 0;
|
||||
long seconds = 0;
|
||||
long elapsedSeconds = time / 1000;
|
||||
long elapsedSeconds = (long) (time * UnitConversions.MS_TO_S);
|
||||
|
||||
if (elapsedSeconds >= 3600) {
|
||||
hours = elapsedSeconds / 3600;
|
||||
@@ -149,6 +149,19 @@ public class StringUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatWeight(double value) {
|
||||
return formatDecimal(value, 1);
|
||||
}
|
||||
|
||||
public static String formatDecimal(double value) {
|
||||
return formatDecimal(value, 2);
|
||||
}
|
||||
|
||||
private static String formatDecimal(double value, int precision) {
|
||||
String result = String.format(Locale.getDefault(), "%1$,." + precision + "f", value);
|
||||
return result.replaceAll("[0]*$", "").replaceAll("\\.$", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance in an array of two strings. The first string is the
|
||||
* distance. The second string is the unit. The first string is null if the
|
||||
@@ -183,7 +196,7 @@ public class StringUtils {
|
||||
unitId = R.string.unit_feet;
|
||||
}
|
||||
}
|
||||
result[0] = String.format("%.2f", distance);
|
||||
result[0] = formatDecimal(distance);
|
||||
result[1] = context.getString(unitId);
|
||||
return result;
|
||||
}
|
||||
@@ -217,13 +230,13 @@ public class StringUtils {
|
||||
speed *= UnitConversions.KM_TO_MI;
|
||||
}
|
||||
if (reportSpeed) {
|
||||
result[0] = String.format("%.2f", speed);
|
||||
result[0] = StringUtils.formatDecimal(speed);
|
||||
} else {
|
||||
// convert from hours to minutes
|
||||
double pace = speed == 0 ? 0.0 : 60.0 / speed;
|
||||
int minutes = (int) pace;
|
||||
int seconds = (int) Math.round((pace - minutes) * 60.0);
|
||||
result[0] = String.format("%d:%02d", minutes, seconds);
|
||||
result[0] = String.format(Locale.US, "%d:%02d", minutes, seconds);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -301,7 +314,7 @@ public class StringUtils {
|
||||
if (fractional != null) {
|
||||
// Regex ensures fractional part is in (0,1)
|
||||
float fractionalSeconds = Float.parseFloat(fractional);
|
||||
long fractionalMillis = (long) (fractionalSeconds * 1000.0f);
|
||||
long fractionalMillis = (long) (fractionalSeconds * UnitConversions.S_TO_MS);
|
||||
time += fractionalMillis;
|
||||
}
|
||||
|
||||
@@ -350,7 +363,7 @@ public class StringUtils {
|
||||
}
|
||||
int[] parts = new int[3];
|
||||
|
||||
long seconds = time / 1000;
|
||||
long seconds = (long) (time * UnitConversions.MS_TO_S);
|
||||
parts[0] = (int) (seconds % 60);
|
||||
int minutes = (int) (seconds / 60);
|
||||
parts[1] = minutes % 60;
|
||||
|
||||
Reference in New Issue
Block a user