Fix #8120
This commit is contained in:
parent
e95aa4483b
commit
fbccdfd659
3 changed files with 64 additions and 11 deletions
|
@ -1,13 +1,11 @@
|
||||||
package net.osmand.plus;
|
package net.osmand.plus;
|
||||||
|
|
||||||
import static net.osmand.data.PointDescription.getLocationOlcName;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
|
|
||||||
import com.jwetherell.openmap.common.LatLonPoint;
|
import com.jwetherell.openmap.common.LatLonPoint;
|
||||||
import com.jwetherell.openmap.common.UTMPoint;
|
import com.jwetherell.openmap.common.UTMPoint;
|
||||||
import java.text.DecimalFormatSymbols;
|
|
||||||
import net.osmand.LocationConvert;
|
import net.osmand.LocationConvert;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.City.CityType;
|
import net.osmand.data.City.CityType;
|
||||||
|
@ -22,12 +20,17 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.text.DateFormatSymbols;
|
import java.text.DateFormatSymbols;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.DecimalFormatSymbols;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import static net.osmand.data.PointDescription.getLocationOlcName;
|
||||||
|
|
||||||
public class OsmAndFormatter {
|
public class OsmAndFormatter {
|
||||||
public final static float METERS_IN_KILOMETER = 1000f;
|
public final static float METERS_IN_KILOMETER = 1000f;
|
||||||
public final static float METERS_IN_ONE_MILE = 1609.344f; // 1609.344
|
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) {
|
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 format1 = forceTrailingZeros ? "{0,number,0.0} " : "{0,number,0.#} ";
|
||||||
String format2 = forceTrailingZeros ? "{0,number,0.00} " : "{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;
|
int mainUnitStr;
|
||||||
float mainUnitInMeters;
|
float mainUnitInMeters;
|
||||||
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
|
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) {
|
public static String getFormattedAlt(double alt, OsmandApplication ctx) {
|
||||||
OsmandSettings settings = ctx.getSettings();
|
OsmandSettings settings = ctx.getSettings();
|
||||||
MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
MetricsConstants mc = settings.METRIC_SYSTEM.get();
|
||||||
|
|
|
@ -44,6 +44,7 @@ import net.osmand.osm.PoiCategory;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
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) {
|
protected void buildButtonRow(final View view, Drawable buttonIcon, String text, OnClickListener onClickListener) {
|
||||||
LinearLayout ll = new LinearLayout(view.getContext());
|
LinearLayout ll = new LinearLayout(view.getContext());
|
||||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||||
|
|
|
@ -426,8 +426,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
} else if (Amenity.COLLECTION_TIMES.equals(key) || Amenity.SERVICE_TIMES.equals(key)) {
|
} else if (Amenity.COLLECTION_TIMES.equals(key) || Amenity.SERVICE_TIMES.equals(key)) {
|
||||||
iconId = R.drawable.ic_action_time;
|
iconId = R.drawable.ic_action_time;
|
||||||
needLinks = false;
|
needLinks = false;
|
||||||
} else if (Amenity.OPENING_HOURS.equals(key) ||
|
} else if (Amenity.OPENING_HOURS.equals(key)) {
|
||||||
Amenity.COLLECTION_TIMES.equals(key) || Amenity.SERVICE_TIMES.equals(key)) {
|
|
||||||
iconId = R.drawable.ic_action_time;
|
iconId = R.drawable.ic_action_time;
|
||||||
collapsableView = getCollapsableTextView(view.getContext(), true,
|
collapsableView = getCollapsableTextView(view.getContext(), true,
|
||||||
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
|
amenity.getAdditionalInfo(key).replace("; ", "\n").replace(",", ", "));
|
||||||
|
@ -526,6 +525,19 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
textPrefix = formattedPrefixAndText[0];
|
textPrefix = formattedPrefixAndText[0];
|
||||||
vl = formattedPrefixAndText[1];
|
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;
|
boolean matchWidthDivider = !isDescription && isWiki;
|
||||||
AmenityInfoRow row;
|
AmenityInfoRow row;
|
||||||
if (isDescription) {
|
if (isDescription) {
|
||||||
|
@ -565,8 +577,8 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
Drawable icon;
|
Drawable icon;
|
||||||
PoiType pType = categoryTypes.get(0);
|
PoiType pType = categoryTypes.get(0);
|
||||||
String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
|
String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
|
||||||
String poiAddidionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
|
String poiAdditionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
|
||||||
icon = getRowIcon(view.getContext(), poiAddidionalIconName);
|
icon = getRowIcon(view.getContext(), poiAdditionalIconName);
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
|
icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
|
||||||
}
|
}
|
||||||
|
@ -627,7 +639,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
AmenityInfoRow descInPrefLang = null;
|
AmenityInfoRow descInPrefLang = null;
|
||||||
for (AmenityInfoRow desc : descriptions) {
|
for (AmenityInfoRow desc : descriptions) {
|
||||||
if (desc.key.length() > langSuffix.length()
|
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;
|
descInPrefLang = desc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -690,7 +702,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
||||||
}
|
}
|
||||||
case "depth":
|
case "depth":
|
||||||
case "seamark_height":
|
case "seamark_height":
|
||||||
if(Algorithms.isFloat(value)) {
|
if (Algorithms.isFloat(value)) {
|
||||||
double valueAsDouble = Double.valueOf(value);
|
double valueAsDouble = Double.valueOf(value);
|
||||||
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
|
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
|
||||||
formattedValue = String.valueOf(DF.format(valueAsDouble * OsmAndFormatter.FEET_IN_ONE_METER))
|
formattedValue = String.valueOf(DF.format(valueAsDouble * OsmAndFormatter.FEET_IN_ONE_METER))
|
||||||
|
|
Loading…
Reference in a new issue