Add parameter to collectObjectsFromPoint(); remove copy-paste for combined markers "one tap make active"

This commit is contained in:
Alexander Sytnyk 2017-12-14 15:44:49 +02:00
parent 5c5258ec36
commit b1961ac6a6
21 changed files with 33 additions and 93 deletions

View file

@ -136,7 +136,7 @@ public class MapActivityLayers {
mapView.addLayer(downloadedRegionsLayer, 0.5f);
// 0.9 gpx layer
gpxLayer = new GPXLayer(activity);
gpxLayer = new GPXLayer();
mapView.addLayer(gpxLayer, 0.9f);
// 1. route layer
@ -148,7 +148,7 @@ public class MapActivityLayers {
poiMapLayer = new POIMapLayer(activity);
mapView.addLayer(poiMapLayer, 3);
// 4. favorites layer
mFavouritesLayer = new FavouritesLayer(activity);
mFavouritesLayer = new FavouritesLayer();
mapView.addLayer(mFavouritesLayer, 4);
// 4.6 measurement tool layer
measurementToolLayer = new MeasurementToolLayer();

View file

@ -188,7 +188,7 @@ public class AudioNotesLayer extends OsmandMapLayer implements
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
getRecordingsFromPoint(point, tileBox, objects);
}

View file

@ -499,7 +499,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
public boolean onLongPressEvent(PointF point, RotatedTileBox tileBox) {
List<Object> s = new ArrayList<>();
collectObjectsFromPoint(point, tileBox, s);
collectObjectsFromPoint(point, tileBox, s, true);
if (s.size() == 0 && distanceMeasurementMode == 1 && measurementPoints.size() > 0) {
LinkedList<WptPt> lt = measurementPoints.get(measurementPoints.size() - 1);
@ -595,7 +595,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getMPointsFromPoint(tileBox, point, o);
}

View file

@ -313,7 +313,7 @@ class MapillaryVectorLayer extends MapTileLayer implements MapillaryLayer, ICont
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects, boolean unknownLocation) {
if (map != null && tileBox.getZoom() >= map.getMinimumZoomSupported()) {
getImagesFromPoint(tileBox, point, objects);
}

View file

@ -380,7 +380,7 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
}

View file

@ -518,7 +518,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
getBugFromPoint(tileBox, point, res);
}

View file

@ -166,7 +166,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
getOsmEditsFromPoint(point, tileBox, o);
}

View file

@ -218,7 +218,7 @@ public class OsMoPositionLayer extends OsmandMapLayer implements ContextMenuLaye
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getOsmoFromPoint(tileBox, point, o);
}

View file

@ -141,7 +141,7 @@ public class ParkingPositionLayer extends OsmandMapLayer implements
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getParkingFromPoint(tileBox, point, o);
}

View file

@ -48,7 +48,7 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
}

View file

@ -134,7 +134,7 @@ public class AidlMapLayer extends OsmandMapLayer implements IContextMenuProvider
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
getFromPoint(tileBox, point, o);
}

View file

@ -576,7 +576,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
LatLon objectLatLon = null;
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false, showUnknownLocation);
NativeOsmandLibrary nativeLib = NativeOsmandLibrary.getLoadedLibrary();
if (nativeLib != null) {
MapRenderRepositories maps = activity.getMyApplication().getResourceManager().getRenderer();
@ -731,7 +731,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox,
PointF point, boolean acquireObjLatLon) {
PointF point, boolean acquireObjLatLon,
boolean unknownLocation) {
List<LatLon> pressedLatLonFull = new ArrayList<>();
List<LatLon> pressedLatLonSmall = new ArrayList<>();
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
@ -740,7 +741,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
s.clear();
final IContextMenuProvider l = (ContextMenuLayer.IContextMenuProvider) lt;
l.collectObjectsFromPoint(point, tileBox, s);
l.collectObjectsFromPoint(point, tileBox, s, unknownLocation);
for (Object o : s) {
selectedObjects.put(o, l);
if (acquireObjLatLon && l.isObjectClickable(o)) {
@ -899,7 +900,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (!mInChangeMarkerPositionMode && !mInGpxDetailsMode) {
selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true);
selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true, true);
if (pressedLatLonFull.size() > 0 || pressedLatLonSmall.size() > 0) {
view.refreshMap();
}
@ -918,7 +919,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
public interface IContextMenuProvider {
void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o);
void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation);
LatLon getObjectLocation(Object o);

View file

@ -410,7 +410,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
// IContextMenuProvider
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects, boolean unknownLocation) {
boolean isMenuVisible = false;
if (view.getContext() instanceof MapActivity) {
MapActivity mapActivity = (MapActivity) view.getContext();

View file

@ -11,9 +11,7 @@ import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.View;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
@ -23,10 +21,8 @@ import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
@ -37,8 +33,6 @@ import java.util.List;
public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<FavouritePoint> {
private MapActivity mapActivity;
protected int startZoom = 6;
protected OsmandMapTileView view;
@ -63,10 +57,6 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return favorites.getFavouritePoints();
}
public FavouritesLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -234,30 +224,11 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
if (unknownLocation || o == null || !(o instanceof FavouritePoint)
|| !view.getApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
return false;
}
MapMarker marker = mapMarkersHelper.getMapMarker((FavouritePoint) o);
if (marker != null) {
final MapMarker old = mapMarkersHelper.getMapMarkers().get(0);
mapMarkersHelper.moveMarkerToTop(marker);
String title = mapActivity.getString(R.string.marker_activated, mapMarkersHelper.getMapMarkers().get(0).getName(mapActivity));
Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
mapMarkersHelper.moveMarkerToTop(old);
}
})
.show();
return true;
}
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
if (this.settings.SHOW_FAVORITES.get() && tileBox.getZoom() >= startZoom) {
getFavoriteFromPoint(tileBox, point, res);
}

View file

@ -18,9 +18,7 @@ import android.os.AsyncTask;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
@ -38,12 +36,10 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.CommonPreference;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints;
import net.osmand.plus.render.OsmandRenderer;
@ -63,7 +59,6 @@ import java.util.Map;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
private MapActivity mapActivity;
private OsmandMapTileView view;
private Paint paint;
@ -111,10 +106,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@ColorInt
private int defPointColor;
public GPXLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
@ -588,30 +579,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
@Override
public boolean runExclusiveAction(Object o, boolean unknownLocation) {
if (unknownLocation || o == null || !(o instanceof WptPt)
|| !view.getApplication().getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
return false;
}
MapMarker marker = mapMarkersHelper.getMapMarker((WptPt) o);
if (marker != null) {
final MapMarker old = mapMarkersHelper.getMapMarkers().get(0);
mapMarkersHelper.moveMarkerToTop(marker);
String title = mapActivity.getString(R.string.marker_activated, mapMarkersHelper.getMapMarkers().get(0).getName(mapActivity));
Snackbar.make(mapActivity.findViewById(R.id.bottomFragmentContainer), title, Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_cancel, new View.OnClickListener() {
@Override
public void onClick(View v) {
mapMarkersHelper.moveMarkerToTop(old);
}
})
.show();
return true;
}
return false;
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
getWptFromPoint(tileBox, point, res);
}

View file

@ -167,7 +167,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
int ex = (int) point.x;
int ey = (int) point.y;

View file

@ -30,11 +30,11 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
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;
@ -511,24 +511,20 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() < 3 || !map.getMyApplication().getSettings().USE_MAP_MARKERS.get()) {
return;
}
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
List<MapMarker> markers = markersHelper.getMapMarkers();
OsmandApplication app = map.getMyApplication();
int r = getRadiusPoi(tileBox);
for (int i = 0; i < markers.size(); i++) {
MapMarker marker = markers.get(i);
if (!isSynced(marker)) {
for (MapMarker marker : app.getMapMarkersHelper().getMapMarkers()) {
if ((!unknownLocation && app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) || !isSynced(marker)) {
LatLon latLon = marker.point;
if (latLon != null) {
int ex = (int) point.x;
int ey = (int) point.y;
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)) {
if (calculateBelongs((int) point.x, (int) point.y, x, y, r)) {
o.add(marker);
}
}

View file

@ -544,7 +544,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> objects, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
getAmenityFromPoint(tileBox, point, objects);
}

View file

@ -182,7 +182,7 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= 3) {
getMyLocationFromPoint(tileBox, point, o);
}

View file

@ -184,7 +184,7 @@ public class PointNavigationLayer extends OsmandMapLayer implements
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= 3) {
TargetPointsHelper tg = map.getMyApplication().getTargetPointsHelper();
List<TargetPoint> intermediatePoints = tg.getAllPoints();

View file

@ -285,7 +285,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
}
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res) {
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> res, boolean unknownLocation) {
if(tileBox.getZoom() >= startZoomRoute && route != null) {
getFromPoint(tileBox, point, res, route.getForwardStops());
} else if (tileBox.getZoom() >= startZoom && data.getResults() != null) {