Fix #9294 [Feature request] add length to the Vehicle parameters

This commit is contained in:
Dima-1 2020-07-03 14:40:13 +03:00
parent eaaf695638
commit 6869639c08
5 changed files with 34 additions and 40 deletions

View file

@ -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<String, String> attributes;
private final Map<String, RoutingParameter> parameters;
private final Map<String, RoutingParameter> parameters;
private final Map<String, Integer> universalRules;
private final List<String> universalRulesById;
private final Map<String, BitSet> tagRuleMask;

View file

@ -88,6 +88,7 @@
<string name="screen_control">Screen control</string>
<string name="shared_string_always">Always</string>
<string name="gpx_parse_error">OsmAnd GPX is not well formed, please contact the support team to investigate further.</string>
<string name="lenght_limit_description">Provide your vehicle length, some routes restrictions may be applied for long vehicles.</string>
<string name="weight_limit_description">Provide your vehicle weight, some route restrictions may apply for heavy vehicles.</string>
<string name="height_limit_description">Provide your vehicle height, some route restrictions may apply for high vehicles.</string>
<string name="width_limit_description">Provide your vehicle width some route restrictions may apply for wide vehicles.</string>

View file

@ -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;

View file

@ -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);

View file

@ -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<String, GeneralRouter.RoutingParameter> 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<String, RoutingParameter> 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;
}