This commit is contained in:
Vitaliy 2020-06-03 17:48:21 +03:00
parent 436b7e685e
commit 3a16a63520
2 changed files with 16 additions and 23 deletions

View file

@ -26,9 +26,7 @@ import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import static net.osmand.data.PointDescription.getLocationOlcName;
@ -276,27 +274,13 @@ public class OsmAndFormatter {
}
}
public static Map<MetricsConstants, String> getDistanceData(OsmandApplication app, float meters) {
Map<MetricsConstants, String> results = new LinkedHashMap<>();
String kilometersAndMeters = getFormattedDistance(meters, app, true, MetricsConstants.KILOMETERS_AND_METERS);
String milesAndFeet = getFormattedDistance(meters, app, true, MetricsConstants.MILES_AND_FEET);
String milesAndMeters = getFormattedDistance(meters, app, true, MetricsConstants.MILES_AND_METERS);
String milesAndYards = getFormattedDistance(meters, app, true, MetricsConstants.MILES_AND_YARDS);
String nauticalMiles = getFormattedDistance(meters, app, true, MetricsConstants.NAUTICAL_MILES);
results.put(MetricsConstants.KILOMETERS_AND_METERS, kilometersAndMeters);
results.put(MetricsConstants.MILES_AND_FEET, milesAndFeet);
results.put(MetricsConstants.MILES_AND_METERS, milesAndMeters);
results.put(MetricsConstants.MILES_AND_YARDS, milesAndYards);
results.put(MetricsConstants.NAUTICAL_MILES, nauticalMiles);
return results;
}
public static String getFormattedAlt(double alt, OsmandApplication ctx) {
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
return getFormattedAlt(alt, ctx, mc);
}
public static String getFormattedAlt(double alt, OsmandApplication ctx, MetricsConstants mc) {
boolean useFeet = (mc == MetricsConstants.MILES_AND_FEET) || (mc == MetricsConstants.MILES_AND_YARDS);
if (!useFeet) {
return ((int) (alt + 0.5)) + " " + ctx.getString(R.string.m);

View file

@ -58,11 +58,13 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class AmenityMenuBuilder extends MenuBuilder {
@ -529,9 +531,16 @@ public class AmenityMenuBuilder extends MenuBuilder {
if ("ele".equals(key)) {
try {
float distance = Float.parseFloat(vl);
vl = OsmAndFormatter.getFormattedDistance(distance, app, true, metricSystem);
Map<MetricsConstants, String> distanceData = OsmAndFormatter.getDistanceData(app, distance);
collapsableView = getDistanceCollapsableView(new LinkedHashSet<>(distanceData.values()));
vl = OsmAndFormatter.getFormattedAlt(distance, app, metricSystem);
String collapsibleVal;
if (metricSystem == MetricsConstants.MILES_AND_FEET || metricSystem == MetricsConstants.MILES_AND_YARDS) {
collapsibleVal = OsmAndFormatter.getFormattedAlt(distance, app, MetricsConstants.KILOMETERS_AND_METERS);
} else {
collapsibleVal = OsmAndFormatter.getFormattedAlt(distance, app, MetricsConstants.MILES_AND_FEET);
}
Set<String> elevationData = new HashSet<>();
elevationData.add(collapsibleVal);
collapsableView = getDistanceCollapsableView(elevationData);
collapsable = true;
} catch (NumberFormatException ex) {
LOG.error(ex);