Add color definition to render xml

This commit is contained in:
Victor Shcherb 2012-09-29 22:38:05 +02:00
parent add321b341
commit 318e294771
3 changed files with 61 additions and 10 deletions

View file

@ -33,6 +33,16 @@
<filter minzoom="9" maxzoom="13" attrIntValue="1" shadowColor="#464646"/>
<filter attrIntValue="0"/>
</renderingAttribute>
<renderingAttribute name="routeColor">
<filter nightMode="false" attrColorValue="#960000FF" />
<filter attrColorValue="#CCFF6600"/>
</renderingAttribute>
<renderingAttribute name="gpxColor">
<filter nightMode="false" attrColorValue="#B400FFFF" />
<filter attrColorValue="#B400FFFF"/>
</renderingAttribute>
<renderingAttribute name="defaultColor">
<filter noPolygons="true" attrColorValue="#00ffffff"/>

View file

@ -6,6 +6,8 @@ import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
@ -25,6 +27,10 @@ public class GPXLayer extends OsmandMapLayer {
private OsmandSettings settings;
private RenderingRulesStorage cachedRrs;
private boolean cachedNightMode;
private int cachedColor;
private void initUI() {
paint = new Paint();
@ -45,6 +51,24 @@ public class GPXLayer extends OsmandMapLayer {
}
private int getColor(DrawSettings nightMode){
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
boolean n = nightMode != null && nightMode.isNightMode();
if (rrs != cachedRrs || cachedNightMode != n) {
cachedRrs = rrs;
cachedNightMode = n;
cachedColor = view.getResources().getColor(R.color.gpx_track);
if (cachedRrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, cachedNightMode);
if (req.searchRenderingAttribute("gpxColor")) {
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
}
}
}
return cachedColor;
}
@Override
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
@ -53,11 +77,8 @@ public class GPXLayer extends OsmandMapLayer {
return;
}
List<List<WptPt>> points = gpxFile.processedPointsToDisplay;
if (false && view.getSettings().FLUORESCENT_OVERLAYS.get()) {
paint.setColor(view.getResources().getColor(R.color.gpx_track_fluorescent));
} else {
paint.setColor(view.getResources().getColor(R.color.gpx_track));
}
paint.setColor(getColor(nightMode));
for (List<WptPt> l : points) {
path.rewind();

View file

@ -5,6 +5,8 @@ import java.util.List;
import net.osmand.plus.R;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.render.RenderingRuleSearchRequest;
import net.osmand.render.RenderingRulesStorage;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Cap;
@ -28,6 +30,11 @@ public class RouteLayer extends OsmandMapLayer {
private Path path;
// cache
private RenderingRulesStorage cachedRrs;
private boolean cachedNightMode;
private int cachedColor;
public RouteLayer(RoutingHelper helper){
this.helper = helper;
}
@ -53,16 +60,29 @@ public class RouteLayer extends OsmandMapLayer {
}
private int getColor(DrawSettings nightMode){
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
boolean n = nightMode != null && nightMode.isNightMode();
if (rrs != cachedRrs || cachedNightMode != n) {
cachedRrs = rrs;
cachedNightMode = n;
cachedColor = view.getResources().getColor(cachedNightMode?R.color.nav_track_fluorescent : R.color.nav_track);
if (cachedRrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, cachedNightMode);
if (req.searchRenderingAttribute("routeColor")) {
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_ATTR_COLOR_VALUE);
}
}
}
return cachedColor;
}
@Override
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
path.reset();
if (helper.getFinalLocation() != null && helper.getRoute().isCalculated()) {
if (nightMode != null && nightMode.isNightMode()) {
paint.setColor(view.getResources().getColor(R.color.nav_track_fluorescent));
} else {
paint.setColor(view.getResources().getColor(R.color.nav_track));
}
paint.setColor(getColor(nightMode));
int w = view.getWidth();
int h = view.getHeight();
Location lastProjection = helper.getLastProjection();