diff --git a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java index fac1ef116f..b3298aa8cd 100644 --- a/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/net/osmand/binary/RouteDataObject.java @@ -517,6 +517,22 @@ public class RouteDataObject { return getHighway(types, region); } + public boolean hasPrivateAccess() { + int sz = types.length; + for (int i = 0; i < sz; i++) { + RouteTypeRule r = region.quickGetEncodingRule(types[i]); + if ("motorcar".equals(r.getTag()) + || "motor_vehicle".equals(r.getTag()) + || "vehicle".equals(r.getTag()) + || "access".equals(r.getTag())) { + if (r.getValue().equals("private")) { + return true; + } + } + } + return false; + } + public String getValue(String tag) { for (int i = 0; i < types.length; i++) { RouteTypeRule r = region.quickGetEncodingRule(types[i]); diff --git a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java index ad0189b99e..7df7a70a6f 100644 --- a/OsmAnd-java/src/net/osmand/router/GeneralRouter.java +++ b/OsmAnd-java/src/net/osmand/router/GeneralRouter.java @@ -31,7 +31,8 @@ public class GeneralRouter implements VehicleRouter { public static final String AVOID_MOTORWAY = "avoid_motorway"; public static final String AVOID_UNPAVED = "avoid_unpaved"; public static final String PREFER_MOTORWAYS = "prefer_motorway"; - + public static final String ALLOW_PRIVATE = "allow_private"; + private final RouteAttributeContext[] objectAttributes; public final Map attributes; private final Map parameters; @@ -41,7 +42,8 @@ public class GeneralRouter implements VehicleRouter { private final ArrayList ruleToValue; private boolean shortestRoute; private boolean heightObstacles; - + private boolean allowPrivate; + private Map> regionConvert = new LinkedHashMap>(); // cached values @@ -130,6 +132,7 @@ public class GeneralRouter implements VehicleRouter { for (int i = 0; i < objectAttributes.length; i++) { objectAttributes[i] = new RouteAttributeContext(parent.objectAttributes[i], params); } + allowPrivate = params.containsKey(ALLOW_PRIVATE) && parseSilentBoolean(params.get(ALLOW_PRIVATE), false); shortestRoute = params.containsKey(USE_SHORTEST_WAY) && parseSilentBoolean(params.get(USE_SHORTEST_WAY), false); heightObstacles = params.containsKey(USE_HEIGHT_OBSTACLES) && parseSilentBoolean(params.get(USE_HEIGHT_OBSTACLES), false); if(shortestRoute) { @@ -195,7 +198,11 @@ public class GeneralRouter implements VehicleRouter { } return res >= 0; } - + + public boolean isAllowPrivate() { + return allowPrivate; + } + public long[] getImpassableRoadIds() { if(impassableRoads == null) { return new long[0]; diff --git a/OsmAnd-java/src/net/osmand/router/RouteCalculationProgress.java b/OsmAnd-java/src/net/osmand/router/RouteCalculationProgress.java index a0607736a0..21f47411cf 100644 --- a/OsmAnd-java/src/net/osmand/router/RouteCalculationProgress.java +++ b/OsmAnd-java/src/net/osmand/router/RouteCalculationProgress.java @@ -16,5 +16,5 @@ public class RouteCalculationProgress { public int visitedSegments = 0; public boolean isCancelled; - + public boolean requestPrivateAccessRouting; } diff --git a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java index f1a84b7c79..530ba88637 100644 --- a/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java +++ b/OsmAnd-java/src/net/osmand/router/RoutePlannerFrontEnd.java @@ -1,13 +1,6 @@ package net.osmand.router; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - import net.osmand.NativeLibrary; import net.osmand.PlatformUtil; import net.osmand.binary.BinaryMapIndexReader; @@ -18,11 +11,19 @@ import net.osmand.data.LatLon; import net.osmand.data.QuadPoint; import net.osmand.router.BinaryRoutePlanner.RouteSegment; import net.osmand.router.BinaryRoutePlanner.RouteSegmentPoint; -import net.osmand.util.Algorithms; +import net.osmand.router.GeneralRouter.GeneralRouterProfile; import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; + public class RoutePlannerFrontEnd { private boolean useOldVersion; @@ -110,12 +111,39 @@ public class RoutePlannerFrontEnd { } + private boolean needRequestPrivateAccessRouting(RoutingContext ctx, List points) throws IOException { + boolean res = false; + GeneralRouter router = (GeneralRouter) ctx.getRouter(); + if (router != null && !router.isAllowPrivate()) { + ctx.setRouter(new GeneralRouter(GeneralRouterProfile.CAR, new LinkedHashMap())); + for (LatLon latLon : points) { + RouteSegmentPoint rp = findRouteSegment(latLon.getLatitude(), latLon.getLongitude(), ctx, null); + if (rp != null && rp.road != null) { + if (rp.road.hasPrivateAccess()) { + res = true; + break; + } + } + } + ctx.setRouter(router); + } + return res; + } + public List searchRoute(final RoutingContext ctx, LatLon start, LatLon end, List intermediates, PrecalculatedRouteDirection routeDirection) throws IOException, InterruptedException { if (ctx.calculationProgress == null) { ctx.calculationProgress = new RouteCalculationProgress(); } boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty(); + List targets = new ArrayList<>(); + targets.add(end); + if (!intermediatesEmpty) { + targets.addAll(intermediates); + } + if (needRequestPrivateAccessRouting(ctx, targets)) { + ctx.calculationProgress.requestPrivateAccessRouting = true; + } double maxDistance = MapUtils.getDistance(start, end); if (!intermediatesEmpty) { LatLon b = start; diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a7caf87576..ffe0ea19d0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Your destination is located in the area with a private access. Do you want to allow access to the private roads for this trip? Restart search Increase search radius Nothing found :( diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index a34e0b1080..8be2d07152 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -703,6 +703,7 @@ public class OsmandSettings { } public final CommonPreference USE_FAST_RECALCULATION = new BooleanPreference("use_fast_recalculation", true).makeGlobal().cache(); + public final CommonPreference FORCE_PRIVATE_ACCESS_ROUTING_ASKED = new BooleanPreference("force_private_access_routing", false).makeProfile().cache(); public final CommonPreference SHOW_CARD_TO_CHOOSE_DRAWER = new BooleanPreference("show_card_to_choose_drawer", false).makeGlobal(); public final CommonPreference SHOW_DASHBOARD_ON_START = new BooleanPreference("should_show_dashboard_on_start", false).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 8e2713d528..1472f416f8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -111,6 +111,7 @@ import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.render.RenderingRulesStorage; +import net.osmand.router.GeneralRouter; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -384,6 +385,37 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } } + @Override + public void requestPrivateAccessRouting() { + if (!settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(getRoutingHelper().getAppMode())) { + final OsmandSettings.CommonPreference allowPrivate + = settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false); + final List modes = ApplicationMode.values(settings); + for (ApplicationMode mode : modes) { + if (!allowPrivate.getModeValue(mode)) { + settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, true); + } + } + if (!allowPrivate.getModeValue(getRoutingHelper().getAppMode())) { + AlertDialog.Builder dlg = new AlertDialog.Builder(MapActivity.this); + dlg.setMessage(R.string.private_access_routing_req); + dlg.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + for (ApplicationMode mode : modes) { + if (!allowPrivate.getModeValue(mode)) { + allowPrivate.setModeValue(mode, true); + } + } + getRoutingHelper().recalculateRouteDueToSettingsChange(); + } + }); + dlg.setNegativeButton(R.string.shared_string_no, null); + dlg.show(); + } + } + } + @Override public void finish() { pbExtView.setVisibility(View.GONE); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 931581cfdf..a190b2a893 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -55,6 +55,7 @@ import net.osmand.plus.views.BaseMapLayer; import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.router.GeneralRouter; import org.apache.commons.logging.Log; @@ -854,6 +855,13 @@ public class MapActivityActions implements DialogProvider { getMyApplication().stopNavigation(); mapActivity.updateApplicationModeSettings(); mapActivity.getDashboard().clearDeletedPoints(); + List modes = ApplicationMode.values(settings); + for (ApplicationMode mode : modes) { + if (settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(mode)) { + settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, false); + settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false).setModeValue(mode, false); + } + } } public AlertDialog stopNavigationActionConfirm() { diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java index 03aabc00c2..971e9f7263 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java @@ -956,6 +956,7 @@ public class RoutingHelper { private void updateProgress(final RouteCalculationParams params) { if(progressRoute != null ) { app.runInUIThread(new Runnable() { + @Override public void run() { RouteCalculationProgress calculationProgress = params.calculationProgress; @@ -971,9 +972,15 @@ public class RoutingHelper { // different calculation started return; } else { + if (calculationProgress.requestPrivateAccessRouting) { + progressRoute.requestPrivateAccessRouting(); + } updateProgress(params); } } else { + if (calculationProgress.requestPrivateAccessRouting) { + progressRoute.requestPrivateAccessRouting(); + } progressRoute.finish(); } } @@ -989,9 +996,8 @@ public class RoutingHelper { // set visibility public void updateProgress(int progress); - + public void requestPrivateAccessRouting(); public void finish(); - }