From f6e5f78a239737a68a28827da378565944c3ff72 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 9 Oct 2014 18:48:16 +0300 Subject: [PATCH] Added setting to set speed limit --- OsmAnd/res/values/strings.xml | 2 ++ OsmAnd/res/xml/navigation_settings.xml | 4 ++++ .../src/net/osmand/plus/OsmandSettings.java | 3 +++ .../SettingsNavigationActivity.java | 24 ++++++++++++++++++- .../osmand/plus/helpers/WaypointHelper.java | 9 +++---- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index f1ac4b49c9..70083edd41 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 --> + Speed limit exceed value. + Select speed limit exceed value on which you will get voice announcement. We changed your favorite point name to %1$s because it is not possible to save string with emoticons to file. Print route Test native render diff --git a/OsmAnd/res/xml/navigation_settings.xml b/OsmAnd/res/xml/navigation_settings.xml index 375e595b88..0465fdef44 100644 --- a/OsmAnd/res/xml/navigation_settings.xml +++ b/OsmAnd/res/xml/navigation_settings.xml @@ -23,6 +23,10 @@ android:key="arrival_distance_factor" android:title="@string/arrival_distance" android:summary="@string/arrival_distance_descr" /> + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 74cf9d1108..16ab3362a0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -675,6 +675,9 @@ public class OsmandSettings { public final OsmandPreference ARRIVAL_DISTANCE_FACTOR = new FloatPreference("arrival_distance_factor", 1f).makeProfile(); + public final OsmandPreference SPEED_LIMIT_EXCEED = + new FloatPreference("speed_limit_exceed", 5000f).makeProfile(); + // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference USE_TRACKBALL_FOR_MOVEMENTS = new BooleanPreference("use_trackball_for_movements", true).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index d1f03e911b..a1ae5a9551 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.AutoZoomMap; import net.osmand.plus.OsmandSettings.OsmandPreference; import net.osmand.plus.R; @@ -109,7 +110,28 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { getString(R.string.arrival_distance_factor_at_last) }; registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues); - + + Float[] speedLimits = new Float[] {5f, 7f, 10f, 15f, 20f}; + if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS){ + + String[] speedNames = new String[] { + speedLimits[0] + " " + getString(R.string.km_h), + speedLimits[1] + " " + getString(R.string.km_h), + speedLimits[2] + " " + getString(R.string.km_h), + speedLimits[3] + " " + getString(R.string.km_h), + speedLimits[4] + " " + getString(R.string.km_h)}; + registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); + } else { + String[] speedNames = new String[] { + (speedLimits[0] / 1.6) + " " + getString(R.string.mile_per_hour), + (speedLimits[1] / 1.6) + " " + getString(R.string.mile_per_hour), + (speedLimits[2] / 1.6) + " " + getString(R.string.mile_per_hour), + (speedLimits[3] / 1.6) + " " + getString(R.string.mile_per_hour), + (speedLimits[4] / 1.6) + " " + getString(R.string.mile_per_hour)}; + registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); + } + + profileDialog(); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index f0f6128230..29d429274b 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -157,7 +157,8 @@ public class WaypointHelper { public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) { Location lastProjection = app.getRoutingHelper().getLastProjection(); float mxspeed = route.getCurrentMaxSpeed(); - AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection); + float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; + AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); } @@ -246,7 +247,8 @@ public class WaypointHelper { public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) { float mxspeed = ro.getMaximumSpeed(); - AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc); + float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; + AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); return speedAlarm; @@ -275,10 +277,9 @@ public class WaypointHelper { } - private static AlarmInfo createSpeedAlarm(MetricsConstants mc, float mxspeed, Location loc) { + private static AlarmInfo createSpeedAlarm(MetricsConstants mc, float mxspeed, Location loc, float delta) { AlarmInfo speedAlarm = null; if (mxspeed != 0 && loc != null && loc.hasSpeed() && mxspeed != RouteDataObject.NONE_MAX_SPEED) { - float delta = 5f / 3.6f; if (loc.getSpeed() > mxspeed + delta) { int speed; if (mc == MetricsConstants.KILOMETERS_AND_METERS) {