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
|
@ -118,6 +118,15 @@ public class OsmAndFormatter {
|
||||||
return fixed2.format(((float) meters) / mainUnitInMeters) + " " + ctx.getString(mainUnitStr);
|
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) {
|
public static String getFormattedDistance(float meters, OsmandApplication ctx) {
|
||||||
return getFormattedDistance(meters, ctx, true);
|
return getFormattedDistance(meters, ctx, true);
|
||||||
|
|
|
@ -208,7 +208,7 @@ public class WaypointHelper {
|
||||||
AlarmInfo inf = new AlarmInfo(AlarmInfoType.TUNNEL, 0);
|
AlarmInfo inf = new AlarmInfo(AlarmInfoType.TUNNEL, 0);
|
||||||
int d = route.getDistanceToPoint(segments.get(0).getStartPointIndex());
|
int d = route.getDistanceToPoint(segments.get(0).getStartPointIndex());
|
||||||
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
|
float time = speed > 0 ? d / speed : Integer.MAX_VALUE;
|
||||||
inf.setFloatValue(calculateDistance(segments, mc));
|
inf.setFloatValue(calculateDistance(segments));
|
||||||
int vl = inf.updateDistanceAndGetPriority(time, d);
|
int vl = inf.updateDistanceAndGetPriority(time, d);
|
||||||
if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
|
if (vl < value && (showCameras || inf.getType() != AlarmInfoType.SPEED_CAMERA)) {
|
||||||
mostImportant = inf;
|
mostImportant = inf;
|
||||||
|
@ -217,16 +217,12 @@ public class WaypointHelper {
|
||||||
return mostImportant;
|
return mostImportant;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calculateDistance(List<RouteSegmentResult> segments, MetricsConstants mc) {
|
private float calculateDistance(List<RouteSegmentResult> segments) {
|
||||||
float sum = 0f;
|
float sum = 0f;
|
||||||
for (RouteSegmentResult r : segments) {
|
for (RouteSegmentResult r : segments) {
|
||||||
sum += r.getDistance();
|
sum += r.getDistance();
|
||||||
}
|
}
|
||||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
return sum;
|
||||||
return sum / 1000f;
|
|
||||||
} else {
|
|
||||||
return sum * 0.00062137f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableWaypointType(int type, boolean enable) {
|
public void enableWaypointType(int type, boolean enable) {
|
||||||
|
|
|
@ -1274,14 +1274,12 @@ public class RouteInfoWidgetsFactory {
|
||||||
locimgId = R.drawable.warnings_pedestrian;
|
locimgId = R.drawable.warnings_pedestrian;
|
||||||
}
|
}
|
||||||
} else if(alarm.getType() == AlarmInfoType.TUNNEL) {
|
} else if(alarm.getType() == AlarmInfoType.TUNNEL) {
|
||||||
DecimalFormat df = new DecimalFormat("#.#");
|
|
||||||
if(settings.DRIVING_REGION.get().americanSigns){
|
if(settings.DRIVING_REGION.get().americanSigns){
|
||||||
locimgId = R.drawable.warnings_tunnel_us;
|
locimgId = R.drawable.warnings_tunnel_us;
|
||||||
text = df.format(alarm.getFloatValue()) +" mi";
|
|
||||||
} else {
|
} else {
|
||||||
locimgId = R.drawable.warnings_tunnel;
|
locimgId = R.drawable.warnings_tunnel;
|
||||||
text = df.format(alarm.getFloatValue()) +" km";
|
|
||||||
}
|
}
|
||||||
|
text = OsmAndFormatter.getFormattedAlarmInfoDistance(settings.getContext(), alarm.getFloatValue());
|
||||||
} else {
|
} else {
|
||||||
text = null;
|
text = null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue