diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 0327c669f2..84fcbb11d7 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 5dbe4db73f..9e1e7c66ec 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -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 segments, MetricsConstants mc) { + private float calculateDistance(List 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) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java index 253666f7bd..5fc6bb40bc 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/RouteInfoWidgetsFactory.java @@ -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; }