Refactor
This commit is contained in:
parent
ca5448286a
commit
6093e4a357
2 changed files with 55 additions and 78 deletions
|
@ -945,7 +945,13 @@ public class RoutingHelper {
|
|||
// return false;
|
||||
// }
|
||||
|
||||
public synchronized String getCurrentName(TurnType[] next, NextDirectionInfo n){
|
||||
|
||||
public static class CurrentStreetName {
|
||||
public String text;
|
||||
}
|
||||
|
||||
public synchronized CurrentStreetName getCurrentName(TurnType[] next, NextDirectionInfo n){
|
||||
CurrentStreetName streetName = new CurrentStreetName();
|
||||
Location l = lastFixedLocation;
|
||||
float speed = 0;
|
||||
if(l != null && l.hasSpeed()) {
|
||||
|
@ -959,27 +965,27 @@ public class RoutingHelper {
|
|||
String nm = n.directionInfo.getStreetName();
|
||||
String rf = n.directionInfo.getRef();
|
||||
String dn = n.directionInfo.getDestinationName();
|
||||
|
||||
return formatStreetName(nm, null, dn, "»");
|
||||
streetName.text = formatStreetName(nm, null, dn, "»");
|
||||
return streetName;
|
||||
}
|
||||
RouteSegmentResult rs = getCurrentSegmentResult();
|
||||
if(rs != null) {
|
||||
String name = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(name)) {
|
||||
return name;
|
||||
streetName.text = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(streetName.text )) {
|
||||
return streetName;
|
||||
}
|
||||
}
|
||||
rs = getNextStreetSegmentResult();
|
||||
if(rs != null) {
|
||||
String name = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(name)) {
|
||||
streetName.text = getRouteSegmentStreetName(rs);
|
||||
if (!Algorithms.isEmpty(streetName.text)) {
|
||||
if(next != null) {
|
||||
next[0] = TurnType.valueOf(TurnType.C, false);
|
||||
}
|
||||
return name;
|
||||
return streetName;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return streetName;
|
||||
}
|
||||
|
||||
private String getRouteSegmentStreetName(RouteSegmentResult rs) {
|
||||
|
|
|
@ -981,96 +981,69 @@ public class MapInfoWidgetsFactory {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public boolean updateInfo(DrawSettings d) {
|
||||
String text = null;
|
||||
RoutingHelper.CurrentStreetName streetName = null;
|
||||
String exitRef = 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;
|
||||
RouteDataObject shieldObject = null;
|
||||
|
||||
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 {
|
||||
streetName = routingHelper.getCurrentName(type, nextDirInfo);
|
||||
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) {
|
||||
RouteDirectionInfo nextDirectionInfo = nextDirInfo.directionInfo;
|
||||
// show exit ref
|
||||
if (nextDirectionInfo != null && nextDirectionInfo.getExitInfo() != null &&
|
||||
nextDirInfo.imminent >= 0) {
|
||||
exitRef = exitInfo.getRef();
|
||||
if (!Algorithms.isEmpty(exitInfo.getExitStreetName())) {
|
||||
text = exitInfo.getExitStreetName();
|
||||
streetName.text = exitInfo.getExitStreetName();
|
||||
}
|
||||
}
|
||||
|
||||
if (directionInfo != null && directionInfo.getRouteDataObject() != null) {
|
||||
object = directionInfo.getRouteDataObject();
|
||||
showShield = true;
|
||||
// show shield
|
||||
if (nextDirectionInfo != null) {
|
||||
shieldObject = nextDirectionInfo.getRouteDataObject();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int di = MapRouteInfoMenu.getDirectionInfo();
|
||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() &&
|
||||
di < routingHelper.getRouteDirections().size()) {
|
||||
if (di >= 0 && map.getMapRouteInfoMenu().isVisible() && di < routingHelper.getRouteDirections().size()) {
|
||||
// TODO shields
|
||||
showNextTurn = true;
|
||||
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
||||
type[0] = next.getTurnType();
|
||||
turnDrawable.setColor(R.color.nav_arrow_distant);
|
||||
text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
||||
if (text == null) {
|
||||
text = "";
|
||||
}
|
||||
} else {
|
||||
text = null;
|
||||
streetName = new RoutingHelper.CurrentStreetName();
|
||||
streetName.text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
} else {
|
||||
text = map.getResources().getString(R.string.shared_string_near) + " " + text;
|
||||
streetName.text = map.getResources().getString(R.string.shared_string_near) + " " + streetName.text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1081,7 +1054,7 @@ public class MapInfoWidgetsFactory {
|
|||
updateVisibility(true);
|
||||
AndroidUiHelper.updateVisibility(addressText, false);
|
||||
AndroidUiHelper.updateVisibility(addressTextShadow, false);
|
||||
} else if (text == null) {
|
||||
} else if (streetName == null) {
|
||||
updateVisibility(false);
|
||||
} else {
|
||||
updateVisibility(true);
|
||||
|
@ -1090,23 +1063,18 @@ public class MapInfoWidgetsFactory {
|
|||
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
||||
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
||||
this.showMarker = showMarker;
|
||||
if (showShield && setRoadShield(shieldIcon, object)) {
|
||||
if (shieldObject != null && setRoadShield(shieldIcon, shieldObject)) {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||
}
|
||||
|
||||
if (showExitInfo) {
|
||||
String exitRef = exitInfo.getRef();
|
||||
if (!Algorithms.isEmpty(exitRef) && imminentTurn) {
|
||||
if (!Algorithms.isEmpty(exitRef) ) {
|
||||
exitRefText.setText(exitRef);
|
||||
AndroidUiHelper.updateVisibility(exitRefText, true);
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
||||
}
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(exitRefText, false);
|
||||
}
|
||||
if (update) {
|
||||
if (type[0] != null) {
|
||||
turnIcon.invalidateDrawable(turnDrawable);
|
||||
|
@ -1120,9 +1088,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