From c3bf97fe7552d2a664b25b27ff6b9dd6b434cfb5 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 10 Mar 2015 23:47:00 +0100 Subject: [PATCH] Fix issue with old rendering --- .../src/net/osmand/render/RenderingRule.java | 2 +- .../osmand/render/RenderingRulesStorage.java | 38 +++++++++++++++---- OsmAnd/src/net/osmand/plus/IconsCache.java | 5 +-- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/render/RenderingRule.java b/OsmAnd-java/src/net/osmand/render/RenderingRule.java index a153b6337f..e597386d47 100644 --- a/OsmAnd-java/src/net/osmand/render/RenderingRule.java +++ b/OsmAnd-java/src/net/osmand/render/RenderingRule.java @@ -95,7 +95,7 @@ public class RenderingRule { public float getFloatPropertyValue(String property) { int i = getPropertyIndex(property); - if(i >= 0){ + if(i >= 0 && floatProperties != null){ return floatProperties[i]; } return 0; diff --git a/OsmAnd-java/src/net/osmand/render/RenderingRulesStorage.java b/OsmAnd-java/src/net/osmand/render/RenderingRulesStorage.java index 766cbb39b5..20059d9b8f 100644 --- a/OsmAnd-java/src/net/osmand/render/RenderingRulesStorage.java +++ b/OsmAnd-java/src/net/osmand/render/RenderingRulesStorage.java @@ -372,10 +372,10 @@ public class RenderingRulesStorage { List apply = applyRules; if(!renderingRule.getIfChildren().isEmpty()) { apply = new ArrayList(); + apply.addAll(renderingRule.getIfChildren()); if(applyRules != null) { apply.addAll(applyRules); } - apply.addAll(renderingRule.getIfChildren()); } Map cattrs = new HashMap(attrs); cattrs.putAll(renderingRule.getAttributes()); @@ -460,22 +460,44 @@ public class RenderingRulesStorage { public static void main(String[] args) throws XmlPullParserException, IOException { - InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml"); +// InputStream is = RenderingRulesStorage.class.getResourceAsStream("default.render.xml"); + String file = "/Users/victorshcherb/osmand/repos/resources/rendering_styles/default.render.xml"; + Map renderingConstants = new LinkedHashMap(); + InputStream is = new FileInputStream(file); if(args != null && args.length > 0) { is = new FileInputStream(args[0]); } - RenderingRulesStorage storage = new RenderingRulesStorage("test", null); + try { + XmlPullParser parser = PlatformUtil.newXMLPullParser(); + parser.setInput(is, "UTF-8"); + int tok; + while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (tok == XmlPullParser.START_TAG) { + String tagName = parser.getName(); + if (tagName.equals("renderingConstant")) { + if (!renderingConstants.containsKey(parser.getAttributeValue("", "name"))) { + renderingConstants.put(parser.getAttributeValue("", "name"), + parser.getAttributeValue("", "value")); + } + } + } + } + } finally { + is.close(); + } + is = new FileInputStream(file); + RenderingRulesStorage storage = new RenderingRulesStorage("default", renderingConstants); final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() { @Override public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref) throws XmlPullParserException, IOException { - RenderingRulesStorage depends = new RenderingRulesStorage("test", null); + RenderingRulesStorage depends = new RenderingRulesStorage(name, null); depends.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream(name + ".render.xml"), ref); return depends; } }; storage.parseRulesFromXmlInputStream(is, resolver); -// printAllRules(storage); + printAllRules(storage); testSearch(storage); } @@ -485,11 +507,11 @@ public class RenderingRulesStorage { // for (int i = 0; i < count; i++) { RenderingRuleSearchRequest searchRequest = new RenderingRuleSearchRequest(storage); searchRequest.setStringFilter(storage.PROPS.R_TAG, "highway"); - searchRequest.setStringFilter(storage.PROPS.R_VALUE, "primary"); + searchRequest.setStringFilter(storage.PROPS.R_VALUE, "residential"); // searchRequest.setStringFilter(storage.PROPS.R_ADDITIONAL, "leaf_type=broadleaved"); // searchRequest.setIntFilter(storage.PROPS.R_LAYER, 1); - searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 9); - searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 9); + searchRequest.setIntFilter(storage.PROPS.R_MINZOOM, 13); + searchRequest.setIntFilter(storage.PROPS.R_MAXZOOM, 13); // searchRequest.setBooleanFilter(storage.PROPS.R_NIGHT_MODE, true); // for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) { // if (customProp.isBoolean()) { diff --git a/OsmAnd/src/net/osmand/plus/IconsCache.java b/OsmAnd/src/net/osmand/plus/IconsCache.java index 68dc3c026d..4aa50d73f5 100644 --- a/OsmAnd/src/net/osmand/plus/IconsCache.java +++ b/OsmAnd/src/net/osmand/plus/IconsCache.java @@ -1,11 +1,8 @@ package net.osmand.plus; -import android.app.Activity; -import android.content.Context; +import gnu.trove.map.hash.TLongObjectHashMap; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; -import gnu.trove.map.hash.TIntObjectHashMap; -import gnu.trove.map.hash.TLongObjectHashMap; public class IconsCache {