diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 82e7906681..4c4ff26d1c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,9 @@ 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 --> + Clear intermediate points + Keep intermediate points + You already have intermediate points set. Directions To Directions From Map: diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java index b213d31a17..69918717ca 100644 --- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java +++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java @@ -165,6 +165,10 @@ public class TargetPointsHelper { } 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(intermediate < 0) { settings.setPointToNavigate(point.getLatitude(), point.getLongitude(), null); @@ -178,7 +182,6 @@ public class TargetPointsHelper { } readFromSettings(settings); updateRouteAndReferesh(updateRoute); - } 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); - } - - } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 29b6c9d50c..18e0c7060d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -304,7 +304,7 @@ public class MapActivity extends AccessibleActivity { Location loc = new Location("map"); loc.setLatitude(mapView.getLatitude()); loc.setLongitude(mapView.getLongitude()); - mapActions.getDirections(loc, DirectionDialogStyle.create()); + mapActions.getDirections(loc, null, DirectionDialogStyle.create()); } if(mapLabelToShow != null && latLonToShow != null){ mapLayers.getContextMenuLayer().setSelectedObject(toShow); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index a11225a462..276ae0cb5e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -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(); Builder builder = new AlertDialog.Builder(mapActivity); 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()].setButtonDrawable(R.drawable.ic_pedestrian); - final Spinner fromSpinner = setupFromSpinner(mapView, view, style); + final Spinner fromSpinner = setupFromSpinner(mapView, name,view, style); final List toList = new ArrayList(); - final Spinner toSpinner = setupToSpinner(mapView, view, toList, style); + final Spinner toSpinner = setupToSpinner(mapView, name,view, toList, style); String via = generateViaDescription(); @@ -622,13 +622,13 @@ public class MapActivityActions implements DialogProvider { 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); ArrayList fromActions = new ArrayList(); fromActions.add(currentLocation); if(mapView != null) { - String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(mapView.getLatitude(), - mapView.getLongitude()); + String oname = name != null ? name : getRoutePointDescription(mapView.getLatitude(),mapView.getLongitude()); + String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + oname; fromActions.add(mapLocation); } final Spinner fromSpinner = ((Spinner) view.findViewById(R.id.FromSpinner)); @@ -643,7 +643,7 @@ public class MapActivityActions implements DialogProvider { return fromSpinner; } - private Spinner setupToSpinner(final Location mapView, View view, List locs, DirectionDialogStyle style) { + private Spinner setupToSpinner(final Location mapView, String name, View view, List locs, DirectionDialogStyle style) { final TargetPointsHelper targets = getTargets(); ArrayList toActions = new ArrayList(); if (targets.getPointToNavigate() != null) { @@ -652,8 +652,8 @@ public class MapActivityActions implements DialogProvider { locs.add(targets.getPointToNavigate()); } if(mapView != null) { - String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + getRoutePointDescription(mapView.getLatitude(), - mapView.getLongitude()); + String oname = name != null ? name : getRoutePointDescription(mapView.getLatitude(),mapView.getLongitude()); + String mapLocation = mapActivity.getString(R.string.route_descr_map_location) + " " + oname; toActions.add(mapLocation); locs.add(new LatLon(mapView.getLatitude(), mapView.getLongitude())); } @@ -874,7 +874,8 @@ public class MapActivityActions implements DialogProvider { Location loc = new Location("map"); loc.setLatitude(latitude); loc.setLongitude(longitude); - getDirections(loc, DirectionDialogStyle.create().gpxRouteEnabled().routeToMapPoint()); + String name = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName(); + getDirections(loc, name, DirectionDialogStyle.create().gpxRouteEnabled().routeToMapPoint()); } else { targets.navigateToPoint(new LatLon(latitude, longitude), true, -1); } @@ -883,19 +884,18 @@ public class MapActivityActions implements DialogProvider { Location loc = new Location("map"); loc.setLatitude(latitude); 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) { - // Issue 1929: Consistently show IntermediatePointDialog, without subsequent Directions screen - //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 + String selected = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName(); 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); // For button-less search UI } 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 - targets.navigateToPoint(new LatLon(latitude, longitude), true, -1); + String selected = mapActivity.getMapLayers().getContextMenuLayer().getSelectedObjectName(); + targets.navigateToPoint(new LatLon(latitude, longitude), true, -1, selected); IntermediatePointsDialog.openIntermediatePointsDialog(mapActivity); } else if (standardId == R.string.context_menu_item_share_location) { shareLocation(latitude, longitude, mapActivity.getMapView().getZoom()); @@ -1071,7 +1071,7 @@ public class MapActivityActions implements DialogProvider { Location loc = new Location("map"); loc.setLatitude(mapView.getLatitude()); loc.setLongitude(mapView.getLongitude()); - getDirections(loc, DirectionDialogStyle.create().gpxRouteEnabled()); + getDirections(loc, null, DirectionDialogStyle.create().gpxRouteEnabled()); } } }).reg(); @@ -1332,9 +1332,8 @@ public class MapActivityActions implements DialogProvider { if (onShow != null) { onShow.onClick(v); } - targetPointsHelper.setDestination(location.getLatitude(), location.getLongitude(), name); - MapActivity.launchMapActivityMoveToTop(activity); qa.dismiss(); + MapActivityActions.directionsToDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name); } }); qa.addActionItem(setAsDestination); @@ -1353,8 +1352,7 @@ public class MapActivityActions implements DialogProvider { if (onShow != null) { onShow.onClick(v); } - // Issue 1929 TODO: Check where this dialogue appears and replace by IntermediatePointsDialog - navigatePointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name); + addWaypointDialogAndLaunchMap(activity, location.getLatitude(), location.getLongitude(), name); qa.dismiss(); } }); @@ -1399,12 +1397,36 @@ public class MapActivityActions implements DialogProvider { } } - - public static void navigatePointDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) { - // Issue 1929: This dialog not needed anymore + public static void directionsToDialogAndLaunchMap(final Activity act, final double lat, final double lon, final String name) { + OsmandApplication ctx = (OsmandApplication) act.getApplication(); + 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(); final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper(); - final OsmandSettings settings = ctx.getSettings(); if (targetPointsHelper.getPointToNavigate() != null) { Builder builder = new AlertDialog.Builder(act); builder.setTitle(R.string.new_destination_point_dialog); @@ -1415,28 +1437,18 @@ public class MapActivityActions implements DialogProvider { @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { - settings.setPointToNavigate(lat, lon, false, name); + targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1); } else if (which == 2) { - int sz = 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); + targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, targetPointsHelper.getIntermediatePoints().size()); } else { - settings.insertIntermediatePoint(lat, lon, name, 0, false); + targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, 0); } - targetPointsHelper.updatePointsFromSettings(); MapActivity.launchMapActivityMoveToTop(act); } }); builder.show(); } else { - settings.setPointToNavigate(lat, lon, false, name); - targetPointsHelper.updatePointsFromSettings(); + targetPointsHelper.navigateToPoint(new LatLon(lat, lon), true, -1); MapActivity.launchMapActivityMoveToTop(act); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java index e7d17a38f4..853cacaef1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java @@ -274,18 +274,9 @@ public class NavigatePointFragment extends SherlockFragment implements SearchAct dlg.show(); MapActivityActions.prepareAddFavouriteDialog(getActivity(), dlg, b, lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == NAVIGATE_TO) { - targetPointsHelper.setDestination(lat, lon, getString(R.string.point_on_map, lat, lon)); - MapActivity.launchMapActivityMoveToTop(getActivity()); + MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == ADD_WAYPOINT) { - MapActivityActions.navigatePointDialogAndLaunchMap(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()); + MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), lat, lon, getString(R.string.point_on_map, lat, lon)); } else if (mode == SHOW_ON_MAP){ OsmandApplication app = (OsmandApplication) getActivity().getApplication(); app.getSettings().setMapLocationToShow(lat, lon, Math.max(12, app.getSettings().getLastKnownMapZoom()), diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java index 4b61b6b429..0229d67717 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java @@ -306,20 +306,10 @@ public class SearchAddressFragment extends SherlockFragment { getActivity().finish(); } else { OsmandApplication ctx = (OsmandApplication) getActivity().getApplication(); - final TargetPointsHelper targetPointsHelper = ctx.getTargetPointsHelper(); if (mode == NAVIGATE_TO) { - targetPointsHelper.setDestination(searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); - MapActivity.launchMapActivityMoveToTop(getActivity()); + MapActivityActions.directionsToDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); } else if (mode == ADD_WAYPOINT) { - MapActivityActions.navigatePointDialogAndLaunchMap(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()); + MapActivityActions.addWaypointDialogAndLaunchMap(getActivity(), searchPoint.getLatitude(), searchPoint.getLongitude(), historyName); } else if (mode == SHOW_ON_MAP) { osmandSettings.setMapLocationToShow(searchPoint.getLatitude(), searchPoint.getLongitude(), zoom, historyName); MapActivity.launchMapActivityMoveToTop(getActivity());