Merge pull request #6474 from osmandapp/issue_6383

Issue 6383
This commit is contained in:
Alexey 2019-01-28 17:53:57 +03:00 committed by GitHub
commit 66a035bfb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 4 deletions

View file

@ -10,6 +10,11 @@
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience - For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
Thx - Hardy Thx - Hardy
--> -->
<string name="cubic_m"></string>
<string name="metric_ton">t</string>
<string name="shared_string_capacity">Сapacity</string>
<string name="shared_string_width">Width</string>
<string name="shared_string_height">Height</string>
<string name="swap_start_and_destination">Swap start and destination</string> <string name="swap_start_and_destination">Swap start and destination</string>
<string name="add_destination_point">Add destination</string> <string name="add_destination_point">Add destination</string>
<string name="add_intermediate_point">Add intermediate</string> <string name="add_intermediate_point">Add intermediate</string>

View file

@ -21,15 +21,15 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes; 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.OsmandPlugin; import net.osmand.plus.*;
import net.osmand.plus.R; import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.Version;
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;
@ -42,7 +42,9 @@ import net.osmand.plus.wikipedia.WikipediaArticleWikiLinkFragment;
import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser; import net.osmand.util.OpeningHoursParser;
import org.apache.commons.logging.Log;
import java.math.RoundingMode;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols; import java.text.DecimalFormatSymbols;
import java.util.ArrayList; import java.util.ArrayList;
@ -59,13 +61,17 @@ import java.util.Map;
public class AmenityMenuBuilder extends MenuBuilder { public class AmenityMenuBuilder extends MenuBuilder {
private static final String WIKI_LINK = ".wikipedia.org/w"; private static final String WIKI_LINK = ".wikipedia.org/w";
public final static Log LOG = PlatformUtil.getLog(AmenityMenuBuilder.class);
private final static DecimalFormat DF = new DecimalFormat("#.##");
private OsmandSettings.MetricsConstants metricSystem;
private final Amenity amenity; private final Amenity amenity;
public AmenityMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull Amenity amenity) { public AmenityMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull Amenity amenity) {
super(mapActivity); super(mapActivity);
this.amenity = amenity; this.amenity = amenity;
setShowNearestWiki(true, amenity.getId()); setShowNearestWiki(true, amenity.getId());
metricSystem = mapActivity.getMyApplication().getSettings().METRIC_SYSTEM.get();
} }
@Override @Override
@ -521,6 +527,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
} }
} }
String[] formattedPrefixAndText = getFormattedPrefixAndText(key, textPrefix, vl);
textPrefix = formattedPrefixAndText[0];
vl = formattedPrefixAndText[1];
boolean matchWidthDivider = !isDescription && isWiki; boolean matchWidthDivider = !isDescription && isWiki;
AmenityInfoRow row; AmenityInfoRow row;
if (isDescription) { if (isDescription) {
@ -674,6 +684,62 @@ public class AmenityMenuBuilder extends MenuBuilder {
} }
} }
private String[] getFormattedPrefixAndText(String key, String prefix, String value) {
DF.setRoundingMode(RoundingMode.CEILING);
String formattedValue = "";
String formattedPrefix = "";
switch (key) {
case "width":
case "height":
if (key.equals("width")) {
formattedPrefix = mapActivity.getResources().getString(R.string.shared_string_width);
} else {
formattedPrefix = mapActivity.getResources().getString(R.string.shared_string_height);
}
case "depth":
case "seamark_height":
double valueAsDouble = Double.valueOf(value);
if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_FEET) {
formattedValue = String.valueOf(DF.format(valueAsDouble * OsmAndFormatter.FEET_IN_ONE_METER))
+ " " + mapActivity.getResources().getString(R.string.foot);
} else if (metricSystem == OsmandSettings.MetricsConstants.MILES_AND_YARDS) {
formattedValue = String.valueOf(DF.format(valueAsDouble * OsmAndFormatter.YARDS_IN_ONE_METER))
+ " " + mapActivity.getResources().getString(R.string.yard);
} else {
formattedValue = value + " " + mapActivity.getResources().getString(R.string.m);
}
break;
case "distance":
float valueAsFloatInMeters = Float.parseFloat(value) * 1000;
if (metricSystem == MetricsConstants.KILOMETERS_AND_METERS) {
formattedValue = value + " " + mapActivity.getResources().getString(R.string.km);
} else {
formattedValue = OsmAndFormatter.getFormattedDistance(valueAsFloatInMeters, mapActivity.getMyApplication());
}
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.distance));
break;
case "capacity":
formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
break;
case "maxweight":
formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton);
break;
case "students":
case "spots":
case "seats":
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.shared_string_capacity));
break;
default:
formattedValue = value;
formattedPrefix = prefix;
}
return new String[]{formattedPrefix, formattedValue};
}
private String formatPrefix(String prefix, String units) {
return (!prefix.isEmpty()) ? (prefix + ", " + units): units;
}
public void buildAmenityRow(View view, AmenityInfoRow info) { public void buildAmenityRow(View view, AmenityInfoRow info) {
if (info.icon != null) { if (info.icon != null) {
buildRow(view, info.icon, info.text, info.textPrefix, info.collapsable, info.collapsableView, buildRow(view, info.icon, info.text, info.textPrefix, info.collapsable, info.collapsableView,