From 0bc0eb7cc93a85bd162a440b193b025c04211350 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 29 Jul 2016 17:24:41 +0200 Subject: [PATCH 1/2] Add transport route --- .../controllers/TransportRouteController.java | 75 +++++++++++++++++++ .../controllers/TransportStopController.java | 2 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java new file mode 100644 index 0000000000..336c4f71bd --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -0,0 +1,75 @@ +package net.osmand.plus.mapcontextmenu.controllers; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; +import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; + +public class TransportRouteController extends MenuController { + + private TransportStopRoute transportStop; + + public TransportRouteController(OsmandApplication app, MapActivity mapActivity, PointDescription pointDescription, + TransportStopRoute transportStop) { + super(new MenuBuilder(app), pointDescription, mapActivity); + this.transportStop = transportStop; + } + + @Override + protected void setObject(Object object) { + if (object instanceof TransportStopRoute) { + this.transportStop = (TransportStopRoute) object; + } + } + + @Override + protected int getSupportedMenuStatesPortrait() { + return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; + } + + @Override + public int getLeftIconId() { + return this.transportStop.type.getTopResourceId(); + } + + @Override + public boolean needStreetName() { + return false; + } + + @Override + public boolean displayDistanceDirection() { + return false; + } + + @Override + public boolean fabVisible() { + return false; + } + + @Override + public boolean displayStreetNameInTitle() { + return super.displayStreetNameInTitle(); + } + + @Override + public String getTypeStr() { + return getPointDescription().getTypeName(); + } + + @Override + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { +// for (TransportStopRoute r : routes) { +// if (r.type == null) { +// addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false); +// } else { +// addPlainMenuItem(r.type.getResourceId(), r.desc, false, false); +// } +// } + super.addPlainMenuItems(typeStr, pointDescription, latLon); + } + +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 094ab171f7..a5c1766bc9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -149,7 +149,7 @@ public class TransportStopController extends MenuController { } } - private class TransportStopRoute { + public static class TransportStopRoute { public TransportStopType type; public String desc; public TransportRoute route; From f7b682e2262be11433a149e3ebd0a3dd45a92802 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 29 Jul 2016 17:52:27 +0200 Subject: [PATCH 2/2] Add transport route --- .../src/net/osmand/data/PointDescription.java | 1 + .../plus/mapcontextmenu/MenuController.java | 5 +++- .../controllers/TransportRouteController.java | 23 +++++++++++++------ .../controllers/TransportStopController.java | 22 ++++++++++++++---- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 7966b592e0..51a1adb858 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -39,6 +39,7 @@ public class PointDescription { public static final String POINT_TYPE_GPX_ITEM = "gpx_item"; 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 PointDescription LOCATION_POINT = new PointDescription(POINT_TYPE_LOCATION, ""); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 0c7afb307b..bdae78162f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -4,7 +4,6 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; - import net.osmand.binary.RouteDataObject; import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; @@ -31,7 +30,9 @@ import net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController; import net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController; import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; +import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; +import net.osmand.plus.mapcontextmenu.controllers.TransportStopController.TransportStopRoute; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.osmedit.EditPOIMenuController; @@ -108,6 +109,8 @@ public abstract class MenuController extends BaseMenuController { menuController = new GpxItemMenuController(app, mapActivity, pointDescription, (GpxDisplayItem) object); } else if (object instanceof MapMarker) { menuController = new MapMarkerMenuController(app, mapActivity, pointDescription, (MapMarker) object); + } else if (object instanceof TransportStopRoute) { + menuController = new TransportRouteController(app, mapActivity, pointDescription, (TransportStopRoute) object); } else if (object instanceof TransportStop) { menuController = new TransportStopController(app, mapActivity, pointDescription, (TransportStop) object); } else if (object instanceof LatLon) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index 336c4f71bd..17ec527f4f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -1,8 +1,12 @@ package net.osmand.plus.mapcontextmenu.controllers; +import java.util.List; + 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.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; @@ -50,6 +54,11 @@ public class TransportRouteController extends MenuController { return false; } + @Override + public boolean buttonsVisible() { + return false; + } + @Override public boolean displayStreetNameInTitle() { return super.displayStreetNameInTitle(); @@ -62,14 +71,14 @@ public class TransportRouteController extends MenuController { @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { -// for (TransportStopRoute r : routes) { -// if (r.type == null) { -// addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false); -// } else { -// addPlainMenuItem(r.type.getResourceId(), r.desc, false, false); -// } -// } super.addPlainMenuItems(typeStr, pointDescription, latLon); + List stops = transportStop.route.getForwardStops(); + boolean useEnglishNames = getMapActivity().getMyApplication().getSettings().usingEnglishNames(); + for (TransportStop stop : stops) { + addPlainMenuItem( + stop == transportStop.stop ? R.drawable.ic_action_marker_dark : transportStop.type.getResourceId(), + useEnglishNames ? stop.getEnName(true) : stop.getName(), false, false, null); + } } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index a5c1766bc9..3df0b6c818 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -7,6 +7,7 @@ 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.resources.TransportIndexRepository; @@ -15,6 +16,9 @@ import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; +import android.view.View; +import android.view.View.OnClickListener; + public class TransportStopController extends MenuController { public enum TransportStopType { @@ -111,12 +115,20 @@ public class TransportStopController extends MenuController { } @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { - for (TransportStopRoute r : routes) { + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { + for (final TransportStopRoute r : routes) { + OnClickListener listener = new OnClickListener() { + @Override + public void onClick(View arg0) { + MapContextMenu mm = getMapActivity().getContextMenu(); + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.desc); + mm.show(latLon, pd, r); + } + }; if (r.type == null) { - addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false, null); + addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.desc, false, false, listener ); } else { - addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, null); + addPlainMenuItem(r.type.getResourceId(), r.desc, false, false, listener); } } super.addPlainMenuItems(typeStr, pointDescription, latLon); @@ -142,6 +154,7 @@ public class TransportStopController extends MenuController { } r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getName() : rs.getEnName(true)); r.route = rs; + r.stop = transportStop; this.routes.add(r); } } @@ -153,5 +166,6 @@ public class TransportStopController extends MenuController { public TransportStopType type; public String desc; public TransportRoute route; + public TransportStop stop; } }