Display pace in mm:second format.

This commit is contained in:
Jimmy Shih
2013-06-10 15:59:47 -07:00
parent 053aae4d5a
commit 849d5bdf1c
4 changed files with 28 additions and 20 deletions
@@ -219,6 +219,15 @@ public class DescriptionGeneratorImpl implements DescriptionGenerator {
void writePace(double speed, StringBuilder builder, int resId, String lineBreak) {
String[] paceInMetrics = StringUtils.getSpeedParts(context, speed, true, false);
String[] paceInImperial = StringUtils.getSpeedParts(context, speed, false, false);
if (paceInMetrics[0] == null) {
paceInMetrics[0] = context.getString(R.string.value_unknown);
}
if (paceInImperial[0] == null) {
paceInImperial[0] = context.getString(R.string.value_unknown);
}
builder.append(context.getString(resId, paceInMetrics[0], paceInImperial[0]));
builder.append(lineBreak);
}
@@ -213,19 +213,18 @@ public class StringUtils {
return result;
}
speed *= UnitConversions.MS_TO_KMH;
if (metricUnits) {
if (!reportSpeed) {
// convert from hours to minutes
speed = speed == 0 ? 0.0 : 60.0 / speed;
}
} else {
if (!metricUnits) {
speed *= UnitConversions.KM_TO_MI;
if (!reportSpeed) {
// convert from hours to minutes
speed = speed == 0 ? 0.0 : 60.0 / speed;
}
}
result[0] = String.format("%.2f", speed);
if (reportSpeed) {
result[0] = String.format("%.2f", 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);
}
return result;
}