From bb62e054e8e8767bd6a8cb5a5e3e180073e87a55 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 15 Dec 2017 10:19:16 +0200 Subject: [PATCH] Display routes in bottom view --- .../ctx_menu_transport_route_layout.xml | 60 ++++++++++++++++ OsmAnd/res/values/phrases.xml | 1 + .../plus/mapcontextmenu/MenuBuilder.java | 68 +++++++++++++++++-- .../controllers/AmenityMenuController.java | 2 +- .../FavouritePointMenuController.java | 11 ++- .../controllers/TransportStopController.java | 16 ++--- 6 files changed, 135 insertions(+), 23 deletions(-) create mode 100644 OsmAnd/res/layout/ctx_menu_transport_route_layout.xml diff --git a/OsmAnd/res/layout/ctx_menu_transport_route_layout.xml b/OsmAnd/res/layout/ctx_menu_transport_route_layout.xml new file mode 100644 index 0000000000..d5a46d20f0 --- /dev/null +++ b/OsmAnd/res/layout/ctx_menu_transport_route_layout.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index 8c6a71c4a8..4e5d59ba61 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -2099,6 +2099,7 @@ Monorail Funicular Ferry + Subway Route of a railroad diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index d6390823b4..72b80c46f3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -17,12 +17,14 @@ import android.text.TextUtils; import android.text.util.Linkify; import android.util.TypedValue; import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.TextView; import android.widget.Toast; import net.osmand.binary.BinaryMapIndexReader; @@ -463,7 +465,6 @@ public class MenuBuilder { baseView.addView(ll); // Icon - boolean showIcon = false; if (icon != null) { LinearLayout llIcon = new LinearLayout(view.getContext()); llIcon.setOrientation(LinearLayout.HORIZONTAL); @@ -479,7 +480,6 @@ public class MenuBuilder { iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); iconView.setImageDrawable(icon); llIcon.addView(iconView); - showIcon = true; } // Text @@ -489,7 +489,7 @@ public class MenuBuilder { TextViewEx textView = new TextViewEx(view.getContext()); LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - llTextParams.setMargins(showIcon ? 0 : dpToPx(16f), dpToPx(8f), 0, dpToPx(8f)); + llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(8f), 0, dpToPx(8f)); textView.setLayoutParams(llTextParams); textView.setTypeface(FontCache.getRobotoRegular(view.getContext())); textView.setTextSize(16); @@ -687,6 +687,65 @@ public class MenuBuilder { ); } + private void buildTransportRouteRow(ViewGroup parent, TransportStopRoute r, OnClickListener listener) { + if (!isFirstRow()) { + buildRowDivider(parent, false); + } + + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ctx_menu_transport_route_layout, parent, false); + TextView routeDesc = (TextView) view.findViewById(R.id.route_desc); + routeDesc.setText(r.getDescription(getMapActivity().getMyApplication(), true)); + routeDesc.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark)); + int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId(); + ((ImageView) view.findViewById(R.id.route_type_icon)).setImageDrawable(getRowIcon(drawableResId)); + ((TextView) view.findViewById(R.id.route_ref)).setText(r.route.getRef()); + view.setOnClickListener(listener); + int typeResId; + switch (r.type) { + case BUS: + typeResId = R.string.poi_route_bus_ref; + break; + case TRAM: + typeResId = R.string.poi_route_tram_ref; + break; + case FERRY: + typeResId = R.string.poi_route_ferry_ref; + break; + case TRAIN: + typeResId = R.string.poi_route_train_ref; + break; + case SHARE_TAXI: + typeResId = R.string.poi_route_share_taxi_ref; + break; + case FUNICULAR: + typeResId = R.string.poi_route_funicular_ref; + break; + case LIGHT_RAIL: + typeResId = R.string.poi_route_light_rail_ref; + break; + case MONORAIL: + typeResId = R.string.poi_route_monorail_ref; + break; + case TROLLEYBUS: + typeResId = R.string.poi_route_trolleybus_ref; + break; + case RAILWAY: + typeResId = R.string.poi_route_railway_ref; + break; + case SUBWAY: + typeResId = R.string.poi_route_subway_ref; + break; + default: + typeResId = R.string.poi_filter_public_transport; + break; + } + ((TextView) view.findViewById(R.id.route_type_text)).setText(typeResId); + + parent.addView(view); + + rowBuilt(); + } + private CollapsableView getCollapsableTransportStopRoutesView(final Context context, boolean collapsed) { LinearLayout view = (LinearLayout) buildCollapsableContentView(context, collapsed, false); @@ -704,8 +763,7 @@ public class MenuBuilder { getMapActivity().changeZoom(cz - getMapActivity().getMapView().getZoom()); } }; - int drawableResId = r.type == null ? R.drawable.ic_action_polygom_dark : r.type.getResourceId(); - buildRow(view, drawableResId, r.getDescription(getMapActivity().getMyApplication(), true), 0, false, null, false, 0, false, listener); + buildTransportRouteRow(view, r, listener); } return new CollapsableView(view, collapsed); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index af1aff59d0..fe08ecf674 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -230,7 +230,7 @@ public class AmenityMenuController extends MenuController { TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType()); TransportStopRoute r = new TransportStopRoute(); r.type = type; - r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName()); + r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName(); r.route = rs; r.stop = s; r.distance = dist; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 074b26d61c..4496bf7f3f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -36,6 +36,11 @@ public class FavouritePointMenuController extends MenuController { leftTitleButtonController = markerMenuController.getLeftTitleButtonController(); rightTitleButtonController = markerMenuController.getRightTitleButtonController(); } + if (getObject() instanceof TransportStop) { + TransportStop stop = (TransportStop) getObject(); + TransportStopController transportStopController = new TransportStopController(getMapActivity(), pointDescription, stop); + transportStopController.processTransportStop(builder); + } } @Override @@ -120,12 +125,6 @@ public class FavouritePointMenuController extends MenuController { if (originObject instanceof Amenity) { Amenity amenity = (Amenity) originObject; AmenityMenuController.addPlainMenuItems(amenity, AmenityMenuController.getTypeStr(amenity), builder); - } else if (originObject instanceof TransportStop) { - TransportStop stop = (TransportStop) originObject; - TransportStopController transportStopController = - new TransportStopController(getMapActivity(), pointDescription, stop); - transportStopController.addPlainMenuItems(builder, latLon); - addMyLocationToPlainItems(latLon); } } else { addMyLocationToPlainItems(latLon); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 73e0698b20..f14b1890c3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -82,14 +82,14 @@ public class TransportStopController extends MenuController { PointDescription pointDescription, TransportStop transportStop) { super(new MenuBuilder(mapActivity), pointDescription, mapActivity); this.transportStop = transportStop; - processTransportStop(); + processTransportStop(builder); } @Override protected void setObject(Object object) { if (object instanceof TransportStop) { this.transportStop = (TransportStop) object; - processTransportStop(); + processTransportStop(builder); } } @@ -127,19 +127,13 @@ public class TransportStopController extends MenuController { return getPointDescription().getTypeName(); } - @Override - public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { - addPlainMenuItems(builder, latLon); - super.addPlainMenuItems(typeStr, pointDescription, latLon); - } - public void addPlainMenuItems(MenuBuilder builder, 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, + PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_ROUTE, r.getDescription(getMapActivity().getMyApplication(), false)); mm.show(latLon, pd, r); TransportStopsLayer stopsLayer = getMapActivity().getMapLayers().getTransportStopsLayer(); @@ -158,7 +152,7 @@ public class TransportStopController extends MenuController { } } - private void processTransportStop() { + public void processTransportStop(MenuBuilder builder) { routes.clear(); List reps = getMapActivity().getMyApplication() .getResourceManager().searchTransportRepositories(transportStop.getLocation().getLatitude(), @@ -212,7 +206,7 @@ public class TransportStopController extends MenuController { topType = type; } r.type = type; - r.desc = rs.getRef() + " " + (useEnglishNames ? rs.getEnName(true) : rs.getName()); + r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName(); r.route = rs; r.refStop = refStop; r.stop = s;