Merge pull request #6584 from osmandapp/issues_fixes_2

Issues fixes 2
This commit is contained in:
Alexey 2019-02-27 14:15:54 +03:00 committed by GitHub
commit 581cdaa4c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 75 additions and 25 deletions

View file

@ -596,6 +596,41 @@ public class Algorithms {
return false;
}
public static boolean isInt(String value) {
int length = value.length();
for (int i = 0; i < length; i++) {
char ch = value.charAt(i);
if (!Character.isDigit(ch)) {
if (length == 1 || i > 0 || ch != '-') {
return false;
}
}
}
return true;
}
public static boolean isFloat(String value) {
int pointsCount = 0;
int length = value.length();
for (int i = 0; i < length; i++) {
char ch = value.charAt(i);
if (!Character.isDigit(ch)) {
if (length < 2) {
return false;
}
if (!(ch == '-' || ch == '.')) {
return false;
} else if (ch == '-' && i != 0) {
return false;
} else if ((ch == '.' && pointsCount >= 1) || (ch == '.' && i == length - 1)) {
return false;
} else if (ch == '.') {
pointsCount++;
}
}
}
return pointsCount == 1;
}
public static String formatDuration(int seconds, boolean fullForm) {
String sec;

View file

@ -2896,8 +2896,8 @@
<string name="quick_action_take_photo_note">New photo note</string>
<string name="quick_action_add_osm_bug">Add OSM Note</string>
<string name="quick_action_navigation_voice">Voice on/off</string>
<string name="quick_action_navigation_voice_off">Voice is off</string>
<string name="quick_action_navigation_voice_on">Voice is on</string>
<string name="quick_action_navigation_voice_off">Unmute Voice</string>
<string name="quick_action_navigation_voice_on">Mute Voice</string>
<string name="quick_action_add_gpx">Add GPX waypoint</string>
<string name="quick_action_add_parking">Add parking place</string>
<string name="quick_action_new_action">Add action</string>

View file

@ -384,7 +384,6 @@ public class AmenityMenuBuilder extends MenuBuilder {
String poiTypeKeyName = "";
PoiType poiType = amenity.getType().getPoiTypeByKeyName(key);
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) {
pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl);
@ -527,7 +526,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
}
String[] formattedPrefixAndText = getFormattedPrefixAndText(key, textPrefix, vl);
String[] formattedPrefixAndText = getFormattedPrefixAndText(key, textPrefix, vl, amenity);
textPrefix = formattedPrefixAndText[0];
vl = formattedPrefixAndText[1];
@ -684,7 +683,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
}
private String[] getFormattedPrefixAndText(String key, String prefix, String value) {
private String[] getFormattedPrefixAndText(String key, String prefix, String value, Amenity amenity) {
DF.setRoundingMode(RoundingMode.CEILING);
String formattedValue = "";
String formattedPrefix = "";
@ -698,36 +697,51 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
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);
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))
+ " " + 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());
if(Algorithms.isFloat(value)) {
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;
}
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.distance));
break;
case "capacity":
formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
if (amenity.getSubType().equals("water_tower") || amenity.getSubType().equals("storage_tank")) {
if(Algorithms.isFloat(value)) {
formattedValue = value + " " + mapActivity.getResources().getString(R.string.cubic_m);
}
}
break;
case "maxweight":
formattedValue = value + " " + mapActivity.getResources().getString(R.string.metric_ton);
if(Algorithms.isInt(value)) {
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));
if(Algorithms.isInt(value)) {
formattedPrefix = formatPrefix(prefix, mapActivity.getResources().getString(R.string.shared_string_capacity));
}
break;
default:
formattedValue = value;

View file

@ -150,6 +150,7 @@ public class WptPtMenuBuilder extends MenuBuilder {
public void onClick(View v) {
LatLon latLon = new LatLon(point.getLatitude(), point.getLongitude());
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, point.name);
mapActivity.getContextMenu().setCenterMarker(true);
mapActivity.getContextMenu().show(latLon, pointDescription, point);
}
});

View file

@ -53,6 +53,6 @@ public class NavVoiceAction extends QuickAction {
@Override
public boolean isActionWithSlash(OsmandApplication application) {
return application.getSettings().VOICE_MUTE.get();
return !application.getSettings().VOICE_MUTE.get();
}
}