From 8551969bc9c98333b292f8903b71def0a237caec Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 21 Dec 2017 15:13:45 +0200 Subject: [PATCH] Prevent NPE in transport type --- .../plus/mapcontextmenu/MenuBuilder.java | 2 +- .../plus/transport/TransportStopRoute.java | 59 +++++++++++++++++-- .../plus/transport/TransportStopType.java | 43 -------------- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index ced1596fc4..77a296f88c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -778,7 +778,7 @@ public class MenuBuilder { TextView typeTextView = new TextView(view.getContext()); LinearLayout.LayoutParams typeTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); typeTextView.setLayoutParams(typeTextParams); - typeTextView.setText(route.type.getTypeStrRes()); + typeTextView.setText(route.getTypeStrRes()); typeView.addView(typeTextView); baseView.setOnClickListener(listener); diff --git a/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java b/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java index ca61058888..d458b27780 100644 --- a/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java +++ b/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java @@ -55,16 +55,63 @@ public class TransportStopRoute { if (cachedColor == 0 || cachedNight != nightMode) { cachedColor = ctx.getResources().getColor(R.color.transport_route_line); cachedNight = nightMode; - RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer(); - RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); - String typeStr = type.getRendeAttr(); - if (req.searchRenderingAttribute(typeStr)) { - cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE); + if (type != null) { + RenderingRulesStorage rrs = ctx.getRendererRegistry().getCurrentSelectedRenderer(); + RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs); + req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); + String typeStr = type.getRendeAttr(); + if (req.searchRenderingAttribute(typeStr)) { + cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE); + } } } return cachedColor; } + public int getTypeStrRes() { + int typeResId = R.string.poi_filter_public_transport; + if (type != null) { + switch (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; + } + } + return typeResId; + } + } diff --git a/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java index 4c7d99b7ad..63dfcae17c 100644 --- a/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java +++ b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java @@ -51,47 +51,4 @@ public enum TransportStopType { return null; } - public int getTypeStrRes() { - int typeResId; - switch (this) { - 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; - } - return typeResId; - } - }