diff --git a/OsmAnd-java/src/net/osmand/map/WorldRegion.java b/OsmAnd-java/src/net/osmand/map/WorldRegion.java index c14adbedd7..52a0102688 100644 --- a/OsmAnd-java/src/net/osmand/map/WorldRegion.java +++ b/OsmAnd-java/src/net/osmand/map/WorldRegion.java @@ -157,5 +157,14 @@ public class WorldRegion { subregions.add(rd); rd.superregion = this; } - + + public int getLevel() { + int res = 0; + WorldRegion parent = superregion; + while (parent != null) { + parent = parent.superregion; + res++; + } + return res; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index 2ae74325e2..e8a3ad67b8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -17,6 +17,7 @@ import net.osmand.plus.mapcontextmenu.MenuController; public class MapDataMenuController extends MenuController { private WorldRegion region; + private String regionName; public MapDataMenuController(OsmandApplication app, MapActivity mapActivity, final BinaryMapDataObject dataObject) { super(new MenuBuilder(app), mapActivity); @@ -24,6 +25,11 @@ public class MapDataMenuController extends MenuController { String fullName = osmandRegions.getFullName(dataObject); final WorldRegion region = osmandRegions.getRegionData(fullName); this.region = region; + if (region != null) { + regionName = region.getLocaleName(); + } else { + regionName = dataObject.getName(); + } titleButtonController = new TitleButtonController() { @Override public void buttonPressed() { @@ -31,7 +37,7 @@ public class MapDataMenuController extends MenuController { final Intent intent = new Intent(getMapActivity(), getMapActivity().getMyApplication() .getAppCustomization().getDownloadIndexActivity()); - intent.putExtra(DownloadActivity.FILTER_KEY, region.getLocaleName()); + intent.putExtra(DownloadActivity.FILTER_KEY, regionName); intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); getMapActivity().startActivity(intent); } @@ -57,12 +63,12 @@ public class MapDataMenuController extends MenuController { @Override public String getNameStr() { - return region.getLocaleName(); + return regionName; } @Override public String getTypeStr() { - if (region.getSuperregion() != null) { + if (region != null && region.getSuperregion() != null) { return region.getSuperregion().getLocaleName() + "\n"; } else { return getMapActivity().getString(R.string.shared_string_map) + "\n"; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java index a80362d95b..f22dc7f8ff 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ObjectSelectionMenu.java @@ -103,11 +103,14 @@ public class ObjectSelectionMenu extends BaseMenuController { private void createCollection(Map selectedObjects) { this.selectedObjects.putAll(selectedObjects); + int order = Integer.MAX_VALUE; + MenuObject topObject = null; for (Map.Entry e : selectedObjects.entrySet()) { Object selectedObj = e.getKey(); IContextMenuProvider contextObject = selectedObjects.get(selectedObj); LatLon ll = null; PointDescription pointDescription = null; + if (contextObject != null) { ll = contextObject.getObjectLocation(selectedObj); pointDescription = contextObject.getObjectName(selectedObj); @@ -121,13 +124,27 @@ public class ObjectSelectionMenu extends BaseMenuController { MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity()); objects.add(menuObject); + + if (contextObject instanceof ContextMenuLayer.IContextMenuProviderSelection) { + int i = ((ContextMenuLayer.IContextMenuProviderSelection) contextObject).getOrder(selectedObj); + if (i < order) { + topObject = menuObject; + order = i; + } + } } + Collections.sort(objects, new Comparator() { @Override public int compare(MenuObject obj1, MenuObject obj2) { return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr()); } }); + + if (topObject != null) { + objects.remove(topObject); + objects.add(0, topObject); + } } public static void show(LatLon latLon, Map selectedObjects, MapActivity mapActivity) { diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java index 333d576229..3f65bcc4b2 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java @@ -400,6 +400,11 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye }, 350); } + @Override + public int getOrder(Object o) { + return 0; + } + @Override public void setSelectedObject(Object o) { if(o instanceof OsMoDevice) { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 091392c6d0..b65e643153 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -39,6 +39,7 @@ public class ContextMenuLayer extends OsmandMapLayer { public interface IContextMenuProviderSelection { + int getOrder(Object o); void setSelectedObject(Object o); void clearSelectedObject(); } diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index a982f3256e..1a63fd3269 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -403,10 +403,25 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe } } + @Override + public int getOrder(Object o) { + if (o instanceof BinaryMapDataObject) { + String fullName = osmandRegions.getFullName((BinaryMapDataObject) o); + final WorldRegion region = osmandRegions.getRegionData(fullName); + if (region != null) { + return region.getLevel(); + } + } + return 0; + } + @Override public void setSelectedObject(Object o) { if (o instanceof BinaryMapDataObject) { List list = new LinkedList<>(); + if (selectedObjects != null) { + list.addAll(selectedObjects); + } list.add((BinaryMapDataObject) o); selectedObjects = list; }