shields in top bar

This commit is contained in:
Dmitriy Ruban 2019-12-18 19:10:33 +02:00
parent 37961c5123
commit 44e2fe3c72
4 changed files with 112 additions and 49 deletions

View file

@ -695,16 +695,16 @@ public class RouteDataObject {
return false; return false;
} }
public boolean isMotorWayLink() { // public boolean isMotorWayLink() {
int sz = types.length; // int sz = types.length;
for (int i = 0; i < sz; i++) { // for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]); // RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals("highway") && r.getValue().equals("motorway_link")) { // if (r.getTag().equals("highway") && r.getValue().equals("motorway_link")) {
return true; // return true;
} // }
} // }
return false; // return false;
} // }
public String getExitName() { public String getExitName() {
if (pointNames != null && pointNameTypes != null) { if (pointNames != null && pointNameTypes != null) {
@ -742,27 +742,33 @@ public class RouteDataObject {
return null; return null;
} }
public String getShieldColor() { public BinaryMapIndexReader.TagValuePair getShieldColor() {
int sz = types.length; int sz = types.length;
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]); RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals("road_shield_color_1") switch (r.getTag()) {
|| r.getTag().equals("road_shield_color_2") case "road_shield_color_1":
|| r.getTag().equals("road_shield_color_3")) { return new BinaryMapIndexReader.TagValuePair("road_shield_color_1", r.getValue(), 0);
return r.getValue(); case "road_shield_color_2":
return new BinaryMapIndexReader.TagValuePair("road_shield_color_2", r.getValue(), 0);
case "road_shield_color_3":
return new BinaryMapIndexReader.TagValuePair("road_shield_color_3", r.getValue(), 0);
} }
} }
return null; return null;
} }
public String getShieldShape() { public BinaryMapIndexReader.TagValuePair getShieldShape() {
int sz = types.length; int sz = types.length;
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
RouteTypeRule r = region.quickGetEncodingRule(types[i]); RouteTypeRule r = region.quickGetEncodingRule(types[i]);
if (r.getTag().equals("road_shield_shape_1") switch (r.getTag()) {
|| r.getTag().equals("road_shield_shape_2") case "road_shield_shape_1":
|| r.getTag().equals("road_shield_shape_3")) { return new BinaryMapIndexReader.TagValuePair("road_shield_shape_1", r.getValue(), 0);
return r.getValue(); case "road_shield_shape_2":
return new BinaryMapIndexReader.TagValuePair("road_shield_shape_2", r.getValue(), 0);
case "road_shield_shape_3":
return new BinaryMapIndexReader.TagValuePair("road_shield_shape_3", r.getValue(), 0);
} }
} }
return null; return null;

View file

@ -4,6 +4,8 @@ import android.content.Context;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion;
import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
@ -24,6 +26,8 @@ import net.osmand.router.TurnType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -31,6 +35,8 @@ import java.util.List;
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED; import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
public class RouteCalculationResult { public class RouteCalculationResult {
private final static Log log = PlatformUtil.getLog(RouteCalculationResult.class);
private static double distanceClosestToIntermediate = 3000; private static double distanceClosestToIntermediate = 3000;
private static double distanceThresholdToIntermediate = 25; private static double distanceThresholdToIntermediate = 25;
// could not be null and immodifiable! // could not be null and immodifiable!
@ -330,6 +336,14 @@ public class RouteCalculationResult {
info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(),
ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection())); ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
if (s.getObject().isExitPoint() && next.getObject().getHighway().equals("motorway_link")) {
ExitInfo exitInfo = new ExitInfo();
exitInfo.setRef(next.getObject().getExitRef());
exitInfo.setExitStreetName(next.getObject().getExitName());
info.setExitInfo(exitInfo);
}
String highwayTag = s.getObject().getHighway();
// Search for nearest shield properties // Search for nearest shield properties
for (int j = lind; j < list.size(); j++) { for (int j = lind; j < list.size(); j++) {
RouteSegmentResult segment = list.get(j); RouteSegmentResult segment = list.get(j);
@ -337,22 +351,20 @@ public class RouteCalculationResult {
segment.isForwardDirection()); segment.isForwardDirection());
// if it's the same road // if it's the same road
if (segmentRef != null && segmentRef.equals(ref)) { if (segmentRef != null && segmentRef.equals(ref)) {
String shieldColor = segment.getObject().getShieldColor(); BinaryMapIndexReader.TagValuePair colorPair = segment.getObject().getShieldColor();
String shieldShape = segment.getObject().getShieldShape(); BinaryMapIndexReader.TagValuePair shapePair = segment.getObject().getShieldShape();
if (shieldColor != null || shieldShape != null) { if (colorPair != null || shapePair != null) {
info.setShieldColor(shieldColor != null ? shieldColor : "white"); info.setShieldColorValue(colorPair != null ? colorPair.value : "white");
info.setShieldShape(shieldShape != null ? shieldShape : "square"); info.setShieldShapeValue(shapePair != null ? shapePair.value : "square");
if (colorPair != null) {
info.setShieldIconName(getShieldIconName(ctx, ref, highwayTag, colorPair));
} else {
info.setShieldIconName(getShieldIconName(ctx, ref, highwayTag, shapePair));
}
break; break;
} }
} }
} }
if (s.getObject().isExitPoint() && next.getObject().isMotorWayLink()) {
ExitInfo exitInfo = new ExitInfo();
exitInfo.setRef(next.getObject().getExitRef());
exitInfo.setExitStreetName(next.getObject().getExitName());
info.setExitInfo(exitInfo);
}
} }
String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(),
@ -385,6 +397,32 @@ public class RouteCalculationResult {
return segmentsToPopulate; return segmentsToPopulate;
} }
private static String getShieldIconName(OsmandApplication ctx, String ref, String highwayTag,
BinaryMapIndexReader.TagValuePair pair) {
String shieldId = null;
RenderingRulesStorage currentRenderer = ctx.getRendererRegistry().getCurrentSelectedRenderer();
MapRenderRepositories maps = ctx.getResourceManager().getRenderer();
boolean nightMode = ctx.getDaynightHelper().isNightMode();
RenderingRuleSearchRequest request = maps.getSearchRequestWithAppliedCustomRules(currentRenderer, nightMode);
request.setInitialTagValueZoom("highway", highwayTag, 10, null);
request.setIntFilter(request.ALL.R_TEXT_LENGTH, ref.length());
request.setStringFilter(request.ALL.R_NAME_TAG, "road_ref_1");
request.setStringFilter(request.ALL.R_ADDITIONAL,
pair.tag + "=" + pair.value);
if (request.search(RenderingRulesStorage.TEXT_RULES)) {
if (request.getFloatPropertyValue(request.ALL.R_TEXT_SIZE) > 0) {
if (request.isSpecified(request.ALL.R_TEXT_SHIELD)) {
shieldId = request.getStringPropertyValue(request.ALL.R_TEXT_SHIELD);
}
if (request.isSpecified(request.ALL.R_ICON)) {
shieldId = request.getStringPropertyValue(request.ALL.R_ICON);
}
}
}
log.info("Shield name: " + shieldId);
return shieldId;
}
protected static void addMissingTurnsToRoute(List<Location> locations, protected static void addMissingTurnsToRoute(List<Location> locations,
List<RouteDirectionInfo> originalDirections, Location start, LatLon end, ApplicationMode mode, Context ctx, List<RouteDirectionInfo> originalDirections, Location start, LatLon end, ApplicationMode mode, Context ctx,
boolean leftSide){ boolean leftSide){

View file

@ -25,9 +25,11 @@ public class RouteDirectionInfo {
private String destinationName; private String destinationName;
private String shieldColor; private String shieldColorValue;
private String shieldShape; private String shieldShapeValue;
private String shieldIconName;
@Nullable @Nullable
private ExitInfo exitInfo; private ExitInfo exitInfo;
@ -126,19 +128,27 @@ public class RouteDirectionInfo {
this.exitInfo = exitInfo; this.exitInfo = exitInfo;
} }
public String getShieldColor() { public String getShieldColorValue() {
return shieldColor; return shieldColorValue;
} }
public void setShieldColor(String shieldColor) { public void setShieldColorValue(String shieldColorValue) {
this.shieldColor = shieldColor; this.shieldColorValue = shieldColorValue;
} }
public String getShieldShape() { public String getShieldShapeValue() {
return shieldShape; return shieldShapeValue;
} }
public void setShieldShape(String shieldShape) { public void setShieldShapeValue(String shieldShapeValue) {
this.shieldShape = shieldShape; this.shieldShapeValue = shieldShapeValue;
}
public String getShieldIconName() {
return shieldIconName;
}
public void setShieldIconName(String shieldIconName) {
this.shieldIconName = shieldIconName;
} }
} }

View file

@ -1003,8 +1003,11 @@ public class MapInfoWidgetsFactory {
} else { } else {
ref = directionInfo != null ? directionInfo.getRef() : null; ref = directionInfo != null ? directionInfo.getRef() : null;
if (ref != null) { if (ref != null) {
setShield(shieldIcon, assembleShieldString(directionInfo.getShieldColor(), setShield(shieldIcon, assembleShieldString(directionInfo.getShieldColorValue(),
directionInfo.getShieldShape(), ref.length()), ref); directionInfo.getShieldShapeValue(), ref.length()), ref);
AndroidUiHelper.updateVisibility(shieldIcon, true);
} else {
AndroidUiHelper.updateVisibility(shieldIcon, false);
} }
turnDrawable.setColor(R.color.nav_arrow); turnDrawable.setColor(R.color.nav_arrow);
} }
@ -1028,9 +1031,12 @@ public class MapInfoWidgetsFactory {
text = ""; text = "";
} }
if (ref != null) { if (ref != null) {
setShield(shieldIcon, assembleShieldString(next.getShieldColor(), setShield(shieldIcon, assembleShieldString(next.getShieldColorValue(),
next.getShieldShape(), next.getShieldShapeValue(),
ref.length()), ref); ref.length()), ref);
AndroidUiHelper.updateVisibility(shieldIcon, true);
} else {
AndroidUiHelper.updateVisibility(shieldIcon, false);
} }
} else { } else {
text = null; text = null;
@ -1049,9 +1055,12 @@ public class MapInfoWidgetsFactory {
"»"); "»");
} }
if (ref != null) { if (ref != null) {
setShield(shieldIcon, assembleShieldString(rt.getShieldColor(), setShield(shieldIcon, assembleShieldString(rt.getShieldColor().value,
rt.getShieldShape(), rt.getShieldShape().value,
ref.length()), ref); ref.length()), ref);
AndroidUiHelper.updateVisibility(shieldIcon, true);
}else {
AndroidUiHelper.updateVisibility(shieldIcon, false);
} }
if (text == null) { if (text == null) {
text = ""; text = "";
@ -1126,10 +1135,10 @@ public class MapInfoWidgetsFactory {
boolean nightMode = app.getDaynightHelper().isNightMode(); boolean nightMode = app.getDaynightHelper().isNightMode();
RenderingRuleSearchRequest renderingReq = RenderingRuleSearchRequest renderingReq =
mapRenderRepo.getSearchRequestWithAppliedCustomRules(storage, nightMode); mapRenderRepo.getSearchRequestWithAppliedCustomRules(storage, nightMode);
renderingReq.setInitialTagValueZoom("highway", "secondary", 15, null); renderingReq.setInitialTagValueZoom("highway", "secondary", 15, null);
renderingReq.setIntFilter(renderingReq.ALL.R_TEXT_LENGTH, ref.length()); renderingReq.setIntFilter(renderingReq.ALL.R_TEXT_LENGTH, ref.length());
renderingReq.setStringFilter(renderingReq.ALL.R_NAME_TAG, "ref"); renderingReq.setStringFilter(renderingReq.ALL.R_NAME_TAG, "ref");
renderingReq.search(RenderingRulesStorage.POINT_RULES);
OsmandRenderer.RenderingContext rc = new OsmandRenderer.RenderingContext(context); OsmandRenderer.RenderingContext rc = new OsmandRenderer.RenderingContext(context);
TextRenderer textRenderer = new TextRenderer(context); TextRenderer textRenderer = new TextRenderer(context);