changed way of drawing using RenderingIcons

This commit is contained in:
Chumva 2018-02-22 17:33:44 +02:00
parent 1dfc515c94
commit b1770c7a5f
2 changed files with 58 additions and 24 deletions

View file

@ -3,26 +3,30 @@ package net.osmand.plus.transport;
import net.osmand.plus.R; import net.osmand.plus.R;
public enum TransportStopType { public enum TransportStopType {
BUS(R.drawable.mx_route_bus_ref, R.drawable.mx_route_bus_ref, "routeBusColor"), 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, "routeFerryColor"), 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, "routeFunicularColor"), 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, "routeLightrailColor"), 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, "routeLightrailColor"), 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, "routeTrainColor"), 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, "routeShareTaxiColor"), 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, "routeTrainColor"), 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, "routeTramColor"), 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, "routeTrolleybusColor"), 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, "routeTrainColor"); SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station, R.drawable.mm_subway_station, "routeTrainColor","subway_station");
final int resId; final int resId;
final int topResId; final int topResId;
final int smallResId;
final String renderAttr; 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.resId = resId;
this.topResId = topResId; this.topResId = topResId;
this.renderAttr = renderAttr; this.renderAttr = renderAttr;
this.smallResId = smallResId;
this.nameDrawable = nameDrawable;
} }
public int getResourceId() { public int getResourceId() {
@ -33,6 +37,14 @@ public enum TransportStopType {
return topResId; return topResId;
} }
public int getSmallResId() {
return smallResId;
}
public String getNameDrawable() {
return nameDrawable;
}
public String getRendeAttr() { public String getRendeAttr() {
return renderAttr; return renderAttr;
} }

View file

@ -7,6 +7,9 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.support.v4.content.ContextCompat;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
@ -20,8 +23,10 @@ import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way; import net.osmand.osm.edit.Way;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.transport.TransportStopType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -39,6 +44,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private OsmandMapTileView view; private OsmandMapTileView view;
private Paint paintIcon; private Paint paintIcon;
private Paint paintWhiteIcon;
private Bitmap backgroundIcon;
private Bitmap stopBus; private Bitmap stopBus;
private Bitmap stopSmall; private Bitmap stopSmall;
private RenderingLineAttributes attrs; private RenderingLineAttributes attrs;
@ -48,6 +55,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private boolean showTransportStops; private boolean showTransportStops;
private Path path; private Path path;
private float backgroundIconHalfWidth;
private float backgroundIconHalfHeight;
public TransportStopsLayer(MapActivity mapActivity) { public TransportStopsLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
@ -56,12 +65,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public void initLayer(final OsmandMapTileView view) { 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; this.view = view;
DisplayMetrics dm = new DisplayMetrics(); DisplayMetrics dm = new DisplayMetrics();
WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE); WindowManager wmgr = (WindowManager) view.getContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.getDefaultDisplay().getMetrics(dm); wmgr.getDefaultDisplay().getMetrics(dm);
paintIcon = new Paint(); 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(); path = new Path();
stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus); stopBus = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_bus);
stopSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_transport_stop_small); 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); fullObjects.add(o);
} }
} }
for (TransportStop o : fullObjects) { for (TransportStop o : fullObjects) {
float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()); float x = tb.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
float y = tb.getPixYFromLatLon(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.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; Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon); canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
} }
} }
}
} }
@Override @Override