diff --git a/OsmAnd/src/net/osmand/access/MapExplorer.java b/OsmAnd/src/net/osmand/access/MapExplorer.java index df09b7e391..ff02d72537 100644 --- a/OsmAnd/src/net/osmand/access/MapExplorer.java +++ b/OsmAnd/src/net/osmand/access/MapExplorer.java @@ -1,25 +1,19 @@ package net.osmand.access; -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import android.graphics.PointF; +import android.view.GestureDetector.SimpleOnGestureListener; +import android.view.MotionEvent; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; import net.osmand.data.RotatedTileBox; import net.osmand.plus.R; -import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; -import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; -import android.graphics.PointF; -import android.os.Build; -import android.view.GestureDetector; -import android.view.GestureDetector.OnGestureListener; -import android.view.GestureDetector.SimpleOnGestureListener; -import android.view.MotionEvent; + +import java.util.List; +import java.util.Map; // Provide touch exploration mode for map view // when scrolling it by gestures is disabled. @@ -91,6 +85,11 @@ public class MapExplorer extends SimpleOnGestureListener implements IContextMenu return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List objects) { int radius = (int)(VICINITY_RADIUS * tileBox.getDensity()); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java index aa26b30ac9..62bc990b99 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioNotesLayer.java @@ -90,14 +90,18 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi final QuadRect latlon = tileBox.getLatLonBounds(); List objects = recs.getObjects(latlon.top, latlon.left, latlon.bottom, latlon.right); List fullObjects = new ArrayList<>(); + List fullObjectsLatLon = new ArrayList<>(); + List smallObjectsLatLon = new ArrayList<>(); for (Recording o : objects) { float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); + smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } else { fullObjects.add(o); + fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } } for (Recording o : fullObjects) { @@ -113,6 +117,8 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi } canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); } + this.fullObjectsLatLon = fullObjectsLatLon; + this.smallObjectsLatLon = smallObjectsLatLon; } } @@ -156,6 +162,11 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof Recording; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List objects) { getRecordingsFromPoint(point, tileBox, objects); diff --git a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java index 7b2b4fd7d5..e6e37d9f76 100644 --- a/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java +++ b/OsmAnd/src/net/osmand/plus/distancecalculator/DistanceCalculatorPlugin.java @@ -587,6 +587,11 @@ public class DistanceCalculatorPlugin extends OsmandPlugin { return distanceMeasurementMode == 1; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { getMPointsFromPoint(tileBox, point, o); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 9bc84658b4..bc13d32513 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -737,6 +737,10 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } } + public boolean supportZoomIn() { + return menuController == null || menuController.supportZoomIn(); + } + public boolean fabVisible() { return menuController == null || menuController.fabVisible(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 122815e1bd..4c7a57c765 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -231,14 +231,14 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { moving = false; int posY = getViewY(); if (!centered) { - if (!zoomIn) { + if (!zoomIn && menu.supportZoomIn()) { LatLon centerLatLon = map.getCurrentRotatedTileBox().getCenterLatLon(); if (centerLatLon.equals(menu.getLatLon())) { zoomIn = true; } } centerMarkerLocation(); - } else if (!zoomIn) { + } else if (!zoomIn && menu.supportZoomIn()) { int fZoom = getZoom(); zoomIn = true; if (fZoom < ZOOM_IN_STANDARD) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index d6bd712bd1..5aa16cc451 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -236,6 +236,10 @@ public abstract class MenuController extends BaseMenuController { return titleProgressController; } + public boolean supportZoomIn() { + return true; + } + public boolean fabVisible() { return true; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java index cbc78829e7..ba4b2182fb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/MapDataMenuController.java @@ -8,6 +8,7 @@ import android.os.AsyncTask; import android.support.v7.app.AlertDialog; import android.widget.Toast; +import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -22,6 +23,7 @@ import net.osmand.plus.download.IndexItem; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; import net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject; @@ -41,17 +43,23 @@ public class MapDataMenuController extends MenuController { private List otherIndexItems; private boolean srtmDisabled; private boolean srtmNeedsInstallation; + boolean downloaded; private DownloadIndexesThread downloadThread; + private ResourceManager rm; public MapDataMenuController(OsmandApplication app, final MapActivity mapActivity, PointDescription pointDescription, final DownloadMapObject mapObject) { super(new MenuBuilder(app), pointDescription, mapActivity); this.mapObject = mapObject; + rm = app.getResourceManager(); indexItem = mapObject.getIndexItem(); downloadThread = app.getDownloadThread(); if (indexItem != null) { + downloaded = indexItem.isDownloaded(); otherIndexItems = new LinkedList<>(downloadThread.getIndexes().getIndexItems(mapObject.getWorldRegion())); otherIndexItems.remove(indexItem); + } else { + downloaded = checkIfObjectDownloaded(rm.getOsmandRegions().getDownloadName(mapObject.getDataObject())); } srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null; @@ -93,6 +101,14 @@ public class MapDataMenuController extends MenuController { public void buttonPressed() { if (indexItem != null) { deleteItem(); + } else if (downloaded) { +/* + File f = new File(info.getPathToData()); + boolean successfull = Algorithms.removeAllFiles(f); + if (successfull) { + getMapActivity().getMyApplication().getResourceManager().closeFile(info.getFileName()); + } +*/ } } }; @@ -215,6 +231,11 @@ public class MapDataMenuController extends MenuController { } } + @Override + public boolean supportZoomIn() { + return false; + } + @Override public boolean fabVisible() { return false; @@ -254,7 +275,7 @@ public class MapDataMenuController extends MenuController { } } - rightTitleButtonController.visible = indexItem != null && indexItem.isDownloaded(); + rightTitleButtonController.visible = downloaded; topRightTitleButtonController.visible = otherIndexItems.size() > 0; boolean downloadIndexes = getMapActivity().getMyApplication().getSettings().isInternetConnectionAvailable() @@ -332,4 +353,12 @@ public class MapDataMenuController extends MenuController { confirm.show(); } } + + private boolean checkIfObjectDownloaded(String downloadName) { + final String regionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + + IndexConstants.BINARY_MAP_INDEX_EXT; + final String roadsRegionName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) + ".road" + + IndexConstants.BINARY_MAP_INDEX_EXT; + return rm.getIndexFileNames().containsKey(regionName) || rm.getIndexFileNames().containsKey(roadsRegionName); + } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index 922792633f..33bdf603c6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -133,6 +133,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider float iconSize = resolvedNote.getWidth() * 3 / 2.5f; QuadTree boundIntersections = initBoundIntersections(tileBox); List fullObjects = new ArrayList<>(); + List fullObjectsLatLon = new ArrayList<>(); + List smallObjectsLatLon = new ArrayList<>(); for (OpenStreetNote o : objects) { float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); @@ -145,8 +147,10 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider b = resolvedNoteSmall; } canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); + smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } else { fullObjects.add(o); + fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } } for (OpenStreetNote o : fullObjects) { @@ -160,6 +164,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); } + this.fullObjectsLatLon = fullObjectsLatLon; + this.smallObjectsLatLon = smallObjectsLatLon; } } } @@ -519,6 +525,11 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof OpenStreetNote; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List res) { getBugFromPoint(tileBox, point, res); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java index b597b34117..1649986e56 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java @@ -15,6 +15,7 @@ import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; +import java.util.ArrayList; import java.util.List; /** @@ -61,6 +62,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC } private void drawPoints(Canvas canvas, RotatedTileBox tileBox, List objects) { + List fullObjectsLatLon = new ArrayList<>(); for (OsmPoint o : objects) { float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude()); float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude()); @@ -73,7 +75,9 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC b = poi; } canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); + fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } + this.fullObjectsLatLon = fullObjectsLatLon; } @Override @@ -133,6 +137,11 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof OsmPoint; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { getOsmEditsFromPoint(point, tileBox, o); diff --git a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java index bc0fb5f22e..52b982f2c0 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmo/OsMoPositionLayer.java @@ -208,6 +208,11 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof OsMoDevice; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { getOsmoFromPoint(tileBox, point, o); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionLayer.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionLayer.java index 9e650951aa..37ffa79c5d 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionLayer.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionLayer.java @@ -113,6 +113,11 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL return false; } + @Override + public boolean isObjectClickable(Object o) { + return o == getParkingPoint(); + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { getParkingFromPoint(tileBox, point, o); diff --git a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java index cd36416676..807a219728 100644 --- a/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java +++ b/OsmAnd/src/net/osmand/plus/routepointsnavigation/RoutePointsLayer.java @@ -40,6 +40,11 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 285b241f38..323740322a 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -14,20 +14,14 @@ import android.widget.FrameLayout.LayoutParams; import android.widget.ImageView; import net.osmand.CallbackWithObject; -import net.osmand.data.Amenity; -import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; -import net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote; -import net.osmand.plus.osmedit.OsmPoint; -import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice; import java.util.ArrayList; import java.util.HashMap; @@ -49,6 +43,8 @@ public class ContextMenuLayer extends OsmandMapLayer { boolean disableSingleTap(); boolean disableLongPressOnMap(); + + boolean isObjectClickable(Object o); } public interface IContextMenuProviderSelection { @@ -70,7 +66,9 @@ public class ContextMenuLayer extends OsmandMapLayer { private ImageView contextMarker; private Paint paint; private Bitmap pressedBitmap; - private LatLon pressedLatLon; + private Bitmap pressedBitmapSmall; + private List pressedLatLonFull = new ArrayList<>(); + private List pressedLatLonSmall = new ArrayList<>(); private GestureDetector movementListener; @@ -99,6 +97,7 @@ public class ContextMenuLayer extends OsmandMapLayer { paint = new Paint(); pressedBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap); + pressedBitmapSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_shield_tap_small); } public boolean isVisible() { @@ -107,9 +106,14 @@ public class ContextMenuLayer extends OsmandMapLayer { @Override public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings nightMode) { - if (pressedLatLon != null) { - int x = (int) box.getPixXFromLatLon(pressedLatLon.getLatitude(), pressedLatLon.getLongitude()); - int y = (int) box.getPixYFromLatLon(pressedLatLon.getLatitude(), pressedLatLon.getLongitude()); + for (LatLon latLon : pressedLatLonSmall) { + int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + canvas.drawBitmap(pressedBitmapSmall, x - pressedBitmapSmall.getWidth() / 2, y - pressedBitmapSmall.getHeight() / 2, paint); + } + for (LatLon latLon : pressedLatLonFull) { + int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); canvas.drawBitmap(pressedBitmap, x - pressedBitmap.getWidth() / 2, y - pressedBitmap.getHeight() / 2, paint); } @@ -162,7 +166,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) { - Map selectedObjects = selectObjectsForContextMenu(tileBox, point); + Map selectedObjects = selectObjectsForContextMenu(tileBox, point, false); if (selectedObjects.size() == 1) { Object selectedObj = selectedObjects.keySet().iterator().next(); IContextMenuProvider contextObject = selectedObjects.get(selectedObj); @@ -229,7 +233,10 @@ public class ContextMenuLayer extends OsmandMapLayer { return res; } - private Map selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point) { + private Map selectObjectsForContextMenu(RotatedTileBox tileBox, + PointF point, boolean acquireObjLatLon) { + List pressedLatLonFull = new ArrayList<>(); + List pressedLatLonSmall = new ArrayList<>(); Map selectedObjects = new HashMap<>(); List s = new ArrayList<>(); for (OsmandMapLayer lt : view.getLayers()) { @@ -239,9 +246,21 @@ public class ContextMenuLayer extends OsmandMapLayer { l.collectObjectsFromPoint(point, tileBox, s); for (Object o : s) { selectedObjects.put(o, l); + if (acquireObjLatLon && l.isObjectClickable(o)) { + LatLon latLon = l.getObjectLocation(o); + if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.contains(latLon)) { + pressedLatLonFull.add(latLon); + } else if (lt.isPresentInSmallObjects(latLon) && !pressedLatLonSmall.contains(latLon)) { + pressedLatLonSmall.add(latLon); + } + } } } } + if (acquireObjLatLon) { + this.pressedLatLonFull = pressedLatLonFull; + this.pressedLatLonSmall = pressedLatLonSmall; + } return selectedObjects; } @@ -316,29 +335,15 @@ public class ContextMenuLayer extends OsmandMapLayer { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: - PointF point = new PointF(event.getX(), event.getY()); - Map selectedObjects = selectObjectsForContextMenu(tileBox, point); - if (selectedObjects.size() == 1) { - Object selectedObj = selectedObjects.keySet().iterator().next(); - IContextMenuProvider contextObject = selectedObjects.get(selectedObj); - LatLon latLon = null; - PointDescription pointDescription = null; - if (contextObject != null) { - latLon = contextObject.getObjectLocation(selectedObj); - pointDescription = contextObject.getObjectName(selectedObj); - } - if (latLon == null) { - latLon = getLatLon(point, tileBox); - } - if (isObjectClickable(selectedObj, pointDescription)) { - pressedLatLon = latLon; - view.refreshMap(); - } + selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true); + if (pressedLatLonFull.size() > 0 || pressedLatLonSmall.size() > 0) { + view.refreshMap(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: - pressedLatLon = null; + pressedLatLonFull.clear(); + pressedLatLonSmall.clear(); view.refreshMap(); break; } @@ -346,30 +351,6 @@ public class ContextMenuLayer extends OsmandMapLayer { return false; } - private boolean isObjectClickable(Object object, PointDescription pointDescription) { - boolean res; - if (pointDescription != null) { - res = pointDescription.isParking() - || pointDescription.isFavorite() - || pointDescription.isAudioNote() - || pointDescription.isPhotoNote() - || pointDescription.isVideoNote() - || pointDescription.isPoi() - || object instanceof OsmPoint - || object instanceof FavouritePoint - || object instanceof OsMoDevice - || object instanceof OpenStreetNote; - } else { - res = object instanceof Amenity - || object instanceof Recording - || object instanceof OsmPoint - || object instanceof FavouritePoint - || object instanceof OsMoDevice - || object instanceof OpenStreetNote; - } - return res; - } - private class MenuLayerOnGestureListener extends GestureDetector.SimpleOnGestureListener { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index a0ab291bbe..801f824506 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -2,7 +2,6 @@ package net.osmand.plus.views; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Cap; import android.graphics.Paint.Join; @@ -495,6 +494,11 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List dataObjects) { int zoom = tb.getZoom(); if (zoom >= ZOOM_TO_SHOW_SELECTION_ST && zoom < ZOOM_TO_SHOW_SELECTION diff --git a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java index 9ccef9ada3..47ba5b353d 100644 --- a/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/FavoritesLayer.java @@ -101,6 +101,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. // request to load final QuadRect latLonBounds = tileBox.getLatLonBounds(); List fullObjects = new ArrayList<>(); + List fullObjectsLatLon = new ArrayList<>(); + List smallObjectsLatLon = new ArrayList<>(); for (LocationPoint o : getPoints()) { if (!o.isVisible()) { continue; @@ -112,13 +114,17 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor(); paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY)); canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); + smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } else { fullObjects.add(o); + fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); } } for (LocationPoint o : fullObjects) { drawPoint(canvas, tileBox, latLonBounds, o); } + this.fullObjectsLatLon = fullObjectsLatLon; + this.smallObjectsLatLon = smallObjectsLatLon; } } if(textLayer.isVisible()) { @@ -196,6 +202,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer. return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof LocationPoint; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List res) { if (this.settings.SHOW_FAVORITES.get() && tileBox.getZoom() >= startZoom) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 2d571d1a3f..6366f6b7c4 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -13,7 +13,6 @@ import android.graphics.PointF; import android.graphics.PorterDuff; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; -import android.support.annotation.NonNull; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -286,6 +285,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex for (SelectedGpxFile g : selectedGPXFiles) { List pts = getListStarPoints(g); List fullObjects = new ArrayList<>(); + List fullObjectsLatLon = new ArrayList<>(); + List smallObjectsLatLon = new ArrayList<>(); int fcolor = g.getColor() == 0 ? defPointColor : g.getColor(); for (WptPt o : pts) { if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top @@ -299,8 +300,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex int col = visit ? visitedColor : o.getColor(fcolor); paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY)); canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); + smallObjectsLatLon.add(new LatLon(o.lat, o.lon)); } else { fullObjects.add(o); + fullObjectsLatLon.add(new LatLon(o.lat, o.lon)); } } } @@ -312,6 +315,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true); fid.drawBitmapInCenter(canvas, x, y); } + this.fullObjectsLatLon = fullObjectsLatLon; + this.smallObjectsLatLon = smallObjectsLatLon; } } } @@ -470,6 +475,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex return false; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof WptPt; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List res) { getWptFromPoint(tileBox, point, res); diff --git a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java index 2f95b0dbfc..63278b6ef6 100644 --- a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java @@ -10,7 +10,6 @@ import android.widget.ArrayAdapter; import net.osmand.Location; import net.osmand.binary.RouteDataObject; import net.osmand.data.LatLon; -import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; @@ -111,6 +110,11 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuL return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { int ex = (int) point.x; diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index af41f07410..10256c8e5d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -385,6 +385,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper(); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index ef89f75c05..2ca444ef8c 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -1,10 +1,11 @@ package net.osmand.plus.views; -import gnu.trove.list.array.TIntArrayList; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import android.graphics.Canvas; +import android.graphics.Path; +import android.graphics.PointF; +import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.view.MotionEvent; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; @@ -12,52 +13,73 @@ import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ContextMenuAdapter; import net.osmand.util.MapAlgorithms; -import android.graphics.Canvas; -import android.graphics.Path; -import android.graphics.PointF; -import android.os.AsyncTask; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.view.MotionEvent; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import gnu.trove.list.array.TIntArrayList; public abstract class OsmandMapLayer { - - + + protected List fullObjectsLatLon; + protected List smallObjectsLatLon; + public abstract void initLayer(OsmandMapTileView view); - + public abstract void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings); public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { } - - public abstract void destroyLayer(); - - public void onRetainNonConfigurationInstance(Map map) {} - public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) {} + public abstract void destroyLayer(); + + public void onRetainNonConfigurationInstance(Map map) { + } + + public void populateObjectContextMenu(LatLon latLon, Object o, ContextMenuAdapter adapter) { + } public boolean onSingleTap(PointF point, RotatedTileBox tileBox) { return false; } - + public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) { return false; } - - public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { return false;} - - public void executeTaskInBackground(AsyncTask task, Params... params){ + + public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) { + return false; + } + + public void executeTaskInBackground(AsyncTask task, Params... params) { task.execute(params); } - + + public boolean isPresentInFullObjects(LatLon latLon) { + if (fullObjectsLatLon == null) { + return true; + } else if (latLon != null) { + return fullObjectsLatLon.contains(latLon); + } + return false; + } + + public boolean isPresentInSmallObjects(LatLon latLon) { + if (smallObjectsLatLon != null && latLon != null) { + return smallObjectsLatLon.contains(latLon); + } + return false; + } + /** - * This method returns whether canvas should be rotated as + * This method returns whether canvas should be rotated as * map rotated before {@link #onDraw(android.graphics.Canvas, net.osmand.data.RotatedTileBox, net.osmand.plus.views.OsmandMapLayer.DrawSettings)}. * If the layer draws simply layer over screen (not over map) * it should return true. */ public abstract boolean drawInScreenPixels(); - + public static class DrawSettings { private final boolean nightMode; private final boolean updateVectorRendering; @@ -70,23 +92,23 @@ public abstract class OsmandMapLayer { this.nightMode = nightMode; this.updateVectorRendering = updateVectorRendering; } - + public boolean isUpdateVectorRendering() { return updateVectorRendering; } - + public boolean isNightMode() { return nightMode; } } - - + + private boolean isIn(int x, int y, int lx, int ty, int rx, int by) { return x >= lx && x <= rx && y >= ty && y <= by; } - + public int calculateSplitPaths(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, - TIntArrayList results) { + TIntArrayList results) { int px = xs.get(0); int py = ys.get(0); int h = tb.getPixHeight(); @@ -94,12 +116,12 @@ public abstract class OsmandMapLayer { int cnt = 0; boolean pin = isIn(px, py, 0, 0, w, h); Path path = null; - for(int i = 1; i < xs.size(); i++) { + for (int i = 1; i < xs.size(); i++) { int x = xs.get(i); int y = ys.get(i); boolean in = isIn(x, y, 0, 0, w, h); boolean draw = false; - if(pin && in) { + if (pin && in) { draw = true; } else { long intersection = MapAlgorithms.calculateIntersection(x, y, @@ -121,7 +143,7 @@ public abstract class OsmandMapLayer { } return cnt; } - + public int calculatePath(RotatedTileBox tb, TIntArrayList xs, TIntArrayList ys, Path path) { boolean start = false; int px = xs.get(0); @@ -130,12 +152,12 @@ public abstract class OsmandMapLayer { int w = tb.getPixWidth(); int cnt = 0; boolean pin = isIn(px, py, 0, 0, w, h); - for(int i = 1; i < xs.size(); i++) { + for (int i = 1; i < xs.size(); i++) { int x = xs.get(i); int y = ys.get(i); boolean in = isIn(x, y, 0, 0, w, h); boolean draw = false; - if(pin && in) { + if (pin && in) { draw = true; } else { long intersection = MapAlgorithms.calculateIntersection(x, y, @@ -153,7 +175,7 @@ public abstract class OsmandMapLayer { } path.lineTo(x, y); start = true; - } else{ + } else { start = false; } pin = in; @@ -166,7 +188,7 @@ public abstract class OsmandMapLayer { @NonNull public QuadTree initBoundIntersections(RotatedTileBox tileBox) { QuadRect bounds = new QuadRect(0, 0, tileBox.getPixWidth(), tileBox.getPixHeight()); - bounds.inset(-bounds.width()/4, -bounds.height()/4); + bounds.inset(-bounds.width() / 4, -bounds.height() / 4); return new QuadTree<>(bounds, 4, 0.6f); } @@ -200,23 +222,23 @@ public abstract class OsmandMapLayer { protected T results; protected Task currentTask; protected Task pendingTask; - + public RotatedTileBox getQueriedBox() { return queriedBox; } - + public T getResults() { return results; } - + public boolean queriedBoxContains(final RotatedTileBox queriedData, final RotatedTileBox newBox) { return queriedData != null && queriedData.containsTileBox(newBox) && Math.abs(queriedData.getZoom() - newBox.getZoom()) <= ZOOM_THRESHOLD; } - + public void queryNewData(RotatedTileBox tileBox) { - if (!queriedBoxContains(queriedBox, tileBox) ) { + if (!queriedBoxContains(queriedBox, tileBox)) { Task ct = currentTask; - if(ct == null || !queriedBoxContains(ct.getDataBox(), tileBox)) { + if (ct == null || !queriedBoxContains(ct.getDataBox(), tileBox)) { RotatedTileBox original = tileBox.copy(); RotatedTileBox extended = original.copy(); extended.increasePixelDimensions(tileBox.getPixWidth() / 2, tileBox.getPixHeight() / 2); @@ -225,41 +247,41 @@ public abstract class OsmandMapLayer { executeTaskInBackground(task); } else { pendingTask = task; - } + } } - + } } - + public void layerOnPostExecute() { } - + public boolean isInterrupted() { return pendingTask != null; } - + protected abstract T calculateResult(RotatedTileBox tileBox); - + public class Task extends AsyncTask { private RotatedTileBox dataBox; private RotatedTileBox requestedBox; - + public Task(RotatedTileBox requestedBox, RotatedTileBox dataBox) { this.requestedBox = requestedBox; this.dataBox = dataBox; } - + public RotatedTileBox getOriginalBox() { return requestedBox; } - + public RotatedTileBox getDataBox() { return dataBox; } - + @Override protected T doInBackground(Object... params) { - if (queriedBoxContains(queriedBox, dataBox) ) { + if (queriedBoxContains(queriedBox, dataBox)) { return null; } return calculateResult(dataBox); @@ -289,9 +311,9 @@ public abstract class OsmandMapLayer { public void clearCache() { results = null; queriedBox = null; - + } - + } } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 0d84fbfb30..31ff74134e 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -232,6 +232,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon List objects = Collections.emptyList(); List fullObjects = new ArrayList<>(); + List fullObjectsLatLon = new ArrayList<>(); + List smallObjectsLatLon = new ArrayList<>(); if (filter != null) { if (tileBox.getZoom() >= startZoom) { data.queryNewData(tileBox); @@ -248,8 +250,12 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon if (intersects(boundIntersections, x, y, iconSize, iconSize)) { canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground); + smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), + o.getLocation().getLongitude())); } else { fullObjects.add(o); + fullObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), + o.getLocation().getLongitude())); } } for (Amenity o : fullObjects) { @@ -274,6 +280,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } } } + this.fullObjectsLatLon = fullObjectsLatLon; + this.smallObjectsLatLon = smallObjectsLatLon; } } } @@ -510,6 +518,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon return null; } + @Override + public boolean isObjectClickable(Object o) { + return o instanceof Amenity; + } + @Override public LatLon getTextLocation(Amenity o) { return o.getLocation(); diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index b85e625df5..6213054f96 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -194,6 +194,11 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + private LatLon getMyLocation() { Location location = locationProvider.getLastKnownLocation(); if (location != null) { diff --git a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java index 849348f046..8eafc1e8d8 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointNavigationLayer.java @@ -172,7 +172,12 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu public boolean disableLongPressOnMap() { return false; } - + + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper(); diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 11aad6309c..6f162c6193 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -198,6 +198,11 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa return false; } + @Override + public boolean isObjectClickable(Object o) { + return false; + } + @Override public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List res) { getFromPoint(tileBox, point, res);