diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index f435e29ea2..dd9eae0d60 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -370,16 +370,5 @@ #ff8800 #d28521 #727272 - - #ff0000 - #f620cb - #920071 - #0000ff - #8c3f01 - #cb6e23 - #009100 - #3880a9 - #53A3BE - #185499 \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 3e1815179c..28e11f79bf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -37,7 +37,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.PointEditor; import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 36775029b4..b68882032d 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -46,7 +46,7 @@ import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; import net.osmand.plus.mapcontextmenu.MenuController.MenuState; import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.OsmandMapTileView; @@ -389,7 +389,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo GridView transportStopRoutesGrid = (GridView) view.findViewById(R.id.transport_stop_routes_grid); List transportStopRoutes = menu.getTransportStopRoutes(); if (transportStopRoutes != null && transportStopRoutes.size() > 0) { - final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getContext(), transportStopRoutes, nightMode); + final TransportStopRouteAdapter adapter = new TransportStopRouteAdapter(getMyApplication(), transportStopRoutes, nightMode); adapter.setListener(new TransportStopRouteAdapter.OnClickListener() { @Override public void onClick(int position) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 8847d4eac6..6a628d4e5c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -52,7 +52,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask; import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.views.TransportStopsLayer; @@ -730,7 +730,7 @@ public class MenuBuilder { TextView refTextView = (TextView) view.findViewById(R.id.route_ref); refTextView.setText(r.route.getRef()); GradientDrawable refBg = (GradientDrawable) refTextView.getBackground(); - refBg.setColor(ContextCompat.getColor(parent.getContext(), r.getColor(!light))); + refBg.setColor(r.getColor(mapActivity.getMyApplication(), !light)); view.setOnClickListener(listener); int typeResId; switch (r.type) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 598a668fce..6d6873774b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -51,7 +51,7 @@ import net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController; import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController; import net.osmand.plus.mapcontextmenu.controllers.TransportRouteController; import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; import net.osmand.plus.mapcontextmenu.other.ShareMenu; import net.osmand.plus.mapillary.MapillaryImage; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java index b0543ede2d..25fc3bb452 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/TransportStopRouteAdapter.java @@ -1,18 +1,17 @@ package net.osmand.plus.mapcontextmenu; -import android.content.Context; import android.graphics.drawable.GradientDrawable; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v4.content.ContextCompat; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.TextView; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import java.util.List; @@ -20,10 +19,12 @@ public class TransportStopRouteAdapter extends ArrayAdapter private boolean nightMode; private OnClickListener listener; + private OsmandApplication app; - public TransportStopRouteAdapter(@NonNull Context context, @NonNull List objects, boolean nightMode) { - super(context, 0, objects); + public TransportStopRouteAdapter(@NonNull OsmandApplication application, @NonNull List objects, boolean nightMode) { + super(application, 0, objects); this.nightMode = nightMode; + this.app = application; } public void setListener(OnClickListener listener) { @@ -42,7 +43,7 @@ public class TransportStopRouteAdapter extends ArrayAdapter TextView transportStopRouteTextView = (TextView) convertView.findViewById(R.id.transport_stop_route_text); transportStopRouteTextView.setText(transportStopRoute.route.getRef()); GradientDrawable gradientDrawableBg = (GradientDrawable) transportStopRouteTextView.getBackground(); - gradientDrawableBg.setColor(ContextCompat.getColor(getContext(), transportStopRoute.getColor(nightMode))); + gradientDrawableBg.setColor(transportStopRoute.getColor(app, nightMode)); } convertView.setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 9f64c1dd8c..3709e3600b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -16,9 +16,10 @@ import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.OpeningHoursInfo; import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.resources.TransportIndexRepository; +import net.osmand.plus.transport.TransportStopType; import net.osmand.plus.views.POIMapLayer; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -252,7 +253,7 @@ public class AmenityMenuController extends MenuController { if (rts != null) { for (TransportRoute rs : rts) { if (!containsRef(rs)) { - TransportStopController.TransportStopType type = TransportStopController.TransportStopType.findType(rs.getType()); + TransportStopType type = TransportStopType.findType(rs.getType()); TransportStopRoute r = new TransportStopRoute(); r.type = type; r.desc = useEnglishNames ? rs.getEnName(true) : rs.getName(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java index a72f2e3544..e0eca34040 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportRouteController.java @@ -12,7 +12,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.views.TransportStopsLayer; import java.util.List; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 0972367bc4..c30775d1c8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -9,12 +9,13 @@ import net.osmand.data.QuadRect; import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; import net.osmand.plus.R; -import net.osmand.plus.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.resources.TransportIndexRepository; +import net.osmand.plus.transport.TransportStopType; import net.osmand.plus.views.TransportStopsLayer; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -27,51 +28,6 @@ import java.util.List; public class TransportStopController extends MenuController { - public enum TransportStopType { - BUS(R.drawable.mx_route_bus_ref, R.drawable.mx_route_bus_ref), - FERRY(R.drawable.mx_route_ferry_ref, R.drawable.mx_route_ferry_ref), - FUNICULAR(R.drawable.mx_route_funicular_ref, R.drawable.mx_route_funicular_ref), - LIGHT_RAIL(R.drawable.mx_route_light_rail_ref, R.drawable.mx_route_light_rail_ref), - MONORAIL(R.drawable.mx_route_monorail_ref, R.drawable.mx_route_monorail_ref), - RAILWAY(R.drawable.mx_route_railway_ref, R.drawable.mx_route_railway_ref), - SHARE_TAXI(R.drawable.mx_route_share_taxi_ref, R.drawable.mx_route_share_taxi_ref), - TRAIN(R.drawable.mx_route_train_ref, R.drawable.mx_route_train_ref), - TRAM(R.drawable.mx_route_tram_ref, R.drawable.mx_railway_tram_stop), - TROLLEYBUS(R.drawable.mx_route_trolleybus_ref, R.drawable.mx_route_trolleybus_ref), - SUBWAY(R.drawable.mx_subway_station, R.drawable.mx_subway_station); - - final int resId; - final int topResId; - - TransportStopType(int resId, int topResId) { - this.resId = resId; - this.topResId = topResId; - } - - public int getResourceId() { - return resId; - } - - public int getTopResourceId() { - return topResId; - } - - public boolean isTopType() { - return this == TRAM || this == SUBWAY; - } - - public static TransportStopType findType(String typeName) { - String tName = typeName.toUpperCase(); - for (TransportStopType t : values()) { - if (t.name().equals(tName)) { - return t; - } - } - return null; - } - - } - private TransportStop transportStop; private List routes = new ArrayList<>(); private TransportStopType topType; diff --git a/OsmAnd/src/net/osmand/plus/TransportStopRoute.java b/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java similarity index 56% rename from OsmAnd/src/net/osmand/plus/TransportStopRoute.java rename to OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java index e0f7d3fb87..aee669811e 100644 --- a/OsmAnd/src/net/osmand/plus/TransportStopRoute.java +++ b/OsmAnd/src/net/osmand/plus/transport/TransportStopRoute.java @@ -1,20 +1,26 @@ -package net.osmand.plus; +package net.osmand.plus.transport; import net.osmand.data.RotatedTileBox; import net.osmand.data.TransportRoute; import net.osmand.data.TransportStop; -import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.render.RenderingRuleSearchRequest; +import net.osmand.render.RenderingRulesStorage; import java.util.List; public class TransportStopRoute { public TransportStop refStop; - public TransportStopController.TransportStopType type; + public TransportStopType type; public String desc; public TransportRoute route; public TransportStop stop; public int distance; public boolean showWholeRoute; + private int cachedColor; + private boolean cachedNight; public String getDescription(OsmandApplication ctx, boolean useDistance) { if (useDistance && distance > 0) { @@ -45,37 +51,20 @@ public class TransportStopRoute { return cp.getZoom(); } - public int getColor(boolean nightMode) { - int color; - switch (type) { - case BUS: - color = R.color.route_bus_color; - break; - case SHARE_TAXI: - color = R.color.route_share_taxi_color; - break; - case TROLLEYBUS: - color = R.color.route_trolleybus_color; - break; - case TRAM: - color = R.color.route_tram_color; - break; - case TRAIN: - color = nightMode ? R.color.route_train_color_dark : R.color.route_train_color_light; - break; - case LIGHT_RAIL: - color = R.color.route_lightrail_color; - break; - case FUNICULAR: - color = R.color.route_funicular_color; - break; - case FERRY: - color = nightMode ? R.color.route_ferry_color_dark : R.color.route_ferry_color_light; - break; - default: - color = R.color.nav_track; - break; + public int getColor(OsmandApplication ctx, boolean nightMode) { + 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.getTypeStr(); + if (req.searchRenderingAttribute(typeStr)) { + cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE); + } } - return color; + + return cachedColor; } + } diff --git a/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java new file mode 100644 index 0000000000..d8273f9090 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/transport/TransportStopType.java @@ -0,0 +1,54 @@ +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"); + + final int resId; + final int topResId; + final String typeStr; + + TransportStopType(int resId, int topResId, String typeStr) { + this.resId = resId; + this.topResId = topResId; + this.typeStr = typeStr; + } + + public int getResourceId() { + return resId; + } + + public int getTopResourceId() { + return topResId; + } + + public String getTypeStr() { + return typeStr; + } + + public boolean isTopType() { + return this == TRAM || this == SUBWAY; + } + + public static TransportStopType findType(String typeName) { + String tName = typeName.toUpperCase(); + for (TransportStopType t : values()) { + if (t.name().equals(tName)) { + return t; + } + } + return null; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 2dee99c725..7fd642d9df 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -7,7 +7,6 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PointF; -import android.support.v4.content.ContextCompat; import android.util.DisplayMetrics; import android.view.WindowManager; @@ -21,7 +20,7 @@ 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.TransportStopRoute; +import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.activities.MapActivity; import java.util.ArrayList; @@ -39,7 +38,6 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa private final MapActivity mapActivity; private OsmandMapTileView view; - private int cachedColor; private Paint paintIcon; private Bitmap stopBus; private Bitmap stopSmall; @@ -183,11 +181,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa if (tb.getZoom() >= startZoomRoute) { if (stopRoute != null) { objects = stopRoute.route.getForwardStops(); - int color = stopRoute.getColor(settings.isNightMode()); - if (cachedColor != color) { - cachedColor = color; - attrs.paint.setColor(ContextCompat.getColor(mapActivity, cachedColor)); - } + int color = stopRoute.getColor(mapActivity.getMyApplication(), settings.isNightMode()); + attrs.paint.setColor(color); attrs.updatePaints(view, settings, tb); try { path.reset();