Get route colors from render.xml
This commit is contained in:
parent
b38f368fb4
commit
a0a9d0d5d5
12 changed files with 99 additions and 114 deletions
|
@ -371,15 +371,4 @@
|
|||
<color name="route_info_checked_mode_icon_color_dark">#d28521</color>
|
||||
<color name="route_info_unchecked_mode_icon_color">#727272</color>
|
||||
|
||||
<color name="route_bus_color">#ff0000</color>
|
||||
<color name="route_share_taxi_color">#f620cb</color>
|
||||
<color name="route_trolleybus_color">#920071</color>
|
||||
<color name="route_tram_color">#0000ff</color>
|
||||
<color name="route_train_color_light">#8c3f01</color>
|
||||
<color name="route_train_color_dark">#cb6e23</color>
|
||||
<color name="route_lightrail_color">#009100</color>
|
||||
<color name="route_funicular_color">#3880a9</color>
|
||||
<color name="route_ferry_color_light">#53A3BE</color>
|
||||
<color name="route_ferry_color_dark">#185499</color>
|
||||
|
||||
</resources>
|
|
@ -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;
|
||||
|
|
|
@ -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<TransportStopRoute> 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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TransportStopRoute>
|
|||
|
||||
private boolean nightMode;
|
||||
private OnClickListener listener;
|
||||
private OsmandApplication app;
|
||||
|
||||
public TransportStopRouteAdapter(@NonNull Context context, @NonNull List<TransportStopRoute> objects, boolean nightMode) {
|
||||
super(context, 0, objects);
|
||||
public TransportStopRouteAdapter(@NonNull OsmandApplication application, @NonNull List<TransportStopRoute> 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<TransportStopRoute>
|
|||
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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TransportStopRoute> routes = new ArrayList<>();
|
||||
private TransportStopType topType;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
54
OsmAnd/src/net/osmand/plus/transport/TransportStopType.java
Normal file
54
OsmAnd/src/net/osmand/plus/transport/TransportStopType.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue