From b8f918f34ffb5107fd19ca3600f2986a7ef6f7c0 Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 11 Jan 2016 17:33:05 +0200 Subject: [PATCH] Impassable roads layer. Context menu implemented. --- OsmAnd/no_translate.xml | 1 + .../plus/mapcontextmenu/MenuController.java | 5 + .../ImpassibleRoadsMenuController.java | 52 ++++++++ .../plus/views/ImpassableRoadsLayer.java | 111 ++++++++++++++++-- 4 files changed, 159 insertions(+), 10 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java diff --git a/OsmAnd/no_translate.xml b/OsmAnd/no_translate.xml index 3df35b06c7..5cf221fd82 100644 --- a/OsmAnd/no_translate.xml +++ b/OsmAnd/no_translate.xml @@ -28,4 +28,5 @@ Value "You can remove downloaded updates and free " Add time span + Road blocked diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 9dada59369..49924b84f9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.LinearLayout; +import net.osmand.binary.RouteDataObject; import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -21,6 +22,7 @@ import net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController; import net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController; import net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController; +import net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController; import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController; import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController; @@ -105,6 +107,9 @@ public abstract class MenuController extends BaseMenuController { } else if (pointDescription.isMyLocation()) { menuController = new MyLocationMenuController(app, mapActivity, pointDescription); } + } else if (object instanceof RouteDataObject) { + menuController = new ImpassibleRoadsMenuController(app, mapActivity, + pointDescription, (RouteDataObject) object); } } if (menuController == null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java new file mode 100644 index 0000000000..f6a750ab53 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/ImpassibleRoadsMenuController.java @@ -0,0 +1,52 @@ +package net.osmand.plus.mapcontextmenu.controllers; + +import android.graphics.drawable.Drawable; + +import net.osmand.binary.RouteDataObject; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.routing.RoutingHelper; + +public class ImpassibleRoadsMenuController extends MenuController { + + private RouteDataObject route; + + public ImpassibleRoadsMenuController(final OsmandApplication app, final MapActivity mapActivity, + PointDescription pointDescription, RouteDataObject route) { + super(new MenuBuilder(app), pointDescription, mapActivity); + this.route = route; + rightTitleButtonController = new TitleButtonController() { + @Override + public void buttonPressed() { + app.getDefaultRoutingConfig().removeImpassableRoad( + ImpassibleRoadsMenuController.this.route); + RoutingHelper rh = app.getRoutingHelper(); + if (rh.isRouteCalculated() || rh.isRouteBeingCalculated()) { + rh.recalculateRouteDueToSettingsChange(); + } + getMapActivity().getContextMenu().close(); + } + }; + rightTitleButtonController.caption = getMapActivity().getString(R.string.shared_string_delete); + rightTitleButtonController.leftIconId = R.drawable.ic_action_delete_dark; + } + + @Override + protected void setObject(Object object) { + route = (RouteDataObject) object; + } + + @Override + public String getTypeStr() { + return getMapActivity().getString(R.string.road_blocked); + } + + @Override + public Drawable getLeftIcon() { + return getMapActivity().getResources().getDrawable(R.drawable.ic_action_road_works_dark); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java index aae75e9a8a..9ca99a0306 100644 --- a/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ImpassableRoadsLayer.java @@ -4,26 +4,32 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.PointF; import net.osmand.Location; +import net.osmand.binary.RouteDataObject; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmNotesPoint; +import net.osmand.plus.osmedit.OsmPoint; +import java.util.List; import java.util.Map; -/** - * Created by Denis on - * 20.03.2015. - */ -public class ImpassableRoadsLayer extends OsmandMapLayer { +public class ImpassableRoadsLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { private static final int startZoom = 10; private final MapActivity activity; private Bitmap roadWorkIcon; private OsmandMapTileView view; private Paint paint; - private Map missingRoads; + private Map missingRoadLocations; + private List missingRoads; public ImpassableRoadsLayer(MapActivity activity) { this.activity = activity; @@ -44,8 +50,8 @@ public class ImpassableRoadsLayer extends OsmandMapLayer { @Override public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) { if (tileBox.getZoom() >= startZoom) { - for (long id : getMissingRoads().keySet()) { - Location location = getMissingRoads().get(id); + for (long id : getMissingRoadLocations().keySet()) { + Location location = getMissingRoadLocations().get(id); float x = tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude()); float y = tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude()); float left = x - roadWorkIcon.getWidth() / 2; @@ -55,9 +61,16 @@ public class ImpassableRoadsLayer extends OsmandMapLayer { } } - public Map getMissingRoads() { + public Map getMissingRoadLocations() { + if(missingRoadLocations == null) { + missingRoadLocations = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations(); + } + return missingRoadLocations; + } + + public List getMissingRoads() { if(missingRoads == null) { - missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoadLocations(); + missingRoads = activity.getMyApplication().getDefaultRoutingConfig().getImpassableRoads(); } return missingRoads; } @@ -71,4 +84,82 @@ public class ImpassableRoadsLayer extends OsmandMapLayer { public boolean drawInScreenPixels() { return true; } + + public int getRadiusPoi(RotatedTileBox tb){ + int r = 0; + if(tb.getZoom() < startZoom){ + r = 0; + } else { + r = 15; + } + return (int) (r * tb.getDensity()); + } + + private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { + return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; + } + + @Override + public boolean disableSingleTap() { + return false; + } + + @Override + public boolean disableLongPressOnMap() { + return false; + } + + @Override + public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { + int ex = (int) point.x; + int ey = (int) point.y; + int compare = getRadiusPoi(tileBox); + int radius = compare * 3 / 2; + + for (RouteDataObject road : getMissingRoads()) { + Location location = getMissingRoadLocations().get(road.getId()); + int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude()); + int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude()); + if (calculateBelongs(ex, ey, x, y, compare)) { + compare = radius; + o.add(road); + } + } + } + + @Override + public LatLon getObjectLocation(Object o) { + if (o instanceof OsmPoint) { + return new LatLon(((OsmPoint)o).getLatitude(),((OsmPoint)o).getLongitude()); + } + return null; + } + + @Override + public String getObjectDescription(Object o) { + if(o instanceof OsmPoint) { + OsmPoint point = (OsmPoint) o; + return OsmEditingPlugin.getEditName(point); + } + return null; + } + + @Override + public PointDescription getObjectName(Object o) { + if(o instanceof OsmPoint) { + OsmPoint point = (OsmPoint) o; + String name = ""; + String type = ""; + if (point.getGroup() == OsmPoint.Group.POI){ + name = ((OpenstreetmapPoint) point).getName(); + type = PointDescription.POINT_TYPE_OSM_NOTE; + } else if (point.getGroup() == OsmPoint.Group.BUG) { + name = ((OsmNotesPoint) point).getText(); + type = PointDescription.POINT_TYPE_OSM_BUG; + } + return new PointDescription(type, name); + } + return null; + } + }