Fix distance formatting for tunnel alarm info

This commit is contained in:
Alexander Sytnyk 2018-02-05 18:30:22 +02:00
parent fd26d9d58d
commit ba10ca0ecc
3 changed files with 13 additions and 10 deletions

View file

@ -118,6 +118,15 @@ public class OsmAndFormatter {
return fixed2.format(((float) meters) / mainUnitInMeters) + " " + ctx.getString(mainUnitStr);
}
}
public static String getFormattedAlarmInfoDistance(OsmandApplication app, float meters) {
boolean kmAndMeters = app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS;
int mainUnitStr = kmAndMeters ? R.string.km : R.string.mile;
float mainUnitInMeters = kmAndMeters ? METERS_IN_KILOMETER : METERS_IN_ONE_MILE;
DecimalFormat df = new DecimalFormat("#.#");
return df.format(meters / mainUnitInMeters) + " " + app.getString(mainUnitStr);
}
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
return getFormattedDistance(meters, ctx, true);

View file

@ -208,7 +208,7 @@ public class WaypointHelper {
AlarmInfo inf = new AlarmInfo(AlarmInfoType.TUNNEL, 0);
int d = route.getDistanceToPoint(segments.get(0).getStartPointIndex());
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
inf.setFloatValue(calculateDistance(segments, mc));
inf.setFloatValue(calculateDistance(segments));
int vl = inf.updateDistanceAndGetPriority(time, d);
if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
mostImportant = inf;
@ -217,16 +217,12 @@ public class WaypointHelper {
return mostImportant;
}
private float calculateDistance(List<RouteSegmentResult> segments, MetricsConstants mc) {
private float calculateDistance(List<RouteSegmentResult> segments) {
float sum = 0f;
for (RouteSegmentResult r : segments) {
sum += r.getDistance();
}
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
return sum / 1000f;
} else {
return sum * 0.00062137f;
}
return sum;
}
public void enableWaypointType(int type, boolean enable) {

View file

@ -1274,14 +1274,12 @@ public class RouteInfoWidgetsFactory {
locimgId = R.drawable.warnings_pedestrian;
}
} else if(alarm.getType() == AlarmInfoType.TUNNEL) {
DecimalFormat df = new DecimalFormat("#.#");
if(settings.DRIVING_REGION.get().americanSigns){
locimgId = R.drawable.warnings_tunnel_us;
text = df.format(alarm.getFloatValue()) +" mi";
} else {
locimgId = R.drawable.warnings_tunnel;
text = df.format(alarm.getFloatValue()) +" km";
}
text = OsmAndFormatter.getFormattedAlarmInfoDistance(settings.getContext(), alarm.getFloatValue());
} else {
text = null;
}