Restructure gpx routing
This commit is contained in:
parent
5f2d7863d6
commit
1840f61f72
8 changed files with 261 additions and 136 deletions
|
@ -9,8 +9,7 @@ import net.osmand.Location;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
|
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
@ -40,18 +39,18 @@ public class OsmAndLocationSimulation {
|
||||||
return routeAnimation != null;
|
return routeAnimation != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startStopRouteAnimationRoute(final MapActivity ma) {
|
// public void startStopRouteAnimationRoute(final MapActivity ma) {
|
||||||
if (!isRouteAnimating()) {
|
// if (!isRouteAnimating()) {
|
||||||
List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
|
// List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
|
||||||
if (currentRoute.isEmpty()) {
|
// if (currentRoute.isEmpty()) {
|
||||||
AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
|
// AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
|
||||||
} else {
|
// } else {
|
||||||
startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
|
// startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
stop();
|
// stop();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void startStopRouteAnimation(final MapActivity ma) {
|
public void startStopRouteAnimation(final MapActivity ma) {
|
||||||
if (!isRouteAnimating()) {
|
if (!isRouteAnimating()) {
|
||||||
|
@ -86,18 +85,17 @@ public class OsmAndLocationSimulation {
|
||||||
new CallbackWithObject<GPXUtilities.GPXFile>() {
|
new CallbackWithObject<GPXUtilities.GPXFile>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean processResult(GPXUtilities.GPXFile result) {
|
public boolean processResult(GPXUtilities.GPXFile result) {
|
||||||
GPXRouteParamsBuilder builder = GPXRouteParams.GPXRouteParamsBuilder.newBuilder(result, app.getSettings());
|
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result, app.getSettings());
|
||||||
if(ch.isChecked()){
|
if(ch.isChecked()){
|
||||||
builder.announceWaypoints();
|
builder.setAnnounceWaypoints(true);
|
||||||
}
|
}
|
||||||
GPXRouteParams prms = builder.build();
|
startAnimationThread(app.getRoutingHelper(), ma, builder.getPoints(), true,
|
||||||
startAnimationThread(app.getRoutingHelper(), ma, prms.getPoints(), true,
|
|
||||||
speedup.getProgress() + 1);
|
speedup.getProgress() + 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
|
List<Location> currentRoute = app.getRoutingHelper().getCurrentCalculatedRoute();
|
||||||
if(currentRoute.isEmpty()) {
|
if(currentRoute.isEmpty()) {
|
||||||
AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
|
AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -32,7 +32,7 @@ import net.osmand.plus.base.FailSafeFuntions;
|
||||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
import net.osmand.plus.resources.ResourceManager;
|
import net.osmand.plus.resources.ResourceManager;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
|
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
|
||||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||||
|
@ -485,7 +485,8 @@ public class MapActivity extends AccessibleActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void followRoute(ApplicationMode appMode, LatLon finalLocation, List<LatLon> intermediatePoints, net.osmand.Location currentLocation, GPXRouteParams gpxRoute){
|
public void followRoute(ApplicationMode appMode, LatLon finalLocation, List<LatLon> intermediatePoints, net.osmand.Location currentLocation,
|
||||||
|
GPXRouteParamsBuilder gpxRoute){
|
||||||
getMapViewTrackingUtilities().backToLocationImpl();
|
getMapViewTrackingUtilities().backToLocationImpl();
|
||||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||||
settings.APPLICATION_MODE.set(appMode);
|
settings.APPLICATION_MODE.set(appMode);
|
||||||
|
|
|
@ -17,8 +17,7 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
|
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
@ -83,35 +82,32 @@ public class NavigateAction {
|
||||||
boolean calculateOsmAndRoute = props[4];
|
boolean calculateOsmAndRoute = props[4];
|
||||||
settings.SPEAK_GPX_WPT.set(announceGpxWpt);
|
settings.SPEAK_GPX_WPT.set(announceGpxWpt);
|
||||||
settings.CALC_GPX_ROUTE.set(calculateOsmAndRoute);
|
settings.CALC_GPX_ROUTE.set(calculateOsmAndRoute);
|
||||||
GPXRouteParamsBuilder bld = GPXRouteParamsBuilder.newBuilder(result, settings);
|
GPXRouteParamsBuilder gpxRoute = new GPXRouteParamsBuilder(result, settings);
|
||||||
if(reverse) {
|
if(reverse) {
|
||||||
bld.reverse();
|
gpxRoute.setReverse(true);
|
||||||
}
|
}
|
||||||
if(announceGpxWpt) {
|
if(announceGpxWpt) {
|
||||||
bld.announceWaypoints();
|
gpxRoute.setAnnounceWaypoints(true);
|
||||||
}
|
}
|
||||||
if(calculateOsmAndRoute) {
|
if(calculateOsmAndRoute) {
|
||||||
bld.calculateOsmAndRoute();
|
gpxRoute.setCalculateOsmAndRoute(true);
|
||||||
}
|
}
|
||||||
GPXRouteParams gpxRoute = bld.build();
|
if(passWholeWay) {
|
||||||
Location loc = getLastKnownLocation();
|
gpxRoute.setPassWholeRoute(true);
|
||||||
if(passWholeWay && loc != null){
|
|
||||||
gpxRoute.setStartPoint(loc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Location startForRouting = getLastKnownLocation();
|
Location startForRouting = getLastKnownLocation();
|
||||||
if(startForRouting == null){
|
if(startForRouting == null){
|
||||||
startForRouting = gpxRoute.getStartPointForRoute();
|
startForRouting = null;//gpxRoute.getStartPointForRoute();
|
||||||
}
|
}
|
||||||
|
|
||||||
LatLon endPoint = endForRouting;
|
LatLon endPoint = endForRouting;
|
||||||
if(endPoint == null || !useDestination){
|
if(endPoint == null || !useDestination){
|
||||||
LatLon point = gpxRoute.getLastPoint();
|
// LatLon point = gpxRoute.getLastPoint();
|
||||||
if(point != null){
|
// if(point != null){
|
||||||
endPoint = point;
|
// endPoint = point;
|
||||||
}
|
// }
|
||||||
if(endPoint != null) {
|
if(endPoint != null) {
|
||||||
app.getTargetPointsHelper().navigateToPoint(point, false, -1);
|
app.getTargetPointsHelper().navigateToPoint(endPoint, false, -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(endPoint != null){
|
if(endPoint != null){
|
||||||
|
|
|
@ -3,8 +3,6 @@ package net.osmand.plus.base;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.access.AccessibleAlertBuilder;
|
import net.osmand.access.AccessibleAlertBuilder;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -15,8 +13,10 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -124,26 +124,24 @@ public class FailSafeFuntions {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile result) {
|
protected void onPostExecute(GPXFile result) {
|
||||||
final GPXRouteParams gpxRoute;
|
final GPXRouteParamsBuilder gpxRoute;
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
GPXRouteParamsBuilder builder = GPXRouteParamsBuilder.newBuilder(result, settings);
|
gpxRoute = new GPXRouteParamsBuilder(result, settings);
|
||||||
if (settings.SPEAK_GPX_WPT.get()) {
|
if (settings.SPEAK_GPX_WPT.get()) {
|
||||||
builder.announceWaypoints();
|
gpxRoute.setAnnounceWaypoints(true);
|
||||||
}
|
}
|
||||||
if(settings.CALC_GPX_ROUTE.get()) {
|
if(settings.CALC_GPX_ROUTE.get()) {
|
||||||
builder.calculateOsmAndRoute();
|
gpxRoute.setCalculateOsmAndRoute(true);
|
||||||
}
|
}
|
||||||
gpxRoute = builder.build();
|
|
||||||
} else {
|
} else {
|
||||||
gpxRoute = null;
|
gpxRoute = null;
|
||||||
}
|
}
|
||||||
LatLon endPoint = pointToNavigate != null ? pointToNavigate : gpxRoute.getLastPoint();
|
LatLon endPoint = pointToNavigate;
|
||||||
net.osmand.Location startPoint = gpxRoute == null ? null : gpxRoute.getStartPointForRoute();
|
|
||||||
if (endPoint == null) {
|
if (endPoint == null) {
|
||||||
notRestoreRoutingMode(ma, app);
|
notRestoreRoutingMode(ma, app);
|
||||||
} else {
|
} else {
|
||||||
ma.followRoute(settings.getApplicationMode(), endPoint,
|
ma.followRoute(settings.getApplicationMode(), endPoint,
|
||||||
targetPoints.getIntermediatePoints(), startPoint, gpxRoute);
|
targetPoints.getIntermediatePoints(), null, gpxRoute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,13 +9,11 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
|
||||||
import net.osmand.plus.views.MonitoringInfoControl;
|
import net.osmand.plus.views.MonitoringInfoControl;
|
||||||
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
|
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
|
|
|
@ -112,18 +112,80 @@ public class RouteProvider {
|
||||||
public RouteProvider(){
|
public RouteProvider(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GPXRouteParamsBuilder {
|
||||||
|
boolean calculateOsmAndRoute = false;
|
||||||
|
// parameters
|
||||||
|
private final GPXFile file;
|
||||||
|
private boolean announceWaypoints;
|
||||||
|
private boolean reverse;
|
||||||
|
private boolean leftSide;
|
||||||
|
private boolean passWholeRoute;
|
||||||
|
|
||||||
|
public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings){
|
||||||
|
leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAnnounceWaypoints() {
|
||||||
|
return announceWaypoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReverse() {
|
||||||
|
return reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCalculateOsmAndRoute() {
|
||||||
|
return calculateOsmAndRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCalculateOsmAndRoute(boolean calculateOsmAndRoute) {
|
||||||
|
this.calculateOsmAndRoute = calculateOsmAndRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassWholeRoute(boolean passWholeRoute){
|
||||||
|
this.passWholeRoute = passWholeRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPassWholeRoute() {
|
||||||
|
return passWholeRoute;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPXRouteParams build(Location start, OsmandSettings settings) {
|
||||||
|
GPXRouteParams res = new GPXRouteParams();
|
||||||
|
res.prepareGPXFile(this);
|
||||||
|
if(passWholeRoute && start != null){
|
||||||
|
res.points.add(0, start);
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setAnnounceWaypoints(boolean announceWaypoints) {
|
||||||
|
this.announceWaypoints = announceWaypoints;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReverse(boolean reverse) {
|
||||||
|
this.reverse = reverse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GPXFile getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getPoints() {
|
||||||
|
GPXRouteParams copy = new GPXRouteParams();
|
||||||
|
copy.prepareGPXFile(this);
|
||||||
|
return copy.getPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class GPXRouteParams {
|
public static class GPXRouteParams {
|
||||||
List<Location> points = new ArrayList<Location>();
|
List<Location> points = new ArrayList<Location>();
|
||||||
List<RouteDirectionInfo> directions;
|
List<RouteDirectionInfo> directions;
|
||||||
DataTileManager<WptPt> wpt;
|
DataTileManager<WptPt> wpt;
|
||||||
boolean calculateOsmAndRoute = false;
|
boolean calculateOsmAndRoute;
|
||||||
|
|
||||||
private GPXRouteParams(){
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartPoint(Location startPoint) {
|
|
||||||
points.add(0, startPoint);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Location> getPoints() {
|
public List<Location> getPoints() {
|
||||||
return points;
|
return points;
|
||||||
|
@ -145,48 +207,12 @@ public class RouteProvider {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class GPXRouteParamsBuilder {
|
public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){
|
||||||
|
GPXFile file = builder.file;
|
||||||
private GPXRouteParams obj = new GPXRouteParams();
|
boolean reverse = builder.reverse;
|
||||||
private GPXFile file;
|
boolean announceWaypoints = builder.announceWaypoints;
|
||||||
private boolean leftHandDriving;
|
|
||||||
private boolean reverse;
|
|
||||||
private boolean announceWaypoints;
|
|
||||||
private GPXRouteParamsBuilder(GPXFile f, OsmandSettings settings) {
|
|
||||||
this.file = f;
|
|
||||||
leftHandDriving = settings.DRIVING_REGION.get().leftHandDriving;
|
|
||||||
// obj = new GPXRouteParams(file, reverse, announceWaypoints, settings)
|
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
}
|
|
||||||
|
|
||||||
public GPXRouteParamsBuilder reverse() {
|
|
||||||
this.reverse = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GPXRouteParamsBuilder announceWaypoints() {
|
|
||||||
this.announceWaypoints = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GPXRouteParamsBuilder calculateOsmAndRoute() {
|
|
||||||
obj.calculateOsmAndRoute = true;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GPXRouteParamsBuilder newBuilder(GPXFile f, OsmandSettings settings) {
|
|
||||||
return new GPXRouteParamsBuilder(f, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GPXRouteParams build(){
|
|
||||||
obj.prepareEverything(file, reverse, announceWaypoints, leftHandDriving);
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void prepareEverything(GPXFile file, boolean reverse, boolean announceWaypoints, boolean leftSide){
|
|
||||||
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){
|
if(file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)){
|
||||||
directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), leftSide, 10);
|
directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10);
|
||||||
if(reverse){
|
if(reverse){
|
||||||
// clear directions all turns should be recalculated
|
// clear directions all turns should be recalculated
|
||||||
directions = null;
|
directions = null;
|
||||||
|
@ -220,7 +246,9 @@ public class RouteProvider {
|
||||||
MapUtils.get31TileNumberY(w.lat),w) ;
|
MapUtils.get31TileNumberY(w.lat),w) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Location createLocation(WptPt pt){
|
private static Location createLocation(WptPt pt){
|
||||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.routing;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
@ -22,7 +21,7 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
|
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
|
||||||
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
|
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
|
||||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import net.osmand.plus.voice.CommandPlayer;
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.router.RouteCalculationProgress;
|
import net.osmand.router.RouteCalculationProgress;
|
||||||
|
@ -51,7 +50,7 @@ public class RoutingHelper {
|
||||||
|
|
||||||
private boolean isRoutePlanningMode = false;
|
private boolean isRoutePlanningMode = false;
|
||||||
|
|
||||||
private GPXRouteParams currentGPXRoute = null;
|
private GPXRouteParamsBuilder currentGPXRoute = null;
|
||||||
|
|
||||||
private RouteCalculationResult route = new RouteCalculationResult("");
|
private RouteCalculationResult route = new RouteCalculationResult("");
|
||||||
|
|
||||||
|
@ -117,9 +116,11 @@ public class RoutingHelper {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation, GPXRouteParams gpxRoute){
|
public synchronized void setFinalAndCurrentLocation(LatLon finalLocation, List<LatLon> intermediatePoints, Location currentLocation,
|
||||||
|
GPXRouteParamsBuilder gpxRoute){
|
||||||
clearCurrentRoute(finalLocation, intermediatePoints);
|
clearCurrentRoute(finalLocation, intermediatePoints);
|
||||||
currentGPXRoute = gpxRoute;
|
|
||||||
|
setGpxParams(gpxRoute);
|
||||||
// to update route
|
// to update route
|
||||||
setCurrentLocation(currentLocation, false);
|
setCurrentLocation(currentLocation, false);
|
||||||
|
|
||||||
|
@ -151,13 +152,18 @@ public class RoutingHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GPXRouteParams getCurrentGPXRoute() {
|
public GPXRouteParamsBuilder getCurrentGPXRoute() {
|
||||||
return currentGPXRoute;
|
return currentGPXRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Location> getCurrentRoute() {
|
|
||||||
return currentGPXRoute == null || currentGPXRoute.points.isEmpty() ? route.getImmutableLocations() : Collections
|
|
||||||
.unmodifiableList(currentGPXRoute.points);
|
public void setGpxParams(GPXRouteParamsBuilder params) {
|
||||||
|
currentGPXRoute = params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> getCurrentCalculatedRoute() {
|
||||||
|
return route.getImmutableLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAppMode(ApplicationMode mode){
|
public void setAppMode(ApplicationMode mode){
|
||||||
|
@ -765,7 +771,8 @@ public class RoutingHelper {
|
||||||
recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, null);
|
recalculateRouteInBackground(true, lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recalculateRouteInBackground(boolean force, final Location start, final LatLon end, final List<LatLon> intermediates, final GPXRouteParams gpxRoute, final RouteCalculationResult previousRoute){
|
private void recalculateRouteInBackground(boolean force, final Location start, final LatLon end, final List<LatLon> intermediates,
|
||||||
|
final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute){
|
||||||
if (start == null || end == null) {
|
if (start == null || end == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -776,7 +783,7 @@ public class RoutingHelper {
|
||||||
params.start = start;
|
params.start = start;
|
||||||
params.end = end;
|
params.end = end;
|
||||||
params.intermediates = intermediates;
|
params.intermediates = intermediates;
|
||||||
params.gpxRoute = gpxRoute;
|
params.gpxRoute = gpxRoute == null? null : gpxRoute.build(start, settings);
|
||||||
params.previousToRecalculate = previousRoute;
|
params.previousToRecalculate = previousRoute;
|
||||||
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||||
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
|
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
|
||||||
|
@ -875,4 +882,5 @@ public class RoutingHelper {
|
||||||
return provider.createOsmandRouterGPX(route, app);
|
return provider.createOsmandRouterGPX(route, app);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import net.osmand.plus.activities.SettingsBaseActivity;
|
||||||
import net.osmand.plus.activities.SettingsNavigationActivity;
|
import net.osmand.plus.activities.SettingsNavigationActivity;
|
||||||
import net.osmand.plus.activities.actions.AppModeDialog;
|
import net.osmand.plus.activities.actions.AppModeDialog;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||||
|
@ -51,13 +52,60 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
private int cachedId;
|
private int cachedId;
|
||||||
private Dialog dialog;
|
private Dialog dialog;
|
||||||
private GPXFile selectedGPXFile = null;
|
private ArrayAdapter<LocalRoutingParameter> listAdapter;
|
||||||
|
|
||||||
public MapRoutePreferencesControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
|
public MapRoutePreferencesControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
|
||||||
super(mapActivity, showUIHandler, scaleCoefficient);
|
super(mapActivity, showUIHandler, scaleCoefficient);
|
||||||
settings = mapActivity.getMyApplication().getSettings();
|
settings = mapActivity.getMyApplication().getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class LocalRoutingParameter {
|
||||||
|
|
||||||
|
public RoutingParameter routingParameter;
|
||||||
|
|
||||||
|
public String getText(MapActivity mapActivity) {
|
||||||
|
return SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, routingParameter.getId(), routingParameter.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected(OsmandSettings settings) {
|
||||||
|
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter.getId());
|
||||||
|
return property.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(OsmandSettings settings, boolean isChecked) {
|
||||||
|
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(routingParameter.getId());
|
||||||
|
property.set(isChecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GPXLocalRoutingParameter extends LocalRoutingParameter {
|
||||||
|
public String text;
|
||||||
|
public boolean selected;
|
||||||
|
public int id;
|
||||||
|
|
||||||
|
public GPXLocalRoutingParameter(int id, String text, boolean selected) {
|
||||||
|
this.text = text;
|
||||||
|
this.selected = selected;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText(MapActivity mapActivity) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSelected(OsmandSettings settings) {
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelected(OsmandSettings settings, boolean isChecked) {
|
||||||
|
selected = isChecked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showControls(FrameLayout parent) {
|
public void showControls(FrameLayout parent) {
|
||||||
settingsAppModeButton = addImageButton(parent, R.string.route_preferences, R.drawable.map_btn_plain);
|
settingsAppModeButton = addImageButton(parent, R.string.route_preferences, R.drawable.map_btn_plain);
|
||||||
|
@ -106,19 +154,55 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private List<RoutingParameter> getRoutingParameters(ApplicationMode am) {
|
private void updateGpxRoutingParameter(GPXLocalRoutingParameter gpxParam) {
|
||||||
List<RoutingParameter> list = new ArrayList<RoutingParameter>();
|
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
|
||||||
|
if (rp != null) {
|
||||||
|
boolean selected = gpxParam.isSelected(settings);
|
||||||
|
if (gpxParam.id == R.string.gpx_option_reverse_route) {
|
||||||
|
rp.setReverse(selected);
|
||||||
|
} else if (gpxParam.id == R.string.gpx_option_from_start_point) {
|
||||||
|
rp.setPassWholeRoute(selected);
|
||||||
|
} else if (gpxParam.id == R.string.announce_gpx_waypoints) {
|
||||||
|
settings.SPEAK_GPX_WPT.set(selected);
|
||||||
|
rp.setAnnounceWaypoints(selected);
|
||||||
|
} else if (gpxParam.id == R.string.calculate_osmand_route_gpx) {
|
||||||
|
settings.CALC_GPX_ROUTE.set(selected);
|
||||||
|
rp.setCalculateOsmAndRoute(selected);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
|
||||||
|
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
||||||
GeneralRouter rm = SettingsNavigationActivity.getRouter(am);
|
GeneralRouter rm = SettingsNavigationActivity.getRouter(am);
|
||||||
if(rm == null) {
|
GPXRouteParamsBuilder rparams = mapActivity.getRoutingHelper().getCurrentGPXRoute();
|
||||||
|
if(rparams != null) {
|
||||||
|
list.add(new GPXLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
||||||
|
getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
||||||
|
list.add(new GPXLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
||||||
|
getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
||||||
|
list.add(new GPXLocalRoutingParameter(R.string.announce_gpx_waypoints,
|
||||||
|
getString(R.string.announce_gpx_waypoints), rparams.isAnnounceWaypoints()));
|
||||||
|
list.add(new GPXLocalRoutingParameter(R.string.calculate_osmand_route_gpx,
|
||||||
|
getString(R.string.calculate_osmand_route_gpx), rparams.isCalculateOsmAndRoute()));
|
||||||
|
}
|
||||||
|
if(rm == null || !settings.CALC_GPX_ROUTE.get()) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
for (RoutingParameter r : rm.getParameters().values()) {
|
for (RoutingParameter r : rm.getParameters().values()) {
|
||||||
if (r.getType() == RoutingParameterType.BOOLEAN) {
|
if (r.getType() == RoutingParameterType.BOOLEAN) {
|
||||||
list.add(r);
|
LocalRoutingParameter rp = new LocalRoutingParameter();
|
||||||
|
rp.routingParameter = r;
|
||||||
|
list.add(rp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
private String getString(int id) {
|
||||||
|
return mapActivity.getString(id);
|
||||||
|
}
|
||||||
|
|
||||||
private View createLayout() {
|
private View createLayout() {
|
||||||
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
|
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
|
||||||
Context ctx = mapActivity;
|
Context ctx = mapActivity;
|
||||||
|
@ -131,23 +215,25 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
setupSpinner(settingsDlg);
|
setupSpinner(settingsDlg);
|
||||||
|
|
||||||
|
|
||||||
final ArrayAdapter<RoutingParameter> listAdapter = new ArrayAdapter<RoutingParameter>(ctx,
|
listAdapter = new ArrayAdapter<LocalRoutingParameter>(ctx,
|
||||||
R.layout.layers_list_activity_item, R.id.title, getRoutingParameters(am)) {
|
R.layout.layers_list_activity_item, R.id.title, getRoutingParameters(am)) {
|
||||||
@Override
|
@Override
|
||||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||||
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
|
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
|
||||||
final TextView tv = (TextView) v.findViewById(R.id.title);
|
final TextView tv = (TextView) v.findViewById(R.id.title);
|
||||||
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
|
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
|
||||||
RoutingParameter rp = getItem(position);
|
final LocalRoutingParameter rp = getItem(position);
|
||||||
tv.setText(SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, rp.getId(), rp.getName()));
|
tv.setText(rp.getText(mapActivity));
|
||||||
tv.setPadding((int) (5 * scaleCoefficient), 0, 0, 0);
|
tv.setPadding((int) (5 * scaleCoefficient), 0, 0, 0);
|
||||||
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(rp.getId());
|
ch.setChecked(rp.isSelected(settings));
|
||||||
ch.setChecked(property.get());
|
|
||||||
ch.setVisibility(View.VISIBLE);
|
ch.setVisibility(View.VISIBLE);
|
||||||
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
property.set(isChecked);
|
rp.setSelected(settings, isChecked);
|
||||||
|
if(rp instanceof GPXLocalRoutingParameter) {
|
||||||
|
updateGpxRoutingParameter((GPXLocalRoutingParameter) rp);
|
||||||
|
}
|
||||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -164,19 +250,26 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
ApplicationMode next = selected.iterator().next();
|
ApplicationMode next = selected.iterator().next();
|
||||||
settings.APPLICATION_MODE.set(next);
|
settings.APPLICATION_MODE.set(next);
|
||||||
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||||
listAdapter.setNotifyOnChange(false);
|
updateParameters();
|
||||||
listAdapter.clear();
|
|
||||||
for(RoutingParameter r : getRoutingParameters(next)) {
|
|
||||||
listAdapter.add(r);
|
|
||||||
}
|
|
||||||
listAdapter.notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
lv.setAdapter(listAdapter);
|
lv.setAdapter(listAdapter);
|
||||||
return settingsDlg;
|
return settingsDlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateParameters() {
|
||||||
|
ApplicationMode am = settings.APPLICATION_MODE.get();
|
||||||
|
listAdapter.setNotifyOnChange(false);
|
||||||
|
listAdapter.clear();
|
||||||
|
for(LocalRoutingParameter r : getRoutingParameters(am)) {
|
||||||
|
listAdapter.add(r);
|
||||||
|
}
|
||||||
|
listAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSpinner(View settingsDlg) {
|
private void setupSpinner(View settingsDlg) {
|
||||||
final Spinner gpxSpinner = (Spinner) settingsDlg.findViewById(R.id.GPXRouteSpinner);
|
final Spinner gpxSpinner = (Spinner) settingsDlg.findViewById(R.id.GPXRouteSpinner);
|
||||||
updateSpinnerItems(gpxSpinner);
|
updateSpinnerItems(gpxSpinner);
|
||||||
|
@ -185,7 +278,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
if(position == 0) {
|
if(position == 0) {
|
||||||
selectedGPXFile = null;
|
mapActivity.getRoutingHelper().setGpxParams(null);
|
||||||
} else if(position == 1) {
|
} else if(position == 1) {
|
||||||
openGPXFileSelection(gpxSpinner);
|
openGPXFileSelection(gpxSpinner);
|
||||||
} else if(position == 2) {
|
} else if(position == 2) {
|
||||||
|
@ -205,8 +298,12 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean processResult(GPXFile result) {
|
public boolean processResult(GPXFile result) {
|
||||||
selectedGPXFile = result;
|
GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication().getSettings());
|
||||||
|
params.setAnnounceWaypoints(settings.SPEAK_GPX_WPT.get());
|
||||||
|
params.setCalculateOsmAndRoute(settings.CALC_GPX_ROUTE.get());
|
||||||
|
mapActivity.getRoutingHelper().setGpxParams(params);
|
||||||
updateSpinnerItems(gpxSpinner);
|
updateSpinnerItems(gpxSpinner);
|
||||||
|
updateParameters();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -216,8 +313,9 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
ArrayList<String> gpxActions = new ArrayList<String>();
|
ArrayList<String> gpxActions = new ArrayList<String>();
|
||||||
gpxActions.add(mapActivity.getString(R.string.default_none));
|
gpxActions.add(mapActivity.getString(R.string.default_none));
|
||||||
gpxActions.add(mapActivity.getString(R.string.select_gpx));
|
gpxActions.add(mapActivity.getString(R.string.select_gpx));
|
||||||
if(selectedGPXFile != null) {
|
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
|
||||||
gpxActions.add(new File(selectedGPXFile.path).getName());
|
if(rp != null) {
|
||||||
|
gpxActions.add(new File(rp.getFile().path).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayAdapter<String> gpxAdapter = new ArrayAdapter<String>(mapActivity,
|
ArrayAdapter<String> gpxAdapter = new ArrayAdapter<String>(mapActivity,
|
||||||
|
@ -226,7 +324,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
||||||
);
|
);
|
||||||
gpxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
gpxAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
gpxSpinner.setAdapter(gpxAdapter);
|
gpxSpinner.setAdapter(gpxAdapter);
|
||||||
if(selectedGPXFile != null) {
|
if(rp != null) {
|
||||||
gpxSpinner.setSelection(2);
|
gpxSpinner.setSelection(2);
|
||||||
} else {
|
} else {
|
||||||
gpxSpinner.setSelection(0);
|
gpxSpinner.setSelection(0);
|
||||||
|
|
Loading…
Reference in a new issue