forked from upstream-mirrors/OpenTracks
@@ -128,27 +128,6 @@ public class StringUtils {
|
||||
return TextUtils.split(value, ":").length == 2 ? "0:" + value : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the distance in meters.
|
||||
*
|
||||
* @param context the context
|
||||
* @param distance the distance
|
||||
* @param metricUnits true to use metric units. False to use imperial units
|
||||
*/
|
||||
public static String formatDistance(Context context, Distance distance, boolean metricUnits) {
|
||||
return formatDistance(context, distance, metricUnits, 2);
|
||||
}
|
||||
|
||||
public static String formatDistance(Context context, Distance distance, boolean metricUnits, int decimalCount) {
|
||||
if (distance.isInvalid()) {
|
||||
return context.getString(R.string.value_unknown);
|
||||
}
|
||||
|
||||
Pair<String, String> distanceParts = getDistanceParts(context, distance, metricUnits, decimalCount);
|
||||
|
||||
return context.getString(R.string.distance_with_unit, distanceParts.first, distanceParts.second);
|
||||
}
|
||||
|
||||
public static String formatSpeed(Context context, Speed speed, boolean metricUnits, boolean reportSpeed) {
|
||||
Pair<String, String> distanceParts = getSpeedParts(context, speed, metricUnits, reportSpeed);
|
||||
|
||||
@@ -191,38 +170,6 @@ public class StringUtils {
|
||||
return context.getString(R.string.location_latitude_longitude, Location.convert(latitude, Location.FORMAT_DEGREES), Location.convert(longitude, Location.FORMAT_DEGREES));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted distance with unit.
|
||||
*
|
||||
* @param context the context
|
||||
* @param distance the distance
|
||||
* @param metricUnits true to use metric unit
|
||||
* @return the formatted distance (or null) and it's unit as {@link Pair}
|
||||
*/
|
||||
public static Pair<String, String> getDistanceParts(Context context, Distance distance, boolean metricUnits) {
|
||||
return getDistanceParts(context, distance, metricUnits, 2);
|
||||
}
|
||||
|
||||
public static Pair<String, String> getDistanceParts(Context context, Distance distance, boolean metricUnits, int decimalCount) {
|
||||
if (distance.isInvalid()) {
|
||||
return new Pair<>(null, context.getString(metricUnits ? R.string.unit_meter : R.string.unit_feet));
|
||||
}
|
||||
|
||||
if (metricUnits) {
|
||||
if (distance.greaterThan(Distance.of(500))) {
|
||||
return new Pair<>(formatDecimal(distance.toKM(), decimalCount), context.getString(R.string.unit_kilometer));
|
||||
} else {
|
||||
return new Pair<>(formatDecimal(distance.toM(), decimalCount), context.getString(R.string.unit_meter));
|
||||
}
|
||||
} else {
|
||||
if (distance.greaterThan(Distance.ofMile(0.5))) {
|
||||
return new Pair<>(formatDecimal(distance.toMI(), decimalCount), context.getString(R.string.unit_mile));
|
||||
} else {
|
||||
return new Pair<>(formatDecimal(distance.toFT(), decimalCount), context.getString(R.string.unit_feet));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the formatted speed with unit.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user