forked from upstream-mirrors/OpenTracks
StatsFragment: show elevation without decimal digits.
This commit is contained in:
@@ -154,33 +154,33 @@ public class StringUtils {
|
|||||||
* Get the formatted distance with unit.
|
* Get the formatted distance with unit.
|
||||||
*
|
*
|
||||||
* @param context the context
|
* @param context the context
|
||||||
* @param distance the distance
|
* @param distance_m the distance
|
||||||
* @param metricUnits true to use metric unit
|
* @param metricUnits true to use metric unit
|
||||||
* @return the formatted distance (or null) and it's unit as {@link Pair}
|
* @return the formatted distance (or null) and it's unit as {@link Pair}
|
||||||
*/
|
*/
|
||||||
public static Pair<String, String> getDistanceParts(Context context, double distance, boolean metricUnits) {
|
public static Pair<String, String> getDistanceParts(Context context, double distance_m, boolean metricUnits) {
|
||||||
if (Double.isNaN(distance) || Double.isInfinite(distance)) {
|
if (Double.isNaN(distance_m) || Double.isInfinite(distance_m)) {
|
||||||
return new Pair<>(null, context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet));
|
return new Pair<>(null, context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet));
|
||||||
}
|
}
|
||||||
|
|
||||||
int unitId;
|
int unitId;
|
||||||
if (metricUnits) {
|
if (metricUnits) {
|
||||||
if (distance > 500.0) {
|
if (distance_m > 500.0) {
|
||||||
distance *= UnitConversions.M_TO_KM;
|
distance_m *= UnitConversions.M_TO_KM;
|
||||||
unitId = R.string.unit_kilometer;
|
unitId = R.string.unit_kilometer;
|
||||||
} else {
|
} else {
|
||||||
unitId = R.string.unit_meter;
|
unitId = R.string.unit_meter;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (distance * UnitConversions.M_TO_MI > 0.5) {
|
if (distance_m * UnitConversions.M_TO_MI > 0.5) {
|
||||||
distance *= UnitConversions.M_TO_MI;
|
distance_m *= UnitConversions.M_TO_MI;
|
||||||
unitId = R.string.unit_mile;
|
unitId = R.string.unit_mile;
|
||||||
} else {
|
} else {
|
||||||
distance *= UnitConversions.M_TO_FT;
|
distance_m *= UnitConversions.M_TO_FT;
|
||||||
unitId = R.string.unit_feet;
|
unitId = R.string.unit_feet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Pair<>(formatDecimal(distance), context.getString(unitId));
|
return new Pair<>(formatDecimal(distance_m), context.getString(unitId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -382,11 +382,10 @@ public class StringUtils {
|
|||||||
String value = context.getString(R.string.value_unknown);
|
String value = context.getString(R.string.value_unknown);
|
||||||
String unit = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet);
|
String unit = context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet);
|
||||||
if (!Double.isNaN(elevation) && !Double.isInfinite(elevation)) {
|
if (!Double.isNaN(elevation) && !Double.isInfinite(elevation)) {
|
||||||
if (metricUnits) {
|
if (!metricUnits) {
|
||||||
value = StringUtils.formatDecimal(elevation);
|
elevation *= UnitConversions.M_TO_FT;
|
||||||
} else {
|
|
||||||
value = StringUtils.formatDecimal(elevation * UnitConversions.M_TO_FT);
|
|
||||||
}
|
}
|
||||||
|
value = StringUtils.formatDecimal(elevation, 0);
|
||||||
}
|
}
|
||||||
return new Pair<>(value, unit);
|
return new Pair<>(value, unit);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user