Fix directions menu - allow to navigate GPX route without destination point

This commit is contained in:
Victor Shcherb 2011-10-16 15:28:16 +02:00
parent 321b67305c
commit 515ac61264

View file

@ -402,24 +402,30 @@ public class MapActivityActions implements DialogProvider {
return builder.create(); return builder.create();
} }
protected void getDirections(final double lat, final double lon, boolean followEnabled){ private boolean checkPointToNavigate(){
MapActivityLayers mapLayers = mapActivity.getMapLayers(); MapActivityLayers mapLayers = mapActivity.getMapLayers();
final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity);
final RoutingHelper routingHelper = mapActivity.getRoutingHelper();
if(mapLayers.getNavigationLayer().getPointToNavigate() == null){ if(mapLayers.getNavigationLayer().getPointToNavigate() == null){
Toast.makeText(mapActivity, R.string.mark_final_location_first, Toast.LENGTH_LONG).show(); Toast.makeText(mapActivity, R.string.mark_final_location_first, Toast.LENGTH_LONG).show();
return; return false;
} }
return true;
}
protected void getDirections(final double lat, final double lon, boolean followEnabled){
final OsmandSettings settings = OsmandSettings.getOsmandSettings(mapActivity);
final RoutingHelper routingHelper = mapActivity.getRoutingHelper();
Builder builder = new AlertDialog.Builder(mapActivity); Builder builder = new AlertDialog.Builder(mapActivity);
View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null); View view = mapActivity.getLayoutInflater().inflate(R.layout.calculate_route, null);
final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length]; final ToggleButton[] buttons = new ToggleButton[ApplicationMode.values().length];
buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton); buttons[ApplicationMode.CAR.ordinal()] = (ToggleButton) view.findViewById(R.id.CarButton);
buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton); buttons[ApplicationMode.BICYCLE.ordinal()] = (ToggleButton) view.findViewById(R.id.BicycleButton);
buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton); buttons[ApplicationMode.PEDESTRIAN.ordinal()] = (ToggleButton) view.findViewById(R.id.PedestrianButton);
ApplicationMode appMode = settings.getApplicationMode(); ApplicationMode appMode = settings.getApplicationMode();
for(int i=0; i< buttons.length; i++){ for (int i = 0; i < buttons.length; i++) {
if(buttons[i] != null){ if(buttons[i] != null){
final int ind = i; final int ind = i;
ToggleButton b = buttons[i]; ToggleButton b = buttons[i];
@ -460,6 +466,9 @@ public class MapActivityActions implements DialogProvider {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
ApplicationMode mode = getAppMode(buttons, settings); ApplicationMode mode = getAppMode(buttons, settings);
if(!checkPointToNavigate()){
return;
}
Location location = new Location("map"); //$NON-NLS-1$ Location location = new Location("map"); //$NON-NLS-1$
location.setLatitude(lat); location.setLatitude(lat);
location.setLongitude(lon); location.setLongitude(lon);
@ -474,6 +483,9 @@ public class MapActivityActions implements DialogProvider {
DialogInterface.OnClickListener followCall = new DialogInterface.OnClickListener(){ DialogInterface.OnClickListener followCall = new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(!checkPointToNavigate()){
return;
}
ApplicationMode mode = getAppMode(buttons, settings); ApplicationMode mode = getAppMode(buttons, settings);
// change global settings // change global settings
boolean changed = settings.APPLICATION_MODE.set(mode); boolean changed = settings.APPLICATION_MODE.set(mode);