diff --git a/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java index 63dfcae17c..6ac69c5ed1 100644 --- a/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java +++ b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java @@ -3,26 +3,30 @@ package net.osmand.plus.transport; import net.osmand.plus.R; public enum TransportStopType { - BUS(R.drawable.mx_route_bus_ref, R.drawable.mx_route_bus_ref, "routeBusColor"), - FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref, "routeFerryColor"), - FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref, "routeFunicularColor"), - LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref, "routeLightrailColor"), - MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref, "routeLightrailColor"), - RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref, "routeTrainColor"), - SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref, "routeShareTaxiColor"), - TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref, "routeTrainColor"), - TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop, "routeTramColor"), - TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref, "routeTrolleybusColor"), - SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station, "routeTrainColor"); + BUS(R.drawable.mx_route_bus_ref, R.drawable.mx_route_bus_ref, R.drawable.mm_route_bus_ref, "routeBusColor","route_bus_ref"), + FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref, R.drawable.mm_route_ferry_ref, "routeFerryColor","route_ferry_ref"), + FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref, R.drawable.mm_route_funicular_ref, "routeFunicularColor","route_funicular_ref"), + LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref, R.drawable.mm_route_light_rail_ref, "routeLightrailColor","route_light_rail_ref"), + MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref, R.drawable.mm_route_monorail_ref, "routeLightrailColor","route_monorail_ref"), + RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref, R.drawable.mm_route_railway_ref, "routeTrainColor","route_railway_ref"), + SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref, R.drawable.mm_route_share_taxi_ref, "routeShareTaxiColor","route_share_taxi_ref"), + TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref, R.drawable.mm_route_train_ref, "routeTrainColor","route_train_ref"), + TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop, R.drawable.mx_route_tram_ref, "routeTramColor","route_tram_ref"), + TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref, R.drawable.mm_route_trolleybus_ref, "routeTrolleybusColor","route_trolleybus_ref"), + SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station, R.drawable.mm_subway_station, "routeTrainColor","subway_station"); final int resId; final int topResId; + final int smallResId; final String renderAttr; + final String nameDrawable; - TransportStopType(int resId, int topResId, String renderAttr) { + TransportStopType(int resId, int topResId, int smallResId, String renderAttr, String nameDrawable) { this.resId = resId; this.topResId = topResId; this.renderAttr = renderAttr; + this.smallResId = smallResId; + this.nameDrawable = nameDrawable; } public int getResourceId() { @@ -33,6 +37,14 @@ public enum TransportStopType { return topResId; } + public int getSmallResId() { + return smallResId; + } + + public String getNameDrawable() { + return nameDrawable; + } + public String getRendeAttr() { return renderAttr; } diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 7fd642d9df..64607905b6 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -7,6 +7,9 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PointF; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.support.v4.content.ContextCompat; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -20,8 +23,10 @@ import net.osmand.data.TransportStop; import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Way; import net.osmand.plus.R; +import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.transport.TransportStopType; import java.util.ArrayList; import java.util.Collections; @@ -39,6 +44,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa private OsmandMapTileView view; private Paint paintIcon; + private Paint paintWhiteIcon; + private Bitmap backgroundIcon; private Bitmap stopBus; private Bitmap stopSmall; private RenderingLineAttributes attrs; @@ -48,6 +55,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa private boolean showTransportStops; private Path path; + private float backgroundIconHalfWidth; + private float backgroundIconHalfHeight; public TransportStopsLayer(MapActivity mapActivity) { this.mapActivity = mapActivity; @@ -56,12 +65,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa @SuppressWarnings("deprecation") @Override public void initLayer(final OsmandMapTileView view) { + backgroundIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bg); + backgroundIconHalfWidth = backgroundIcon.getWidth() / 2; + backgroundIconHalfHeight = backgroundIcon.getWidth() / 2; this.view = view; DisplayMetrics dm = new DisplayMetrics(); WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); wmgr.getDefaultDisplay().getMetrics(dm); - paintIcon = new Paint(); + paintWhiteIcon = new Paint(); + paintWhiteIcon.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(mapActivity,R.color.primary_text_dark), PorterDuff.Mode.SRC_IN)); path = new Path(); stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus); stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small); @@ -112,9 +125,9 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa } }; } - + public void getFromPoint(RotatedTileBox tb, PointF point, List res, - List objects) { + List objects) { int ex = (int) point.x; int ey = (int) point.y; final int rp = getRadiusPoi(tb); @@ -141,11 +154,11 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa // that's really rare case, but is much efficient than introduce synchronized block } } - + public TransportStopRoute getRoute() { return stopRoute; } - + public void setRoute(TransportStopRoute route) { this.stopRoute = route; } @@ -212,7 +225,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa data.queryNewData(tb); objects = data.getResults(); } - + if (objects != null) { float iconSize = stopBus.getWidth() * 3 / 2.5f; QuadTree boundIntersections = initBoundIntersections(tb); @@ -227,16 +240,25 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa fullObjects.add(o); } } + for (TransportStop o : fullObjects) { float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); - Bitmap b = stopBus; - canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); + if (stopRoute != null) { + TransportStopType type = TransportStopType.findType(stopRoute.route.getType()); + if (type != null) { + Bitmap foregroundIcon = RenderingIcons.getIcon(mapActivity, type.getNameDrawable(), false); + canvas.drawBitmap(backgroundIcon, x - backgroundIconHalfWidth, y - backgroundIconHalfHeight, paintIcon); + canvas.drawBitmap(foregroundIcon, x - foregroundIcon.getWidth() / 2, y - foregroundIcon.getHeight() / 2, paintWhiteIcon); + } + } else { + Bitmap b = stopBus; + canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); + } } } - } - + @Override public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings settings) { } @@ -259,7 +281,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa public PointDescription getObjectName(Object o) { if(o instanceof TransportStop){ return new PointDescription(PointDescription.POINT_TYPE_TRANSPORT_STOP, mapActivity.getString(R.string.transport_Stop), - ((TransportStop)o).getName()); + ((TransportStop)o).getName()); } return null; } @@ -290,7 +312,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa getFromPoint(tileBox, point, res, stopRoute.route.getForwardStops()); } else if (tileBox.getZoom() >= startZoom && data.getResults() != null) { getFromPoint(tileBox, point, res, data.getResults()); - } + } } @Override