Search in sources :

Example 1 with IContextMenuProvider

use of net.osmand.plus.views.layers.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();
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        ContextMenuLayer contextMenuLayer = mapActivity.getMapLayers().getContextMenuLayer();
        contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider);
    }
}
Also used : ContextMenuLayer(net.osmand.plus.views.layers.ContextMenuLayer) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with IContextMenuProvider

use of net.osmand.plus.views.layers.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 = e.getValue();
        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.layers.ContextMenuLayer) HashMap(java.util.HashMap) Map(java.util.Map) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider)

Example 3 with IContextMenuProvider

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

the class MapRouteInfoMenu method getObjectLocation.

private Pair<LatLon, PointDescription> getObjectLocation(OsmandMapTileView mapView, PointF point, RotatedTileBox tileBox) {
    List<Object> objects = new ArrayList<>();
    for (OsmandMapLayer layer : mapView.getLayers()) {
        if (layer instanceof IContextMenuProvider) {
            objects.clear();
            IContextMenuProvider provider = (IContextMenuProvider) layer;
            provider.collectObjectsFromPoint(point, tileBox, objects, true);
            for (Object o : objects) {
                if (provider.isObjectClickable(o)) {
                    LatLon latLon = provider.getObjectLocation(o);
                    PointDescription name = null;
                    if (o instanceof FavouritePoint) {
                        name = ((FavouritePoint) o).getPointDescription(mapView.getApplication());
                    }
                    return new Pair<>(latLon, name);
                }
            }
        }
    }
    return null;
}
Also used : LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) OsmandMapLayer(net.osmand.plus.views.layers.base.OsmandMapLayer) PointDescription(net.osmand.data.PointDescription) ArrayList(java.util.ArrayList) IContextMenuProvider(net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider) Pair(android.util.Pair)

Aggregations

IContextMenuProvider (net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider)3 LatLon (net.osmand.data.LatLon)2 PointDescription (net.osmand.data.PointDescription)2 ContextMenuLayer (net.osmand.plus.views.layers.ContextMenuLayer)2 Pair (android.util.Pair)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FavouritePoint (net.osmand.data.FavouritePoint)1 MapActivity (net.osmand.plus.activities.MapActivity)1 OsmandMapLayer (net.osmand.plus.views.layers.base.OsmandMapLayer)1