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
-->
<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="add_online_source">Add online source</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.PointDescription;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.routepreparationmenu.cards.NauticalBridgeHeightWarningCard;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoritesListener;
@ -633,6 +634,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
} else if (routeCalculationInProgress) {
if (app.getRoutingHelper().isPublicTransportMode()) {
menuCards.add(new PublicTransportBetaWarningCard(mapActivity));
} else if (app.getRoutingHelper().isBoatMode()) {
menuCards.add(new NauticalBridgeHeightWarningCard(mapActivity));
} else if (app.getTargetPointsHelper().hasTooLongDistanceToNavigate()) {
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);
}
public boolean isBoatMode() {
return mode.isDerivedRoutingFrom(ApplicationMode.BOAT);
}
public boolean isOsmandRouting() {
return mode.getRouteService() == RouteService.OSMAND;
}

View file

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

View file

@ -1,26 +1,38 @@
package net.osmand.plus.settings.bottomsheets;
import net.osmand.plus.R;
import net.osmand.router.GeneralRouter;
import static net.osmand.router.GeneralRouter.*;
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),
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),
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);
String routerParameterName;
GeneralRouterProfile routerProfile;
int dayIconId;
int nightIconId;
int descriptionRes;
int metricRes;
int metricShortRes;
VehicleSizeAssets(String routerParameterName, int dayIconId, int nightIconId, int descriptionRes, int metricRes,
int metricShortRes) {
VehicleSizeAssets(String routerParameterName, GeneralRouterProfile routerProfile, int dayIconId, int nightIconId,
int descriptionRes, int metricRes, int metricShortRes) {
this.routerParameterName = routerParameterName;
this.routerProfile = routerProfile;
this.dayIconId = dayIconId;
this.nightIconId = nightIconId;
this.descriptionRes = descriptionRes;
@ -28,9 +40,9 @@ public enum VehicleSizeAssets {
this.metricShortRes = metricShortRes;
}
public static VehicleSizeAssets getAssets(String parameterName) {
public static VehicleSizeAssets getAssets(String parameterName, GeneralRouterProfile routerProfile) {
for (VehicleSizeAssets type : VehicleSizeAssets.values()) {
if (type.routerParameterName.equals(parameterName)) {
if (type.routerParameterName.equals(parameterName) && type.routerProfile == routerProfile) {
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.SizePreference;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import java.util.Map;
@ -48,21 +49,22 @@ 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);
setupCustomRoutingPropertyPref(vehicleHeight, routerProfile);
}
GeneralRouter.RoutingParameter vehicleWeight = parameters.get(GeneralRouter.VEHICLE_WEIGHT);
if (vehicleWeight != null) {
setupCustomRoutingPropertyPref(vehicleWeight);
setupCustomRoutingPropertyPref(vehicleWeight, routerProfile);
}
GeneralRouter.RoutingParameter vehicleWidth = parameters.get(GeneralRouter.VEHICLE_WIDTH);
if (vehicleWidth != null) {
setupCustomRoutingPropertyPref(vehicleWidth);
setupCustomRoutingPropertyPref(vehicleWidth, routerProfile);
}
if (router.getProfile() != GeneralRouter.GeneralRouterProfile.PUBLIC_TRANSPORT) {
if (router.getProfile() != GeneralRouterProfile.PUBLIC_TRANSPORT) {
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();
if (app == null) {
return;
@ -80,8 +83,10 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, parameterId, parameter.getName());
String description = SettingsBaseActivity.getRoutingStringPropertyDescription(app, parameterId, parameter.getDescription());
String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC ? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings().getCustomRoutingProperty(parameterId, defValue);
String defValue = parameter.getType() == GeneralRouter.RoutingParameterType.NUMERIC
? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings()
.getCustomRoutingProperty(parameterId, defValue);
Object[] values = parameter.getPossibleValues();
String[] valuesStr = new String[values.length];
for (int i = 0; i < values.length; i++) {
@ -96,7 +101,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
}
SizePreference vehicleSizePref = new SizePreference(ctx);
vehicleSizePref.setKey(pref.getId());
vehicleSizePref.setAssets(VehicleSizeAssets.getAssets(parameterId));
vehicleSizePref.setAssets(VehicleSizeAssets.getAssets(parameterId, routerProfile));
vehicleSizePref.setDefaultValue(defValue);
vehicleSizePref.setTitle(title);
vehicleSizePref.setEntries(entriesStr);