From 112dd1da2943e7e1254622d3ef599e286ec1a1f5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Sat, 9 Nov 2019 09:36:19 +0300 Subject: [PATCH] Issue #7646 "Directions from" quick actions --- OsmAnd/res/values/strings.xml | 1 + .../plus/quickaction/QuickActionFactory.java | 18 ++++++++ .../actions/NavDirectionsFromAction.java | 42 +++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a97cda1ec9..af645a8b15 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -877,6 +877,7 @@ Replace destination Add first intermediate A button to make the screen center the route destination, any previously selected destination becomes the last intermediate destination. + A button to make the screen center the point of departure and calculate route to the destination or open a dialog to select destination if the destination marker is not on the map. Tapping this action button makes the screen center the new route destination, replacing the previously selected destination (if any). A button to make the screen center the first intermediate destination. No overlay diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index d9e37937ce..2469093cf8 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -30,6 +30,7 @@ import net.osmand.plus.quickaction.actions.MarkerAction; import net.osmand.plus.quickaction.actions.NavAddDestinationAction; import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction; import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction; +import net.osmand.plus.quickaction.actions.NavDirectionsFromAction; import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction; import net.osmand.plus.quickaction.actions.NavResumePauseAction; import net.osmand.plus.quickaction.actions.NavStartStopAction; @@ -133,6 +134,7 @@ public class QuickActionFactory { QuickAction voice = new NavVoiceAction(); + QuickAction directionFrom = new NavDirectionsFromAction(); QuickAction addDestination = new NavAddDestinationAction(); QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction(); QuickAction replaceDestination = new NavReplaceDestinationAction(); @@ -145,6 +147,9 @@ public class QuickActionFactory { if (!voice.hasInstanceInList(active)) { navigationQuickActions.add(voice); } + if (!directionFrom.hasInstanceInList(active)) { + navigationQuickActions.add(directionFrom); + } if (!addDestination.hasInstanceInList(active)) { navigationQuickActions.add(addDestination); } @@ -230,6 +235,9 @@ public class QuickActionFactory { case MapUnderlayAction.TYPE: return new MapUnderlayAction(); + case NavDirectionsFromAction.TYPE: + return new NavDirectionsFromAction(); + case NavAddDestinationAction.TYPE: return new NavAddDestinationAction(); @@ -323,6 +331,9 @@ public class QuickActionFactory { case MapUnderlayAction.TYPE: return new MapUnderlayAction(quickAction); + case NavDirectionsFromAction.TYPE: + return new NavDirectionsFromAction(quickAction); + case NavAddDestinationAction.TYPE: return new NavAddDestinationAction(quickAction); @@ -416,6 +427,9 @@ public class QuickActionFactory { case MapUnderlayAction.TYPE: return R.drawable.ic_layer_bottom_dark; + case NavDirectionsFromAction.TYPE: + return R.drawable.ic_action_route_direction_from_here; + case NavAddDestinationAction.TYPE: return R.drawable.ic_action_point_add_destination; @@ -512,6 +526,9 @@ public class QuickActionFactory { case DayNightModeAction.TYPE: return R.string.quick_action_day_night_switch_mode; + case NavDirectionsFromAction.TYPE: + return R.string.context_menu_item_directions_from; + case NavAddDestinationAction.TYPE: return R.string.quick_action_add_destination; @@ -557,6 +574,7 @@ public class QuickActionFactory { case TakePhotoNoteAction.TYPE: case TakeVideoNoteAction.TYPE: case NavVoiceAction.TYPE: + case NavDirectionsFromAction.TYPE: case NavAddDestinationAction.TYPE: case NavAddFirstIntermediateAction.TYPE: case NavReplaceDestinationAction.TYPE: diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java new file mode 100644 index 0000000000..c20af4c8e9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java @@ -0,0 +1,42 @@ +package net.osmand.plus.quickaction.actions; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import net.osmand.data.LatLon; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.quickaction.QuickAction; + +public class NavDirectionsFromAction extends QuickAction { + + public static final int TYPE = 19; + + public NavDirectionsFromAction() { + super(TYPE); + } + + public NavDirectionsFromAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute(MapActivity activity) { + LatLon latLon = activity.getMapView().getCurrentRotatedTileBox().getCenterLatLon(); + activity.getMapActions().enterDirectionsFromPoint(latLon.getLatitude(), latLon.getLongitude()); + } + + @Override + public void drawUI(ViewGroup parent, MapActivity activity) { + + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_with_text, parent, false); + + ((TextView) view.findViewById(R.id.text)).setText( + R.string.quick_action_directions_from_desc); + + parent.addView(view); + } +}