Restructure gpx routing

This commit is contained in:
vshcherb 2014-03-22 01:22:35 +01:00
parent 5f2d7863d6
commit 1840f61f72
8 changed files with 261 additions and 136 deletions

View file

@ -9,8 +9,7 @@ import net.osmand.Location;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@ -40,18 +39,18 @@ public class OsmAndLocationSimulation {
return routeAnimation != null;
}
public void startStopRouteAnimationRoute(final MapActivity ma) {
if (!isRouteAnimating()) {
List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
if (currentRoute.isEmpty()) {
AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
} else {
startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
}
} else {
stop();
}
}
// public void startStopRouteAnimationRoute(final MapActivity ma) {
// if (!isRouteAnimating()) {
// List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
// if (currentRoute.isEmpty()) {
// AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
// } else {
// startAnimationThread(app.getRoutingHelper(), ma, new ArrayList<Location>(currentRoute), false, 1);
// }
// } else {
// stop();
// }
// }
public void startStopRouteAnimation(final MapActivity ma) {
if (!isRouteAnimating()) {
@ -86,18 +85,17 @@ public class OsmAndLocationSimulation {
new CallbackWithObject<GPXUtilities.GPXFile>() {
@Override
public boolean processResult(GPXUtilities.GPXFile result) {
GPXRouteParamsBuilder builder = GPXRouteParams.GPXRouteParamsBuilder.newBuilder(result, app.getSettings());
GPXRouteParamsBuilder builder = new GPXRouteParamsBuilder(result, app.getSettings());
if(ch.isChecked()){
builder.announceWaypoints();
builder.setAnnounceWaypoints(true);
}
GPXRouteParams prms = builder.build();
startAnimationThread(app.getRoutingHelper(), ma, prms.getPoints(), true,
startAnimationThread(app.getRoutingHelper(), ma, builder.getPoints(), true,
speedup.getProgress() + 1);
return true;
}
});
} else {
List<Location> currentRoute = app.getRoutingHelper().getCurrentRoute();
List<Location> currentRoute = app.getRoutingHelper().getCurrentCalculatedRoute();
if(currentRoute.isEmpty()) {
AccessibleToast.makeText(app, R.string.animate_routing_route_not_calculated, Toast.LENGTH_LONG).show();
} else {

View file

@ -32,7 +32,7 @@ import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.render.RendererRegistry;
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.RouteCalculationProgressCallback;
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();
RoutingHelper routingHelper = app.getRoutingHelper();
settings.APPLICATION_MODE.set(appMode);

View file

@ -17,8 +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.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.RouteService;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
@ -83,35 +82,32 @@ public class NavigateAction {
boolean calculateOsmAndRoute = props[4];
settings.SPEAK_GPX_WPT.set(announceGpxWpt);
settings.CALC_GPX_ROUTE.set(calculateOsmAndRoute);
GPXRouteParamsBuilder bld = GPXRouteParamsBuilder.newBuilder(result, settings);
GPXRouteParamsBuilder gpxRoute = new GPXRouteParamsBuilder(result, settings);
if(reverse) {
bld.reverse();
gpxRoute.setReverse(true);
}
if(announceGpxWpt) {
bld.announceWaypoints();
gpxRoute.setAnnounceWaypoints(true);
}
if(calculateOsmAndRoute) {
bld.calculateOsmAndRoute();
gpxRoute.setCalculateOsmAndRoute(true);
}
GPXRouteParams gpxRoute = bld.build();
Location loc = getLastKnownLocation();
if(passWholeWay && loc != null){
gpxRoute.setStartPoint(loc);
if(passWholeWay) {
gpxRoute.setPassWholeRoute(true);
}
Location startForRouting = getLastKnownLocation();
if(startForRouting == null){
startForRouting = gpxRoute.getStartPointForRoute();
startForRouting = null;//gpxRoute.getStartPointForRoute();
}
LatLon endPoint = endForRouting;
if(endPoint == null || !useDestination){
LatLon point = gpxRoute.getLastPoint();
if(point != null){
endPoint = point;
}
// LatLon point = gpxRoute.getLastPoint();
// if(point != null){
// endPoint = point;
// }
if(endPoint != null) {
app.getTargetPointsHelper().navigateToPoint(point, false, -1);
app.getTargetPointsHelper().navigateToPoint(endPoint, false, -1);
}
}
if(endPoint != null){

View file

@ -3,8 +3,6 @@ package net.osmand.plus.base;
import java.io.File;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.data.LatLon;
@ -15,8 +13,10 @@ 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.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import org.apache.commons.logging.Log;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
@ -124,26 +124,24 @@ public class FailSafeFuntions {
@Override
protected void onPostExecute(GPXFile result) {
final GPXRouteParams gpxRoute;
final GPXRouteParamsBuilder gpxRoute;
if (result != null) {
GPXRouteParamsBuilder builder = GPXRouteParamsBuilder.newBuilder(result, settings);
gpxRoute = new GPXRouteParamsBuilder(result, settings);
if (settings.SPEAK_GPX_WPT.get()) {
builder.announceWaypoints();
gpxRoute.setAnnounceWaypoints(true);
}
if(settings.CALC_GPX_ROUTE.get()) {
builder.calculateOsmAndRoute();
gpxRoute.setCalculateOsmAndRoute(true);
}
gpxRoute = builder.build();
} else {
gpxRoute = null;
}
LatLon endPoint = pointToNavigate != null ? pointToNavigate : gpxRoute.getLastPoint();
net.osmand.Location startPoint = gpxRoute == null ? null : gpxRoute.getStartPointForRoute();
LatLon endPoint = pointToNavigate;
if (endPoint == null) {
notRestoreRoutingMode(ma, app);
} else {
ma.followRoute(settings.getApplicationMode(), endPoint,
targetPoints.getIntermediatePoints(), startPoint, gpxRoute);
targetPoints.getIntermediatePoints(), null, gpxRoute);
}
}
};

View file

@ -9,13 +9,11 @@ import net.osmand.data.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
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.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.views.MonitoringInfoControl;
import net.osmand.plus.views.MonitoringInfoControl.MonitoringInfoControlServices;
import net.osmand.plus.views.OsmandMapTileView;

View file

@ -112,18 +112,80 @@ public class 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 {
List<Location> points = new ArrayList<Location>();
List<RouteDirectionInfo> directions;
DataTileManager<WptPt> wpt;
boolean calculateOsmAndRoute = false;
private GPXRouteParams(){
}
public void setStartPoint(Location startPoint) {
points.add(0, startPoint);
}
boolean calculateOsmAndRoute;
public List<Location> getPoints() {
return points;
@ -145,48 +207,12 @@ public class RouteProvider {
return null;
}
public static class GPXRouteParamsBuilder {
private GPXRouteParams obj = new GPXRouteParams();
private GPXFile file;
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){
public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder){
GPXFile file = builder.file;
boolean reverse = builder.reverse;
boolean announceWaypoints = builder.announceWaypoints;
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){
// clear directions all turns should be recalculated
directions = null;
@ -220,7 +246,9 @@ public class RouteProvider {
MapUtils.get31TileNumberY(w.lat),w) ;
}
}
}
return this;
}
}
private static Location createLocation(WptPt pt){

View file

@ -2,7 +2,6 @@ package net.osmand.plus.routing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.osmand.Location;
@ -22,7 +21,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
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.voice.CommandPlayer;
import net.osmand.router.RouteCalculationProgress;
@ -51,7 +50,7 @@ public class RoutingHelper {
private boolean isRoutePlanningMode = false;
private GPXRouteParams currentGPXRoute = null;
private GPXRouteParamsBuilder currentGPXRoute = null;
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);
currentGPXRoute = gpxRoute;
setGpxParams(gpxRoute);
// to update route
setCurrentLocation(currentLocation, false);
@ -151,13 +152,18 @@ public class RoutingHelper {
}
}
public GPXRouteParams getCurrentGPXRoute() {
public GPXRouteParamsBuilder getCurrentGPXRoute() {
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){
@ -765,7 +771,8 @@ public class RoutingHelper {
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) {
return;
}
@ -776,7 +783,7 @@ public class RoutingHelper {
params.start = start;
params.end = end;
params.intermediates = intermediates;
params.gpxRoute = gpxRoute;
params.gpxRoute = gpxRoute == null? null : gpxRoute.build(start, settings);
params.previousToRecalculate = previousRoute;
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
@ -873,6 +880,7 @@ public class RoutingHelper {
public GPXFile generateGPXFileWithRoute(){
return provider.createOsmandRouterGPX(route, app);
}
}
}

View file

@ -19,6 +19,7 @@ import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
import net.osmand.router.GeneralRouter;
import net.osmand.router.GeneralRouter.RoutingParameter;
@ -51,13 +52,60 @@ public class MapRoutePreferencesControl extends MapControls {
private OsmandSettings settings;
private int cachedId;
private Dialog dialog;
private GPXFile selectedGPXFile = null;
private ArrayAdapter<LocalRoutingParameter> listAdapter;
public MapRoutePreferencesControl(MapActivity mapActivity, Handler showUIHandler, float scaleCoefficient) {
super(mapActivity, showUIHandler, scaleCoefficient);
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
public void showControls(FrameLayout parent) {
settingsAppModeButton = addImageButton(parent, R.string.route_preferences, R.drawable.map_btn_plain);
@ -104,21 +152,57 @@ public class MapRoutePreferencesControl extends MapControls {
dialog.getWindow().setAttributes(lp);
return dialog;
}
private void updateGpxRoutingParameter(GPXLocalRoutingParameter gpxParam) {
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<RoutingParameter> getRoutingParameters(ApplicationMode am) {
List<RoutingParameter> list = new ArrayList<RoutingParameter>();
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
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;
}
for (RoutingParameter r : rm.getParameters().values()) {
if (r.getType() == RoutingParameterType.BOOLEAN) {
list.add(r);
LocalRoutingParameter rp = new LocalRoutingParameter();
rp.routingParameter = r;
list.add(rp);
}
}
return list;
}
private String getString(int id) {
return mapActivity.getString(id);
}
private View createLayout() {
View settingsDlg = View.inflate(mapActivity, R.layout.plan_route_settings, null);
Context ctx = mapActivity;
@ -131,23 +215,25 @@ public class MapRoutePreferencesControl extends MapControls {
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)) {
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
final TextView tv = (TextView) v.findViewById(R.id.title);
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
RoutingParameter rp = getItem(position);
tv.setText(SettingsBaseActivity.getRoutingStringPropertyName(mapActivity, rp.getId(), rp.getName()));
final LocalRoutingParameter rp = getItem(position);
tv.setText(rp.getText(mapActivity));
tv.setPadding((int) (5 * scaleCoefficient), 0, 0, 0);
final CommonPreference<Boolean> property = settings.getCustomRoutingBooleanProperty(rp.getId());
ch.setChecked(property.get());
ch.setChecked(rp.isSelected(settings));
ch.setVisibility(View.VISIBLE);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
property.set(isChecked);
rp.setSelected(settings, isChecked);
if(rp instanceof GPXLocalRoutingParameter) {
updateGpxRoutingParameter((GPXLocalRoutingParameter) rp);
}
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
}
});
@ -164,18 +250,25 @@ public class MapRoutePreferencesControl extends MapControls {
ApplicationMode next = selected.iterator().next();
settings.APPLICATION_MODE.set(next);
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
listAdapter.setNotifyOnChange(false);
listAdapter.clear();
for(RoutingParameter r : getRoutingParameters(next)) {
listAdapter.add(r);
}
listAdapter.notifyDataSetChanged();
updateParameters();
}
}
});
lv.setAdapter(listAdapter);
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) {
final Spinner gpxSpinner = (Spinner) settingsDlg.findViewById(R.id.GPXRouteSpinner);
@ -185,7 +278,7 @@ public class MapRoutePreferencesControl extends MapControls {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if(position == 0) {
selectedGPXFile = null;
mapActivity.getRoutingHelper().setGpxParams(null);
} else if(position == 1) {
openGPXFileSelection(gpxSpinner);
} else if(position == 2) {
@ -205,8 +298,12 @@ public class MapRoutePreferencesControl extends MapControls {
@Override
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);
updateParameters();
return true;
}
});
@ -216,8 +313,9 @@ public class MapRoutePreferencesControl extends MapControls {
ArrayList<String> gpxActions = new ArrayList<String>();
gpxActions.add(mapActivity.getString(R.string.default_none));
gpxActions.add(mapActivity.getString(R.string.select_gpx));
if(selectedGPXFile != null) {
gpxActions.add(new File(selectedGPXFile.path).getName());
GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
if(rp != null) {
gpxActions.add(new File(rp.getFile().path).getName());
}
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);
gpxSpinner.setAdapter(gpxAdapter);
if(selectedGPXFile != null) {
if(rp != null) {
gpxSpinner.setSelection(2);
} else {
gpxSpinner.setSelection(0);