From 35f2361a3306407d3839977c0e43ea268b5f307f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 13 Dec 2017 16:50:33 +0200 Subject: [PATCH 1/4] Open the combined context menu for marker which was added on map object --- .../src/net/osmand/plus/MapMarkersHelper.java | 24 ++++++++-- .../plus/activities/MapActivityActions.java | 5 ++- .../plus/mapcontextmenu/MapContextMenu.java | 2 +- .../controllers/AmenityMenuController.java | 14 ++++++ .../mapmarkers/MapMarkersActiveFragment.java | 14 +++++- .../plus/mapmarkers/MapMarkersDbHelper.java | 18 +++++--- .../quickaction/actions/MarkerAction.java | 3 +- .../osmand/plus/views/ContextMenuLayer.java | 45 +------------------ .../osmand/plus/views/MapMarkersLayer.java | 14 +++++- .../net/osmand/plus/views/OsmandMapLayer.java | 45 ++++++++++++++++++- 10 files changed, 123 insertions(+), 61 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 6b27448356..5e45d9fe92 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -76,6 +76,7 @@ public class MapMarkersHelper { public String groupName; public WptPt wptPt; public FavouritePoint favouritePoint; + public String mapObjectName; public MapMarker(LatLon point, PointDescription name, int colorIndex, boolean selected, int index) { @@ -597,6 +598,16 @@ public class MapMarkersHelper { return null; } + @Nullable + public MapMarker getMapMarker(@NonNull String mapObjectName) { + for (MapMarker marker : mapMarkers) { + if (marker.mapObjectName != null && marker.mapObjectName.equals(mapObjectName)) { + return marker; + } + } + return null; + } + private void addNewMarkerIfNeeded(@NonNull MarkersSyncGroup group, @NonNull List markers, @NonNull LatLon latLon, @@ -628,7 +639,7 @@ public class MapMarkersHelper { if (!exists) { addMarkers(Collections.singletonList(latLon), Collections.singletonList(new PointDescription(POINT_TYPE_MAP_MARKER, name)), - group, enabled, Collections.singletonList(favouritePoint), Collections.singletonList(wptPt)); + group, enabled, Collections.singletonList(favouritePoint), Collections.singletonList(wptPt), null); } } @@ -936,16 +947,21 @@ public class MapMarkersHelper { addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, true); } + public void addMapMarker(@NonNull LatLon point, @Nullable PointDescription historyName, @Nullable String mapObjectName) { + addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null, + true, null, null, Collections.singletonList(mapObjectName)); + } + public void addMapMarkers(@NonNull List points, @NonNull List historyNames, @Nullable MarkersSyncGroup group) { addMarkers(points, historyNames, group, true); } private void addMarkers(@NonNull List points, @NonNull List historyNames, @Nullable MarkersSyncGroup group, boolean enabled) { - addMarkers(points, historyNames, group, enabled, null, null); + addMarkers(points, historyNames, group, enabled, null, null, null); } private void addMarkers(@NonNull List points, @NonNull List historyNames, @Nullable MarkersSyncGroup group, - boolean enabled, @Nullable List favouritePoints, @Nullable List wptPts) { + boolean enabled, @Nullable List favouritePoints, @Nullable List wptPts, @Nullable List mapObjNames) { if (points.size() > 0) { int colorIndex = -1; List addedMarkers = new ArrayList<>(); @@ -954,6 +970,7 @@ public class MapMarkersHelper { PointDescription historyName = historyNames.get(i); FavouritePoint favouritePoint = favouritePoints == null ? null : favouritePoints.get(i); WptPt wptPt = wptPts == null ? null : wptPts.get(i); + String mapObjName = mapObjNames == null ? null : mapObjNames.get(i); final PointDescription pointDescription; if (historyName == null) { pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, ""); @@ -986,6 +1003,7 @@ public class MapMarkersHelper { marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE; marker.favouritePoint = favouritePoint; marker.wptPt = wptPt; + marker.mapObjectName = mapObjName; markersDbHelper.addMarker(marker); if (enabled) { addToMapMarkersList(0, marker); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index aed969a25e..ab56118d2c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -6,6 +6,7 @@ import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; import android.view.View; @@ -104,9 +105,9 @@ public class MapActivityActions implements DialogProvider { } - public void addMapMarker(double latitude, double longitude, PointDescription pd) { + public void addMapMarker(double latitude, double longitude, PointDescription pd, @Nullable String mapObjectName) { MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper(); - markersHelper.addMapMarker(new LatLon(latitude, longitude), pd); + markersHelper.addMapMarker(new LatLon(latitude, longitude), pd, mapObjectName); } public void editWaypoints() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 68b1b93c9d..0d7236c23a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -789,7 +789,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL MapMarkersDialogFragment.showInstance(mapActivity); } else { mapActivity.getMapActions().addMapMarker(latLon.getLatitude(), latLon.getLongitude(), - getPointDescriptionForMarker()); + getPointDescriptionForMarker(), object instanceof Amenity ? ((Amenity) object).getName() : null); } } else { mapActivity.getMapActions().addAsTarget(latLon.getLatitude(), latLon.getLongitude(), diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index dcbacd66df..9a4e83c729 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -11,6 +11,7 @@ import net.osmand.data.TransportStop; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; +import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -53,6 +54,14 @@ public class AmenityMenuController extends MenuController { processTransportStop(); } } + + final MapMarker marker = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()); + if (marker != null) { + MapMarkerMenuController markerMenuController = + new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); + leftTitleButtonController = markerMenuController.getLeftTitleButtonController(); + leftSubtitleButtonController = markerMenuController.getLeftSubtitleButtonController(); + } } @Override @@ -67,6 +76,11 @@ public class AmenityMenuController extends MenuController { return amenity; } + @Override + public boolean isWaypointButtonEnabled() { + return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()) == null; + } + @Override public boolean needStreetName() { if (amenity.getSubType() != null && amenity.getType() != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 867700c77c..d2e2181ddc 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -13,6 +13,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import net.osmand.Location; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -32,6 +33,8 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.widgets.EmptyStateRecyclerView; import net.osmand.util.MapUtils; +import java.util.Collections; + public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { private MapMarkersActiveAdapter adapter; @@ -78,8 +81,15 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, favouritePoint.getName()); objectToShow = favouritePoint; } else { - pointDescription = marker.getPointDescription(mapActivity); - objectToShow = marker; + Amenity mapObj = null; + if (marker.mapObjectName != null && marker.point != null) { + mapObj = mapActivity.getMapLayers().getMapMarkersLayer() + .findAmenity(mapActivity.getMyApplication(), -1, Collections.singletonList(marker.mapObjectName), marker.point); + } + pointDescription = mapObj == null + ? marker.getPointDescription(mapActivity) + : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj); + objectToShow = mapObj == null ? marker : mapObj; } mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), 15, pointDescription, true, objectToShow); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java index 3cab3d6b15..556bf4148e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDbHelper.java @@ -25,7 +25,7 @@ import java.util.Set; public class MapMarkersDbHelper { - private static final int DB_VERSION = 11; + private static final int DB_VERSION = 12; public static final String DB_NAME = "map_markers_db"; private static final String MARKERS_TABLE_NAME = "map_markers"; @@ -42,6 +42,7 @@ public class MapMarkersDbHelper { private static final String MARKERS_COL_NEXT_KEY = "marker_next_key"; private static final String MARKERS_COL_DISABLED = "marker_disabled"; private static final String MARKERS_COL_SELECTED = "marker_selected"; + private static final String MARKERS_COL_MAP_OBJECT_NAME = "marker_map_object_name"; private static final String MARKERS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + MARKERS_TABLE_NAME + " (" + @@ -57,7 +58,8 @@ public class MapMarkersDbHelper { MARKERS_COL_COLOR + " int, " + MARKERS_COL_NEXT_KEY + " TEXT, " + MARKERS_COL_DISABLED + " int, " + // 1 = true, 0 = false - MARKERS_COL_SELECTED + " int);"; // 1 = true, 0 = false + MARKERS_COL_SELECTED + " int, " + // 1 = true, 0 = false + MARKERS_COL_MAP_OBJECT_NAME + " TEXT);"; private static final String MARKERS_TABLE_SELECT = "SELECT " + MARKERS_COL_ID + ", " + @@ -72,7 +74,8 @@ public class MapMarkersDbHelper { MARKERS_COL_COLOR + ", " + MARKERS_COL_NEXT_KEY + ", " + MARKERS_COL_DISABLED + ", " + - MARKERS_COL_SELECTED + + MARKERS_COL_SELECTED + ", " + + MARKERS_COL_MAP_OBJECT_NAME + " FROM " + MARKERS_TABLE_NAME; private static final String GROUPS_TABLE_NAME = "map_markers_groups"; @@ -150,6 +153,9 @@ public class MapMarkersDbHelper { " SET " + MARKERS_COL_SELECTED + " = ? " + "WHERE " + MARKERS_COL_SELECTED + " IS NULL", new Object[]{0}); } + if (oldVersion < 12) { + db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT"); + } } private void saveExistingMarkersToDb() { @@ -365,10 +371,10 @@ public class MapMarkersDbHelper { "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); } - db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", + db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active, currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex, - marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0}); + marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE, 0, 0, marker.mapObjectName}); } public List getMarkersFromGroup(MarkersSyncGroup group) { @@ -445,6 +451,7 @@ public class MapMarkersDbHelper { int colorIndex = query.getInt(9); String nextKey = query.getString(10); boolean selected = query.getInt(12) == 1; + String mapObjectName = query.getString(13); LatLon latLon = new LatLon(lat, lon); MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), @@ -457,6 +464,7 @@ public class MapMarkersDbHelper { marker.groupKey = groupKey; marker.nextKey = nextKey; marker.selected = selected; + marker.mapObjectName = mapObjectName; return marker; } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java index 1a9488172a..64121971a0 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java @@ -40,7 +40,8 @@ public class MarkerAction extends QuickAction { activity.getMapActions().addMapMarker( latLon.getLatitude(), latLon.getLongitude(), - pointDescription); + pointDescription, + null); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index 7614f8d7fc..d56479c0b9 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -24,13 +24,10 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.NativeLibrary.RenderedObject; import net.osmand.RenderingContext; -import net.osmand.binary.BinaryMapIndexReader; import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; -import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.ContextMenuAdapter; @@ -627,7 +624,7 @@ public class ContextMenuLayer extends OsmandMapLayer { if (searchLatLon == null) { searchLatLon = tileBox.getLatLonFromPixel(point.x, point.y); } - Amenity amenity = findAmenity(renderedObject.getId() >> 7, names, searchLatLon); + Amenity amenity = findAmenity(activity.getMyApplication(), renderedObject.getId() >> 7, names, searchLatLon); if (amenity != null) { if (renderedObject.getX() != null && renderedObject.getX().size() > 1 && renderedObject.getY() != null && renderedObject.getY().size() > 1) { @@ -823,46 +820,6 @@ public class ContextMenuLayer extends OsmandMapLayer { return false; } - private Amenity findAmenity(long id, List names, LatLon latLon) { - QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 50); - List amenities = activity.getMyApplication().getResourceManager().searchAmenities( - new BinaryMapIndexReader.SearchPoiTypeFilter() { - @Override - public boolean accept(PoiCategory type, String subcategory) { - return true; - } - - @Override - public boolean isEmpty() { - return false; - } - }, rect.top, rect.left, rect.bottom, rect.right, -1, null); - - Amenity res = null; - for (Amenity amenity : amenities) { - Long amenityId = amenity.getId() >> 1; - if (amenityId == id) { - res = amenity; - break; - } - } - if (res == null && names != null && names.size() > 0) { - for (Amenity amenity : amenities) { - for (String name : names) { - if (name.equals(amenity.getName())) { - res = amenity; - break; - } - } - if (res != null) { - break; - } - } - } - - return res; - } - private boolean hideVisibleMenues() { if (multiSelectionMenu.isVisible()) { multiSelectionMenu.hide(); diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 38efc761ff..680255d434 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -21,6 +21,7 @@ import android.view.MotionEvent; import android.view.View; import net.osmand.Location; +import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; @@ -34,7 +35,6 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; @@ -43,6 +43,7 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.MapUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import gnu.trove.list.array.TIntArrayList; @@ -529,7 +530,16 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); if (calculateBelongs(ex, ey, x, y, r)) { - o.add(marker); + if (map.getMyApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) { + o.add(marker); + } else { + Amenity mapObj = null; + if (marker.mapObjectName != null && marker.point != null) { + mapObj = findAmenity(map.getMyApplication(), -1, + Collections.singletonList(marker.mapObjectName), marker.point); + } + o.add(mapObj == null ? marker : mapObj); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index bdbb19c4e8..46e1d76cd5 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -12,14 +12,16 @@ import android.graphics.PointF; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; import android.os.AsyncTask; -import android.os.Build; import android.support.annotation.NonNull; import android.view.MotionEvent; +import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.QuadTree; import net.osmand.data.RotatedTileBox; +import net.osmand.osm.PoiCategory; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; @@ -28,6 +30,7 @@ import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRulesStorage; import net.osmand.util.MapAlgorithms; +import net.osmand.util.MapUtils; import java.util.ArrayList; import java.util.Arrays; @@ -218,6 +221,46 @@ public abstract class OsmandMapLayer { return rf; } + public Amenity findAmenity(OsmandApplication app, long id, List names, LatLon latLon) { + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 50); + List amenities = app.getResourceManager().searchAmenities( + new BinaryMapIndexReader.SearchPoiTypeFilter() { + @Override + public boolean accept(PoiCategory type, String subcategory) { + return true; + } + + @Override + public boolean isEmpty() { + return false; + } + }, rect.top, rect.left, rect.bottom, rect.right, -1, null); + + Amenity res = null; + for (Amenity amenity : amenities) { + Long amenityId = amenity.getId() >> 1; + if (amenityId == id) { + res = amenity; + break; + } + } + if (res == null && names != null && names.size() > 0) { + for (Amenity amenity : amenities) { + for (String name : names) { + if (name.equals(amenity.getName())) { + res = amenity; + break; + } + } + if (res != null) { + break; + } + } + } + + return res; + } + public abstract class MapLayerData { public int ZOOM_THRESHOLD = 1; public RotatedTileBox queriedBox; From 75066e4a3b20600b974b8eae25f1097db5a88e4a Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 13 Dec 2017 17:31:41 +0200 Subject: [PATCH 2/4] Find marker by amenity name only once --- .../mapcontextmenu/controllers/AmenityMenuController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 9a4e83c729..1b4a2e5ce4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -36,6 +36,8 @@ public class AmenityMenuController extends MenuController { private Amenity amenity; private List routes = new ArrayList<>(); + private MapMarker marker; + public AmenityMenuController(MapActivity mapActivity, PointDescription pointDescription, Amenity amenity) { super(new AmenityMenuBuilder(mapActivity, amenity), pointDescription, mapActivity); this.amenity = amenity; @@ -55,7 +57,7 @@ public class AmenityMenuController extends MenuController { } } - final MapMarker marker = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()); + marker = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()); if (marker != null) { MapMarkerMenuController markerMenuController = new MapMarkerMenuController(mapActivity, marker.getPointDescription(mapActivity), marker); @@ -78,7 +80,7 @@ public class AmenityMenuController extends MenuController { @Override public boolean isWaypointButtonEnabled() { - return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(amenity.getName()) == null; + return marker == null; } @Override From 20ce59612a3032f906e70364ba1ea84b8873670e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 14 Dec 2017 17:24:52 +0200 Subject: [PATCH 3/4] Add an considering of the map object on which the marker stands --- .../net/osmand/plus/views/MapMarkersLayer.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index b75f9e0fb1..76ac2761dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -21,6 +21,7 @@ import android.view.MotionEvent; import android.view.View; import net.osmand.Location; +import net.osmand.data.Amenity; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadPoint; @@ -43,6 +44,7 @@ import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory; import net.osmand.util.MapUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import gnu.trove.list.array.TIntArrayList; @@ -518,14 +520,26 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi OsmandApplication app = map.getMyApplication(); int r = getRadiusPoi(tileBox); + boolean selectMarkerOnSingleTap = app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get(); + for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) { - if ((!unknownLocation && app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) || !isSynced(marker)) { + if ((!unknownLocation && selectMarkerOnSingleTap) || !isSynced(marker)) { LatLon latLon = marker.point; if (latLon != null) { int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); + if (calculateBelongs((int) point.x, (int) point.y, x, y, r)) { - o.add(marker); + if (!unknownLocation && selectMarkerOnSingleTap) { + o.add(marker); + } else { + Amenity mapObj = null; + if (marker.mapObjectName != null && marker.point != null) { + mapObj = findAmenity(map.getMyApplication(), -1, + Collections.singletonList(marker.mapObjectName), marker.point); + } + o.add(mapObj == null ? marker : mapObj); + } } } } From 6e63b644bd7defdbd165542efb3fd5170720c0e9 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 15 Dec 2017 13:40:10 +0200 Subject: [PATCH 4/4] Open combined context menu for marker which was added on waypoint or favorite --- .../net/osmand/plus/FavouritesDbHelper.java | 13 ++++ .../net/osmand/plus/GpxSelectionHelper.java | 17 +++++ .../src/net/osmand/plus/MapMarkersHelper.java | 10 +++ .../FavouritePointMenuController.java | 8 +- .../controllers/WptPtMenuController.java | 10 ++- .../mapmarkers/MapMarkersActiveFragment.java | 59 +++++++------- .../mapmarkers/MapMarkersGroupsFragment.java | 76 +++++++++++-------- .../osmand/plus/views/MapMarkersLayer.java | 23 +++++- 8 files changed, 149 insertions(+), 67 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 47635fa5f9..a4a71c4efa 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -1,10 +1,13 @@ package net.osmand.plus; import android.content.Context; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; +import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; @@ -451,6 +454,16 @@ public class FavouritesDbHelper { return fp; } + @Nullable + public FavouritePoint getVisibleFavByLatLon(@NonNull LatLon latLon) { + for (FavouritePoint fav : cachedFavoritePoints) { + if (fav.isVisible() && latLon.equals(new LatLon(fav.getLatitude(), fav.getLongitude()))) { + return fav; + } + } + return null; + } + public List getFavoriteGroups() { return favoriteGroups; diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 3225081c2f..3cf44fe0a8 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -3,10 +3,12 @@ package net.osmand.plus; import android.graphics.Bitmap; import android.graphics.Matrix; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import net.osmand.AndroidUtils; import net.osmand.IProgress; +import net.osmand.data.LatLon; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; @@ -389,6 +391,21 @@ public class GpxSelectionHelper { return null; } + @Nullable + public WptPt getVisibleWayPointByLatLon(@NonNull LatLon latLon) { + for (SelectedGpxFile selectedGpx : selectedGPXFiles) { + GPXFile gpx; + if (selectedGpx != null && (gpx = selectedGpx.getGpxFile()) != null) { + for (WptPt pt : gpx.getPoints()) { + if (latLon.equals(new LatLon(pt.getLatitude(), pt.getLongitude()))) { + return pt; + } + } + } + } + return null; + } + public void setGpxFileToDisplay(GPXFile... gpxs) { // special case for gpx current route for (GPXFile gpx : gpxs) { diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 5e45d9fe92..0d69166011 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -598,6 +598,16 @@ public class MapMarkersHelper { return null; } + @Nullable + public MapMarker getMapMarker(@NonNull LatLon latLon) { + for (MapMarker marker : mapMarkers) { + if (marker.point != null && marker.point.equals(latLon)) { + return marker; + } + } + return null; + } + @Nullable public MapMarker getMapMarker(@NonNull String mapObjectName) { for (MapMarker marker : mapMarkers) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index f9f16681ad..96dec7c05c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -22,13 +22,17 @@ import net.osmand.util.Algorithms; public class FavouritePointMenuController extends MenuController { private FavouritePoint fav; + private MapMarker mapMarker; public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) { super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity); this.fav = fav; final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); - final MapMarker mapMarker = markersHelper.getMapMarker(fav); + mapMarker = markersHelper.getMapMarker(fav); + if (mapMarker == null) { + mapMarker = markersHelper.getMapMarker(new LatLon(fav.getLatitude(), fav.getLongitude())); + } if (mapMarker != null) { MapMarkerMenuController markerMenuController = new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker); @@ -81,7 +85,7 @@ public class FavouritePointMenuController extends MenuController { @Override public boolean isWaypointButtonEnabled() { - return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(fav) == null; + return mapMarker == null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java index cf57c719e6..74c7fe2d44 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.MapMarkersHelper; @@ -17,14 +18,17 @@ import net.osmand.util.Algorithms; public class WptPtMenuController extends MenuController { private WptPt wpt; + private MapMarker mapMarker; public WptPtMenuController(MapActivity mapActivity, PointDescription pointDescription, WptPt wpt) { super(new WptPtMenuBuilder(mapActivity, wpt), pointDescription, mapActivity); this.wpt = wpt; final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper(); - final MapMarker mapMarker = markersHelper.getMapMarker(wpt); - + mapMarker = markersHelper.getMapMarker(wpt); + if (mapMarker == null) { + mapMarker = markersHelper.getMapMarker(new LatLon(wpt.lat, wpt.lon)); + } if (mapMarker != null) { MapMarkerMenuController markerMenuController = new MapMarkerMenuController(mapActivity, mapMarker.getPointDescription(mapActivity), mapMarker); @@ -84,7 +88,7 @@ public class WptPtMenuController extends MenuController { @Override public boolean isWaypointButtonEnabled() { - return getMapActivity().getMyApplication().getMapMarkersHelper().getMapMarker(wpt) == null; + return mapMarker == null; } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index d2e2181ddc..4f561ebdfe 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -33,8 +33,6 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.widgets.EmptyStateRecyclerView; import net.osmand.util.MapUtils; -import java.util.Collections; - public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { private MapMarkersActiveAdapter adapter; @@ -65,39 +63,44 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL if (pos == RecyclerView.NO_POSITION) { return; } + MapMarker marker = adapter.getItem(pos); - if (mapActivity.getMyApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) { - mapActivity.getMyApplication().getMapMarkersHelper().moveMarkerToTop(marker); + OsmandApplication app = mapActivity.getMyApplication(); + if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) { + app.getMapMarkersHelper().moveMarkerToTop(marker); updateAdapter(); } else { - WptPt wptPt = marker.wptPt; - FavouritePoint favouritePoint = marker.favouritePoint; - Object objectToShow; - PointDescription pointDescription; - if (wptPt != null) { - pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, wptPt.name); - objectToShow = wptPt; - } else if (favouritePoint != null) { - pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, favouritePoint.getName()); - objectToShow = favouritePoint; - } else { - Amenity mapObj = null; - if (marker.mapObjectName != null && marker.point != null) { - mapObj = mapActivity.getMapLayers().getMapMarkersLayer() - .findAmenity(mapActivity.getMyApplication(), -1, Collections.singletonList(marker.mapObjectName), marker.point); - } - pointDescription = mapObj == null - ? marker.getPointDescription(mapActivity) - : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj); - objectToShow = mapObj == null ? marker : mapObj; + FavouritePoint fav = marker.favouritePoint == null + ? app.getFavorites().getVisibleFavByLatLon(marker.point) + : marker.favouritePoint; + if (fav != null) { + showMap(marker.point, fav.getPointDescription(), fav); + return; } - mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), - 15, pointDescription, true, objectToShow); - MapActivity.launchMapActivityMoveToTop(mapActivity); - ((DialogFragment) getParentFragment()).dismiss(); + + WptPt pt = marker.wptPt == null + ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) + : marker.wptPt; + if (pt != null) { + showMap(marker.point, pt.getPointDescription(mapActivity), pt); + return; + } + + Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker); + PointDescription desc = mapObj == null + ? marker.getPointDescription(mapActivity) + : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj); + showMap(marker.point, desc, mapObj == null ? marker : mapObj); } } + private void showMap(LatLon latLon, PointDescription desc, Object objToShow) { + mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), + latLon.getLongitude(), 15, desc, true, objToShow); + MapActivity.launchMapActivityMoveToTop(mapActivity); + ((DialogFragment) getParentFragment()).dismiss(); + } + @Override public void onDragStarted(RecyclerView.ViewHolder holder) { compassUpdateAllowed = false; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index 9f23c3de6f..8e139ce0fb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -23,6 +23,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.Location; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -35,9 +36,9 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashLocationFragment; +import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener; import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder; import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter; -import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener; import net.osmand.plus.widgets.EmptyStateRecyclerView; import net.osmand.util.MapUtils; @@ -230,44 +231,59 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL Object item = adapter.getItem(pos); if (item instanceof MapMarker) { MapMarker marker = (MapMarker) item; + OsmandApplication app = mapActivity.getMyApplication(); if (!marker.history) { - if (mapActivity.getMyApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) { - mapActivity.getMyApplication().getMapMarkersHelper().moveMarkerToTop(marker); + if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) { + app.getMapMarkersHelper().moveMarkerToTop(marker); updateAdapter(); } else { - WptPt wptPt = marker.wptPt; - FavouritePoint favouritePoint = marker.favouritePoint; - Object objectToShow; - PointDescription pointDescription; - if (wptPt != null) { - pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, wptPt.name); - objectToShow = wptPt; - } else if (favouritePoint != null) { - pointDescription = new PointDescription(PointDescription.POINT_TYPE_FAVORITE, favouritePoint.getName()); - objectToShow = favouritePoint; - } else { - pointDescription = marker.getPointDescription(mapActivity); - objectToShow = marker; + FavouritePoint fav = marker.favouritePoint == null + ? app.getFavorites().getVisibleFavByLatLon(marker.point) + : marker.favouritePoint; + if (fav != null) { + showMap(marker.point, fav.getPointDescription(), fav); + return; } - mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), - 15, pointDescription, true, objectToShow); - MapActivity.launchMapActivityMoveToTop(mapActivity); - ((DialogFragment) getParentFragment()).dismiss(); + + WptPt pt = marker.wptPt == null + ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) + : marker.wptPt; + if (pt != null) { + showMap(marker.point, pt.getPointDescription(mapActivity), pt); + return; + } + + Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker); + PointDescription desc = mapObj == null + ? marker.getPointDescription(mapActivity) + : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj); + showMap(marker.point, desc, mapObj == null ? marker : mapObj); } } else { - HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); - fragment.setUsedOnMap(false); - Bundle arguments = new Bundle(); - arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos); - arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); - arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex); - arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate); - fragment.setArguments(arguments); - fragment.setListener(createHistoryMarkerMenuListener()); - fragment.show(getChildFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); + showHistoryMenuFragment(pos, marker); } } } + + private void showMap(LatLon latLon, PointDescription desc, Object objToShow) { + mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), + latLon.getLongitude(), 15, desc, true, objToShow); + MapActivity.launchMapActivityMoveToTop(mapActivity); + ((DialogFragment) getParentFragment()).dismiss(); + } + + private void showHistoryMenuFragment(int pos, MapMarker marker) { + HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); + Bundle arguments = new Bundle(); + arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos); + arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); + arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex); + arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate); + fragment.setArguments(arguments); + fragment.setListener(createHistoryMarkerMenuListener()); + fragment.show(getChildFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG); + } }); adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 76ac2761dc..34216fc1c2 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -533,11 +533,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi if (!unknownLocation && selectMarkerOnSingleTap) { o.add(marker); } else { - Amenity mapObj = null; - if (marker.mapObjectName != null && marker.point != null) { - mapObj = findAmenity(map.getMyApplication(), -1, - Collections.singletonList(marker.mapObjectName), marker.point); + if (isMarkerOnFavorite(marker) || isMarkerOnWaypoint(marker)) { + continue; } + Amenity mapObj = getMapObjectByMarker(marker); o.add(mapObj == null ? marker : mapObj); } } @@ -546,6 +545,22 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi } } + private boolean isMarkerOnWaypoint(@NonNull MapMarker marker) { + return marker.point != null && map.getMyApplication().getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) != null; + } + + private boolean isMarkerOnFavorite(@NonNull MapMarker marker) { + return marker.point != null && map.getMyApplication().getFavorites().getVisibleFavByLatLon(marker.point) != null; + } + + @Nullable + public Amenity getMapObjectByMarker(@NonNull MapMarker marker) { + if (marker.mapObjectName != null && marker.point != null) { + return findAmenity(map.getMyApplication(), -1, Collections.singletonList(marker.mapObjectName), marker.point); + } + return null; + } + private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { return Math.abs(objx - ex) <= radius && (ey - objy) <= radius && (objy - ey) <= 2.5 * radius; }