From 30304cf11abd64b349e495b0159100fecca8fd9e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 29 Jul 2016 18:53:31 +0200 Subject: [PATCH] update context menu --- .../src/net/osmand/data/PointDescription.java | 1 + .../plus/mapcontextmenu/MapContextMenu.java | 3 ++ .../plus/mapcontextmenu/MenuController.java | 4 +++ .../controllers/TransportRouteController.java | 31 +++++++++++++++++-- .../net/osmand/plus/views/OsmandMapLayer.java | 12 +++++-- .../plus/views/TransportStopsLayer.java | 2 +- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 51a1adb858..49dc0d365a 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -40,6 +40,7 @@ public class PointDescription { public static final String POINT_TYPE_WORLD_REGION_SHOW_ON_MAP = "world_region_show_on_map"; public static final String POINT_TYPE_BLOCKED_ROAD = "blocked_road"; public static final String POINT_TYPE_TRANSPORT_ROUTE = "transport_route"; + public static final String POINT_TYPE_TRANSPORT_STOP = "transport_stop"; public static final PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index c3fbae0e6c..43f57e6fc3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -357,6 +357,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL mapActivity.getMapView().setMapPosition(mapPosition); mapPosition = 0; } + if(getMenuController() != null) { + getMenuController().onHide(); + } WeakReference fragmentRef = findMenuFragment(); if (fragmentRef != null) { fragmentRef.get().dismissMenu(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index bdae78162f..06015fdad6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -340,4 +340,8 @@ public abstract class MenuController extends BaseMenuController { public abstract void buttonPressed(); } + + public void onHide() { + + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index a9f63e70a1..dc64b0ce9a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -2,15 +2,19 @@ package net.osmand.plus.mapcontextmenu.controllers; import java.util.List; +import android.view.View; +import android.view.View.OnClickListener; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.TransportStop; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; +import net.osmand.plus.views.TransportStopsLayer; public class TransportRouteController extends MenuController { @@ -70,17 +74,38 @@ public class TransportRouteController extends MenuController { public String getTypeStr() { return getPointDescription().getTypeName(); } + + @Override + public void onHide() { + super.onHide(); + MapContextMenu mm = getMapActivity().getContextMenu(); + TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); + stopsLayer.setRoute(null); + } @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { super.addPlainMenuItems(typeStr, pointDescription, latLon); List stops = transportStop.route.getForwardStops(); boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames(); - for (TransportStop stop : stops) { + for (final TransportStop stop : stops) { + final String name = useEnglishNames ? stop.getEnName(true) : stop.getName(); addPlainMenuItem( stop == transportStop.stop ? R.drawable.ic_action_marker_dark : (transportStop.type == null ? R.drawable.mx_route_bus_ref : transportStop.type.getResourceId()), - useEnglishNames ? stop.getEnName(true) : stop.getName(), false, false, null); + name , false, false, new OnClickListener() { + + @Override + public void onClick(View arg0) { + MapContextMenu mm = getMapActivity().getContextMenu(); + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP, + getMapActivity().getString(R.string.transport_Stop), + name); + TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); + stopsLayer.setRoute(null); + mm.show(latLon, pd, stop); + } + }); } } diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java index 1de62a314c..405bd0cdc2 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapLayer.java @@ -1,6 +1,7 @@ package net.osmand.plus.views; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; @@ -393,9 +394,7 @@ public abstract class OsmandMapLayer { rc.setDensityValue((float) tileBox.getMapDensity()); // cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR); renderer.updatePaint(req, paint, 0, false, rc); - if(paint.getColor() == 0 && defaultColor != 0) { - paint.setColor(defaultColor); - } + updateDefaultColor(paint, defaultColor); if (paint.getStrokeWidth() == 0 && defaultWidth != 0) { paint.setStrokeWidth(defaultWidth); } @@ -428,6 +427,13 @@ public abstract class OsmandMapLayer { } return false; } + + + private void updateDefaultColor(Paint paint, int defaultColor) { + if((paint.getColor() == 0 || paint.getColor() == Color.BLACK) && defaultColor != 0) { + paint.setColor(defaultColor); + } + } private int calculateHash(Object... o) { return Arrays.hashCode(o); diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index cb0432a330..57b24f2ad2 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -232,7 +232,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa @Override public PointDescription getObjectName(Object o) { if(o instanceof TransportStop){ - return new PointDescription(PointDescription.POINT_TYPE_POI, view.getContext().getString(R.string.transport_Stop), + return new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP, view.getContext().getString(R.string.transport_Stop), ((TransportStop)o).getName()); } return null;