From 98eae23f6e09eeb3d7c4c8360bba86123e4fe8d4 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 5 Feb 2018 18:30:22 +0200 Subject: [PATCH] Fix distance formatting for tunnel alarm info --- OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 9 +++++++++ OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java | 10 +++------- .../plus/views/mapwidgets/RouteInfoWidgetsFactory.java | 4 +--- 3 files changed, 13 insertions(+), 10 deletions(-) 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; }