Update routing

This commit is contained in:
vshcherb 2014-03-26 21:20:50 +01:00
parent 22c65c06c7
commit 5bfa50d994
11 changed files with 69 additions and 41 deletions

View file

@ -4,11 +4,15 @@
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
<!-- <LinearLayout
android:id="@+id/TopBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
android:gravity="center_horizontal"
android:orientation="horizontal" /> -->
<ScrollView
android:layout_width="fill_parent"
@ -23,6 +27,9 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/RouteTargets" >
<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>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -142,7 +142,7 @@ public class TargetPointsHelper {
public void updateRoutingHelper() {
LatLon start = settings.getPointToStart();
if(routingHelper.isFollowingMode() || start == null) {
if((routingHelper.isFollowingMode() && routingHelper.getLastProjection() != null) || start == null) {
Location lastKnownLocation = ctx.getLocationProvider().getLastKnownLocation();
//Location lastKnownLocation = routingHelper.getLastProjection();
routingHelper.setFinalAndCurrentLocation(settings.getPointToNavigate(),
@ -209,7 +209,6 @@ public class TargetPointsHelper {
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) {

View file

@ -485,21 +485,6 @@ public class MapActivity extends AccessibleActivity {
}
public void followRoute(ApplicationMode appMode, LatLon finalLocation, List<LatLon> intermediatePoints, net.osmand.Location currentLocation,
GPXRouteParamsBuilder gpxRoute){
getMapViewTrackingUtilities().backToLocationImpl();
RoutingHelper routingHelper = app.getRoutingHelper();
settings.APPLICATION_MODE.set(appMode);
settings.FOLLOW_THE_ROUTE.set(true);
if(gpxRoute == null) {
settings.FOLLOW_THE_GPX_ROUTE.set(null);
}
routingHelper.setFollowingMode(true);
routingHelper.setFinalAndCurrentLocation(finalLocation, intermediatePoints, currentLocation, gpxRoute);
app.initVoiceCommandPlayer(MapActivity.this);
}
public LatLon getMapLocation(){
return new LatLon(mapView.getLatitude(), mapView.getLongitude());

View file

@ -17,6 +17,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import android.app.AlertDialog;
@ -111,7 +112,7 @@ public class NavigateAction {
}
}
if(endPoint != null){
mapActivity.followRoute(appMode, endPoint,
followRoute(appMode, endPoint,
new ArrayList<LatLon>(), startForRouting, gpxRoute);
settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
}
@ -252,7 +253,7 @@ public class NavigateAction {
ApplicationMode mode = getAppMode(buttons, settings, values);
// save application mode controls (optimal)
dialog.dismiss();
mapActivity.followRoute(mode, targets.getPointToNavigate(), targets.getIntermediatePoints(),
followRoute(mode, targets.getPointToNavigate(), targets.getIntermediatePoints(),
from, null);
}
};
@ -421,5 +422,19 @@ public class NavigateAction {
return settings.getApplicationMode();
}
public void followRoute(ApplicationMode appMode, LatLon finalLocation, List<LatLon> intermediatePoints, net.osmand.Location currentLocation,
GPXRouteParamsBuilder gpxRoute){
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
RoutingHelper routingHelper = app.getRoutingHelper();
settings.APPLICATION_MODE.set(appMode);
settings.FOLLOW_THE_ROUTE.set(true);
if(gpxRoute == null) {
settings.FOLLOW_THE_GPX_ROUTE.set(null);
}
routingHelper.setFollowingMode(true);
routingHelper.setFinalAndCurrentLocation(finalLocation, intermediatePoints, currentLocation, gpxRoute);
app.initVoiceCommandPlayer(mapActivity);
}
}

View file

@ -13,6 +13,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import org.apache.commons.logging.Log;
@ -140,10 +141,11 @@ public class FailSafeFuntions {
if (endPoint == null) {
notRestoreRoutingMode(ma, app);
} else {
ma.followRoute(settings.getApplicationMode(), endPoint,
targetPoints.getIntermediatePoints(), null, gpxRoute);
enterRoutingMode(ma, gpxRoute);
}
}
};
task.execute(gpxPath);
@ -154,6 +156,22 @@ public class FailSafeFuntions {
}
public static void enterRoutingMode(MapActivity ma,
GPXRouteParamsBuilder gpxRoute) {
OsmandApplication app = ma.getMyApplication();
ma.getMapViewTrackingUtilities().backToLocationImpl();
RoutingHelper routingHelper = app.getRoutingHelper();
if(gpxRoute == null) {
app.getSettings().FOLLOW_THE_GPX_ROUTE.set(null);
}
routingHelper.setGpxParams(gpxRoute);
app.getTargetPointsHelper().setStartPoint(null, false, null);
app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true);
app.getTargetPointsHelper().updateRoutingHelper();
app.initVoiceCommandPlayer(ma);
}
private static void notRestoreRoutingMode(MapActivity ma, OsmandApplication app){
ma.updateApplicationModeSettings();
app.getRoutingHelper().clearCurrentRoute(null, new ArrayList<LatLon>());

View file

@ -112,21 +112,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc
mapView.setLatLon(location.getLatitude(), location.getLongitude());
}
RoutingHelper routingHelper = app.getRoutingHelper();
// we arrived at destination finished
if (!routingHelper.isFollowingMode() && followingMode) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
}
});
}
followingMode = routingHelper.isFollowingMode();
if(routePlanningMode != routingHelper.isRoutePlanningMode()) {
switchToRoutePlanningMode();
}
// When location is changed we need to refresh map in order to show movement!
mapView.refreshMap();
}

View file

@ -14,6 +14,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.OsmandMapTileView;
@ -73,7 +74,7 @@ public class OsMoDroidPlugin extends OsmandPlugin implements MonitoringInfoContr
@Override
public void run() {
activity.followRoute(app.getSettings().getApplicationMode(), targets.getPointToNavigate(), targets.getIntermediatePoints(),app.getLastKnownLocation(), null);
FailSafeFuntions.enterRoutingMode(activity, null);
}
});

View file

@ -427,6 +427,13 @@ public class RoutingHelper {
String description = targets.getPointNavigateDescription();
voiceRouter.arrivedDestinationPoint(description);
clearCurrentRoute(null, null);
setRoutePlanningMode(false);
app.runInUIThread(new Runnable() {
@Override
public void run() {
settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
}
});
// targets.clearPointToNavigate(false);
return true;

View file

@ -4,7 +4,6 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import android.graphics.Canvas;
@ -41,10 +40,6 @@ public class MapNavigateControl extends MapControls {
ri.showDialog();
} else {
mapActivity.getMapViewTrackingUtilities().backToLocationImpl();
GPXRouteParams gpxRoute = null; // TODO gpx route
if (gpxRoute == null) {
app.getSettings().FOLLOW_THE_GPX_ROUTE.set(null);
}
app.getSettings().FOLLOW_THE_ROUTE.set(true);
routingHelper.setFollowingMode(true);
routingHelper.setRoutePlanningMode(false);

View file

@ -16,6 +16,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoActivity;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
import net.osmand.plus.views.ContextMenuLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -111,6 +112,15 @@ public class MapRouteInfoControl extends MapControls implements IRouteInformatio
} else {
lmain.findViewById(R.id.RouteInfoControls).setVisibility(View.GONE);
lmain.findViewById(R.id.SimulateRoute).setVisibility(View.GONE);
TextView textView = (TextView) lmain.findViewById(R.id.ValidateTextView);
TargetPointsHelper targets = getTargets();
boolean osmandRouter = mapActivity.getMyApplication().getSettings().ROUTER_SERVICE.get() == RouteService.OSMAND;
if(osmandRouter && targets.hasLongDistancesInBetween(routingHelper.getLastProjection(), 15000)) {
textView.setText(R.string.route_is_too_long);
textView.setVisibility(View.VISIBLE);
} else{
textView.setVisibility(View.GONE);
}
}
builder.setView(lmain);

View file

@ -283,6 +283,7 @@ public class MapRoutePreferencesControl extends MapControls {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position == 0) {
mapActivity.getRoutingHelper().setGpxParams(null);
settings.FOLLOW_THE_GPX_ROUTE.set(null);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
updateParameters();
} else if(position == 1) {
@ -319,6 +320,7 @@ public class MapRoutePreferencesControl extends MapControls {
}
}
mapActivity.getRoutingHelper().setGpxParams(params);
settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
updateSpinnerItems(gpxSpinner);
updateParameters();