From a5384abb1358f9ceb47294dc6a6bee7468dfffe5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 18 Aug 2016 19:55:22 +0200 Subject: [PATCH] Add Miles/meters setting and make it default --- OsmAnd/res/values/strings.xml | 2 ++ OsmAnd/src/net/osmand/plus/OsmAndFormatter.java | 15 ++++++++++++--- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 5 +++-- .../plus/download/DownloadIndexesThread.java | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 60a4811f47..3a5768f3ae 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -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 --> + + Miles/meters Skip downloading maps You have no offline map installed. You may choose a map from the list or download maps later via Menu - %1$s. Select another region diff --git a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java index 3b33103865..94d84b38e5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndFormatter.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 1448be3dd9..de9c7c095e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 0ff0fbca64..1a416a12ca 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -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) {