Add warning for long routes

This commit is contained in:
vshcherb 2013-10-23 21:59:36 +02:00
parent 2c5532e4f5
commit 3dd3ec8fa9
4 changed files with 30 additions and 4 deletions

View file

@ -3,7 +3,8 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" > android:orientation="vertical" >
<TextView android:id="@+id/ValidateTextView" android:textSize="16sp" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="" android:gravity="center" android:textColor="@color/color_invalid"></TextView>
<LinearLayout <LinearLayout
android:id="@+id/LinearLayout" android:id="@+id/LinearLayout"
android:layout_width="fill_parent" android:layout_width="fill_parent"

View file

@ -9,6 +9,8 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="route_is_too_long">The possible route is too long to be calculated by OsmAnd offline router.
In average routing is possible between points located in 200km radius, please add a waypoint to see the route. </string>
<string name="route_distance_none">No auto zoom</string> <string name="route_distance_none">No auto zoom</string>
<string name="route_distance_close">To close-up</string> <string name="route_distance_close">To close-up</string>
<string name="route_distance_far">To mid-range</string> <string name="route_distance_far">To mid-range</string>

View file

@ -8,6 +8,7 @@ import net.osmand.Location;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.util.MapUtils;
public class TargetPointsHelper { public class TargetPointsHelper {
@ -16,11 +17,9 @@ public class TargetPointsHelper {
private LatLon pointToNavigate = null; private LatLon pointToNavigate = null;
private OsmandSettings settings; private OsmandSettings settings;
private RoutingHelper routingHelper; private RoutingHelper routingHelper;
private ClientContext ctx;
private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>(); private List<StateChangedListener<Void>> listeners = new ArrayList<StateChangedListener<Void>>();
public TargetPointsHelper(ClientContext ctx){ public TargetPointsHelper(ClientContext ctx){
this.ctx = ctx;
this.settings = ctx.getSettings(); this.settings = ctx.getSettings();
this.routingHelper = ctx.getRoutingHelper(); this.routingHelper = ctx.getRoutingHelper();
readFromSettings(settings); readFromSettings(settings);
@ -164,6 +163,23 @@ public class TargetPointsHelper {
updateRouteAndReferesh(updateRoute); updateRouteAndReferesh(updateRoute);
} }
public boolean hasLongDistancesInBetween(Location current, double dist) {
List<LatLon> list = getIntermediatePointsWithTarget();
if(!list.isEmpty()) {
if(current != null && MapUtils.getDistance(list.get(0), current.getLatitude(), current.getLongitude()) > dist) {
return true;
}
for(int i = 1; i < list.size(); i++) {
if(MapUtils.getDistance(list.get(i-1), list.get(i)) > dist) {
return true;
}
}
}
return false;
}
public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){ public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){
navigateToPoint(point, updateRoute, intermediate, null); navigateToPoint(point, updateRoute, intermediate, null);
} }

View file

@ -538,6 +538,8 @@ public class MapActivityActions implements DialogProvider {
} }
return view; return view;
} }
public void getDirections(final Location mapView, String name, DirectionDialogStyle style) { public void getDirections(final Location mapView, String name, DirectionDialogStyle style) {
final Location current = getLastKnownLocation(); final Location current = getLastKnownLocation();
Builder builder = new AlertDialog.Builder(mapActivity); Builder builder = new AlertDialog.Builder(mapActivity);
@ -554,10 +556,15 @@ public class MapActivityActions implements DialogProvider {
buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton); buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton);
buttons[ApplicationMode.PEDESTRIAN.ordinal()].setButtonDrawable(R.drawable.ic_pedestrian); buttons[ApplicationMode.PEDESTRIAN.ordinal()].setButtonDrawable(R.drawable.ic_pedestrian);
final Spinner fromSpinner = setupFromSpinner(mapView, name,view, style); final Spinner fromSpinner = setupFromSpinner(mapView, name, view, style);
final List<LatLon> toList = new ArrayList<LatLon>(); final List<LatLon> toList = new ArrayList<LatLon>();
final Spinner toSpinner = setupToSpinner(mapView, name,view, toList, style); final Spinner toSpinner = setupToSpinner(mapView, name,view, toList, style);
if(targets.hasLongDistancesInBetween(current != null ? current : mapView, 150000)) {
TextView textView = (TextView) view.findViewById(R.id.ValidateTextView);
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
}
String via = generateViaDescription(); String via = generateViaDescription();
if(via.length() == 0){ if(via.length() == 0){