From 318e294771e75bff24d4adc1d7db1c4d3c21e62c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 29 Sep 2012 22:38:05 +0200 Subject: [PATCH] Add color definition to render xml --- .../src/net/osmand/render/default.render.xml | 10 ++++++ .../src/net/osmand/plus/views/GPXLayer.java | 31 ++++++++++++++++--- .../src/net/osmand/plus/views/RouteLayer.java | 30 +++++++++++++++--- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/render/default.render.xml b/DataExtractionOSM/src/net/osmand/render/default.render.xml index db506b26dd..6378067314 100644 --- a/DataExtractionOSM/src/net/osmand/render/default.render.xml +++ b/DataExtractionOSM/src/net/osmand/render/default.render.xml @@ -33,6 +33,16 @@ + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 8af9972462..7a962c329f 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -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> 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 l : points) { path.rewind(); diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index f9772418c0..40137b6b7a 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -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();