use contrast color for direction arrows

This commit is contained in:
nazar-kutz 2021-04-05 23:03:45 +03:00
parent d9bea4ecd4
commit 294040aaf9
3 changed files with 43 additions and 10 deletions

View file

@ -30,6 +30,7 @@ import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
@ -105,6 +106,10 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
private LayerDrawable projectionIcon;
private LayerDrawable previewIcon;
private int routeLineColor;
private float routeLineWidth;
private Integer directionArrowsColor;
public RouteLayer(RoutingHelper helper) {
this.helper = helper;
this.transportHelper = helper.getTransportRoutingHelper();
@ -326,7 +331,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
DrawSettings settings,
RouteLineDrawInfo drawInfo) {
updateAttrs(settings, tileBox);
paintRouteLinePreview.setColor(getRouteLineColor(nightMode));
updateRouteColors(nightMode);
paintRouteLinePreview.setColor(getRouteLineColor());
paintRouteLinePreview.setStrokeWidth(getRouteLineWidth(tileBox));
int centerX = drawInfo.getCenterX();
@ -418,6 +424,22 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
@ColorInt
public int getRouteLineColor(boolean night) {
updateRouteColors(night);
return routeLineColor;
}
@ColorInt
public int getRouteLineColor() {
return routeLineColor;
}
@Nullable
@ColorInt
public Integer getDirectionArrowsColor() {
return directionArrowsColor;
}
public void updateRouteColors(boolean night) {
Integer color;
if (routeLineDrawInfo != null) {
color = routeLineDrawInfo.getColor(night);
@ -429,10 +451,13 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
color = storedValue != 0 ? storedValue : null;
}
if (color == null) {
directionArrowsColor = null;
updateAttrs(new DrawSettings(night), view.getCurrentRotatedTileBox());
color = attrs.paint.getColor();
} else if (routeLineColor != color) {
directionArrowsColor = UiUtilities.getContrastColor(view.getContext(), color, false);
}
return color;
routeLineColor = color;
}
private float getRouteLineWidth(@NonNull RotatedTileBox tileBox) {
@ -442,7 +467,7 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
} else {
widthKey = view.getSettings().ROUTE_LINE_WIDTH.getModeValue(helper.getAppMode());
}
return widthKey != null ? getWidthByKey(tileBox, widthKey) : attrs.paint.getStrokeWidth();
return routeLineWidth = widthKey != null ? getWidthByKey(tileBox, widthKey) : attrs.paint.getStrokeWidth();
}
@Nullable
@ -500,7 +525,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
boolean straight = route.getRouteService() == RouteService.STRAIGHT;
publicTransportRouteGeometry.clearRoute();
routeGeometry.updateRoute(tb, route);
routeGeometry.setRouteStyleParams(getRouteLineColor(nightMode), getRouteLineWidth(tb));
updateRouteColors(nightMode);
routeGeometry.setRouteStyleParams(getRouteLineColor(), getRouteLineWidth(tb), getDirectionArrowsColor());
if (directTo) {
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude,
null, 0);

View file

@ -8,6 +8,7 @@ public abstract class GeometryWayStyle<T extends GeometryWayContext> {
private T context;
protected Integer color;
protected Float width;
protected Integer pointColor;
public GeometryWayStyle(T context) {
this.context = context;
@ -18,10 +19,11 @@ public abstract class GeometryWayStyle<T extends GeometryWayContext> {
this.color = color;
}
public GeometryWayStyle(T context, Integer color, Float width) {
public GeometryWayStyle(T context, Integer color, Float width, Integer pointColor) {
this.context = context;
this.color = color;
this.width = width;
this.pointColor = pointColor;
}
public T getContext() {
@ -45,7 +47,7 @@ public abstract class GeometryWayStyle<T extends GeometryWayContext> {
}
public Integer getPointColor() {
return null;
return pointColor;
}
public boolean isNightMode() {

View file

@ -22,15 +22,19 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
private Integer customColor;
private Float customWidth;
private Integer customPointColor;
public RouteGeometryWay(RouteGeometryWayContext context) {
super(context, new GeometryWayDrawer<>(context));
this.helper = context.getApp().getRoutingHelper();
}
public void setRouteStyleParams(@Nullable @ColorInt Integer color, @Nullable Float width) {
public void setRouteStyleParams(@Nullable @ColorInt Integer color,
@Nullable Float width,
@Nullable @ColorInt Integer pointColor) {
this.customColor = color;
this.customWidth = width;
this.customPointColor = pointColor;
}
@NonNull
@ -39,7 +43,7 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
Paint paint = getContext().getAttrs().paint;
int color = customColor != null ? customColor : paint.getColor();
float width = customWidth != null ? customWidth : paint.getStrokeWidth();
return new GeometrySolidWayStyle(getContext(), color, width);
return new GeometrySolidWayStyle(getContext(), color, width, customPointColor);
}
public void updateRoute(RotatedTileBox tb, RouteCalculationResult route) {
@ -64,8 +68,9 @@ public class RouteGeometryWay extends GeometryWay<RouteGeometryWayContext, Geome
private static class GeometrySolidWayStyle extends GeometryWayStyle<RouteGeometryWayContext> {
GeometrySolidWayStyle(RouteGeometryWayContext context, Integer color, Float width) {
super(context, color, width);
GeometrySolidWayStyle(RouteGeometryWayContext context, Integer color, Float width,
Integer pointColor) {
super(context, color, width, pointColor);
}
@Override