From 6869639c08234cbdf6c407a6c529c5b59e109be9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 3 Jul 2020 14:40:13 +0300 Subject: [PATCH] Fix #9294 [Feature request] add length to the Vehicle parameters --- .../java/net/osmand/router/GeneralRouter.java | 5 +- OsmAnd/res/values/strings.xml | 1 + .../bottomsheets/VehicleSizeAssets.java | 5 +- .../fragments/RouteParametersFragment.java | 6 +- .../fragments/VehicleParametersFragment.java | 57 +++++++------------ 5 files changed, 34 insertions(+), 40 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java index f8de46a783..3c6553f523 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/GeneralRouter.java @@ -41,13 +41,14 @@ public class GeneralRouter implements VehicleRouter { public static final String VEHICLE_HEIGHT = "height"; public static final String VEHICLE_WEIGHT = "weight"; public static final String VEHICLE_WIDTH = "width"; - + public static final String VEHICLE_LENGTH = "length"; + private static boolean USE_CACHE = true; public static long TIMER = 0; private final RouteAttributeContext[] objectAttributes; public final Map attributes; - private final Map parameters; + private final Map parameters; private final Map universalRules; private final List universalRulesById; private final Map tagRuleMask; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 1182e236cb..555ab3133d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -88,6 +88,7 @@ Screen control Always OsmAnd GPX is not well formed, please contact the support team to investigate further. + Provide your vehicle length, some routes restrictions may be applied for long vehicles. Provide your vehicle weight, some route restrictions may apply for heavy vehicles. Provide your vehicle height, some route restrictions may apply for high vehicles. Provide your vehicle width some route restrictions may apply for wide vehicles. diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleSizeAssets.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleSizeAssets.java index 6bedc098b2..5c017dd3cc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleSizeAssets.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/VehicleSizeAssets.java @@ -19,7 +19,10 @@ public enum VehicleSizeAssets { R.string.height_limit_description, R.string.shared_string_meters, R.string.m), WEIGHT(VEHICLE_WEIGHT, GeneralRouterProfile.CAR, R.drawable.img_help_weight_limit_day, R.drawable.img_help_weight_limit_night, - R.string.weight_limit_description, R.string.shared_string_tones, R.string.metric_ton); + R.string.weight_limit_description, R.string.shared_string_tones, R.string.metric_ton), + LENGTH(VEHICLE_LENGTH, GeneralRouterProfile.CAR, R.drawable.img_help_length_limit_day, + R.drawable.img_help_length_limit_night, + R.string.lenght_limit_description, R.string.shared_string_meters, R.string.m); String routerParameterName; GeneralRouterProfile routerProfile; diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java index f46330f949..f394d5aff4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java @@ -180,7 +180,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP } else if ((!param.equals(GeneralRouter.USE_SHORTEST_WAY) || am.isDerivedRoutingFrom(ApplicationMode.CAR)) && !param.equals(GeneralRouter.VEHICLE_HEIGHT) && !param.equals(GeneralRouter.VEHICLE_WEIGHT) - && !param.equals(GeneralRouter.VEHICLE_WIDTH)) { + && !param.equals(GeneralRouter.VEHICLE_WIDTH) + && !param.equals(GeneralRouter.VEHICLE_LENGTH)) { otherRoutingParameters.add(routingParameter); } } @@ -253,7 +254,8 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP straightAngle.setPersistent(false); straightAngle.setKey(settings.ROUTE_STRAIGHT_ANGLE.getId()); straightAngle.setTitle(getString(R.string.recalc_angle_dialog_title)); - straightAngle.setSummary(String.format(getString(R.string.shared_string_angle_param), (int) am.getStrAngle())); + straightAngle.setSummary(String.format(getString(R.string.shared_string_angle_param), + (int) am.getStrAngle() + "")); straightAngle.setLayoutResource(R.layout.preference_with_descr); straightAngle.setIcon(getRoutingPrefIcon("routing_recalc_distance")); //TODO change for appropriate icon when available getPreferenceScreen().addPreference(straightAngle); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java index aa9fee8058..3238579c48 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java @@ -26,6 +26,7 @@ import net.osmand.router.GeneralRouter.GeneralRouterProfile; import java.util.Map; import static net.osmand.plus.activities.SettingsNavigationActivity.showSeekbarSettingsDialog; +import static net.osmand.router.GeneralRouter.*; public class VehicleParametersFragment extends BaseSettingsFragment implements OnPreferenceChanged { @@ -36,12 +37,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O @Override protected void setupPreferences() { - OsmandApplication app = getMyApplication(); - if (app == null) { - return; - } ApplicationMode mode = getSelectedAppMode(); - Preference vehicleParametersInfo = findPreference("vehicle_parameters_info"); vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, mode.toHumanString())); @@ -50,21 +46,11 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O if (routeService == RouteService.OSMAND) { GeneralRouter router = app.getRouter(mode); if (router != null) { - GeneralRouterProfile routerProfile = router.getProfile(); - Map parameters = router.getParameters(); - - GeneralRouter.RoutingParameter vehicleHeight = parameters.get(GeneralRouter.VEHICLE_HEIGHT); - if (vehicleHeight != null) { - setupCustomRoutingPropertyPref(vehicleHeight, routerProfile); - } - GeneralRouter.RoutingParameter vehicleWeight = parameters.get(GeneralRouter.VEHICLE_WEIGHT); - if (vehicleWeight != null) { - setupCustomRoutingPropertyPref(vehicleWeight, routerProfile); - } - GeneralRouter.RoutingParameter vehicleWidth = parameters.get(GeneralRouter.VEHICLE_WIDTH); - if (vehicleWidth != null) { - setupCustomRoutingPropertyPref(vehicleWidth, routerProfile); - } + Map parameters = router.getParameters(); + setupCustomRoutingPropertyPref(parameters.get(VEHICLE_HEIGHT)); + setupCustomRoutingPropertyPref(parameters.get(VEHICLE_WEIGHT)); + setupCustomRoutingPropertyPref(parameters.get(VEHICLE_WIDTH)); + setupCustomRoutingPropertyPref(parameters.get(VEHICLE_LENGTH)); if (router.getProfile() != GeneralRouterProfile.PUBLIC_TRANSPORT) { setupDefaultSpeedPref(); } @@ -74,17 +60,16 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O } } - private void setupCustomRoutingPropertyPref(GeneralRouter.RoutingParameter parameter, - GeneralRouterProfile routerProfile) { - OsmandApplication app = getMyApplication(); - if (app == null) { + private void setupCustomRoutingPropertyPref(RoutingParameter parameter) { + GeneralRouterProfile routerProfile = app.getRouter(getSelectedAppMode()).getProfile(); + if (parameter == null) { return; } String parameterId = parameter.getId(); String title = SettingsBaseActivity.getRoutingStringPropertyName(app, parameterId, parameter.getName()); - String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription()); - - String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC + String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, + parameter.getDescription()); + String defValue = parameter.getType() == RoutingParameterType.NUMERIC ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT; OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings() .getCustomRoutingProperty(parameterId, defValue); @@ -125,10 +110,10 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O return; } Preference defaultSpeedPref = new Preference(ctx); - defaultSpeedPref.setKey(GeneralRouter.DEFAULT_SPEED); + defaultSpeedPref.setKey(DEFAULT_SPEED); defaultSpeedPref.setTitle(R.string.default_speed_setting_title); defaultSpeedPref.setSummary(R.string.default_speed_setting_descr); - defaultSpeedPref.setIcon(getPreferenceIcon(GeneralRouter.DEFAULT_SPEED)); + defaultSpeedPref.setIcon(getPreferenceIcon(DEFAULT_SPEED)); defaultSpeedPref.setLayoutResource(R.layout.preference_with_descr); getPreferenceScreen().addPreference(defaultSpeedPref); } @@ -136,7 +121,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O @Override protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) { super.onBindPreferenceViewHolder(preference, holder); - if (!GeneralRouter.DEFAULT_SPEED.equals(preference.getKey()) && preference instanceof ListPreferenceEx) { + if (!DEFAULT_SPEED.equals(preference.getKey()) && preference instanceof ListPreferenceEx) { ImageView imageView = (ImageView) holder.findViewById(android.R.id.icon); if (imageView != null) { Object currentValue = ((ListPreferenceEx) preference).getValue(); @@ -157,7 +142,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O @Override public boolean onPreferenceClick(Preference preference) { - if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) { + if (preference.getKey().equals(DEFAULT_SPEED)) { RouteService routeService = getSelectedAppMode().getRouteService(); boolean defaultSpeedOnly = routeService == RouteService.STRAIGHT || routeService == RouteService.DIRECT_TO; showSeekbarSettingsDialog(getActivity(), defaultSpeedOnly, getSelectedAppMode()); @@ -194,14 +179,16 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O private Drawable getPreferenceIcon(String prefId) { switch (prefId) { - case GeneralRouter.DEFAULT_SPEED: + case DEFAULT_SPEED: return getPersistentPrefIcon(R.drawable.ic_action_speed); - case GeneralRouter.VEHICLE_HEIGHT: + case VEHICLE_HEIGHT: return getPersistentPrefIcon(R.drawable.ic_action_height_limit); - case GeneralRouter.VEHICLE_WEIGHT: + case VEHICLE_WEIGHT: return getPersistentPrefIcon(R.drawable.ic_action_weight_limit); - case GeneralRouter.VEHICLE_WIDTH: + case VEHICLE_WIDTH: return getPersistentPrefIcon(R.drawable.ic_action_width_limit); + case VEHICLE_LENGTH: + return getPersistentPrefIcon(R.drawable.ic_action_length_limit); default: return null; }