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) {
|
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 = "";
|
String formattedStreetName = "";
|
||||||
if (ref != null && ref.length() > 0) {
|
if (ref != null && ref.length() > 0) {
|
||||||
formattedStreetName = ref;
|
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;
|
Location l = lastFixedLocation;
|
||||||
float speed = 0;
|
float speed = 0;
|
||||||
if(l != null && l.hasSpeed()) {
|
if (l != null && l.hasSpeed()) {
|
||||||
speed = l.getSpeed();
|
speed = l.getSpeed();
|
||||||
}
|
}
|
||||||
if(next != null && n.directionInfo != null) {
|
boolean isSet = false;
|
||||||
next[0] = n.directionInfo.getTurnType();
|
// 1. turn is imminent
|
||||||
}
|
if (n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
|
||||||
if(n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() &&
|
|
||||||
voiceRouter.isDistanceLess(speed, n.distanceTo, voiceRouter.PREPARE_DISTANCE * 0.75f)) {
|
voiceRouter.isDistanceLess(speed, n.distanceTo, voiceRouter.PREPARE_DISTANCE * 0.75f)) {
|
||||||
String nm = n.directionInfo.getStreetName();
|
String nm = n.directionInfo.getStreetName();
|
||||||
String rf = n.directionInfo.getRef();
|
String rf = n.directionInfo.getRef();
|
||||||
String dn = n.directionInfo.getDestinationName();
|
String dn = n.directionInfo.getDestinationName();
|
||||||
|
isSet = !(Algorithms.isEmpty(nm) && Algorithms.isEmpty(rf) && Algorithms.isEmpty(dn));
|
||||||
return formatStreetName(nm, null, dn, "»");
|
streetName.text = formatStreetName(nm, null, dn, "»");
|
||||||
}
|
streetName.turnType = n.directionInfo.getTurnType();
|
||||||
RouteSegmentResult rs = getCurrentSegmentResult();
|
streetName.shieldObject = n.directionInfo.getRouteDataObject();
|
||||||
if(rs != null) {
|
if (streetName.turnType == null) {
|
||||||
String name = getRouteSegmentStreetName(rs);
|
streetName.turnType = TurnType.valueOf(TurnType.C, false);
|
||||||
if (!Algorithms.isEmpty(name)) {
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
}
|
if (n.directionInfo.getExitInfo() != null) {
|
||||||
rs = getNextStreetSegmentResult();
|
streetName.exitRef = n.directionInfo.getExitInfo().getRef();
|
||||||
if(rs != null) {
|
if (!Algorithms.isEmpty(n.directionInfo.getExitInfo().getExitStreetName())) {
|
||||||
String name = getRouteSegmentStreetName(rs);
|
streetName.text = n.directionInfo.getExitInfo().getExitStreetName();
|
||||||
if (!Algorithms.isEmpty(name)) {
|
|
||||||
if(next != null) {
|
|
||||||
next[0] = TurnType.valueOf(TurnType.C, false);
|
|
||||||
}
|
}
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
// 2. display current road street name
|
||||||
|
if (!isSet) {
|
||||||
|
RouteSegmentResult rs = getCurrentSegmentResult();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 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(),
|
String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get(),
|
||||||
settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
|
settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
|
||||||
return formatStreetName(nm, null, dn, "»");
|
return formatStreetName(nm, includeRef ? rf : null, dn, "»");
|
||||||
}
|
}
|
||||||
|
|
||||||
public RouteSegmentResult getCurrentSegmentResult() {
|
public RouteSegmentResult getCurrentSegmentResult() {
|
||||||
|
|
|
@ -931,11 +931,11 @@ public class MapInfoWidgetsFactory {
|
||||||
private View waypointInfoBar;
|
private View waypointInfoBar;
|
||||||
private LocationPointWrapper lastPoint;
|
private LocationPointWrapper lastPoint;
|
||||||
private TurnDrawable turnDrawable;
|
private TurnDrawable turnDrawable;
|
||||||
private boolean showMarker;
|
|
||||||
private int shadowRad;
|
private int shadowRad;
|
||||||
RouteCalculationResult.NextDirectionInfo calc1;
|
RouteCalculationResult.NextDirectionInfo calc1;
|
||||||
|
|
||||||
private static final Log LOG = PlatformUtil.getLog(TopTextView.class);
|
private static final Log LOG = PlatformUtil.getLog(TopTextView.class);
|
||||||
|
private boolean showMarker;
|
||||||
|
|
||||||
public TopTextView(OsmandApplication app, MapActivity map) {
|
public TopTextView(OsmandApplication app, MapActivity map) {
|
||||||
turnDrawable = new NextTurnInfoWidget.TurnDrawable(map, true);
|
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 != null && routingHelper.isRouteCalculated() && !routingHelper.isDeviatedFromRoute()) {
|
||||||
if (routingHelper.isFollowingMode()) {
|
if (routingHelper.isFollowingMode()) {
|
||||||
if (settings.SHOW_STREET_NAME.get()) {
|
if (settings.SHOW_STREET_NAME.get()) {
|
||||||
RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc1, true);
|
RouteCalculationResult.NextDirectionInfo nextDirInfo = routingHelper.getNextRouteDirectionInfo(calc1, true);
|
||||||
text = routingHelper.getCurrentName(type, nextDirInfo);
|
streetName = routingHelper.getCurrentName(nextDirInfo);
|
||||||
if (text == null) {
|
turnDrawable.setColor(R.color.nav_arrow);
|
||||||
text = "";
|
|
||||||
} else {
|
|
||||||
if (type[0] == null) {
|
|
||||||
showMarker = true;
|
|
||||||
} else {
|
|
||||||
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 {
|
} else {
|
||||||
int di = MapRouteInfoMenu.getDirectionInfo();
|
int di = MapRouteInfoMenu.getDirectionInfo();
|
||||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() &&
|
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && di < routingHelper.getRouteDirections().size()) {
|
||||||
di < routingHelper.getRouteDirections().size()) {
|
showClosestWaypointFirstInAddress = false;
|
||||||
showNextTurn = true;
|
|
||||||
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
||||||
type[0] = next.getTurnType();
|
streetName = routingHelper.getCurrentName(routingHelper.getNextRouteDirectionInfo(calc1, true));
|
||||||
turnDrawable.setColor(R.color.nav_arrow_distant);
|
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() &&
|
} else if (map.getMapViewTrackingUtilities().isMapLinkedToLocation() &&
|
||||||
settings.SHOW_STREET_NAME.get()) {
|
settings.SHOW_STREET_NAME.get()) {
|
||||||
|
streetName = new RoutingHelper.CurrentStreetName();
|
||||||
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
RouteDataObject rt = locationProvider.getLastKnownRouteSegment();
|
||||||
if (rt != null) {
|
if (rt != null) {
|
||||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
||||||
text = RoutingHelper.formatStreetName(
|
streetName.text = RoutingHelper.formatStreetName(
|
||||||
rt.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()),
|
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.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)),
|
rt.getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rt.bearingVsRouteDirection(lastKnownLocation)),
|
||||||
"»");
|
"»");
|
||||||
}
|
if (!Algorithms.isEmpty(streetName.text) && lastKnownLocation != null) {
|
||||||
if (text == null) {
|
double dist = CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
|
||||||
text = "";
|
|
||||||
} else {
|
|
||||||
Location lastKnownLocation = locationProvider.getLastKnownLocation();
|
|
||||||
if (!Algorithms.isEmpty(text) && lastKnownLocation != null) {
|
|
||||||
double dist =
|
|
||||||
CurrentPositionHelper.getOrthogonalDistance(rt, lastKnownLocation);
|
|
||||||
if (dist < 50) {
|
if (dist < 50) {
|
||||||
showMarker = true;
|
streetName.showMarker = true;
|
||||||
} else {
|
} 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) {
|
if (map.isTopToolbarActive() || !map.getContextMenu().shouldShowTopControls() || MapRouteInfoMenu.chooseRoutesVisible || MapRouteInfoMenu.waypointsVisible) {
|
||||||
updateVisibility(false);
|
updateVisibility(false);
|
||||||
} else if (!showNextTurn && updateWaypoint()) {
|
} else if (!showClosestWaypointFirstInAddress && updateWaypoint()) {
|
||||||
updateVisibility(true);
|
updateVisibility(true);
|
||||||
AndroidUiHelper.updateVisibility(addressText, false);
|
AndroidUiHelper.updateVisibility(addressText, false);
|
||||||
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
||||||
} else if (text == null) {
|
} else if (streetName == null) {
|
||||||
updateVisibility(false);
|
updateVisibility(false);
|
||||||
} else {
|
} else {
|
||||||
updateVisibility(true);
|
updateVisibility(true);
|
||||||
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
|
AndroidUiHelper.updateVisibility(waypointInfoBar, false);
|
||||||
AndroidUiHelper.updateVisibility(addressText, true);
|
AndroidUiHelper.updateVisibility(addressText, true);
|
||||||
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
||||||
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
|
||||||
this.showMarker = showMarker;
|
if (streetName.shieldObject != null && setRoadShield(shieldIcon, streetName.shieldObject)) {
|
||||||
if (showShield && setRoadShield(shieldIcon, object)) {
|
|
||||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||||
} else {
|
} else {
|
||||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showExitInfo) {
|
if (!Algorithms.isEmpty(streetName.exitRef) ) {
|
||||||
String exitRef = exitInfo.getRef();
|
exitRefText.setText(streetName.exitRef);
|
||||||
if (!Algorithms.isEmpty(exitRef) && imminentTurn) {
|
AndroidUiHelper.updateVisibility(exitRefText, true);
|
||||||
exitRefText.setText(exitRef);
|
|
||||||
AndroidUiHelper.updateVisibility(exitRefText, true);
|
|
||||||
} else {
|
|
||||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
AndroidUiHelper.updateVisibility(exitRefText, false);
|
||||||
}
|
}
|
||||||
if (update) {
|
if (turnDrawable.setTurnType(streetName.turnType) || streetName.showMarker != this.showMarker) {
|
||||||
if (type[0] != null) {
|
this.showMarker = streetName.showMarker;
|
||||||
|
if (streetName.turnType != null) {
|
||||||
turnIcon.invalidateDrawable(turnDrawable);
|
turnIcon.invalidateDrawable(turnDrawable);
|
||||||
turnIcon.setImageDrawable(turnDrawable);
|
turnIcon.setImageDrawable(turnDrawable);
|
||||||
AndroidUiHelper.updateVisibility(turnIcon, true);
|
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);
|
Drawable marker = map.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance);
|
||||||
turnIcon.setImageDrawable(marker);
|
turnIcon.setImageDrawable(marker);
|
||||||
AndroidUiHelper.updateVisibility(turnIcon, true);
|
AndroidUiHelper.updateVisibility(turnIcon, true);
|
||||||
|
@ -1120,9 +1062,12 @@ public class MapInfoWidgetsFactory {
|
||||||
AndroidUiHelper.updateVisibility(turnIcon, false);
|
AndroidUiHelper.updateVisibility(turnIcon, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!text.equals(addressText.getText().toString())) {
|
if(streetName.text == null || streetName.text.isEmpty()) {
|
||||||
addressTextShadow.setText(text);
|
addressTextShadow.setText("");
|
||||||
addressText.setText(text);
|
addressText.setText("");
|
||||||
|
} else if (!streetName.text.equals(addressText.getText().toString())) {
|
||||||
|
addressTextShadow.setText(streetName.text);
|
||||||
|
addressText.setText(streetName.text );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue