// Find touched objects if any and emit accessible toast message // with it's brief description. private void describePointedObjects(RotatedTileBox tb, MotionEvent event) { PointF point = new PointF(event.getX(), event.getY()); List<Object> ns = new ArrayList<Object>(); Map<Object, IContextMenuProvider> newSelectedObjects = new LinkedHashMap<Object, ContextMenuLayer.IContextMenuProvider>(); for (OsmandMapLayer layer : mapView.getLayers()) { if (layer instanceof IContextMenuProvider) { ns.clear(); ((IContextMenuProvider) layer).collectObjectsFromPoint(point, tb, ns); for (Object o : ns) { newSelectedObjects.put(o, (IContextMenuProvider) layer); } } } if (newSelectedObjects.isEmpty()) { ns.clear(); collectObjectsFromPoint(point, tb, ns); for (Object o : ns) { newSelectedObjects.put(o, this); } } if (different(newSelectedObjects, selectedObjects)) { ContextMenuLayer contextMenuLayer = mapView.getLayerByClass(ContextMenuLayer.class); if (contextMenuLayer != null) { contextMenuLayer.setSelections(newSelectedObjects); if (!ns.isEmpty()) mapView.showMessage( mapView.getSettings().USE_SHORT_OBJECT_NAMES.get() ? contextMenuLayer.getSelectedObjectName() : contextMenuLayer.getSelectedObjectDescription()); } selectedObjects = newSelectedObjects; } }
@Override public boolean onDown(MotionEvent e) { if ((Build.VERSION.SDK_INT >= 14) || mapView.getSettings().SCROLL_MAP_BY_GESTURES.get()) return fallback.onDown(e); ContextMenuLayer contextMenuLayer = mapView.getLayerByClass(ContextMenuLayer.class); if (contextMenuLayer != null) contextMenuLayer.setSelections(null); selectedObjects = null; describePointedObjects(mapView.getCurrentRotatedTileBox(), e); return false; }