consolidate directions

This commit is contained in:
Victor Shcherb 2013-07-15 01:55:37 +02:00
parent 78f78c3998
commit c3b0e8a07c
6 changed files with 64 additions and 80 deletions

View file

@ -9,6 +9,9 @@
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="clear_intermediate_points">Clear intermediate points</string>
<string name="keep_intermediate_points">Keep intermediate points</string>
<string name="new_directions_point_dialog">You already have intermediate points set.</string>
<string name="context_menu_item_directions_to">Directions To</string> <string name="context_menu_item_directions_to">Directions To</string>
<string name="context_menu_item_directions_from">Directions From</string> <string name="context_menu_item_directions_from">Directions From</string>
<string name="route_descr_map_location">Map: </string> <string name="route_descr_map_location">Map: </string>

View file

@ -165,6 +165,10 @@ public class TargetPointsHelper {
} }
public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){ public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate){
navigateToPoint(point, updateRoute, intermediate, null);
}
public void navigateToPoint(LatLon point, boolean updateRoute, int intermediate, String historyName){
if(point != null){ if(point != null){
if(intermediate < 0) { if(intermediate < 0) {
settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null);
@ -178,7 +182,6 @@ public class TargetPointsHelper {
} }
readFromSettings(settings); readFromSettings(settings);
updateRouteAndReferesh(updateRoute); updateRouteAndReferesh(updateRoute);
} }
public boolean checkPointToNavigate(ClientContext ctx ){ public boolean checkPointToNavigate(ClientContext ctx ){
@ -190,19 +193,4 @@ public class TargetPointsHelper {
} }
public void setDestination(double lat, double lon, String historyName) {
//clearPointToNavigate(false);
// Do not delete waypoints here
settings.clearPointToNavigate();
settings.setPointToNavigate(lat, lon, true, historyName);
updatePointsFromSettings();
}
public void updatePointsFromSettings() {
readFromSettings(settings);
}
} }

View file

@ -304,7 +304,7 @@ public class MapActivity extends AccessibleActivity {
Location loc = new Location("map"); Location loc = new Location("map");
loc.setLatitude(mapView.getLatitude()); loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude()); loc.setLongitude(mapView.getLongitude());
mapActions.getDirections(loc, DirectionDialogStyle.create()); mapActions.getDirections(loc, null, DirectionDialogStyle.create());
} }
if(mapLabelToShow != null && latLonToShow != null){ if(mapLabelToShow != null && latLonToShow != null){
mapLayers.getContextMenuLayer().setSelectedObject(toShow); mapLayers.getContextMenuLayer().setSelectedObject(toShow);

View file

@ -464,7 +464,7 @@ public class MapActivityActions implements DialogProvider {
} }
public void getDirections(final Location mapView, 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);
final TargetPointsHelper targets = getTargets(); final TargetPointsHelper targets = getTargets();
@ -480,9 +480,9 @@ 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, 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, view, toList, style); final Spinner toSpinner = setupToSpinner(mapView, name,view, toList, style);
String via = generateViaDescription(); String via = generateViaDescription();
@ -622,13 +622,13 @@ public class MapActivityActions implements DialogProvider {
builder.show(); builder.show();
} }
private Spinner setupFromSpinner(final Location mapView, View view, DirectionDialogStyle style) { private Spinner setupFromSpinner(final Location mapView, String name, View view, DirectionDialogStyle style) {
String currentLocation = mapActivity.getString(R.string.route_descr_current_location); String currentLocation = mapActivity.getString(R.string.route_descr_current_location);
ArrayList<String> fromActions = new ArrayList<String>(); ArrayList<String> fromActions = new ArrayList<String>();
fromActions.add(currentLocation); fromActions.add(currentLocation);
if(mapView != null) { if(mapView != null) {
String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(mapView.getLatitude(), String oname = name != null ? name : getRoutePointDescription(mapView.getLatitude(),mapView.getLongitude());
mapView.getLongitude()); String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + oname;
fromActions.add(mapLocation); fromActions.add(mapLocation);
} }
final Spinner fromSpinner = ((Spinner) view.findViewById(R.id.FromSpinner)); final Spinner fromSpinner = ((Spinner) view.findViewById(R.id.FromSpinner));
@ -643,7 +643,7 @@ public class MapActivityActions implements DialogProvider {
return fromSpinner; return fromSpinner;
} }
private Spinner setupToSpinner(final Location mapView, View view, List<LatLon> locs, DirectionDialogStyle style) { private Spinner setupToSpinner(final Location mapView, String name, View view, List<LatLon> locs, DirectionDialogStyle style) {
final TargetPointsHelper targets = getTargets(); final TargetPointsHelper targets = getTargets();
ArrayList<String> toActions = new ArrayList<String>(); ArrayList<String> toActions = new ArrayList<String>();
if (targets.getPointToNavigate() != null) { if (targets.getPointToNavigate() != null) {
@ -652,8 +652,8 @@ public class MapActivityActions implements DialogProvider {
locs.add(targets.getPointToNavigate()); locs.add(targets.getPointToNavigate());
} }
if(mapView != null) { if(mapView != null) {
String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(mapView.getLatitude(), String oname = name != null ? name : getRoutePointDescription(mapView.getLatitude(),mapView.getLongitude());
mapView.getLongitude()); String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + oname;
toActions.add(mapLocation); toActions.add(mapLocation);
locs.add(new LatLon(mapView.getLatitude(), mapView.getLongitude())); locs.add(new LatLon(mapView.getLatitude(), mapView.getLongitude()));
} }
@ -874,7 +874,8 @@ public class MapActivityActions implements DialogProvider {
Location loc = new Location("map"); Location loc = new Location("map");
loc.setLatitude(latitude); loc.setLatitude(latitude);
loc.setLongitude(longitude); loc.setLongitude(longitude);
getDirections(loc, DirectionDialogStyle.create().gpxRouteEnabled().routeToMapPoint()); String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
getDirections(loc, name, DirectionDialogStyle.create().gpxRouteEnabled().routeToMapPoint());
} else { } else {
targets.navigateToPoint(new LatLon(latitude, longitude), true, -1); targets.navigateToPoint(new LatLon(latitude, longitude), true, -1);
} }
@ -883,19 +884,18 @@ public class MapActivityActions implements DialogProvider {
Location loc = new Location("map"); Location loc = new Location("map");
loc.setLatitude(latitude); loc.setLatitude(latitude);
loc.setLongitude(longitude); loc.setLongitude(longitude);
getDirections(loc, DirectionDialogStyle.create().gpxRouteEnabled().routeFromMapPoint()); String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
getDirections(loc, name, DirectionDialogStyle.create().gpxRouteEnabled().routeFromMapPoint());
} }
} else if (standardId == R.string.context_menu_item_intermediate_point) { } else if (standardId == R.string.context_menu_item_intermediate_point) {
// Issue 1929: Consistently show IntermediatePointDialog, without subsequent Directions screen String selected = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
//targets.navigateToPoint(new LatLon(latitude, longitude), true, targets.getIntermediatePoints().size());
// TODO: enhance next statement to transmit getSelectedObjectName for clicked objects like favorites instead of just coordinates
int sz = targets.getIntermediatePoints().size(); int sz = targets.getIntermediatePoints().size();
targets.navigateToPoint(new LatLon(latitude, longitude), true, sz); targets.navigateToPoint(new LatLon(latitude, longitude), true, sz, selected);
IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity); IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity);
// For button-less search UI // For button-less search UI
} else if (standardId == R.string.context_menu_item_destination_point) { } else if (standardId == R.string.context_menu_item_destination_point) {
// TODO: enhance next statement to transmit getSelectedObjectName for clicked objects like favorites instead of just coordinates String selected = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName();
targets.navigateToPoint(new LatLon(latitude, longitude), true, -1); targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, selected);
IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity); IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity);
} else if (standardId == R.string.context_menu_item_share_location) { } else if (standardId == R.string.context_menu_item_share_location) {
shareLocation(latitude, longitude, mapActivity.getMapView().getZoom()); shareLocation(latitude, longitude, mapActivity.getMapView().getZoom());
@ -1071,7 +1071,7 @@ public class MapActivityActions implements DialogProvider {
Location loc = new Location("map"); Location loc = new Location("map");
loc.setLatitude(mapView.getLatitude()); loc.setLatitude(mapView.getLatitude());
loc.setLongitude(mapView.getLongitude()); loc.setLongitude(mapView.getLongitude());
getDirections(loc, DirectionDialogStyle.create().gpxRouteEnabled()); getDirections(loc, null, DirectionDialogStyle.create().gpxRouteEnabled());
} }
} }
}).reg(); }).reg();
@ -1332,9 +1332,8 @@ public class MapActivityActions implements DialogProvider {
if (onShow != null) { if (onShow != null) {
onShow.onClick(v); onShow.onClick(v);
} }
targetPointsHelper.setDestination(location.getLatitude(), location.getLongitude(), name);
MapActivity.launchMapActivityMoveToTop(activity);
qa.dismiss(); qa.dismiss();
MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
} }
}); });
qa.addActionItem(setAsDestination); qa.addActionItem(setAsDestination);
@ -1353,8 +1352,7 @@ public class MapActivityActions implements DialogProvider {
if (onShow != null) { if (onShow != null) {
onShow.onClick(v); onShow.onClick(v);
} }
// Issue 1929 TODO: Check where this dialogue appears and replace by IntermediatePointsDialog addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
navigatePointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name);
qa.dismiss(); qa.dismiss();
} }
}); });
@ -1399,12 +1397,36 @@ public class MapActivityActions implements DialogProvider {
} }
} }
public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
public static void navigatePointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) { OsmandApplication ctx = (OsmandApplication) act.getApplication();
// Issue 1929: This dialog not needed anymore final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (targetPointsHelper.getIntermediatePoints().size() > 0) {
Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_directions_point_dialog);
builder.setItems(
new String[] { act.getString(R.string.keep_intermediate_points),
act.getString(R.string.clear_intermediate_points)},
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 1) {
targetPointsHelper.clearPointToNavigate(false);
}
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1);
MapActivity.launchMapActivityMoveToTop(act);
}
});
builder.show();
} else {
targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1);
MapActivity.launchMapActivityMoveToTop(act);
}
}
public static void addWaypointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) {
OsmandApplication ctx = (OsmandApplication) act.getApplication(); OsmandApplication ctx = (OsmandApplication) act.getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper(); final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
final OsmandSettings settings = ctx.getSettings();
if (targetPointsHelper.getPointToNavigate() != null) { if (targetPointsHelper.getPointToNavigate() != null) {
Builder builder = new AlertDialog.Builder(act); Builder builder = new AlertDialog.Builder(act);
builder.setTitle(R.string.new_destination_point_dialog); builder.setTitle(R.string.new_destination_point_dialog);
@ -1415,28 +1437,18 @@ public class MapActivityActions implements DialogProvider {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == 0) { if (which == 0) {
settings.setPointToNavigate(lat, lon, false, name); targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1);
} else if (which == 2) { } else if (which == 2) {
int sz = targetPointsHelper.getIntermediatePoints().size(); targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size());
// LatLon pt = targetPointsHelper.getPointToNavigate();
settings.insertIntermediatePoint(lat, lon, name, sz, false);
// settings.setPointToNavigate(pt.getLatitude(), pt.getLongitude(), false,
// settings.getPointNavigateDescription());
// I believe the following prior code was buggy, Hardy 2013-06-10:
// settings.insertIntermediatePoint(pt.getLatitude(), pt.getLongitude(),
// settings.getPointNavigateDescription(), sz, true);
// settings.setPointToNavigate(lat, lon, true, name);
} else { } else {
settings.insertIntermediatePoint(lat, lon, name, 0, false); targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, 0);
} }
targetPointsHelper.updatePointsFromSettings();
MapActivity.launchMapActivityMoveToTop(act); MapActivity.launchMapActivityMoveToTop(act);
} }
}); });
builder.show(); builder.show();
} else { } else {
settings.setPointToNavigate(lat, lon, false, name); targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1);
targetPointsHelper.updatePointsFromSettings();
MapActivity.launchMapActivityMoveToTop(act); MapActivity.launchMapActivityMoveToTop(act);
} }
} }

View file

@ -274,18 +274,9 @@ public class NavigatePointFragment extends SherlockFragment implements SearchAct
dlg.show(); dlg.show();
MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon)); MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon));
} else if (mode == NAVIGATE_TO) { } else if (mode == NAVIGATE_TO) {
targetPointsHelper.setDestination(lat, lon, getString(R.string.point_on_map, lat, lon)); MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
MapActivity.launchMapActivityMoveToTop(getActivity());
} else if (mode == ADD_WAYPOINT) { } else if (mode == ADD_WAYPOINT) {
MapActivityActions.navigatePointDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon)); MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon));
// Issue 1929 TODO: show IntermediatePointsDialog here instead of navigatePointDialog, without subsequent Directions
//if (targetPointsHelper.getIntermediatePoints().size() == 0) {
// targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1);
//} else {
// targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size());
//}
//IntermediatePointsDialog.openIntermediatePointsDialog(getActivity());
//MapActivity.launchMapActivityMoveToTop(getActivity());
} else if (mode == SHOW_ON_MAP){ } else if (mode == SHOW_ON_MAP){
OsmandApplication app = (OsmandApplication) getActivity().getApplication(); OsmandApplication app = (OsmandApplication) getActivity().getApplication();
app.getSettings().setMapLocationToShow(lat, lon, Math.max(12, app.getSettings().getLastKnownMapZoom()), app.getSettings().setMapLocationToShow(lat, lon, Math.max(12, app.getSettings().getLastKnownMapZoom()),

View file

@ -306,20 +306,10 @@ public class SearchAddressFragment extends SherlockFragment {
getActivity().finish(); getActivity().finish();
} else { } else {
OsmandApplication ctx = (OsmandApplication) getActivity().getApplication(); OsmandApplication ctx = (OsmandApplication) getActivity().getApplication();
final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper();
if (mode == NAVIGATE_TO) { if (mode == NAVIGATE_TO) {
targetPointsHelper.setDestination(searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName);
MapActivity.launchMapActivityMoveToTop(getActivity());
} else if (mode == ADD_WAYPOINT) { } else if (mode == ADD_WAYPOINT) {
MapActivityActions.navigatePointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName);
// Issue 1929 TODO: show IntermediatePointsDialog here instead of navigatePointDialog, without subsequent Directions
//if (targetPointsHelper.getIntermediatePoints().size() == 0) {
// targetPointsHelper.navigateToPoint(searchPoint, true, -1);
//} else {
// targetPointsHelper.navigateToPoint(searchPoint, true, targetPointsHelper.getIntermediatePoints().size());
//}
//IntermediatePointsDialog.openIntermediatePointsDialog(getActivity());
//MapActivity.launchMapActivityMoveToTop(getActivity());
} else if (mode == SHOW_ON_MAP) { } else if (mode == SHOW_ON_MAP) {
osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName);
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());