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;
|
// 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;
|
Location l = lastFixedLocation;
|
||||||
float speed = 0;
|
float speed = 0;
|
||||||
if(l != null && l.hasSpeed()) {
|
if(l != null && l.hasSpeed()) {
|
||||||
|
@ -959,27 +965,27 @@ public class RoutingHelper {
|
||||||
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();
|
||||||
|
streetName.text = formatStreetName(nm, null, dn, "»");
|
||||||
return formatStreetName(nm, null, dn, "»");
|
return streetName;
|
||||||
}
|
}
|
||||||
RouteSegmentResult rs = getCurrentSegmentResult();
|
RouteSegmentResult rs = getCurrentSegmentResult();
|
||||||
if(rs != null) {
|
if(rs != null) {
|
||||||
String name = getRouteSegmentStreetName(rs);
|
streetName.text = getRouteSegmentStreetName(rs);
|
||||||
if (!Algorithms.isEmpty(name)) {
|
if (!Algorithms.isEmpty(streetName.text )) {
|
||||||
return name;
|
return streetName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs = getNextStreetSegmentResult();
|
rs = getNextStreetSegmentResult();
|
||||||
if(rs != null) {
|
if(rs != null) {
|
||||||
String name = getRouteSegmentStreetName(rs);
|
streetName.text = getRouteSegmentStreetName(rs);
|
||||||
if (!Algorithms.isEmpty(name)) {
|
if (!Algorithms.isEmpty(streetName.text)) {
|
||||||
if(next != null) {
|
if(next != null) {
|
||||||
next[0] = TurnType.valueOf(TurnType.C, false);
|
next[0] = TurnType.valueOf(TurnType.C, false);
|
||||||
}
|
}
|
||||||
return name;
|
return streetName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return streetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRouteSegmentStreetName(RouteSegmentResult rs) {
|
private String getRouteSegmentStreetName(RouteSegmentResult rs) {
|
||||||
|
|
|
@ -981,96 +981,69 @@ public class MapInfoWidgetsFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean updateInfo(DrawSettings d) {
|
public boolean updateInfo(DrawSettings d) {
|
||||||
String text = null;
|
RoutingHelper.CurrentStreetName streetName = null;
|
||||||
|
String exitRef = null;
|
||||||
TurnType[] type = new TurnType[1];
|
TurnType[] type = new TurnType[1];
|
||||||
boolean showNextTurn = false;
|
boolean showNextTurn = false;
|
||||||
boolean showMarker = this.showMarker;
|
boolean showMarker = this.showMarker;
|
||||||
boolean showExitInfo = false;
|
|
||||||
boolean showShield = false;
|
|
||||||
boolean imminentTurn = false;
|
|
||||||
ExitInfo exitInfo = null;
|
ExitInfo exitInfo = null;
|
||||||
RouteDataObject object = null;
|
RouteDataObject shieldObject = null;
|
||||||
|
|
||||||
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(type, nextDirInfo);
|
||||||
if (text == null) {
|
if (type[0] == null) {
|
||||||
text = "";
|
showMarker = true;
|
||||||
} else {
|
} else {
|
||||||
if (type[0] == null) {
|
turnDrawable.setColor(R.color.nav_arrow);
|
||||||
showMarker = true;
|
}
|
||||||
} else {
|
RouteDirectionInfo nextDirectionInfo = nextDirInfo.directionInfo;
|
||||||
turnDrawable.setColor(R.color.nav_arrow);
|
// show exit ref
|
||||||
|
if (nextDirectionInfo != null && nextDirectionInfo.getExitInfo() != null &&
|
||||||
|
nextDirInfo.imminent >= 0) {
|
||||||
|
exitRef = exitInfo.getRef();
|
||||||
|
if (!Algorithms.isEmpty(exitInfo.getExitStreetName())) {
|
||||||
|
streetName.text = exitInfo.getExitStreetName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// show shield
|
||||||
RouteDirectionInfo directionInfo = nextDirInfo.directionInfo;
|
if (nextDirectionInfo != null) {
|
||||||
|
shieldObject = nextDirectionInfo.getRouteDataObject();
|
||||||
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()) {
|
// TODO shields
|
||||||
showNextTurn = true;
|
showNextTurn = true;
|
||||||
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
RouteDirectionInfo next = routingHelper.getRouteDirections().get(di);
|
||||||
type[0] = next.getTurnType();
|
type[0] = next.getTurnType();
|
||||||
turnDrawable.setColor(R.color.nav_arrow_distant);
|
turnDrawable.setColor(R.color.nav_arrow_distant);
|
||||||
text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
streetName = new RoutingHelper.CurrentStreetName();
|
||||||
if (text == null) {
|
streetName.text = RoutingHelper.formatStreetName(next.getStreetName(), null, next.getDestinationName(), "»");
|
||||||
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;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1081,7 +1054,7 @@ public class MapInfoWidgetsFactory {
|
||||||
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);
|
||||||
|
@ -1090,20 +1063,15 @@ public class MapInfoWidgetsFactory {
|
||||||
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
AndroidUiHelper.updateVisibility(addressTextShadow, shadowRad > 0);
|
||||||
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
boolean update = turnDrawable.setTurnType(type[0]) || showMarker != this.showMarker;
|
||||||
this.showMarker = showMarker;
|
this.showMarker = showMarker;
|
||||||
if (showShield && setRoadShield(shieldIcon, object)) {
|
if (shieldObject != null && setRoadShield(shieldIcon, shieldObject)) {
|
||||||
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
AndroidUiHelper.updateVisibility(shieldIcon, true);
|
||||||
} else {
|
} else {
|
||||||
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
AndroidUiHelper.updateVisibility(shieldIcon, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showExitInfo) {
|
if (!Algorithms.isEmpty(exitRef) ) {
|
||||||
String exitRef = exitInfo.getRef();
|
exitRefText.setText(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);
|
||||||
}
|
}
|
||||||
|
@ -1120,9 +1088,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