Merge branch 'master' of https://github.com/osmandapp/Osmand
This commit is contained in:
commit
0e767ba406
5 changed files with 109 additions and 57 deletions
|
@ -104,9 +104,6 @@ public class MapContextMenu extends MenuTitleController {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.object != null) {
|
||||
clearSelectedObject(this.object);
|
||||
}
|
||||
setSelectedObject(object);
|
||||
|
||||
if (pointDescription == null) {
|
||||
|
@ -166,6 +163,9 @@ public class MapContextMenu extends MenuTitleController {
|
|||
|
||||
public void close() {
|
||||
active = false;
|
||||
if (this.object != null) {
|
||||
clearSelectedObject(this.object);
|
||||
}
|
||||
hide();
|
||||
mapActivity.getMapView().refreshMap();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu;
|
|||
import android.graphics.drawable.Drawable;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -25,7 +26,7 @@ import net.osmand.plus.mapcontextmenu.controllers.OsMoMenuController;
|
|||
import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.WorldRegionMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
|
||||
import net.osmand.plus.osmedit.OsmPoint;
|
||||
|
@ -111,8 +112,8 @@ public abstract class MenuController extends BaseMenuController {
|
|||
menuController = new EditPOIMenuController(app, mapActivity, pointDescription, (OsmPoint) object);
|
||||
} else if (object instanceof WptPt) {
|
||||
menuController = new WptPtMenuController(app, mapActivity, (WptPt) object);
|
||||
} else if (object instanceof WorldRegion) {
|
||||
menuController = new WorldRegionMenuController(app, mapActivity, (WorldRegion) object);
|
||||
} else if (object instanceof BinaryMapDataObject) {
|
||||
menuController = new MapDataMenuController(app, mapActivity, (BinaryMapDataObject) object);
|
||||
} else if (object instanceof LatLon) {
|
||||
if (pointDescription.isParking()) {
|
||||
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);
|
||||
|
|
|
@ -2,26 +2,27 @@ package net.osmand.plus.mapcontextmenu.controllers;
|
|||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.download.DownloadActivity;
|
||||
import net.osmand.plus.download.DownloadResourceGroup;
|
||||
import net.osmand.plus.download.DownloadResources;
|
||||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
|
||||
public class WorldRegionMenuController extends MenuController {
|
||||
public class MapDataMenuController extends MenuController {
|
||||
private WorldRegion region;
|
||||
|
||||
public WorldRegionMenuController(OsmandApplication app, MapActivity mapActivity, final WorldRegion region) {
|
||||
public MapDataMenuController(OsmandApplication app, MapActivity mapActivity, final BinaryMapDataObject dataObject) {
|
||||
super(new MenuBuilder(app), mapActivity);
|
||||
OsmandRegions osmandRegions = app.getRegions();
|
||||
String fullName = osmandRegions.getFullName(dataObject);
|
||||
final WorldRegion region = osmandRegions.getRegionData(fullName);
|
||||
this.region = region;
|
||||
titleButtonController = new TitleButtonController() {
|
||||
@Override
|
|
@ -155,13 +155,13 @@ public class ObjectSelectionMenu extends BaseMenuController {
|
|||
}
|
||||
|
||||
public void onDismiss() {
|
||||
clearSelectedObjects();
|
||||
}
|
||||
|
||||
public void openContextMenu(MenuObject menuObject) {
|
||||
if (selectedObjects.containsKey(menuObject.getObject())) {
|
||||
selectedObjects.remove(menuObject.getObject());
|
||||
}
|
||||
clearSelectedObjects();
|
||||
hide(getMapActivity());
|
||||
getMapActivity().getContextMenu()
|
||||
.show(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject());
|
||||
|
|
|
@ -1,24 +1,5 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
|
@ -32,13 +13,37 @@ import android.text.TextPaint;
|
|||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.binary.BinaryMapDataObject;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
|
||||
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMenuProvider, IContextMenuProviderSelection {
|
||||
|
||||
private static final int ZOOM_THRESHOLD = 2;
|
||||
|
||||
private OsmandMapTileView view;
|
||||
private Paint paint;
|
||||
private Paint paintSelected;
|
||||
private Path path;
|
||||
private Path pathSelected;
|
||||
private OsmandRegions osmandRegions;
|
||||
|
||||
|
||||
|
@ -46,7 +51,8 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
private ResourceManager rm;
|
||||
|
||||
private MapLayerData<List<BinaryMapDataObject>> data;
|
||||
|
||||
private List<BinaryMapDataObject> selectedObjects;
|
||||
|
||||
private static int ZOOM_TO_SHOW_MAP_NAMES = 6;
|
||||
private static int ZOOM_AFTER_BASEMAP = 12;
|
||||
|
||||
|
@ -64,6 +70,14 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
paint.setStrokeCap(Cap.ROUND);
|
||||
paint.setStrokeJoin(Join.ROUND);
|
||||
|
||||
paintSelected = new Paint();
|
||||
paintSelected.setStyle(Style.FILL_AND_STROKE);
|
||||
paintSelected.setStrokeWidth(1);
|
||||
paintSelected.setColor(Color.argb(100, 255, 143, 0));
|
||||
paintSelected.setAntiAlias(true);
|
||||
paintSelected.setStrokeCap(Cap.ROUND);
|
||||
paintSelected.setStrokeJoin(Join.ROUND);
|
||||
|
||||
textPaint = new TextPaint();
|
||||
final WindowManager wmgr = (WindowManager) view.getApplication().getSystemService(Context.WINDOW_SERVICE);
|
||||
DisplayMetrics dm = new DisplayMetrics();
|
||||
|
@ -73,6 +87,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
textPaint.setTextAlign(Paint.Align.CENTER);
|
||||
|
||||
path = new Path();
|
||||
pathSelected = new Path();
|
||||
data = new MapLayerData<List<BinaryMapDataObject>>() {
|
||||
|
||||
@Override
|
||||
|
@ -117,25 +132,42 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
}
|
||||
// draw objects
|
||||
final List<BinaryMapDataObject> currentObjects = data.results;
|
||||
final List<BinaryMapDataObject> selectedObjects = this.selectedObjects;
|
||||
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS && osmandRegions.isInitialized() &&
|
||||
currentObjects != null) {
|
||||
path.reset();
|
||||
for (BinaryMapDataObject o : currentObjects) {
|
||||
String downloadName = osmandRegions.getDownloadName(o);
|
||||
boolean downloaded = checkIfObjectDownloaded(downloadName);
|
||||
if (!downloaded) {
|
||||
continue;
|
||||
}
|
||||
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
|
||||
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
for (int j = 1; j < o.getPointsLength(); j++) {
|
||||
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
|
||||
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
|
||||
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
(currentObjects != null || selectedObjects != null)) {
|
||||
if (currentObjects != null) {
|
||||
path.reset();
|
||||
for (BinaryMapDataObject o : currentObjects) {
|
||||
String downloadName = osmandRegions.getDownloadName(o);
|
||||
boolean downloaded = checkIfObjectDownloaded(downloadName);
|
||||
if (!downloaded) {
|
||||
continue;
|
||||
}
|
||||
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
|
||||
path.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
for (int j = 1; j < o.getPointsLength(); j++) {
|
||||
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
|
||||
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
|
||||
path.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
}
|
||||
}
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
if (selectedObjects != null) {
|
||||
pathSelected.reset();
|
||||
for (BinaryMapDataObject o : selectedObjects) {
|
||||
double lat = MapUtils.get31LatitudeY(o.getPoint31YTile(0));
|
||||
double lon = MapUtils.get31LongitudeX(o.getPoint31XTile(0));
|
||||
pathSelected.moveTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
for (int j = 1; j < o.getPointsLength(); j++) {
|
||||
lat = MapUtils.get31LatitudeY(o.getPoint31YTile(j));
|
||||
lon = MapUtils.get31LongitudeX(o.getPoint31XTile(j));
|
||||
pathSelected.lineTo(tileBox.getPixXFromLonNoRot(lon), tileBox.getPixYFromLatNoRot(lat));
|
||||
}
|
||||
}
|
||||
canvas.drawPath(pathSelected, paintSelected);
|
||||
}
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -305,8 +337,12 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
|
||||
@Override
|
||||
public LatLon getObjectLocation(Object o) {
|
||||
if (o instanceof WorldRegion) {
|
||||
return ((WorldRegion) o).getRegionCenter();
|
||||
if (o instanceof BinaryMapDataObject) {
|
||||
String fullName = osmandRegions.getFullName((BinaryMapDataObject) o);
|
||||
final WorldRegion region = osmandRegions.getRegionData(fullName);
|
||||
if (region != null) {
|
||||
return region.getRegionCenter();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -332,7 +368,7 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
return false;
|
||||
}
|
||||
|
||||
private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super WorldRegion> regions) {
|
||||
private void getWorldRegionFromPoint(RotatedTileBox tb, PointF point, List<? super BinaryMapDataObject> dataObjects) {
|
||||
int zoom = tb.getZoom();
|
||||
if (zoom >= ZOOM_TO_SHOW_BORDERS_ST && zoom < ZOOM_TO_SHOW_BORDERS && osmandRegions.isInitialized()) {
|
||||
LatLon pointLatLon = tb.getLatLonFromPixel(point.x, point.y);
|
||||
|
@ -359,11 +395,25 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen
|
|||
}
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
String fullName = osmandRegions.getFullName(result.get(0));
|
||||
WorldRegion region = osmandRegions.getRegionData(fullName);
|
||||
regions.add(region);
|
||||
selectedObjects = result;
|
||||
|
||||
for (BinaryMapDataObject o : result) {
|
||||
dataObjects.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedObject(Object o) {
|
||||
if (o instanceof BinaryMapDataObject) {
|
||||
List<BinaryMapDataObject> list = new LinkedList<>();
|
||||
list.add((BinaryMapDataObject) o);
|
||||
selectedObjects = list;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSelectedObject() {
|
||||
selectedObjects = null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue