From f6e5f78a239737a68a28827da378565944c3ff72 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 9 Oct 2014 18:48:16 +0300 Subject: [PATCH 1/8] 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) { From 54fbf15ea270490d849a1b45c75921171c666a32 Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 9 Oct 2014 19:47:08 +0300 Subject: [PATCH 2/8] Fixed wrong menu opening on menu hardware button --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index a8edaea6f8..d6a03cb0ab 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -466,7 +466,7 @@ public class MapActivity extends AccessibleActivity { } return true; } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) { - mapActions.openOptionsMenuAsList(); + mapActions.openOptionsMenuAsDrawer(); return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization().getSearchActivity()); From 45f266b1bccb5c9bd7e8fc3a9bc28be1be9895ad Mon Sep 17 00:00:00 2001 From: Denis Date: Thu, 9 Oct 2014 21:29:42 +0300 Subject: [PATCH 3/8] Updated to delta of speed exceed limit --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 2 +- .../activities/SettingsNavigationActivity.java | 10 +++++----- .../net/osmand/plus/helpers/WaypointHelper.java | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 16ab3362a0..0383c1a0f4 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -676,7 +676,7 @@ public class OsmandSettings { new FloatPreference("arrival_distance_factor", 1f).makeProfile(); public final OsmandPreference SPEED_LIMIT_EXCEED = - new FloatPreference("speed_limit_exceed", 5000f).makeProfile(); + new FloatPreference("speed_limit_exceed", 5f).makeProfile(); // this value string is synchronized with settings_pref.xml preference name public final OsmandPreference USE_TRACKBALL_FOR_MOVEMENTS = diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index a1ae5a9551..b0826dd6d2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -123,11 +123,11 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { 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)}; + speedLimits[0] + " " + getString(R.string.mile_per_hour), + speedLimits[1] + " " + getString(R.string.mile_per_hour), + speedLimits[2] + " " + getString(R.string.mile_per_hour), + speedLimits[3] + " " + getString(R.string.mile_per_hour), + speedLimits[4] + " " + getString(R.string.mile_per_hour)}; registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 29d429274b..888ce601e1 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -157,7 +157,12 @@ public class WaypointHelper { public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) { Location lastProjection = app.getRoutingHelper().getLastProjection(); float mxspeed = route.getCurrentMaxSpeed(); - float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; + float delta; + if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ + delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); + } else { + delta = app.getSettings().SPEED_LIMIT_EXCEED.get() * 1.6f; + } AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); @@ -247,7 +252,12 @@ public class WaypointHelper { public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) { float mxspeed = ro.getMaximumSpeed(); - float delta = app.getSettings().SPEED_LIMIT_EXCEED.get() / 3.6f; + float delta; + if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ + delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); + } else { + delta = app.getSettings().SPEED_LIMIT_EXCEED.get() * 1.6f; + } AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); From 90b4c7f8f708597cf5f67247f17b9bd92bf9bbe1 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 10 Oct 2014 12:06:14 +0300 Subject: [PATCH 4/8] Speed limit exceed setting will be shown for car and other simular mods. --- .../SettingsNavigationActivity.java | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index b0826dd6d2..0113f32147 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -111,27 +111,29 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { }; 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){ + ApplicationMode mode = getMyApplication().getSettings().getApplicationMode(); + if (mode == ApplicationMode.CAR || mode == ApplicationMode.TRUCK || mode == ApplicationMode.MOTORCYCLE){ + 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] + " " + getString(R.string.mile_per_hour), - speedLimits[1] + " " + getString(R.string.mile_per_hour), - speedLimits[2] + " " + getString(R.string.mile_per_hour), - speedLimits[3] + " " + getString(R.string.mile_per_hour), - speedLimits[4] + " " + getString(R.string.mile_per_hour)}; - registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); + 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] + " " + getString(R.string.mile_per_hour), + speedLimits[1] + " " + getString(R.string.mile_per_hour), + speedLimits[2] + " " + getString(R.string.mile_per_hour), + speedLimits[3] + " " + getString(R.string.mile_per_hour), + speedLimits[4] + " " + getString(R.string.mile_per_hour)}; + registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); + } } - profileDialog(); } From 3863a864aa907faa42839dc2ee947e3a239023d4 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 10 Oct 2014 12:47:33 +0300 Subject: [PATCH 5/8] Fixed issue with drawer not showing when swype from left side first time --- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 4 +++- .../net/osmand/plus/activities/MapActivityActions.java | 8 +++++--- .../net/osmand/plus/views/controls/MapMenuControls.java | 2 +- .../osmand/plus/views/controls/SmallMapMenuControls.java | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index d6a03cb0ab..c048728991 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -213,6 +213,8 @@ public class MapActivity extends AccessibleActivity { ((FrameLayout)mapView.getParent()).addView(lockView); } gpxImportHelper = new GpxImportHelper(this, getMyApplication(), getMapView()); + + mapActions.createOptionsMenuAsDrawer(false); } public void addLockView(FrameLayout lockView) { @@ -466,7 +468,7 @@ public class MapActivity extends AccessibleActivity { } return true; } else if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0) { - mapActions.openOptionsMenuAsDrawer(); + mapActions.createOptionsMenuAsDrawer(true); return true; } else if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { Intent newIntent = new Intent(MapActivity.this, getMyApplication().getAppCustomization().getSearchActivity()); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 0a4ebf7ee8..689bd1a111 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -723,12 +723,12 @@ public class MapActivityActions implements DialogProvider { } } - public void openOptionsMenuAsDrawer(){ + public void createOptionsMenuAsDrawer(boolean show){ final ContextMenuAdapter cm = createOptionsMenu(); final DrawerLayout mDrawerLayout = (DrawerLayout) mapActivity.findViewById(R.id.drawer_layout); final ListView mDrawerList = (ListView) mapActivity.findViewById(R.id.left_drawer); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); - ListAdapter listAdapter ; + ListAdapter listAdapter; if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){ listAdapter = cm.createListAdapter(mapActivity, R.layout.list_menu_item, getMyApplication().getSettings().isLightContentMenu()); @@ -755,7 +755,9 @@ public class MapActivityActions implements DialogProvider { } }); - mDrawerLayout.openDrawer(mDrawerList); + if (show){ + mDrawerLayout.openDrawer(mDrawerList); + } } public AlertDialog openOptionsMenuAsList() { diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java b/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java index c4ce14bcc3..10d7b16356 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapMenuControls.java @@ -39,7 +39,7 @@ public class MapMenuControls extends MapControls { // double lat = activity.getMapView().getLatitude(); // double lon = activity.getMapView().getLongitude(); // MainMenuActivity.backToMainMenuDialog(activity, new LatLon(lat, lon)); - mapActivity.getMapActions().openOptionsMenuAsDrawer(); + mapActivity.getMapActions().createOptionsMenuAsDrawer(true); notifyClicked(); } }); diff --git a/OsmAnd/src/net/osmand/plus/views/controls/SmallMapMenuControls.java b/OsmAnd/src/net/osmand/plus/views/controls/SmallMapMenuControls.java index aa8c7b1ed0..e671bb3617 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/SmallMapMenuControls.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/SmallMapMenuControls.java @@ -27,7 +27,7 @@ public class SmallMapMenuControls extends MapControls { public void onClick(View v) { notifyClicked(); //mapActivity.getMapActions().openOptionsMenuAsDrawer(); - mapActivity.getMapActions().openOptionsMenuAsDrawer(); + mapActivity.getMapActions().createOptionsMenuAsDrawer(true); } }); } From bf288499e70e32e0084150540ebca8a0c0d1c8e2 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 10 Oct 2014 12:57:55 +0300 Subject: [PATCH 6/8] Added different speed limit for miles --- OsmAnd/src/net/osmand/plus/OsmandSettings.java | 5 ++++- .../plus/activities/SettingsNavigationActivity.java | 9 +++++---- OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java | 8 ++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 0383c1a0f4..e52cac68f4 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -675,9 +675,12 @@ public class OsmandSettings { public final OsmandPreference ARRIVAL_DISTANCE_FACTOR = new FloatPreference("arrival_distance_factor", 1f).makeProfile(); - public final OsmandPreference SPEED_LIMIT_EXCEED = + public final OsmandPreference SPEED_LIMIT_EXCEED_KM = new FloatPreference("speed_limit_exceed", 5f).makeProfile(); + public final OsmandPreference SPEED_LIMIT_EXCEED_MILE = + new FloatPreference("speed_limit_exceed", 3f).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 0113f32147..34b2d415c7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -112,9 +112,9 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues); ApplicationMode mode = getMyApplication().getSettings().getApplicationMode(); - if (mode == ApplicationMode.CAR || mode == ApplicationMode.TRUCK || mode == ApplicationMode.MOTORCYCLE){ - Float[] speedLimits = new Float[] {5f, 7f, 10f, 15f, 20f}; + if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)){ if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS){ + Float[] speedLimits = new Float[] {5f, 7f, 10f, 15f, 20f}; String[] speedNames = new String[] { speedLimits[0] + " " + getString(R.string.km_h), @@ -122,15 +122,16 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { 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); + registerListPreference(settings.SPEED_LIMIT_EXCEED_KM, screen, speedNames, speedLimits); } else { + Float[] speedLimits = new Float[] {3f, 5f, 7f, 10f, 15f}; String[] speedNames = new String[] { speedLimits[0] + " " + getString(R.string.mile_per_hour), speedLimits[1] + " " + getString(R.string.mile_per_hour), speedLimits[2] + " " + getString(R.string.mile_per_hour), speedLimits[3] + " " + getString(R.string.mile_per_hour), speedLimits[4] + " " + getString(R.string.mile_per_hour)}; - registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); + registerListPreference(settings.SPEED_LIMIT_EXCEED_MILE, screen, speedNames, speedLimits); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 888ce601e1..752e892022 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -159,9 +159,9 @@ public class WaypointHelper { float mxspeed = route.getCurrentMaxSpeed(); float delta; if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ - delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); + delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get(); } else { - delta = app.getSettings().SPEED_LIMIT_EXCEED.get() * 1.6f; + delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get() * 1.6f; } AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta); if (speedAlarm != null) { @@ -254,9 +254,9 @@ public class WaypointHelper { float mxspeed = ro.getMaximumSpeed(); float delta; if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ - delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); + delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get(); } else { - delta = app.getSettings().SPEED_LIMIT_EXCEED.get() * 1.6f; + delta = app.getSettings().SPEED_LIMIT_EXCEED_MILE.get() * 1.6f; } AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { From c7d654319738cac6f179347fd172513fb158586a Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 10 Oct 2014 14:01:06 +0300 Subject: [PATCH 7/8] Updated speed limit exceed. --- .../src/net/osmand/plus/OsmandSettings.java | 5 +- .../SettingsNavigationActivity.java | 56 +++++++++++-------- .../osmand/plus/helpers/WaypointHelper.java | 14 +---- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index e52cac68f4..0383c1a0f4 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -675,12 +675,9 @@ public class OsmandSettings { public final OsmandPreference ARRIVAL_DISTANCE_FACTOR = new FloatPreference("arrival_distance_factor", 1f).makeProfile(); - public final OsmandPreference SPEED_LIMIT_EXCEED_KM = + public final OsmandPreference SPEED_LIMIT_EXCEED = new FloatPreference("speed_limit_exceed", 5f).makeProfile(); - public final OsmandPreference SPEED_LIMIT_EXCEED_MILE = - new FloatPreference("speed_limit_exceed", 3f).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 34b2d415c7..66cf379648 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -33,6 +33,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { private Preference speakAlarms; private ListPreference routerServicePreference; private ListPreference autoZoomMapPreference; + private ListPreference speedLimitExceed; private List avoidParameters = new ArrayList(); @@ -111,30 +112,33 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { }; registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues); - ApplicationMode mode = getMyApplication().getSettings().getApplicationMode(); - if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)){ - if (settings.METRIC_SYSTEM.get() == OsmandSettings.MetricsConstants.KILOMETERS_AND_METERS){ - Float[] speedLimits = new Float[] {5f, 7f, 10f, 15f, 20f}; - - 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_KM, screen, speedNames, speedLimits); - } else { - Float[] speedLimits = new Float[] {3f, 5f, 7f, 10f, 15f}; - String[] speedNames = new String[] { - speedLimits[0] + " " + getString(R.string.mile_per_hour), - speedLimits[1] + " " + getString(R.string.mile_per_hour), - speedLimits[2] + " " + getString(R.string.mile_per_hour), - speedLimits[3] + " " + getString(R.string.mile_per_hour), - speedLimits[4] + " " + getString(R.string.mile_per_hour)}; - registerListPreference(settings.SPEED_LIMIT_EXCEED_MILE, screen, speedNames, speedLimits); - } + 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[]{ + 3f + " " + getString(R.string.mile_per_hour), + 5f + " " + getString(R.string.mile_per_hour), + 7f + " " + getString(R.string.mile_per_hour), + 10f + " " + getString(R.string.mile_per_hour), + 15f + " " + getString(R.string.mile_per_hour)}; + registerListPreference(settings.SPEED_LIMIT_EXCEED, screen, speedNames, speedLimits); } + PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences"); + speedLimitExceed = (ListPreference) category.findPreference("speed_limit_exceed"); + ApplicationMode mode = getMyApplication().getSettings().getApplicationMode(); + if (!mode.isDerivedRoutingFrom(ApplicationMode.CAR)) { + category.removePreference(speedLimitExceed); + } + + profileDialog(); } @@ -200,6 +204,14 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { cat.addPreference(basePref); } } + ApplicationMode mode = getMyApplication().getSettings().getApplicationMode(); + if (mode.isDerivedRoutingFrom(ApplicationMode.CAR)) { + PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences"); + category.addPreference(speedLimitExceed); + } else { + PreferenceCategory category = (PreferenceCategory) screen.findPreference("guidance_preferences"); + category.removePreference(speedLimitExceed); + } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 752e892022..22eba272f7 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -157,12 +157,7 @@ public class WaypointHelper { public AlarmInfo getMostImportantAlarm(MetricsConstants mc, boolean showCameras) { Location lastProjection = app.getRoutingHelper().getLastProjection(); float mxspeed = route.getCurrentMaxSpeed(); - float delta; - if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ - delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get(); - } else { - delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get() * 1.6f; - } + float delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, lastProjection, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); @@ -252,12 +247,7 @@ public class WaypointHelper { public AlarmInfo calculateMostImportantAlarm(RouteDataObject ro, Location loc, MetricsConstants mc, boolean showCameras) { float mxspeed = ro.getMaximumSpeed(); - float delta; - if (app.getSettings().METRIC_SYSTEM.get() == MetricsConstants.KILOMETERS_AND_METERS){ - delta = app.getSettings().SPEED_LIMIT_EXCEED_KM.get(); - } else { - delta = app.getSettings().SPEED_LIMIT_EXCEED_MILE.get() * 1.6f; - } + float delta = app.getSettings().SPEED_LIMIT_EXCEED.get(); AlarmInfo speedAlarm = createSpeedAlarm(mc, mxspeed, loc, delta); if (speedAlarm != null) { getVoiceRouter().announceSpeedAlarm(); From a2f0e41731f93679b7592902172c0cfbee8a0976 Mon Sep 17 00:00:00 2001 From: Denis Date: Fri, 10 Oct 2014 15:23:55 +0300 Subject: [PATCH 8/8] Refactored creation of speed limits setting --- .../SettingsNavigationActivity.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 66cf379648..a2f1949aa6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -112,23 +112,21 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { }; registerListPreference(settings.ARRIVAL_DISTANCE_FACTOR, screen, arrivalNames, arrivalValues); - Float[] speedLimits = new Float[]{5f, 7f, 10f, 15f, 20f}; + //array size should be equal! + Float[] speedLimitsKm = new Float[]{5f, 7f, 10f, 15f, 20f}; + Float[] speedLimitsMiles = new Float[]{3f, 5f, 7f, 10f, 15f}; 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); + String[] speedNames = new String[speedLimitsKm.length]; + for (int i =0; i