From f907705656b02d7728ab83415d043a15f09f194b Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 17 Mar 2019 16:00:54 +0100 Subject: [PATCH] Refactor avoid roads parameters --- OsmAnd/res/values/strings.xml | 2 + .../AvoidRoadsBottomSheetDialogFragment.java | 84 ++++++++++------- .../MapRouteInfoMenu.java | 90 +++++++++---------- .../RouteOptionsBottomSheet.java | 20 +++-- .../RoutingOptionsHelper.java | 13 ++- .../osmand/plus/routing/RoutingHelper.java | 2 + .../plus/routing/TransportRoutingHelper.java | 43 ++++++--- 7 files changed, 145 insertions(+), 109 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 659523e2c4..8db3df1f74 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + Select a public transport types you want to avoid during navigation: + Avoid transport types… Walk Value of tag \"%s\" cannot exceed 255 chars. \nPlease edit it before continue. Length of \"%s\" value diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java index 8886aa6510..7bda8e71d6 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/AvoidRoadsBottomSheetDialogFragment.java @@ -48,6 +48,7 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr public static final int OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE = 1; private static final String AVOID_ROADS_TYPES_KEY = "avoid_roads_types"; + private static final String HIDE_IMPASSABLE_ROADS_KEY = "hide_impassable_roads"; private static final String AVOID_ROADS_OBJECTS_KEY = "avoid_roads_objects"; private RoutingOptionsHelper routingOptionsHelper; @@ -55,6 +56,14 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr private HashMap routingParametersMap; private List removedImpassableRoads; private LinearLayout stylesContainer; + private boolean hideImpassableRoads; + + public AvoidRoadsBottomSheetDialogFragment() { + } + + public AvoidRoadsBottomSheetDialogFragment(boolean hideImpassableRoads) { + this.hideImpassableRoads = hideImpassableRoads; + } List compoundButtons = new ArrayList<>(); @@ -69,6 +78,9 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr if (savedInstanceState.containsKey(AVOID_ROADS_TYPES_KEY)) { routingParametersMap = (HashMap) savedInstanceState.getSerializable(AVOID_ROADS_TYPES_KEY); } + if (savedInstanceState.containsKey(HIDE_IMPASSABLE_ROADS_KEY)) { + hideImpassableRoads = true; + } if (savedInstanceState.containsKey(AVOID_ROADS_OBJECTS_KEY)) { removedImpassableRoads = (List) savedInstanceState.getSerializable(AVOID_ROADS_OBJECTS_KEY); } @@ -101,7 +113,8 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr items.add(titleItem); final SimpleBottomSheetItem descriptionItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setTitle(getString(R.string.avoid_roads_descr)) + .setTitle( + !hideImpassableRoads ? getString(R.string.avoid_roads_descr) : getString(R.string.avoid_pt_types_descr)) .setLayoutId(R.layout.bottom_sheet_item_title_long) .create(); items.add(descriptionItem); @@ -119,42 +132,46 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr } items.add(new BaseBottomSheetItem.Builder().setCustomView(stylesContainer).create()); - populateImpassableRoadsObjects(); + if(!hideImpassableRoads) { + populateImpassableRoadsObjects(); - final View buttonView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_btn, null); - TextView buttonDescription = (TextView) buttonView.findViewById(R.id.button_descr); - buttonDescription.setText(R.string.shared_string_select_on_map); - buttonDescription.setTextColor(getResolvedColor(nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); + final View buttonView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_btn, null); + TextView buttonDescription = (TextView) buttonView.findViewById(R.id.button_descr); + buttonDescription.setText(R.string.shared_string_select_on_map); + buttonDescription.setTextColor(getResolvedColor(nightMode ? R.color.active_buttons_and_links_dark : R.color.active_buttons_and_links_light)); + + FrameLayout buttonContainer = buttonView.findViewById(R.id.button_container); + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { + AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark); + AndroidUtils.setBackground(app, buttonDescription, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); + } else { + AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); + } + + buttonContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); + mapActivity.getMapRouteInfoMenu().hide(); + app.getAvoidSpecificRoads().selectFromMap(mapActivity); + Fragment fragment = getTargetFragment(); + if (fragment != null) { + fragment.onActivityResult(getTargetRequestCode(), OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE, null); + } + } + dismiss(); + } + }); + final SimpleBottomSheetItem buttonItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() + .setCustomView(buttonView) + .create(); + items.add(buttonItem); - FrameLayout buttonContainer = buttonView.findViewById(R.id.button_container); - if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { - AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.btn_border_light, R.drawable.btn_border_dark); - AndroidUtils.setBackground(app, buttonDescription, nightMode, R.drawable.ripple_light, R.drawable.ripple_dark); - } else { - AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.btn_border_trans_light, R.drawable.btn_border_trans_dark); } - buttonContainer.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); - mapActivity.getMapRouteInfoMenu().hide(); - app.getAvoidSpecificRoads().selectFromMap(mapActivity); - Fragment fragment = getTargetFragment(); - if (fragment != null) { - fragment.onActivityResult(getTargetRequestCode(), OPEN_AVOID_ROADS_DIALOG_REQUEST_CODE, null); - } - } - dismiss(); - } - }); - final SimpleBottomSheetItem buttonItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() - .setCustomView(buttonView) - .create(); - items.add(buttonItem); items.add(new SubtitleDividerItem(app)); @@ -243,6 +260,9 @@ public class AvoidRoadsBottomSheetDialogFragment extends MenuBottomSheetDialogFr super.onSaveInstanceState(outState); outState.putSerializable(AVOID_ROADS_TYPES_KEY, routingParametersMap); outState.putSerializable(AVOID_ROADS_OBJECTS_KEY, (Serializable) removedImpassableRoads); + if(hideImpassableRoads) { + outState.putBoolean(HIDE_IMPASSABLE_ROADS_KEY, true); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index 8d45cc98f6..7d282f9f43 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -61,7 +61,6 @@ import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; -import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameterGroup; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRouteItem; @@ -95,6 +94,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeMap; import static net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DRIVING_STYLE; @@ -971,60 +971,20 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } } } - } else if (parameter instanceof AvoidRoadsTypesRoutingParameter) { - final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null); - if (item != null) { - item.findViewById(R.id.route_option_container).setVisibility(View.GONE); - List avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(applicationMode); - final List avoidedParameters = new ArrayList<>(); - for (int i = 0; i < avoidParameters.size(); i++) { - RoutingParameter p = avoidParameters.get(i); - CommonPreference preference = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); - if (preference != null && preference.get()) { - avoidedParameters.add(p); - } - } - if (avoidedParameters.isEmpty()) { - continue; - } - for (int i = 0; i < avoidedParameters.size(); i++) { - final RoutingParameter routingParameter = avoidedParameters.get(i); - final View container = createToolbarSubOptionView(false, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), R.drawable.ic_action_remove_dark, i == avoidedParameters.size() - 1, new OnClickListener() { - @Override - public void onClick(View v) { - CommonPreference preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); - preference.set(false); - avoidedParameters.remove(routingParameter); - if (avoidedParameters.isEmpty()) { - mode.parameters.remove(parameter); - } - if (mode.parameters.size() > 2) { - item.removeView(v); - } else { - updateOptionsButtons(); - } - } - }); - if (container != null) { - item.addView(container, newLp); - } - } - optionsContainer.addView(item, lp); - } - } else if (parameter instanceof AvoidRoadsRoutingParameter) { + } else if (parameter instanceof AvoidRoadsRoutingParameter || parameter instanceof RoutingOptionsHelper.AvoidPTTypesRoutingParameter) { final LinearLayout item = createToolbarOptionView(false, null, -1, -1, null); if (item != null) { + item.findViewById(R.id.route_option_container).setVisibility(View.GONE); - AvoidSpecificRoads avoidSpecificRoads = app.getAvoidSpecificRoads(); - Map impassableRoads = avoidSpecificRoads.getImpassableRoads(); - if (impassableRoads.isEmpty()) { - continue; + Map impassableRoads = new TreeMap<>(); + if (parameter instanceof AvoidRoadsRoutingParameter) { + impassableRoads = app.getAvoidSpecificRoads().getImpassableRoads(); } Iterator it = impassableRoads.values().iterator(); while (it.hasNext()) { final RouteDataObject routeDataObject = it.next(); - final View container = createToolbarSubOptionView(false, avoidSpecificRoads.getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() { + final View container = createToolbarSubOptionView(false, app.getAvoidSpecificRoads().getText(routeDataObject), R.drawable.ic_action_remove_dark, !it.hasNext(), new OnClickListener() { @Override public void onClick(View v) { MapActivity mapActivity = getMapActivity(); @@ -1053,7 +1013,41 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener item.addView(container, newLp); } } - optionsContainer.addView(item, lp); + + List avoidParameters = app.getRoutingOptionsHelper().getAvoidRoutingPrefsForAppMode(applicationMode); + final List avoidedParameters = new ArrayList<>(); + for (int i = 0; i < avoidParameters.size(); i++) { + RoutingParameter p = avoidParameters.get(i); + CommonPreference preference = settings.getCustomRoutingBooleanProperty(p.getId(), p.getDefaultBoolean()); + if (preference != null && preference.get()) { + avoidedParameters.add(p); + } + } + for (int i = 0; i < avoidedParameters.size(); i++) { + final RoutingParameter routingParameter = avoidedParameters.get(i); + final View container = createToolbarSubOptionView(false, SettingsBaseActivity.getRoutingStringPropertyName(app, routingParameter.getId(), routingParameter.getName()), R.drawable.ic_action_remove_dark, i == avoidedParameters.size() - 1, new OnClickListener() { + @Override + public void onClick(View v) { + CommonPreference preference = settings.getCustomRoutingBooleanProperty(routingParameter.getId(), routingParameter.getDefaultBoolean()); + preference.set(false); + avoidedParameters.remove(routingParameter); + if (avoidedParameters.isEmpty()) { + mode.parameters.remove(parameter); + } + if (mode.parameters.size() > 2) { + item.removeView(v); + } else { + updateOptionsButtons(); + } + } + }); + if (container != null) { + item.addView(container, newLp); + } + } + if(avoidedParameters.size() > 0 || impassableRoads.size() > 0) { + optionsContainer.addView(item, lp); + } } } else if (parameter instanceof LocalRoutingParameterGroup) { final LocalRoutingParameterGroup group = (LocalRoutingParameterGroup) parameter; diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index ebb4caf678..53ed92288b 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -32,7 +32,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; -import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsTypesRoutingParameter; +import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.DividerItem; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.GpxLocalRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingParameter; @@ -91,8 +91,8 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { if (OsmandPlugin.getEnabledPlugin(OsmandDevelopmentPlugin.class) != null) { items.add(createRouteSimulationItem(optionsItem)); } - } else if (optionsItem instanceof AvoidRoadsTypesRoutingParameter) { - items.add(createAvoidRoadsTypesItem(optionsItem)); + } else if (optionsItem instanceof AvoidPTTypesRoutingParameter) { + items.add(createAvoidPTTypesItem(optionsItem)); } else if (optionsItem instanceof AvoidRoadsRoutingParameter) { items.add(createAvoidRoadsItem(optionsItem)); } else if (optionsItem instanceof GpxLocalRoutingParameter) { @@ -198,7 +198,8 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { .create(); } - private BaseBottomSheetItem createAvoidRoadsTypesItem(final LocalRoutingParameter optionsItem) { + + private BaseBottomSheetItem createAvoidRoadsItem(final LocalRoutingParameter optionsItem) { return new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon((optionsItem.getActiveIconId()))) .setTitle(getString(R.string.impassable_road)) @@ -216,10 +217,11 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { .create(); } - private BaseBottomSheetItem createAvoidRoadsItem(final LocalRoutingParameter optionsItem) { + + private BaseBottomSheetItem createAvoidPTTypesItem(final LocalRoutingParameter optionsItem) { return new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon((optionsItem.getActiveIconId()))) - .setTitle(getString(R.string.impassable_road)) + .setTitle(getString(R.string.avoid_pt_types)) .setLayoutId(R.layout.bottom_sheet_item_simple_56dp) .setOnClickListener(new View.OnClickListener() { @Override @@ -461,7 +463,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { GeneralRouter.USE_HEIGHT_OBSTACLES, DividerItem.KEY, GeneralRouter.ALLOW_MOTORWAYS, - AvoidRoadsTypesRoutingParameter.KEY, + AvoidRoadsRoutingParameter.KEY, ShowAlongTheRouteItem.KEY, DividerItem.KEY, GpxLocalRoutingParameter.KEY, @@ -471,7 +473,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { PEDESTRIAN(MuteSoundRoutingParameter.KEY, GeneralRouter.USE_HEIGHT_OBSTACLES, DividerItem.KEY, - AvoidRoadsTypesRoutingParameter.KEY, + AvoidRoadsRoutingParameter.KEY, ShowAlongTheRouteItem.KEY, DividerItem.KEY, GpxLocalRoutingParameter.KEY, @@ -480,7 +482,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { PUBLIC_TRANSPORT(// MuteSoundRoutingParameter.KEY, // DividerItem.KEY, - AvoidRoadsTypesRoutingParameter.KEY, + AvoidPTTypesRoutingParameter.KEY, // ShowAlongTheRouteItem.KEY, // DividerItem.KEY, OtherSettingsRoutingParameter.KEY), diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java index 9a7067e272..1cf42dc376 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java @@ -355,8 +355,6 @@ public class RoutingOptionsHelper { return new RouteSimulationItem(); case ShowAlongTheRouteItem.KEY: return new ShowAlongTheRouteItem(); - case AvoidRoadsTypesRoutingParameter.KEY: - return new AvoidRoadsTypesRoutingParameter(); case AvoidRoadsRoutingParameter.KEY: return new AvoidRoadsRoutingParameter(); case GpxLocalRoutingParameter.KEY: @@ -781,11 +779,11 @@ public class RoutingOptionsHelper { } } - public static class AvoidRoadsTypesRoutingParameter extends LocalRoutingParameter { + public static class AvoidPTTypesRoutingParameter extends LocalRoutingParameter { - public static final String KEY = "AvoidRoadsTypesRoutingParameter"; + public static final String KEY = "AvoidPTTypesRoutingParameter"; - public AvoidRoadsTypesRoutingParameter() { + public AvoidPTTypesRoutingParameter() { super(null); } @@ -795,15 +793,16 @@ public class RoutingOptionsHelper { @Override public int getActiveIconId() { - return R.drawable.ic_action_road_works_dark; + return R.drawable.ic_action_bus_dark; } @Override public int getDisabledIconId() { - return R.drawable.ic_action_road_works_dark; + return R.drawable.ic_action_bus_dark; } } + public static class GpxLocalRoutingParameter extends LocalRoutingParameter { public static final String KEY = "GpxLocalRoutingParameter"; diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 828e50356e..90289963f8 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -308,6 +308,7 @@ public class RoutingHelper { Location locationProjection = currentLocation; if (isPublicTransportMode() && currentLocation != null && finalLocation != null && (targetPointsChanged || transportRoutingHelper.getStartLocation() == null)) { + transportRoutingHelper.setApplicationMode(mode); transportRoutingHelper.setFinalAndCurrentLocation(finalLocation, new LatLon(currentLocation.getLatitude(), currentLocation.getLongitude())); } @@ -946,6 +947,7 @@ public class RoutingHelper { if (isPublicTransportMode()) { Location start = lastFixedLocation; LatLon finish = finalLocation; + transportRoutingHelper.setApplicationMode(mode); if (start != null && finish != null) { transportRoutingHelper.setFinalAndCurrentLocation(finish, new LatLon(start.getLatitude(), start.getLongitude())); diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java index 17c983418d..efa2130a21 100644 --- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java @@ -14,10 +14,12 @@ import net.osmand.osm.edit.Node; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.routing.RouteCalculationParams.RouteCalculationResultListener; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback; +import net.osmand.router.GeneralRouter; import net.osmand.router.RouteCalculationProgress; import net.osmand.router.RoutingConfiguration; import net.osmand.router.TransportRoutePlanner; @@ -35,6 +37,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.TreeMap; import java.util.concurrent.ConcurrentLinkedQueue; import static net.osmand.plus.notifications.OsmandNotification.NotificationType.NAVIGATION; @@ -46,6 +49,7 @@ public class TransportRoutingHelper { private List> listeners = new LinkedList<>(); private OsmandApplication app; + private ApplicationMode applicationMode = ApplicationMode.PUBLIC_TRANSPORT; private RoutingHelper routingHelper; private List routes; @@ -54,7 +58,6 @@ public class TransportRoutingHelper { private LatLon startLocation; private LatLon endLocation; - private boolean useSchedule; private Thread currentRunningJob; private String lastRouteCalcError; @@ -63,6 +66,7 @@ public class TransportRoutingHelper { private TransportRouteCalculationProgressCallback progressRoute; + public TransportRoutingHelper(@NonNull OsmandApplication app) { this.app = app; } @@ -79,13 +83,6 @@ public class TransportRoutingHelper { return endLocation; } - public boolean isUseSchedule() { - return useSchedule; - } - - public void setUseSchedule(boolean useSchedule) { - this.useSchedule = useSchedule; - } public int getCurrentRoute() { return currentRoute; @@ -188,7 +185,7 @@ public class TransportRoutingHelper { TransportRouteCalculationParams params = new TransportRouteCalculationParams(); params.start = start; params.end = end; - params.useSchedule = useSchedule; + params.mode = applicationMode; params.type = RouteService.OSMAND; params.ctx = app; params.calculationProgress = new RouteCalculationProgress(); @@ -360,6 +357,10 @@ public class TransportRoutingHelper { return r.left == 0 && r.right == 0 ? null : r; } + public void setApplicationMode(ApplicationMode applicationMode) { + this.applicationMode = applicationMode; + } + public interface TransportRouteCalculationProgressCallback { void start(); @@ -375,8 +376,9 @@ public class TransportRoutingHelper { public LatLon end; public OsmandApplication ctx; + public ApplicationMode mode; public RouteService type; - public boolean useSchedule; + public Map params = new TreeMap<>(); public RouteCalculationProgress calculationProgress; public TransportRouteCalculationResultListener resultListener; @@ -442,9 +444,24 @@ public class TransportRoutingHelper { private List calculateRouteImpl(TransportRouteCalculationParams params) throws IOException, InterruptedException { RoutingConfiguration.Builder config = params.ctx.getDefaultRoutingConfig(); BinaryMapIndexReader[] files = params.ctx.getResourceManager().getTransportRoutingMapFiles(); - - TransportRoutingConfiguration cfg = new TransportRoutingConfiguration(config); - cfg.useSchedule = params.useSchedule; + params.params.clear(); + OsmandSettings settings = params.ctx.getSettings(); + for(Map.Entry e : config.getRouter(params.mode.getStringKey()).getParameters().entrySet()){ + String key = e.getKey(); + GeneralRouter.RoutingParameter pr = e.getValue(); + String vl; + if(pr.getType() == GeneralRouter.RoutingParameterType.BOOLEAN) { + OsmandSettings.CommonPreference pref = settings.getCustomRoutingBooleanProperty(key, pr.getDefaultBoolean()); + Boolean bool = pref.getModeValue(params.mode); + vl = bool ? "true" : null; + } else { + vl = settings.getCustomRoutingProperty(key, "").getModeValue(params.mode); + } + if(vl != null && vl.length() > 0) { + params.params.put(key, vl); + } + } + TransportRoutingConfiguration cfg = new TransportRoutingConfiguration(config, params.params); TransportRoutePlanner planner = new TransportRoutePlanner(); TransportRoutingContext ctx = new TransportRoutingContext(cfg, files); ctx.calculationProgress = params.calculationProgress;