Search in sources :

Example 1 with IContextMenuProvider

use of net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider in project Osmand by osmandapp.

the class MapMultiSelectionMenu method createCollection.

private void createCollection(Map<Object, IContextMenuProvider> selectedObjects) {
    this.selectedObjects.clear();
    this.selectedObjects.putAll(selectedObjects);
    objects.clear();
    for (Map.Entry<Object, IContextMenuProvider> 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);
        }
        if (ll == null) {
            ll = latLon;
        }
        if (pointDescription == null) {
            pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
        }
        MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMapActivity());
        objects.add(menuObject);
        if (contextObject instanceof ContextMenuLayer.IContextMenuProviderSelection) {
            menuObject.order = ((ContextMenuLayer.IContextMenuProviderSelection) contextObject).getOrder(selectedObj);
        }
    }
    Collections.sort(objects, new Comparator<MenuObject>() {

        @Override
        public int compare(MenuObject obj1, MenuObject obj2) {
            if (obj1.order == obj2.order) {
                return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr());
            } else {
                return obj1.order - obj2.order;
            }
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) ContextMenuLayer(net.osmand.plus.views.ContextMenuLayer) HashMap(java.util.HashMap) Map(java.util.Map) IContextMenuProvider(net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider)

Example 2 with IContextMenuProvider

use of net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider in project Osmand by osmandapp.

the class MapMultiSelectionMenu method openContextMenu.

public void openContextMenu(@NonNull MenuObject menuObject) {
    IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject());
    hide();
    ContextMenuLayer contextMenuLayer = getMapActivity().getMapLayers().getContextMenuLayer();
    contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider);
}
Also used : ContextMenuLayer(net.osmand.plus.views.ContextMenuLayer) IContextMenuProvider(net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider)

Aggregations

ContextMenuLayer (net.osmand.plus.views.ContextMenuLayer)2 IContextMenuProvider (net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 LatLon (net.osmand.data.LatLon)1 PointDescription (net.osmand.data.PointDescription)1