Merge branch 'r3.3' of https://github.com/osmandapp/Osmand into r3.3

This commit is contained in:
crimean 2019-03-14 22:13:10 +03:00
commit 635805475a
5 changed files with 112 additions and 77 deletions

View file

@ -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);

View file

@ -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<RouteSegmentResult> route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
private RouteStatistics(List<RouteSegmentResult> 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<RouteSegmentResult> route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
return new RouteStatistics(route, currentRenderer, defaultRenderer, nightMode);
public static RouteStatistics newRouteStatistic(List<RouteSegmentResult> 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<Incline> 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<RouteSegmentResult> 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<RouteSegmentResult> route, StatisticType type, boolean nightMode) {
public RouteStatisticComputer(RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, List<RouteSegmentResult> 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<E, RouteSegmentAttribute<E>> makePartition(List<RouteSegmentAttribute<E>> 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<RouteSegmentResult> route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
super(currentRenderer, defaultRenderer, route, StatisticType.SURFACE, nightMode);
public RouteSurfaceStatisticComputer(List<RouteSegmentResult> 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<RouteSegmentResult> route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
super(currentRenderer, defaultRenderer, route, StatisticType.SMOOTHNESS, nightMode);
public RouteSmoothnessStatisticComputer(List<RouteSegmentResult> 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<RouteSegmentResult> route, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
super(currentRenderer, defaultRenderer, route, StatisticType.CLASS, nightMode);
public RouteClassStatisticComputer(List<RouteSegmentResult> 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<Incline> inclines;
public RouteSteepnessStatisticComputer(List<Incline> inclines, RenderingRulesStorage currentRenderer, RenderingRulesStorage defaultRenderer, boolean nightMode) {
super(currentRenderer, defaultRenderer, null, StatisticType.STEEPNESS, nightMode);
public RouteSteepnessStatisticComputer(List<Incline> 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);
}

View file

@ -46,6 +46,7 @@ public class TransportRoutePlanner {
queue.add(r);
}
double finishTime = ctx.cfg.maxRouteTime;
double maxTravelTimeCmpToWalk = MapUtils.getDistance(start, end) / ctx.cfg.walkSpeed - ctx.cfg.changeTime / 2;
List<TransportRouteSegment> results = new ArrayList<TransportRouteSegment>();
initProgressBar(ctx, start, end);
while (!queue.isEmpty()) {
@ -67,7 +68,8 @@ public class TransportRoutePlanner {
if (segment.getDepth() > ctx.cfg.maxNumberOfChanges) {
continue;
}
if (segment.distFromStart > finishTime + ctx.cfg.finishTimeSeconds) {
if (segment.distFromStart > finishTime + ctx.cfg.finishTimeSeconds ||
segment.distFromStart > maxTravelTimeCmpToWalk) {
break;
}
long segmentId = segment.getId();
@ -148,7 +150,8 @@ public class TransportRoutePlanner {
if (finishTime > finish.distFromStart) {
finishTime = finish.distFromStart;
}
if(finish.distFromStart < finishTime + ctx.cfg.finishTimeSeconds) {
if(finish.distFromStart < finishTime + ctx.cfg.finishTimeSeconds &&
(finish.distFromStart < maxTravelTimeCmpToWalk || results.size() == 0)) {
results.add(finish);
}
}

View file

@ -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<Boolean> 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<String> 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<Boolean> 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<String> 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;
}

View file

@ -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.PublicTransportCard.PublicTransportCardListener;
@ -104,6 +105,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;
@ -522,7 +524,12 @@ public class ShowRouteInfoDialogFragment extends BaseOsmAndFragment implements P
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);