diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index f5421a7919..978f791328 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; @@ -215,11 +216,16 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public MapContextMenu() { } - public boolean init(LatLon latLon, PointDescription pointDescription, @Nullable Object object) { + public boolean init(@NonNull LatLon latLon, + @Nullable PointDescription pointDescription, + @Nullable Object object) { return init(latLon, pointDescription, object, false); } - public boolean init(LatLon latLon, PointDescription pointDescription, Object object, boolean update) { + public boolean init(@NonNull LatLon latLon, + @Nullable PointDescription pointDescription, + @Nullable Object object, + boolean update) { if (myLocation == null) { myLocation = getMapActivity().getMyApplication().getSettings().getLastKnownMapLocation(); @@ -296,7 +302,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } - public void show(LatLon latLon, PointDescription pointDescription, @Nullable Object object) { + public void show(@NonNull LatLon latLon, + @Nullable PointDescription pointDescription, + @Nullable Object object) { if (init(latLon, pointDescription, object)) { if (!MapContextMenuFragment.showInstance(this, mapActivity, centerMarker)) { active = false; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index d34f8f5f0b..34beb26604 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapcontextmenu.other; +import android.support.annotation.NonNull; import android.support.v4.app.Fragment; import net.osmand.data.LatLon; @@ -185,13 +186,11 @@ public class MapMultiSelectionMenu extends BaseMenuController { clearSelectedObjects(); } - public void openContextMenu(MenuObject menuObject) { - if (selectedObjects.containsKey(menuObject.getObject())) { - selectedObjects.remove(menuObject.getObject()); - } + public void openContextMenu(@NonNull MenuObject menuObject) { + IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject()); hide(); getMapActivity().getMapLayers().getContextMenuLayer().showContextMenu( - menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject()); + menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider); } private void clearSelectedObjects() { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index f23293475d..80bf2ca653 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -317,16 +317,10 @@ public class ContextMenuLayer extends OsmandMapLayer { } public boolean showContextMenu(@NonNull LatLon latLon, - @NonNull PointDescription pointDescription, - @NonNull Object object) { - RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox(); - double latitude = latLon.getLatitude(); - double longitude = latLon.getLongitude(); - float x = tileBox.getPixXFromLatLon(latitude, longitude); - float y = tileBox.getPixYFromLatLon(latitude, longitude); - Map selectedObjects = - selectObjectsForContextMenu(tileBox, new PointF(x, y), false); - selectedObjectContextMenuProvider = selectedObjects.get(object); + @Nullable PointDescription pointDescription, + @Nullable Object object, + @Nullable IContextMenuProvider provider) { + selectedObjectContextMenuProvider = provider; hideVisibleMenues(); activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); menu.show(latLon, pointDescription, object); @@ -337,7 +331,6 @@ public class ContextMenuLayer extends OsmandMapLayer { Map selectedObjects = selectObjectsForContextMenu(tileBox, point, false); if (selectedObjects.size() == 1) { Object selectedObj = selectedObjects.keySet().iterator().next(); - selectedObjectContextMenuProvider = selectedObjects.get(selectedObj); LatLon latLon = null; PointDescription pointDescription = null; if (selectedObjectContextMenuProvider != null) { @@ -347,9 +340,7 @@ public class ContextMenuLayer extends OsmandMapLayer { if (latLon == null) { latLon = getLatLon(point, tileBox); } - hideVisibleMenues(); - activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); - menu.show(latLon, pointDescription, selectedObj); + showContextMenu(latLon, pointDescription, selectedObj, selectedObjects.get(selectedObj)); return true; } else if (selectedObjects.size() > 1) {