Merge pull request #9026 from osmandapp/fixNextStreetName
Fix next street name showing too early #8988
This commit is contained in:
commit
1b269f8a00
2 changed files with 86 additions and 122 deletions
|
@ -915,9 +915,6 @@ public class RoutingHelper {
|
|||
|
||||
|
||||
public static String formatStreetName(String name, String ref, String destination, String towards) {
|
||||
//Hardy, 2016-08-05:
|
||||
//Now returns: (ref) + ((" ")+name) + ((" ")+"toward "+dest) or ""
|
||||
|
||||
String formattedStreetName = "";
|
||||
if (ref != null && ref.length() > 0) {
|
||||
formattedStreetName = ref;
|
||||
|
@ -938,56 +935,78 @@ public class RoutingHelper {
|
|||
|
||||
}
|
||||
|
||||
// protected boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed){
|
||||
// if(dist < etalon || ((dist / currentSpeed) < (etalon / defSpeed))){
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
|
||||
public synchronized String getCurrentName(TurnType[] next, NextDirectionInfo n){
|
||||
public static class CurrentStreetName {
|
||||
public String text;
|
||||
public TurnType turnType;
|
||||
public boolean showMarker; // turn type has priority over showMarker
|
||||
public RouteDataObject shieldObject;
|
||||
public String exitRef;
|
||||
}
|
||||
|
||||
public synchronized CurrentStreetName getCurrentName(NextDirectionInfo n){
|
||||
CurrentStreetName streetName = new CurrentStreetName();
|
||||
Location l = lastFixedLocation;
|
||||
float speed = 0;
|
||||
if(l != null && l.hasSpeed()) {
|
||||
if (l != null && l.hasSpeed()) {
|
||||
speed = l.getSpeed();
|
||||
}
|
||||
if(next != null && n.directionInfo != null) {
|
||||
next[0] = n.directionInfo.getTurnType();
|
||||
}
|
||||
if(n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
|
||||
boolean isSet = false;
|
||||
// 1. turn is imminent
|
||||
if (n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
|
||||
voiceRouter.isDistanceLess(speed, n.distanceTo, voiceRouter.PREPARE_DISTANCE * 0.75f)) {
|
||||
String nm = n.directionInfo.getStreetName();
|
||||
String rf = n.directionInfo.getRef();
|
||||
String dn = n.directionInfo.getDestinationName();
|
||||
|
||||
return formatStreetName(nm, null, dn, "»");
|
||||
isSet = !(Algorithms.isEmpty(nm) && Algorithms.isEmpty(rf) && Algorithms.isEmpty(dn));
|
||||
streetName.text = formatStreetName(nm, null, dn, "»");
|
||||
streetName.turnType = n.directionInfo.getTurnType();
|
||||
streetName.shieldObject = n.directionInfo.getRouteDataObject();
|
||||
if (streetName.turnType == null) {
|
||||
streetName.turnType = TurnType.valueOf(TurnType.C, false);
|
||||
}
|
||||
if (n.directionInfo.getExitInfo() != null) {
|
||||
streetName.exitRef = n.directionInfo.getExitInfo().getRef();
|
||||
if (!Algorithms.isEmpty(n.directionInfo.getExitInfo().getExitStreetName())) {
|
||||
streetName.text = n.directionInfo.getExitInfo().getExitStreetName();
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2. display current road street name
|
||||
if (!isSet) {
|
||||
RouteSegmentResult rs = getCurrentSegmentResult();
|
||||
if(rs != null) {
|
||||
String name = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(name)) {
|
||||
return name;
|
||||
if (rs != null) {
|
||||
streetName.text = getRouteSegmentStreetName(rs, false);
|
||||
if (Algorithms.isEmpty(streetName.text)) {
|
||||
isSet = !Algorithms.isEmpty(getRouteSegmentStreetName(rs, true));
|
||||
} else {
|
||||
isSet = true;
|
||||
}
|
||||
streetName.showMarker = true;
|
||||
streetName.shieldObject = rs.getObject();
|
||||
}
|
||||
}
|
||||
rs = getNextStreetSegmentResult();
|
||||
if(rs != null) {
|
||||
String name = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(name)) {
|
||||
if(next != null) {
|
||||
next[0] = TurnType.valueOf(TurnType.C, false);
|
||||
}
|
||||
return name;
|
||||
// 3. display next road street name if this one empty
|
||||
if (!isSet) {
|
||||
RouteSegmentResult rs = getNextStreetSegmentResult();
|
||||
if (rs != null) {
|
||||
streetName.text = getRouteSegmentStreetName(rs, false);
|
||||
streetName.turnType = TurnType.valueOf(TurnType.C, false);
|
||||
streetName.shieldObject = rs.getObject();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
if (streetName.turnType == null) {
|
||||
streetName.showMarker = true;
|
||||
}
|
||||
return streetName;
|
||||
}
|
||||
|
||||
private String getRouteSegmentStreetName(RouteSegmentResult rs) {
|
||||
private String getRouteSegmentStreetName(RouteSegmentResult rs, boolean includeRef) {
|
||||
String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get());
|
||||
// String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
|
||||
String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
|
||||
String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get(),
|
||||
settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
|
||||
return formatStreetName(nm, null, dn, "»");
|
||||
return formatStreetName(nm, includeRef ? rf : null, dn, "»");
|
||||
}
|
||||
|
||||
public RouteSegmentResult getCurrentSegmentResult() {
|
||||
|
|
|
@ -931,11 +931,11 @@ public class MapInfoWidgetsFactory {
|
|||
private View waypointInfoBar;
|
||||
private LocationPointWrapper lastPoint;
|
||||
private TurnDrawable turnDrawable;
|
||||
private boolean showMarker;
|
||||
private int shadowRad;
|
||||
RouteCalculationResult.NextDirectionInfo calc1;
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(TopTextView.class);
|
||||
private boolean showMarker;
|
||||
|
||||
public TopTextView(OsmandApplication app, MapActivity map) {
|
||||
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map, true);
|
||||
|
@ -981,138 +981,80 @@ public class MapInfoWidgetsFactory {
|
|||
}
|
||||
|
||||
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
String text = null;
|
||||
TurnType[] type = new TurnType[1];
|
||||
boolean showNextTurn = false;
|
||||
boolean showMarker = this.showMarker;
|
||||
boolean showExitInfo = false;
|
||||
boolean showShield = false;
|
||||
boolean imminentTurn = false;
|
||||
ExitInfo exitInfo = null;
|
||||
RouteDataObject object = null;
|
||||
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
RoutingHelper.CurrentStreetName streetName = null;
|
||||
boolean showClosestWaypointFirstInAddress = true;
|
||||
if (routingHelper != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
|
||||
if (routingHelper.isFollowingMode()) {
|
||||
if (settings.SHOW_STREET_NAME.get()) {
|
||||
RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc1, true);
|
||||
text = routingHelper.getCurrentName(type, nextDirInfo);
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
if (type[0] == null) {
|
||||
showMarker = true;
|
||||
} else {
|
||||
streetName = routingHelper.getCurrentName(nextDirInfo);
|
||||
turnDrawable.setColor(R.color.nav_arrow);
|
||||
}
|
||||
}
|
||||
|
||||
RouteDirectionInfo directionInfo = nextDirInfo.directionInfo;
|
||||
|
||||
if (nextDirInfo.imminent >= 0) {
|
||||
imminentTurn = true;
|
||||
} else {
|
||||
imminentTurn = false;
|
||||
}
|
||||
|
||||
if (directionInfo != null && directionInfo.getExitInfo() != null) {
|
||||
exitInfo = directionInfo.getExitInfo();
|
||||
showExitInfo = true;
|
||||
} else {
|
||||
showExitInfo = false;
|
||||
}
|
||||
|
||||
if (showExitInfo) {
|
||||
if(!Algorithms.isEmpty(exitInfo.getExitStreetName())) {
|
||||
text = exitInfo.getExitStreetName();
|
||||
}
|
||||
}
|
||||
|
||||
if (directionInfo != null && directionInfo.getRouteDataObject() != null) {
|
||||
object = directionInfo.getRouteDataObject();
|
||||
showShield = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int di = MapRouteInfoMenu.getDirectionInfo();
|
||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() &&
|
||||
di < routingHelper.getRouteDirections().size()) {
|
||||
showNextTurn = true;
|
||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && di < routingHelper.getRouteDirections().size()) {
|
||||
showClosestWaypointFirstInAddress = false;
|
||||
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
||||
type[0] = next.getTurnType();
|
||||
streetName = routingHelper.getCurrentName(routingHelper.getNextRouteDirectionInfo(calc1, true));
|
||||
turnDrawable.setColor(R.color.nav_arrow_distant);
|
||||
text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
||||
if (text == null) {
|
||||
text = "";
|
||||
}
|
||||
} else {
|
||||
text = null;
|
||||
}
|
||||
}
|
||||
} else if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() &&
|
||||
settings.SHOW_STREET_NAME.get()) {
|
||||
streetName = new RoutingHelper.CurrentStreetName();
|
||||
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
||||
if (rt != null) {
|
||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||
text = RoutingHelper.formatStreetName(
|
||||
streetName.text = RoutingHelper.formatStreetName(
|
||||
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
|
||||
rt.getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
|
||||
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
|
||||
"»");
|
||||
}
|
||||
if (text == null) {
|
||||
text = "";
|
||||
} else {
|
||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||
if (!Algorithms.isEmpty(text) && lastKnownLocation != null) {
|
||||
double dist =
|
||||
CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
|
||||
if (!Algorithms.isEmpty(streetName.text) && lastKnownLocation != null) {
|
||||
double dist = CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
|
||||
if (dist < 50) {
|
||||
showMarker = true;
|
||||
streetName.showMarker = true;
|
||||
} else {
|
||||
text = map.getResources().getString(R.string.shared_string_near) + " " + text;
|
||||
streetName.text = map.getResources().getString(R.string.shared_string_near) + " " + streetName.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) {
|
||||
updateVisibility(false);
|
||||
} else if (!showNextTurn && updateWaypoint()) {
|
||||
} else if (!showClosestWaypointFirstInAddress && updateWaypoint()) {
|
||||
updateVisibility(true);
|
||||
AndroidUiHelper.updateVisibility(addressText, false);
|
||||
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
||||
} else if (text == null) {
|
||||
} else if (streetName == null) {
|
||||
updateVisibility(false);
|
||||
} else {
|
||||
updateVisibility(true);
|
||||
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
|
||||
AndroidUiHelper.updateVisibility(addressText, true);
|
||||
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
||||
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
||||
this.showMarker = showMarker;
|
||||
if (showShield && setRoadShield(shieldIcon, object)) {
|
||||
|
||||
if (streetName.shieldObject != null && setRoadShield(shieldIcon, streetName.shieldObject)) {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
}
|
||||
|
||||
if (showExitInfo) {
|
||||
String exitRef = exitInfo.getRef();
|
||||
if (!Algorithms.isEmpty(exitRef) && imminentTurn) {
|
||||
exitRefText.setText(exitRef);
|
||||
if (!Algorithms.isEmpty(streetName.exitRef) ) {
|
||||
exitRefText.setText(streetName.exitRef);
|
||||
AndroidUiHelper.updateVisibility(exitRefText, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
||||
}
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
||||
}
|
||||
if (update) {
|
||||
if (type[0] != null) {
|
||||
if (turnDrawable.setTurnType(streetName.turnType) || streetName.showMarker != this.showMarker) {
|
||||
this.showMarker = streetName.showMarker;
|
||||
if (streetName.turnType != null) {
|
||||
turnIcon.invalidateDrawable(turnDrawable);
|
||||
turnIcon.setImageDrawable(turnDrawable);
|
||||
AndroidUiHelper.updateVisibility(turnIcon, true);
|
||||
} else if (showMarker) {
|
||||
} else if (streetName.showMarker) {
|
||||
Drawable marker = map.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance);
|
||||
turnIcon.setImageDrawable(marker);
|
||||
AndroidUiHelper.updateVisibility(turnIcon, true);
|
||||
|
@ -1120,9 +1062,12 @@ public class MapInfoWidgetsFactory {
|
|||
AndroidUiHelper.updateVisibility(turnIcon, false);
|
||||
}
|
||||
}
|
||||
if (!text.equals(addressText.getText().toString())) {
|
||||
addressTextShadow.setText(text);
|
||||
addressText.setText(text);
|
||||
if(streetName.text == null || streetName.text.isEmpty()) {
|
||||
addressTextShadow.setText("");
|
||||
addressText.setText("");
|
||||
} else if (!streetName.text.equals(addressText.getText().toString())) {
|
||||
addressTextShadow.setText(streetName.text);
|
||||
addressText.setText(streetName.text );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue