Merge pull request #5057 from osmandapp/TransportIconsOnRoutes

changed way of drawing using RenderingIcons
This commit is contained in:
Alexey 2018-02-23 19:12:10 +03:00 committed by GitHub
commit 4978217197
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 24 deletions

View file

@ -3,26 +3,28 @@ 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, "routeBusColor", "route_bus_ref"),
FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref, "routeFerryColor", "route_ferry_ref"),
FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref, "routeFunicularColor", "route_funicular_ref"),
LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref, "routeLightrailColor", "route_light_rail_ref"),
MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref, "routeLightrailColor", "route_monorail_ref"),
RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref, "routeTrainColor", "route_railway_ref"),
SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref, "routeShareTaxiColor", "route_share_taxi_ref"),
TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref, "routeTrainColor", "route_train_ref"),
TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop, "routeTramColor", "route_tram_ref"),
TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref, "routeTrolleybusColor", "route_trolleybus_ref"),
SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station, "routeTrainColor", "subway_station");
final int resId;
final int topResId;
final String renderAttr;
final String resName;
TransportStopType(int resId, int topResId, String renderAttr) {
TransportStopType(int resId, int topResId, String renderAttr, String resName) {
this.resId = resId;
this.topResId = topResId;
this.renderAttr = renderAttr;
this.resName = resName;
}
public int getResourceId() {
@ -33,6 +35,10 @@ public enum TransportStopType {
return topResId;
}
public String getResName() {
return resName;
}
public String getRendeAttr() {
return renderAttr;
}

View file

@ -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);
@ -227,14 +240,23 @@ 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());
if (stopRoute != null) {
TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
if (type != null) {
Bitmap foregroundIcon = RenderingIcons.getIcon(mapActivity, type.getResName(), 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