Fixes on pR

This commit is contained in:
madwasp79 2019-01-28 14:22:16 +02:00
parent 88c75bf524
commit e9af81c3a5
2 changed files with 32 additions and 28 deletions

View file

@ -2424,7 +2424,11 @@
<string name="km_h">km/h</string> <string name="km_h">km/h</string>
<string name="m">m</string> <string name="m">m</string>
<string name="cubic_m"></string> <string name="cubic_m"></string>
<string name ="capacity">capacity</string> <string name="metric_ton">t</string>
<string name ="capacity">Сapacity</string>
<string name="width_label">Width</string>
<string name="height_label">Height</string>
<string name="distance_label">Distance</string>
<string name="old_map_index_is_not_supported">Deprecated map data format \'\'{0}\'\', not supported</string> <string name="old_map_index_is_not_supported">Deprecated map data format \'\'{0}\'\', not supported</string>
<string name="poi_filter_closest_poi">Nearest POIs</string> <string name="poi_filter_closest_poi">Nearest POIs</string>
<string name="poi_filter_custom_filter">Custom filter</string> <string name="poi_filter_custom_filter">Custom filter</string>

View file

@ -29,6 +29,7 @@ import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.*; import net.osmand.plus.*;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
@ -685,55 +686,54 @@ public class AmenityMenuBuilder extends MenuBuilder {
private String[] getFormattedPrefixAndText(String key, String prefix, String value) { private String[] getFormattedPrefixAndText(String key, String prefix, String value) {
DecimalFormat df = new DecimalFormat("#.##"); DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.CEILING); df.setRoundingMode(RoundingMode.CEILING);
String formattedValue = "";
switch (key) { switch (key) {
case "width": case "width":
case "height": case "height":
prefix = Algorithms.capitalizeFirstLetter(key); if (key.equals("width")) {
prefix = mapActivity.getResources().getString(R.string.width_label);
} else {
prefix = mapActivity.getResources().getString(R.string.height_label);
}
case "depth": case "depth":
case "seamark_height": case "seamark_height":
double valueAsDouble = Double.valueOf(value);
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) { if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
value = String.valueOf(df.format(Double.valueOf(value)*OsmAndFormatter.FEET_IN_ONE_METER)) formattedValue = String.valueOf(df.format(valueAsDouble * OsmAndFormatter.FEET_IN_ONE_METER))
+ " " + mapActivity.getResources().getString(R.string.foot); + " " + mapActivity.getResources().getString(R.string.foot);
} else if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_YARDS) { } else if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_YARDS) {
value = String.valueOf(df.format(Double.valueOf(value)*OsmAndFormatter.YARDS_IN_ONE_METER)) formattedValue = String.valueOf(df.format(valueAsDouble * OsmAndFormatter.YARDS_IN_ONE_METER))
+ " " + mapActivity.getResources().getString(R.string.yard); + " " + mapActivity.getResources().getString(R.string.yard);
} else { } else {
value = value + " " + mapActivity.getResources().getString(R.string.m); formattedValue = value + " " + mapActivity.getResources().getString(R.string.m);
} }
break; break;
case "distance": case "distance":
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET || float valueAsFloatInMeters = Float.parseFloat(value) * 1000;
metricSystem == OsmandSettings.MetricsConstants.MILES_AND_YARDS || if (metricSystem == MetricsConstants.KILOMETERS_AND_METERS) {
metricSystem == OsmandSettings.MetricsConstants.MILES_AND_METERS) { formattedValue = value + " " + mapActivity.getResources().getString(R.string.km);
value = String.valueOf(df.format(Double.valueOf(value)*1000/OsmAndFormatter.METERS_IN_ONE_MILE))
+ " " + mapActivity.getResources().getString(R.string.mile);
} else if (metricSystem == OsmandSettings.MetricsConstants.NAUTICAL_MILES) {
value = String.valueOf(df.format(Double.valueOf(value)*1000/OsmAndFormatter.METERS_IN_ONE_NAUTICALMILE))
+ " " + mapActivity.getResources().getString(R.string.nm);
} else { } else {
value = value + " " + mapActivity.getResources().getString(R.string.km); formattedValue = OsmAndFormatter.getFormattedDistance(valueAsFloatInMeters, mapActivity.getMyApplication());
} }
prefix = Algorithms.capitalizeFirstLetter(key); prefix = (!prefix.isEmpty()) ? (prefix + ", " + mapActivity.getResources().getString(R.string.distance))
: mapActivity.getResources().getString(R.string.distance);
break; break;
case "capacity": case "capacity":
value = value + " " + mapActivity.getResources().getString(R.string.cubic_m); formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
break; break;
case "maxweight": case "maxweight":
value = value + " " + mapActivity.getResources().getString(R.string.cubic_m); formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton);
break; break;
case "students": case "students":
case "spots": case "spots":
case "seats": case "seats":
prefix = prefixConstructor(prefix, mapActivity.getResources().getString(R.string.capacity)); prefix = (!prefix.isEmpty()) ? (prefix + ", " + mapActivity.getResources().getString(R.string.capacity))
: mapActivity.getResources().getString(R.string.capacity);
break; break;
default:
formattedValue = value;
} }
return new String[]{prefix, formattedValue};
return new String[]{prefix, value};
}
private String prefixConstructor(String prefix, String units){
return (!prefix.isEmpty()) ? (prefix + ", " + units) : Algorithms.capitalizeFirstLetter(units);
} }
public void buildAmenityRow(View view, AmenityInfoRow info) { public void buildAmenityRow(View view, AmenityInfoRow info) {