Merge pull request #9210 from osmandapp/vessel_height

Add vessel's height for Boat navigation
This commit is contained in:
max-klaus 2020-06-12 15:50:39 +03:00 committed by GitHub
commit 68e8993d0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 69 additions and 19 deletions

View file

@ -11,6 +11,10 @@
Thx - Hardy Thx - Hardy
--> -->
<string name="vessel_width_limit_description">Set vessel width to avoid narrow bridges</string>
<string name="vessel_height_limit_description">Set vessel height to avoid low bridges. Keep in mind, if the bridge is movable, we will use its height in the open state.</string>
<string name="vessel_height_warning">You can set vessel height to avoid low bridges. Keep in mind, if the bridge is movable, we will use its height in the open state.</string>
<string name="vessel_height_warning_link">Set vessel height</string>
<string name="clear_tiles_warning">Applying these changes will clear the cached data for this tile source</string> <string name="clear_tiles_warning">Applying these changes will clear the cached data for this tile source</string>
<string name="add_online_source">Add online source</string> <string name="add_online_source">Add online source</string>
<!-- string name="shared_string_all_time">All time</string --> <!-- string name="shared_string_all_time">All time</string -->

View file

@ -44,6 +44,7 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
import net.osmand.plus.routepreparationmenu.cards.NauticalBridgeHeightWarningCard;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener; import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
@ -633,6 +634,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (routeCalculationInProgress) { } else if (routeCalculationInProgress) {
if (app.getRoutingHelper().isPublicTransportMode()) { if (app.getRoutingHelper().isPublicTransportMode()) {
menuCards.add(new PublicTransportBetaWarningCard(mapActivity)); menuCards.add(new PublicTransportBetaWarningCard(mapActivity));
} else if (app.getRoutingHelper().isBoatMode()) {
menuCards.add(new NauticalBridgeHeightWarningCard(mapActivity));
} else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate()) { } else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate()) {
menuCards.add(new LongDistanceWarningCard(mapActivity)); menuCards.add(new LongDistanceWarningCard(mapActivity));
} }

View file

@ -0,0 +1,24 @@
package net.osmand.plus.routepreparationmenu.cards;
import androidx.annotation.NonNull;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import static net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType.*;
public class NauticalBridgeHeightWarningCard extends WarningCard {
public NauticalBridgeHeightWarningCard(@NonNull MapActivity mapActivity) {
super(mapActivity);
imageId = R.drawable.ic_action_sail_boat_dark;
title = mapActivity.getString(R.string.vessel_height_warning);
linkText = mapActivity.getString(R.string.vessel_height_warning_link);
}
@Override
protected void onLinkClicked() {
BaseSettingsFragment.showInstance(mapActivity, VEHICLE_PARAMETERS, mapActivity.getRoutingHelper().getAppMode());
}
}

View file

@ -1314,6 +1314,10 @@ public class RoutingHelper {
return mode.isDerivedRoutingFrom(ApplicationMode.PUBLIC_TRANSPORT); return mode.isDerivedRoutingFrom(ApplicationMode.PUBLIC_TRANSPORT);
} }
public boolean isBoatMode() {
return mode.isDerivedRoutingFrom(ApplicationMode.BOAT);
}
public boolean isOsmandRouting() { public boolean isOsmandRouting() {
return mode.getRouteService() == RouteService.OSMAND; return mode.getRouteService() == RouteService.OSMAND;
} }

View file

@ -49,11 +49,9 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
final SizePreference preference = (SizePreference) getPreference(); final SizePreference preference = (SizePreference) getPreference();
View mainView = UiUtilities.getMaterialInflater(app, nightMode) View mainView = UiUtilities.getMaterialInflater(app, nightMode)
.inflate(R.layout.bottom_sheet_item_edit_with_recyclerview, null); .inflate(R.layout.bottom_sheet_item_edit_with_recyclerview, null);
String key = preference.getKey();
TextView title = mainView.findViewById(R.id.title); TextView title = mainView.findViewById(R.id.title);
title.setText(preference.getTitle().toString()); title.setText(preference.getTitle().toString());
String parameterName = key.substring(key.lastIndexOf("_") + 1); VehicleSizeAssets vehicleSizeAssets = preference.getAssets();
VehicleSizeAssets vehicleSizeAssets = VehicleSizeAssets.getAssets(parameterName);
if (vehicleSizeAssets != null) { if (vehicleSizeAssets != null) {
ImageView imageView = mainView.findViewById(R.id.image_view); ImageView imageView = mainView.findViewById(R.id.image_view);
imageView.setImageDrawable(app.getUIUtilities() imageView.setImageDrawable(app.getUIUtilities()

View file

@ -1,26 +1,38 @@
package net.osmand.plus.settings.bottomsheets; package net.osmand.plus.settings.bottomsheets;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.router.GeneralRouter;
import static net.osmand.router.GeneralRouter.*;
public enum VehicleSizeAssets { public enum VehicleSizeAssets {
WIDTH(GeneralRouter.VEHICLE_WIDTH, R.drawable.img_help_width_limit_day, R.drawable.img_help_width_limit_night, BOAT_HEIGHT(VEHICLE_HEIGHT, GeneralRouterProfile.BOAT, R.drawable.img_help_vessel_height_day,
R.drawable.img_help_vessel_height_night,
R.string.vessel_height_limit_description, R.string.shared_string_meters, R.string.m),
BOAT_WIDTH(VEHICLE_WIDTH, GeneralRouterProfile.BOAT, R.drawable.img_help_vessel_width_day,
R.drawable.img_help_vessel_width_night,
R.string.vessel_width_limit_description, R.string.shared_string_meters, R.string.m),
WIDTH(VEHICLE_WIDTH, GeneralRouterProfile.CAR, R.drawable.img_help_width_limit_day,
R.drawable.img_help_width_limit_night,
R.string.width_limit_description, R.string.shared_string_meters, R.string.m), R.string.width_limit_description, R.string.shared_string_meters, R.string.m),
HEIGHT(GeneralRouter.VEHICLE_HEIGHT, R.drawable.img_help_height_limit_day, R.drawable.img_help_height_limit_night, HEIGHT(VEHICLE_HEIGHT, GeneralRouterProfile.CAR, R.drawable.img_help_height_limit_day,
R.drawable.img_help_height_limit_night,
R.string.height_limit_description, R.string.shared_string_meters, R.string.m), R.string.height_limit_description, R.string.shared_string_meters, R.string.m),
WEIGHT(GeneralRouter.VEHICLE_WEIGHT, R.drawable.img_help_weight_limit_day, R.drawable.img_help_weight_limit_night, 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);
String routerParameterName; String routerParameterName;
GeneralRouterProfile routerProfile;
int dayIconId; int dayIconId;
int nightIconId; int nightIconId;
int descriptionRes; int descriptionRes;
int metricRes; int metricRes;
int metricShortRes; int metricShortRes;
VehicleSizeAssets(String routerParameterName, int dayIconId, int nightIconId, int descriptionRes, int metricRes, VehicleSizeAssets(String routerParameterName, GeneralRouterProfile routerProfile, int dayIconId, int nightIconId,
int metricShortRes) { int descriptionRes, int metricRes, int metricShortRes) {
this.routerParameterName = routerParameterName; this.routerParameterName = routerParameterName;
this.routerProfile = routerProfile;
this.dayIconId = dayIconId; this.dayIconId = dayIconId;
this.nightIconId = nightIconId; this.nightIconId = nightIconId;
this.descriptionRes = descriptionRes; this.descriptionRes = descriptionRes;
@ -28,9 +40,9 @@ public enum VehicleSizeAssets {
this.metricShortRes = metricShortRes; this.metricShortRes = metricShortRes;
} }
public static VehicleSizeAssets getAssets(String parameterName) { public static VehicleSizeAssets getAssets(String parameterName, GeneralRouterProfile routerProfile) {
for (VehicleSizeAssets type : VehicleSizeAssets.values()) { for (VehicleSizeAssets type : VehicleSizeAssets.values()) {
if (type.routerParameterName.equals(parameterName)) { if (type.routerParameterName.equals(parameterName) && type.routerProfile == routerProfile) {
return type; return type;
} }
} }

View file

@ -20,6 +20,7 @@ import net.osmand.plus.settings.bottomsheets.VehicleSizeAssets;
import net.osmand.plus.settings.preferences.ListPreferenceEx; import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.SizePreference; import net.osmand.plus.settings.preferences.SizePreference;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import java.util.Map; import java.util.Map;
@ -48,21 +49,22 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
if (routeService == RouteService.OSMAND) { if (routeService == RouteService.OSMAND) {
GeneralRouter router = app.getRouter(mode); GeneralRouter router = app.getRouter(mode);
if (router != null) { if (router != null) {
GeneralRouterProfile routerProfile = router.getProfile();
Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters(); Map<String, GeneralRouter.RoutingParameter> parameters = router.getParameters();
GeneralRouter.RoutingParameter vehicleHeight = parameters.get(GeneralRouter.VEHICLE_HEIGHT); GeneralRouter.RoutingParameter vehicleHeight = parameters.get(GeneralRouter.VEHICLE_HEIGHT);
if (vehicleHeight != null) { if (vehicleHeight != null) {
setupCustomRoutingPropertyPref(vehicleHeight); setupCustomRoutingPropertyPref(vehicleHeight, routerProfile);
} }
GeneralRouter.RoutingParameter vehicleWeight = parameters.get(GeneralRouter.VEHICLE_WEIGHT); GeneralRouter.RoutingParameter vehicleWeight = parameters.get(GeneralRouter.VEHICLE_WEIGHT);
if (vehicleWeight != null) { if (vehicleWeight != null) {
setupCustomRoutingPropertyPref(vehicleWeight); setupCustomRoutingPropertyPref(vehicleWeight, routerProfile);
} }
GeneralRouter.RoutingParameter vehicleWidth = parameters.get(GeneralRouter.VEHICLE_WIDTH); GeneralRouter.RoutingParameter vehicleWidth = parameters.get(GeneralRouter.VEHICLE_WIDTH);
if (vehicleWidth != null) { if (vehicleWidth != null) {
setupCustomRoutingPropertyPref(vehicleWidth); setupCustomRoutingPropertyPref(vehicleWidth, routerProfile);
} }
if (router.getProfile() != GeneralRouter.GeneralRouterProfile.PUBLIC_TRANSPORT) { if (router.getProfile() != GeneralRouterProfile.PUBLIC_TRANSPORT) {
setupDefaultSpeedPref(); setupDefaultSpeedPref();
} }
} }
@ -71,7 +73,8 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
} }
} }
private void setupCustomRoutingPropertyPref(GeneralRouter.RoutingParameter parameter) { private void setupCustomRoutingPropertyPref(GeneralRouter.RoutingParameter parameter,
GeneralRouterProfile routerProfile) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app == null) { if (app == null) {
return; return;
@ -80,8 +83,10 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, parameterId, parameter.getName()); String title = SettingsBaseActivity.getRoutingStringPropertyName(app, parameterId, parameter.getName());
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription()); String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription());
String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT; String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings().getCustomRoutingProperty(parameterId, defValue); ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings()
.getCustomRoutingProperty(parameterId, defValue);
Object[] values = parameter.getPossibleValues(); Object[] values = parameter.getPossibleValues();
String[] valuesStr = new String[values.length]; String[] valuesStr = new String[values.length];
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {
@ -96,7 +101,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
} }
SizePreference vehicleSizePref = new SizePreference(ctx); SizePreference vehicleSizePref = new SizePreference(ctx);
vehicleSizePref.setKey(pref.getId()); vehicleSizePref.setKey(pref.getId());
vehicleSizePref.setAssets(VehicleSizeAssets.getAssets(parameterId)); vehicleSizePref.setAssets(VehicleSizeAssets.getAssets(parameterId, routerProfile));
vehicleSizePref.setDefaultValue(defValue); vehicleSizePref.setDefaultValue(defValue);
vehicleSizePref.setTitle(title); vehicleSizePref.setTitle(title);
vehicleSizePref.setEntries(entriesStr); vehicleSizePref.setEntries(entriesStr);