diff --git a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleSearchRequest.java b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleSearchRequest.java index 4c7f7a07a7..345eaeab36 100644 --- a/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleSearchRequest.java +++ b/OsmAnd-java/src/main/java/net/osmand/render/RenderingRuleSearchRequest.java @@ -35,6 +35,19 @@ public class RenderingRuleSearchRequest { saveState(); } + public RenderingRuleSearchRequest(RenderingRuleSearchRequest renderingRuleSearchRequest) { + this.storage = renderingRuleSearchRequest.storage; + this.props = renderingRuleSearchRequest.props; + this.values = new int[renderingRuleSearchRequest.values.length]; + this.fvalues = new float[renderingRuleSearchRequest.fvalues.length]; + this.object = renderingRuleSearchRequest.object; + this.searchResult = renderingRuleSearchRequest.searchResult; + this.ALL = renderingRuleSearchRequest.ALL; + System.arraycopy(renderingRuleSearchRequest.values, 0, values, 0, renderingRuleSearchRequest.values.length); + System.arraycopy(renderingRuleSearchRequest.fvalues, 0, fvalues, 0, renderingRuleSearchRequest.fvalues.length); + saveState(); + } + public void setStringFilter(RenderingRuleProperty p, String filter) { assert p.isInputProperty(); values[p.getId()] = storage.getDictionaryValue(filter); diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java index e9ebba749f..ef2dae665f 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteStatistics.java @@ -16,36 +16,39 @@ public class RouteStatistics { private final RenderingRulesStorage currentRenderer; private final RenderingRulesStorage defaultRenderer; - private final boolean nightMode; + private final RenderingRuleSearchRequest currentSearchRequest; + private final RenderingRuleSearchRequest defaultSearchRequest; - private RouteStatistics(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { + + private RouteStatistics(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { this.route = route; this.currentRenderer = currentRenderer; this.defaultRenderer = defaultRenderer; - this.nightMode = nightMode; + this.defaultSearchRequest = defaultSearchRequest; + this.currentSearchRequest = currentSearchRequest; } - public static RouteStatistics newRouteStatistic(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { - return new RouteStatistics(route, currentRenderer, defaultRenderer, nightMode); + public static RouteStatistics newRouteStatistic(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { + return new RouteStatistics(route, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); } public Statistics getRouteSurfaceStatistic() { - RouteStatisticComputer statisticComputer = new RouteSurfaceStatisticComputer(route, currentRenderer, defaultRenderer, nightMode); + RouteStatisticComputer statisticComputer = new RouteSurfaceStatisticComputer(route, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); return statisticComputer.computeStatistic(); } public Statistics getRouteSmoothnessStatistic() { - RouteStatisticComputer statisticComputer = new RouteSmoothnessStatisticComputer(route, currentRenderer, defaultRenderer, nightMode); + RouteStatisticComputer statisticComputer = new RouteSmoothnessStatisticComputer(route, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); return statisticComputer.computeStatistic(); } public Statistics getRouteClassStatistic() { - RouteStatisticComputer statisticComputer = new RouteClassStatisticComputer(route, currentRenderer, defaultRenderer, nightMode); + RouteStatisticComputer statisticComputer = new RouteClassStatisticComputer(route, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); return statisticComputer.computeStatistic(); } public Statistics getRouteSteepnessStatistic(List inclines) { - RouteStatisticComputer statisticComputer = new RouteSteepnessStatisticComputer(inclines, currentRenderer, defaultRenderer, nightMode); + RouteStatisticComputer statisticComputer = new RouteSteepnessStatisticComputer(inclines, currentRenderer, defaultRenderer, currentSearchRequest, defaultSearchRequest); return statisticComputer.computeStatistic(); } @@ -55,16 +58,19 @@ public class RouteStatistics { private final List route; private final StatisticType type; - protected final RenderingRulesStorage currentRenderer; - protected final RenderingRulesStorage defaultRenderer; - protected final boolean nightMode; + final RenderingRulesStorage currentRenderer; + final RenderingRulesStorage defaultRenderer; + final RenderingRuleSearchRequest currentRenderingRuleSearchRequest; + final RenderingRuleSearchRequest defaultRenderingRuleSearchRequest; - public RouteStatisticComputer(RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, List route, StatisticType type, boolean nightMode) { + public RouteStatisticComputer(RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, List route, StatisticType type, + RenderingRuleSearchRequest currentRenderingRuleSearchRequest, RenderingRuleSearchRequest defaultRenderingRuleSearchRequest) { this.route = route; this.currentRenderer = currentRenderer; this.defaultRenderer = defaultRenderer; this.type = type; - this.nightMode = nightMode; + this.currentRenderingRuleSearchRequest = currentRenderingRuleSearchRequest; + this.defaultRenderingRuleSearchRequest = defaultRenderingRuleSearchRequest; } protected Map> makePartition(List> routeAttributes) { @@ -121,13 +127,17 @@ public class RouteStatistics { return new Statistics<>(routeAttributes, partition, totalDistance, type); } + RenderingRuleSearchRequest getSearchRequest(boolean useCurrentRenderer) { + return new RenderingRuleSearchRequest(useCurrentRenderer ? currentRenderingRuleSearchRequest : defaultRenderingRuleSearchRequest); + } + public int getColor(E attribute) { int color = 0; - RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderer); + RenderingRuleSearchRequest currentRequest = getSearchRequest(true); if (searchRenderingAttribute(currentRenderer, currentRequest, attribute)) { color = currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE); } else { - RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderer); + RenderingRuleSearchRequest defaultRequest = getSearchRequest(false); if (searchRenderingAttribute(defaultRenderer, defaultRequest, attribute)) { color = defaultRequest.getIntPropertyValue(defaultRenderer.PROPS.R_ATTR_COLOR_VALUE); } @@ -147,8 +157,8 @@ public class RouteStatistics { private static final String SURFACE_ATTR = "surface"; private static final String SURFACE_COLOR_ATTR = "surfaceColor"; - public RouteSurfaceStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { - super(currentRenderer, defaultRenderer, route, StatisticType.SURFACE, nightMode); + public RouteSurfaceStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { + super(currentRenderer, defaultRenderer, route, StatisticType.SURFACE, currentSearchRequest, defaultSearchRequest); } @Override @@ -157,11 +167,11 @@ public class RouteStatistics { if (segmentSurface == null) { return UNDEFINED_ATTR; } - RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderer); + RenderingRuleSearchRequest currentRequest = getSearchRequest(true); if (searchRenderingAttribute(currentRenderer, currentRequest, segmentSurface)) { return segmentSurface; } else { - RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderer); + RenderingRuleSearchRequest defaultRequest = getSearchRequest(false); if (searchRenderingAttribute(defaultRenderer, defaultRequest, segmentSurface)) { return segmentSurface; } @@ -177,7 +187,6 @@ public class RouteStatistics { @Override public boolean searchRenderingAttribute(RenderingRulesStorage rrs, RenderingRuleSearchRequest req, String attribute) { String additional = SURFACE_ATTR + "=" + attribute; - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); req.setStringFilter(rrs.PROPS.R_ATTR_STRING_VALUE, SURFACE_ATTR + "_" + attribute); req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional); return req.searchRenderingAttribute(SURFACE_COLOR_ATTR); @@ -189,8 +198,8 @@ public class RouteStatistics { private static final String SMOOTHNESS_ATTR = "smoothness"; private static final String SMOOTHNESS_COLOR_ATTR = "smoothnessColor"; - public RouteSmoothnessStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { - super(currentRenderer, defaultRenderer, route, StatisticType.SMOOTHNESS, nightMode); + public RouteSmoothnessStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { + super(currentRenderer, defaultRenderer, route, StatisticType.SMOOTHNESS, currentSearchRequest, defaultSearchRequest); } @Override @@ -199,11 +208,11 @@ public class RouteStatistics { if (segmentSmoothness == null) { return UNDEFINED_ATTR; } - RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderer); + RenderingRuleSearchRequest currentRequest = getSearchRequest(true); if (searchRenderingAttribute(currentRenderer, currentRequest, segmentSmoothness)) { return segmentSmoothness; } else { - RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderer); + RenderingRuleSearchRequest defaultRequest = getSearchRequest(false); if (searchRenderingAttribute(defaultRenderer, defaultRequest, segmentSmoothness)) { return segmentSmoothness; } @@ -219,7 +228,6 @@ public class RouteStatistics { @Override public boolean searchRenderingAttribute(RenderingRulesStorage rrs, RenderingRuleSearchRequest req, String attribute) { String additional = SMOOTHNESS_ATTR + "=" + attribute; - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); req.setStringFilter(rrs.PROPS.R_ATTR_STRING_VALUE, SMOOTHNESS_ATTR + "_" + attribute); req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional); return req.searchRenderingAttribute(SMOOTHNESS_COLOR_ATTR); @@ -231,8 +239,8 @@ public class RouteStatistics { private static final String HIGHWAY_ATTR = "highway"; private static final String ROAD_CLASS_COLOR_ATTR = "roadClassColor"; - public RouteClassStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { - super(currentRenderer, defaultRenderer, route, StatisticType.CLASS, nightMode); + public RouteClassStatisticComputer(List route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { + super(currentRenderer, defaultRenderer, route, StatisticType.CLASS, currentSearchRequest, defaultSearchRequest); } @Override @@ -248,11 +256,11 @@ public class RouteStatistics { @Override public int getColor(String attribute) { int color = 0; - RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderer); + RenderingRuleSearchRequest currentRequest = getSearchRequest(true); if (currentRequest.searchRenderingAttribute(attribute)) { color = currentRequest.getIntPropertyValue(currentRenderer.PROPS.R_ATTR_COLOR_VALUE); } else { - RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderer); + RenderingRuleSearchRequest defaultRequest = getSearchRequest(false); if (defaultRequest.searchRenderingAttribute(attribute)) { color = defaultRequest.getIntPropertyValue(defaultRenderer.PROPS.R_ATTR_COLOR_VALUE); } @@ -268,7 +276,6 @@ public class RouteStatistics { @Override public boolean searchRenderingAttribute(RenderingRulesStorage rrs, RenderingRuleSearchRequest req, String attribute) { - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); req.setStringFilter(rrs.PROPS.R_TAG, HIGHWAY_ATTR); req.setStringFilter(rrs.PROPS.R_VALUE, attribute); return req.searchRenderingAttribute(ROAD_CLASS_COLOR_ATTR); @@ -276,14 +283,14 @@ public class RouteStatistics { private String getAttributeType(String attribute) { String type = null; - RenderingRuleSearchRequest currentRequest = new RenderingRuleSearchRequest(currentRenderer); + RenderingRuleSearchRequest currentRequest = getSearchRequest(true); if (searchRenderingAttribute(currentRenderer, currentRequest, attribute)) { type = currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE); if (currentRequest.searchRenderingAttribute(type)) { type = currentRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE); } } else { - RenderingRuleSearchRequest defaultRequest = new RenderingRuleSearchRequest(defaultRenderer); + RenderingRuleSearchRequest defaultRequest = getSearchRequest(false); if (searchRenderingAttribute(defaultRenderer, defaultRequest, attribute)) { type = defaultRequest.getStringPropertyValue(currentRenderer.PROPS.R_ATTR_STRING_VALUE); if (defaultRequest.searchRenderingAttribute(type)) { @@ -302,8 +309,8 @@ public class RouteStatistics { private final List inclines; - public RouteSteepnessStatisticComputer(List inclines, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) { - super(currentRenderer, defaultRenderer, null, StatisticType.STEEPNESS, nightMode); + public RouteSteepnessStatisticComputer(List inclines, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, RenderingRuleSearchRequest currentSearchRequest, RenderingRuleSearchRequest defaultSearchRequest) { + super(currentRenderer, defaultRenderer, null, StatisticType.STEEPNESS, currentSearchRequest, defaultSearchRequest); this.inclines = inclines; } @@ -365,7 +372,6 @@ public class RouteStatistics { range.append(upperBoundary < 0 ? "_" : "-"); range.append(upperBoundary); String additional = STEEPNESS_ATTR + "=" + range; - req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode); req.setStringFilter(rrs.PROPS.R_ADDITIONAL, additional); return req.searchRenderingAttribute(STEEPNESS_COLOR_ATTR); } diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index 2575c4d6fc..17b4da9d4b 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -641,44 +641,7 @@ public class MapRenderRepositories { boolean nightMode = app.getDaynightHelper().isNightMode(); // boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get(); RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer(); - RenderingRuleSearchRequest renderingReq = new RenderingRuleSearchRequest(storage); - renderingReq.setBooleanFilter(renderingReq.ALL.R_NIGHT_MODE, nightMode); - for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) { - if (customProp.isBoolean()) { - if(customProp.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) { - renderingReq.setBooleanFilter(customProp, true); - } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) { - renderingReq.setBooleanFilter(customProp, false); - } else { - CommonPreference pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName()); - renderingReq.setBooleanFilter(customProp, pref.get()); - } - } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) { - if (customProp.isString()) { - renderingReq.setStringFilter(customProp, ""); - } else { - renderingReq.setIntFilter(customProp, 0); - } - } else { - CommonPreference settings = prefs.getCustomRenderProperty(customProp.getAttrName()); - String res = settings.get(); - if (!Algorithms.isEmpty(res)) { - if (customProp.isString()) { - renderingReq.setStringFilter(customProp, res); - } else { - try { - renderingReq.setIntFilter(customProp, Integer.parseInt(res)); - } catch (NumberFormatException e) { - e.printStackTrace(); - } - } - } else { - if (customProp.isString()) { - renderingReq.setStringFilter(customProp, ""); - } - } - } - } + RenderingRuleSearchRequest renderingReq = getSearchRequestWithAppliedCustomRules(storage, nightMode); renderingReq.saveState(); NativeOsmandLibrary nativeLib = !prefs.SAFE_MODE.get() ? NativeOsmandLibrary.getLibrary(storage, context) : null; @@ -880,6 +843,49 @@ public class MapRenderRepositories { } + public RenderingRuleSearchRequest getSearchRequestWithAppliedCustomRules(RenderingRulesStorage storage, boolean nightMode) { + // boolean moreDetail = prefs.SHOW_MORE_MAP_DETAIL.get(); + RenderingRuleSearchRequest renderingReq = new RenderingRuleSearchRequest(storage); + renderingReq.setBooleanFilter(renderingReq.ALL.R_NIGHT_MODE, nightMode); + for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) { + if (customProp.isBoolean()) { + if(customProp.getAttrName().equals(RenderingRuleStorageProperties.A_ENGINE_V1)) { + renderingReq.setBooleanFilter(customProp, true); + } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) { + renderingReq.setBooleanFilter(customProp, false); + } else { + CommonPreference pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName()); + renderingReq.setBooleanFilter(customProp, pref.get()); + } + } else if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) { + if (customProp.isString()) { + renderingReq.setStringFilter(customProp, ""); + } else { + renderingReq.setIntFilter(customProp, 0); + } + } else { + CommonPreference settings = prefs.getCustomRenderProperty(customProp.getAttrName()); + String res = settings.get(); + if (!Algorithms.isEmpty(res)) { + if (customProp.isString()) { + renderingReq.setStringFilter(customProp, res); + } else { + try { + renderingReq.setIntFilter(customProp, Integer.parseInt(res)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } else { + if (customProp.isString()) { + renderingReq.setStringFilter(customProp, ""); + } + } + } + } + return renderingReq; + } + public Bitmap getBitmap() { return bmp; } diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowRouteInfoDialogFragment.java index e023eb2ebc..cb76899951 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ShowRouteInfoDialogFragment.java @@ -90,6 +90,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView; import net.osmand.plus.mapcontextmenu.MenuController; +import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard; import net.osmand.plus.routepreparationmenu.cards.RouteInfoCard; @@ -103,6 +104,7 @@ import net.osmand.plus.views.TurnPathHelper; import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.style.CustomTypefaceSpan; +import net.osmand.render.RenderingRuleSearchRequest; import net.osmand.render.RenderingRulesStorage; import net.osmand.router.RouteSegmentResult; import net.osmand.router.RouteStatistics; @@ -518,7 +520,12 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment { if (route != null) { RenderingRulesStorage currentRenderer = app.getRendererRegistry().getCurrentSelectedRenderer(); RenderingRulesStorage defaultRender = app.getRendererRegistry().defaultRender(); - RouteStatistics routeStatistics = RouteStatistics.newRouteStatistic(route, currentRenderer,defaultRender, nightMode); + + MapRenderRepositories maps = app.getResourceManager().getRenderer(); + RenderingRuleSearchRequest currentSearchRequest = maps.getSearchRequestWithAppliedCustomRules(currentRenderer, nightMode); + RenderingRuleSearchRequest defaultSearchRequest = maps.getSearchRequestWithAppliedCustomRules(defaultRender, nightMode); + + RouteStatistics routeStatistics = RouteStatistics.newRouteStatistic(route, currentRenderer, defaultRender, currentSearchRequest, defaultSearchRequest); GPXUtilities.GPXTrackAnalysis analysis = gpx.getAnalysis(0); RouteInfoCard routeClassCard = new RouteInfoCard(mapActivity, routeStatistics.getRouteClassStatistic(), analysis);