From be1e776d4ad627e02db87a05256c5c6a4e823d20 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 2 Nov 2015 16:57:12 +0300 Subject: [PATCH] Context menu: download from map in progress --- .../plus/mapcontextmenu/MapContextMenu.java | 6 +- .../WorldRegionMenuController.java | 4 - .../plus/views/DownloadedRegionsLayer.java | 121 ++++++++++++------ 3 files changed, 85 insertions(+), 46 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 4f0baee064..34ac9745a4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -104,9 +104,6 @@ public class MapContextMenu extends MenuTitleController { } } - if (this.object != null) { - clearSelectedObject(this.object); - } setSelectedObject(object); if (pointDescription == null) { @@ -171,6 +168,9 @@ public class MapContextMenu extends MenuTitleController { } public void hide() { + if (this.object != null) { + clearSelectedObject(this.object); + } if (mapPosition != 0) { mapActivity.getMapView().setMapPosition(mapPosition); mapPosition = 0; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java index 6baacc37b7..3bb0901597 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WorldRegionMenuController.java @@ -2,7 +2,6 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.content.Intent; import android.graphics.drawable.Drawable; -import android.util.Log; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -11,9 +10,6 @@ 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; diff --git a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java index b18be10b31..b43c998015 100644 --- a/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/DownloadedRegionsLayer.java @@ -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> data; - + private List 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>() { @Override @@ -117,25 +132,42 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen } // draw objects final List currentObjects = data.results; + final List 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); } } @@ -359,11 +391,22 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements ContextMen } } - if (result.size() > 0) { - String fullName = osmandRegions.getFullName(result.get(0)); + selectedObjects = result; + + for (BinaryMapDataObject o : result) { + String fullName = osmandRegions.getFullName(o); WorldRegion region = osmandRegions.getRegionData(fullName); regions.add(region); } } } + + @Override + public void setSelectedObject(Object o) { + } + + @Override + public void clearSelectedObject() { + //selectedObjects = null; + } }