Fix distance formatting for tunnel alarm info
This commit is contained in:
parent
09f9643162
commit
98eae23f6e
3 changed files with 13 additions and 10 deletions
|
@ -119,6 +119,15 @@ public class OsmAndFormatter {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue