This commit is contained in:
Vitaliy 2020-05-18 14:43:44 +03:00
parent e95aa4483b
commit fbccdfd659
3 changed files with 64 additions and 11 deletions

View file

@ -1,13 +1,11 @@
package net.osmand.plus;
import static net.osmand.data.PointDescription.getLocationOlcName;
import android.content.Context;
import android.text.format.DateUtils;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import java.text.DecimalFormatSymbols;
import net.osmand.LocationConvert;
import net.osmand.data.Amenity;
import net.osmand.data.City.CityType;
@ -22,12 +20,17 @@ import net.osmand.util.Algorithms;
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
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;
public class OsmAndFormatter {
public final static float METERS_IN_KILOMETER = 1000f;
public final static float METERS_IN_ONE_MILE = 1609.344f; // 1609.344
@ -222,11 +225,14 @@ public class OsmAndFormatter {
}
public static String getFormattedDistance(float meters, OsmandApplication ctx, boolean forceTrailingZeros) {
MetricsConstants mc = ctx.getSettings().METRIC_SYSTEM.get();
return getFormattedDistance(meters, ctx, forceTrailingZeros, mc);
}
public static String getFormattedDistance(float meters, OsmandApplication ctx, boolean forceTrailingZeros, MetricsConstants mc) {
String format1 = forceTrailingZeros ? "{0,number,0.0} " : "{0,number,0.#} ";
String format2 = forceTrailingZeros ? "{0,number,0.00} " : "{0,number,0.##} ";
OsmandSettings settings = ctx.getSettings();
MetricsConstants mc = settings.METRIC_SYSTEM.get();
int mainUnitStr;
float mainUnitInMeters;
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
@ -268,6 +274,24 @@ 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();

View file

@ -44,6 +44,7 @@ import net.osmand.osm.PoiCategory;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -805,6 +806,22 @@ public class MenuBuilder {
}
protected CollapsableView getDistanceCollapsableView(Map<OsmandSettings.MetricsConstants, String> distanceData) {
LinearLayout llv = buildCollapsableContentView(mapActivity, true, true);
for (final Map.Entry<OsmandSettings.MetricsConstants, String> line : distanceData.entrySet()) {
TextView button = buildButtonInCollapsableView(mapActivity, false, false);
button.setText(line.getValue());
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
copyToClipboard(line.getValue(), mapActivity);
}
});
llv.addView(button);
}
return new CollapsableView(llv, this, true);
}
protected void buildButtonRow(final View view, Drawable buttonIcon, String text, OnClickListener onClickListener) {
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);

View file

@ -426,8 +426,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
} else if (Amenity.COLLECTION_TIMES.equals(key) || Amenity.SERVICE_TIMES.equals(key)) {
iconId = R.drawable.ic_action_time;
needLinks = false;
} else if (Amenity.OPENING_HOURS.equals(key) ||
Amenity.COLLECTION_TIMES.equals(key) || Amenity.SERVICE_TIMES.equals(key)) {
} else if (Amenity.OPENING_HOURS.equals(key)) {
iconId = R.drawable.ic_action_time;
collapsableView = getCollapsableTextView(view.getContext(), true,
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
@ -526,6 +525,19 @@ public class AmenityMenuBuilder extends MenuBuilder {
textPrefix = formattedPrefixAndText[0];
vl = formattedPrefixAndText[1];
if ("ele".equals(key)) {
try {
float distance = Float.parseFloat(vl);
Map<MetricsConstants, String> distanceData = OsmAndFormatter.getDistanceData(app, distance);
MetricsConstants currentFormat = app.getSettings().METRIC_SYSTEM.get();
vl = OsmAndFormatter.getFormattedDistance(distance, app, true, currentFormat);
collapsableView = getDistanceCollapsableView(distanceData);
collapsable = true;
} catch (NumberFormatException ex) {
LOG.error(ex);
}
}
boolean matchWidthDivider = !isDescription && isWiki;
AmenityInfoRow row;
if (isDescription) {
@ -565,8 +577,8 @@ public class AmenityMenuBuilder extends MenuBuilder {
Drawable icon;
PoiType pType = categoryTypes.get(0);
String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
String poiAddidionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
icon = getRowIcon(view.getContext(), poiAddidionalIconName);
String poiAdditionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
icon = getRowIcon(view.getContext(), poiAdditionalIconName);
if (icon == null) {
icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
}
@ -627,7 +639,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
AmenityInfoRow descInPrefLang = null;
for (AmenityInfoRow desc : descriptions) {
if (desc.key.length() > langSuffix.length()
&& desc.key.substring(desc.key.length() - langSuffix.length(), desc.key.length()).equals(langSuffix)) {
&& desc.key.substring(desc.key.length() - langSuffix.length()).equals(langSuffix)) {
descInPrefLang = desc;
break;
}
@ -690,7 +702,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
case "depth":
case "seamark_height":
if(Algorithms.isFloat(value)) {
if (Algorithms.isFloat(value)) {
double valueAsDouble = Double.valueOf(value);
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
formattedValue = String.valueOf(DF.format(valueAsDouble * OsmAndFormatter.FEET_IN_ONE_METER))