Add Miles/meters setting and make it default

This commit is contained in:
Victor Shcherb 2016-08-18 19:55:22 +02:00
parent 1003031f5c
commit a5384abb13
4 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="si_mi_meters">Miles/meters</string>
<string name="skip_map_downloading">Skip downloading maps</string>
<string name="skip_map_downloading_desc">You have no offline map installed. You may choose a map from the list or download maps later via Menu - %1$s.</string>
<string name="search_another_country">Select another region</string>

View file

@ -39,6 +39,9 @@ public class OsmAndFormatter {
if (mc == MetricsConstants.MILES_AND_FOOTS) {
mainUnitInMeter = FOOTS_IN_ONE_METER;
metersInSecondUnit = METERS_IN_ONE_MILE;
} else if (mc == MetricsConstants.MILES_AND_METERS) {
mainUnitInMeter = 1;
metersInSecondUnit = METERS_IN_ONE_MILE;
} else if (mc == MetricsConstants.NAUTICAL_MILES) {
mainUnitInMeter = 1;
metersInSecondUnit = METERS_IN_ONE_NAUTICALMILE;
@ -66,8 +69,12 @@ public class OsmAndFormatter {
pointer = 1;
}
}
//Miles exceptions: 2000ft->0.5mi, 1000ft->0.25mi, 1000yd->0.5mi, 500yd->0.25mi
if (mc == MetricsConstants.MILES_AND_FOOTS && roundDist == 2000 / (double) FOOTS_IN_ONE_METER) {
//Miles exceptions: 2000ft->0.5mi, 1000ft->0.25mi, 1000yd->0.5mi, 500yd->0.25mi, 1000m ->0.5mi, 500m -> 0.3mi
if (mc == MetricsConstants.MILES_AND_METERS && roundDist == 500) {
roundDist = 0.5f * METERS_IN_ONE_MILE;
} else if (mc == MetricsConstants.MILES_AND_METERS && roundDist == 500) {
roundDist = 0.3f * METERS_IN_ONE_MILE;
} else if (mc == MetricsConstants.MILES_AND_FOOTS && roundDist == 2000 / (double) FOOTS_IN_ONE_METER) {
roundDist = 0.5f * METERS_IN_ONE_MILE;
} else if (mc == MetricsConstants.MILES_AND_FOOTS && roundDist == 1000 / (double) FOOTS_IN_ONE_METER) {
roundDist = 0.25f * METERS_IN_ONE_MILE;
@ -115,12 +122,14 @@ public class OsmAndFormatter {
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
} else if (mc == MetricsConstants.MILES_AND_FOOTS && meters > 0.249f * mainUnitInMeters) {
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
} else if (mc == MetricsConstants.MILES_AND_METERS && meters > 0.499f * mainUnitInMeters) {
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
} else if (mc == MetricsConstants.MILES_AND_YARDS && meters > 0.249f * mainUnitInMeters) {
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
} else if (mc == MetricsConstants.NAUTICAL_MILES && meters > 0.99f * mainUnitInMeters) {
return MessageFormat.format("{0,number,#.##} " + ctx.getString(mainUnitStr), ((float) meters) / mainUnitInMeters).replace('\n', ' '); //$NON-NLS-1$
} else {
if (mc == MetricsConstants.KILOMETERS_AND_METERS) {
if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
return ((int) (meters + 0.5)) + " " + ctx.getString(R.string.m); //$NON-NLS-1$
} else if (mc == MetricsConstants.MILES_AND_FOOTS) {
int foots = (int) (meters * FOOTS_IN_ONE_METER + 0.5);

View file

@ -2882,6 +2882,7 @@ public class OsmandSettings {
public enum MetricsConstants {
KILOMETERS_AND_METERS(R.string.si_km_m, "km-m"),
MILES_AND_METERS(R.string.si_mi_meters, "mi-m"),
MILES_AND_FOOTS(R.string.si_mi_foots, "mi-f"),
NAUTICAL_MILES(R.string.si_nm, "nm"),
MILES_AND_YARDS(R.string.si_mi_yard, "mi-y");
@ -2928,9 +2929,9 @@ public class OsmandSettings {
public enum DrivingRegion {
EUROPE_ASIA(R.string.driving_region_europe_asia, MetricsConstants.KILOMETERS_AND_METERS, false, false),
US(R.string.driving_region_us, MetricsConstants.MILES_AND_FOOTS, false, true),
US(R.string.driving_region_us, MetricsConstants.MILES_AND_METERS, false, true),
CANADA(R.string.driving_region_canada, MetricsConstants.KILOMETERS_AND_METERS, false, true),
UK_AND_OTHERS(R.string.driving_region_uk, MetricsConstants.MILES_AND_FOOTS, true, false),
UK_AND_OTHERS(R.string.driving_region_uk, MetricsConstants.MILES_AND_METERS, true, false),
JAPAN(R.string.driving_region_japan, MetricsConstants.KILOMETERS_AND_METERS, true, false);
public final boolean leftHandDriving;

View file

@ -165,7 +165,7 @@ public class DownloadIndexesThread {
boolean americanSigns = "american".equals(params.getRegionRoadSigns());
boolean leftHand = "yes".equals(params.getRegionLeftHandDriving());
MetricsConstants mc = "miles".equals(params.getRegionMetric()) ?
MetricsConstants.MILES_AND_FOOTS : MetricsConstants.KILOMETERS_AND_METERS;
MetricsConstants.MILES_AND_METERS : MetricsConstants.KILOMETERS_AND_METERS;
for (DrivingRegion r : DrivingRegion.values()) {
if (r.americanSigns == americanSigns && r.leftHandDriving == leftHand &&
r.defMetrics == mc) {