use of net.osmand.plus.routing.RouteDirectionInfo in project Osmand by osmandapp.
the class ShowRouteInfoDialogFragment method generateHtmlPrint.
private StringBuilder generateHtmlPrint(RouteInfoAdapter routeInfo, String title) {
StringBuilder html = new StringBuilder();
html.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
html.append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">");
html.append("<head>");
html.append("<title>Route info</title>");
html.append("<meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />");
html.append("<style>");
html.append("table, th, td {");
html.append("border: 1px solid black;");
html.append("border-collapse: collapse;}");
html.append("th, td {");
html.append("padding: 5px;}");
html.append("</style>");
html.append("</head>");
html.append("<body>");
if (!TextUtils.isEmpty(title)) {
html.append("<h1>");
html.append(title);
html.append("</h1>");
}
html.append("<table style=\"width:100%\">");
final String NBSP = " ";
final String BR = "<br>";
for (int i = 0; i < routeInfo.getCount(); i++) {
RouteDirectionInfo routeDirectionInfo = (RouteDirectionInfo) routeInfo.getItem(i);
html.append("<tr>");
StringBuilder sb = new StringBuilder();
sb.append(OsmAndFormatter.getFormattedDistance(routeDirectionInfo.distance, getMyApplication()));
sb.append(", ");
sb.append(getTimeDescription(routeDirectionInfo));
String distance = sb.toString().replaceAll("\\s", NBSP);
html.append("<td>");
html.append(distance);
html.append("</td>");
String description = routeDirectionInfo.getDescriptionRoutePart();
html.append("<td>");
html.append(String.valueOf(i + 1) + ". " + description);
html.append("</td>");
RouteInfoAdapter.CumulativeInfo cumulativeInfo = routeInfo.getRouteDirectionCumulativeInfo(i);
html.append("<td>");
sb = new StringBuilder();
sb.append(OsmAndFormatter.getFormattedDistance(cumulativeInfo.distance, getMyApplication()));
sb.append(" - ");
sb.append(OsmAndFormatter.getFormattedDistance(cumulativeInfo.distance + routeDirectionInfo.distance, getMyApplication()));
sb.append(BR);
sb.append(Algorithms.formatDuration(cumulativeInfo.time, getMyApplication().accessibilityEnabled()));
sb.append(" - ");
sb.append(Algorithms.formatDuration(cumulativeInfo.time + routeDirectionInfo.getExpectedTime(), getMyApplication().accessibilityEnabled()));
String cumulativeTimeAndDistance = sb.toString().replaceAll("\\s", NBSP);
html.append(cumulativeTimeAndDistance);
html.append("</td>");
html.append("</tr>");
}
html.append("</table>");
html.append("</body>");
html.append("</html>");
return html;
}
use of net.osmand.plus.routing.RouteDirectionInfo in project Osmand by osmandapp.
the class RouteLayer method drawLocations.
public void drawLocations(RotatedTileBox tb, Canvas canvas, double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
RouteCalculationResult route = helper.getRoute();
routeGeometry.updateRoute(tb, route);
routeGeometry.drawSegments(tb, canvas, topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), route == null ? 0 : route.getCurrentRoute());
List<RouteDirectionInfo> rd = helper.getRouteDirections();
Iterator<RouteDirectionInfo> it = rd.iterator();
if (tb.getZoom() >= 14) {
List<Location> actionPoints = calculateActionPoints(topLatitude, leftLongitude, bottomLatitude, rightLongitude, helper.getLastProjection(), helper.getRoute().getRouteLocations(), helper.getRoute().getCurrentRoute(), it, tb.getZoom());
drawAction(tb, canvas, actionPoints);
}
}
use of net.osmand.plus.routing.RouteDirectionInfo in project Osmand by osmandapp.
the class RouteLayer method calculateActionPoints.
private List<Location> calculateActionPoints(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude, Location lastProjection, List<Location> routeNodes, int cd, Iterator<RouteDirectionInfo> it, int zoom) {
RouteDirectionInfo nf = null;
double DISTANCE_ACTION = 35;
if (zoom >= 17) {
DISTANCE_ACTION = 15;
} else if (zoom == 15) {
DISTANCE_ACTION = 70;
} else if (zoom < 15) {
DISTANCE_ACTION = 110;
}
double actionDist = 0;
Location previousAction = null;
List<Location> actionPoints = this.actionPoints;
actionPoints.clear();
int prevFinishPoint = -1;
for (int routePoint = 0; routePoint < routeNodes.size(); routePoint++) {
Location loc = routeNodes.get(routePoint);
if (nf != null) {
int pnt = nf.routeEndPointOffset == 0 ? nf.routePointOffset : nf.routeEndPointOffset;
if (pnt < routePoint + cd) {
nf = null;
}
}
while (nf == null && it.hasNext()) {
nf = it.next();
int pnt = nf.routeEndPointOffset == 0 ? nf.routePointOffset : nf.routeEndPointOffset;
if (pnt < routePoint + cd) {
nf = null;
}
}
boolean action = nf != null && (nf.routePointOffset == routePoint + cd || (nf.routePointOffset <= routePoint + cd && routePoint + cd <= nf.routeEndPointOffset));
if (!action && previousAction == null) {
// no need to check
continue;
}
boolean visible = leftLongitude <= loc.getLongitude() && loc.getLongitude() <= rightLongitude && bottomLatitude <= loc.getLatitude() && loc.getLatitude() <= topLatitude;
if (action && !visible && previousAction == null) {
continue;
}
if (!action) {
// previousAction != null
float dist = loc.distanceTo(previousAction);
actionDist += dist;
if (actionDist >= DISTANCE_ACTION) {
actionPoints.add(calculateProjection(1 - (actionDist - DISTANCE_ACTION) / dist, previousAction, loc));
actionPoints.add(null);
prevFinishPoint = routePoint;
previousAction = null;
actionDist = 0;
} else {
actionPoints.add(loc);
previousAction = loc;
}
} else {
// action point
if (previousAction == null) {
addPreviousToActionPoints(actionPoints, lastProjection, routeNodes, DISTANCE_ACTION, prevFinishPoint, routePoint, loc);
}
actionPoints.add(loc);
previousAction = loc;
prevFinishPoint = -1;
actionDist = 0;
}
}
if (previousAction != null) {
actionPoints.add(null);
}
return actionPoints;
}
use of net.osmand.plus.routing.RouteDirectionInfo in project Osmand by osmandapp.
the class NavigationNotification method buildNotification.
@Override
public Builder buildNotification(boolean wearable) {
if (!isEnabled()) {
return null;
}
NavigationService service = app.getNavigationService();
String notificationTitle;
StringBuilder notificationText = new StringBuilder();
color = 0;
icon = R.drawable.ic_action_start_navigation;
turnBitmap = null;
ongoing = true;
RoutingHelper routingHelper = app.getRoutingHelper();
boolean followingMode = routingHelper.isFollowingMode() || app.getLocationProvider().getLocationSimulation().isRouteAnimating();
if (service != null && (service.getUsedBy() & USED_BY_NAVIGATION) != 0) {
color = app.getResources().getColor(R.color.osmand_orange);
String distanceStr = OsmAndFormatter.getFormattedDistance(app.getRoutingHelper().getLeftDistance(), app);
String timeStr = OsmAndFormatter.getFormattedDuration(app.getRoutingHelper().getLeftTime(), app);
String etaStr = SimpleDateFormat.getTimeInstance(DateFormat.SHORT).format(new Date(System.currentTimeMillis() + app.getRoutingHelper().getLeftTime() * 1000));
TurnType turnType = null;
boolean deviatedFromRoute;
int turnImminent = 0;
int nextTurnDistance = 0;
int nextNextTurnDistance = 0;
RouteDirectionInfo ri = null;
if (routingHelper.isRouteCalculated() && followingMode) {
deviatedFromRoute = routingHelper.isDeviatedFromRoute();
if (deviatedFromRoute) {
turnImminent = 0;
turnType = TurnType.valueOf(TurnType.OFFR, leftSide);
nextTurnDistance = (int) routingHelper.getRouteDeviation();
} else {
NextDirectionInfo calc1 = new NextDirectionInfo();
NextDirectionInfo r = routingHelper.getNextRouteDirectionInfo(calc1, true);
if (r != null && r.distanceTo > 0 && r.directionInfo != null) {
ri = r.directionInfo;
turnType = r.directionInfo.getTurnType();
nextTurnDistance = r.distanceTo;
turnImminent = r.imminent;
NextDirectionInfo next = routingHelper.getNextRouteDirectionInfoAfter(r, calc1, true);
nextNextTurnDistance = next.distanceTo;
}
}
if (turnType != null) {
TurnDrawable drawable = new TurnDrawable(app, false);
int height = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) app.getResources().getDimension(android.R.dimen.notification_large_icon_width);
drawable.setBounds(0, 0, width, height);
drawable.setTurnType(turnType);
drawable.setTurnImminent(turnImminent, deviatedFromRoute);
turnBitmap = drawableToBitmap(drawable);
}
notificationTitle = OsmAndFormatter.getFormattedDistance(nextTurnDistance, app) + (turnType != null ? " • " + RouteCalculationResult.toString(turnType, app, true) : "");
if (ri != null && !Algorithms.isEmpty(ri.getDescriptionRoutePart())) {
notificationText.append(ri.getDescriptionRoutePart());
if (nextNextTurnDistance > 0) {
notificationText.append(" ").append(OsmAndFormatter.getFormattedDistance(nextNextTurnDistance, app));
}
notificationText.append("\n");
}
int distanceToNextIntermediate = routingHelper.getLeftDistanceNextIntermediate();
if (distanceToNextIntermediate > 0) {
int nextIntermediateIndex = routingHelper.getRoute().getNextIntermediate();
List<TargetPoint> intermediatePoints = app.getTargetPointsHelper().getIntermediatePoints();
if (nextIntermediateIndex < intermediatePoints.size()) {
TargetPoint nextIntermediate = intermediatePoints.get(nextIntermediateIndex);
notificationText.append(OsmAndFormatter.getFormattedDistance(distanceToNextIntermediate, app)).append(" • ").append(nextIntermediate.getOnlyName());
notificationText.append("\n");
}
}
notificationText.append(distanceStr).append(" • ").append(timeStr).append(" • ").append(etaStr);
} else {
notificationTitle = app.getString(R.string.shared_string_navigation);
String error = routingHelper.getLastRouteCalcErrorShort();
if (Algorithms.isEmpty(error)) {
notificationText.append(app.getString(R.string.route_calculation)).append("...");
} else {
notificationText.append(error);
}
}
} else if (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation()) {
ongoing = false;
notificationTitle = app.getString(R.string.shared_string_navigation);
notificationText.append(app.getString(R.string.shared_string_paused));
} else {
return null;
}
final Builder notificationBuilder = createBuilder(wearable).setContentTitle(notificationTitle).setStyle(new BigTextStyle().bigText(notificationText)).setLargeIcon(turnBitmap);
Intent stopIntent = new Intent(OSMAND_STOP_NAVIGATION_SERVICE_ACTION);
PendingIntent stopPendingIntent = PendingIntent.getBroadcast(app, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_action_remove_dark, app.getString(R.string.shared_string_control_stop), stopPendingIntent);
if (routingHelper.isRouteCalculated() && followingMode) {
Intent pauseIntent = new Intent(OSMAND_PAUSE_NAVIGATION_SERVICE_ACTION);
PendingIntent pausePendingIntent = PendingIntent.getBroadcast(app, 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_pause, app.getString(R.string.shared_string_pause), pausePendingIntent);
} else if (routingHelper.isRouteCalculated() && routingHelper.isPauseNavigation()) {
Intent resumeIntent = new Intent(OSMAND_RESUME_NAVIGATION_SERVICE_ACTION);
PendingIntent resumePendingIntent = PendingIntent.getBroadcast(app, 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(R.drawable.ic_play_dark, app.getString(R.string.shared_string_continue), resumePendingIntent);
}
return notificationBuilder;
}
use of net.osmand.plus.routing.RouteDirectionInfo in project Osmand by osmandapp.
the class MapRouteInfoMenu method updateRouteButtons.
private void updateRouteButtons(final View mainView) {
mainView.findViewById(R.id.dividerToDropDown).setVisibility(View.VISIBLE);
mainView.findViewById(R.id.RouteInfoControls).setVisibility(View.VISIBLE);
final OsmandApplication ctx = mapActivity.getMyApplication();
ImageView prev = (ImageView) mainView.findViewById(R.id.Prev);
prev.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_prev, isLight()));
if (directionInfo >= 0) {
prev.setVisibility(View.VISIBLE);
prev.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (directionInfo >= 0) {
directionInfo--;
}
if (routingHelper.getRouteDirections() != null && directionInfo >= 0) {
if (routingHelper.getRouteDirections().size() > directionInfo) {
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
contextMenu.showMinimized(new LatLon(l.getLatitude(), l.getLongitude()), null, info);
showLocationOnMap(mapActivity, l.getLatitude(), l.getLongitude());
}
}
mapView.refreshMap();
updateInfo(mainView);
}
});
} else {
prev.setVisibility(View.GONE);
}
ImageView next = (ImageView) mainView.findViewById(R.id.Next);
next.setVisibility(View.VISIBLE);
next.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_next, isLight()));
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (routingHelper.getRouteDirections() != null && directionInfo < routingHelper.getRouteDirections().size() - 1) {
directionInfo++;
RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo);
net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info);
contextMenu.showMinimized(new LatLon(l.getLatitude(), l.getLongitude()), null, info);
showLocationOnMap(mapActivity, l.getLatitude(), l.getLongitude());
}
mapView.refreshMap();
updateInfo(mainView);
}
});
View info = mainView.findViewById(R.id.Info);
info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowRouteInfoDialogFragment.showDialog(mapActivity.getSupportFragmentManager());
}
});
TextView textView = (TextView) mainView.findViewById(R.id.InfoTextView);
ImageView infoIcon = (ImageView) mainView.findViewById(R.id.InfoIcon);
ImageView durationIcon = (ImageView) mainView.findViewById(R.id.DurationIcon);
View infoDistanceView = mainView.findViewById(R.id.InfoDistance);
View infoDurationView = mainView.findViewById(R.id.InfoDuration);
if (directionInfo >= 0) {
infoIcon.setVisibility(View.GONE);
durationIcon.setVisibility(View.GONE);
infoDistanceView.setVisibility(View.GONE);
infoDurationView.setVisibility(View.GONE);
textView.setVisibility(View.VISIBLE);
} else {
infoIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_route_distance, R.color.route_info_unchecked_mode_icon_color));
infoIcon.setVisibility(View.VISIBLE);
durationIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_time_span, R.color.route_info_unchecked_mode_icon_color));
durationIcon.setVisibility(View.VISIBLE);
infoDistanceView.setVisibility(View.VISIBLE);
infoDurationView.setVisibility(View.VISIBLE);
textView.setVisibility(View.GONE);
}
if (directionInfo >= 0 && routingHelper.getRouteDirections() != null && directionInfo < routingHelper.getRouteDirections().size()) {
RouteDirectionInfo ri = routingHelper.getRouteDirections().get(directionInfo);
if (!ri.getDescriptionRoutePart().endsWith(OsmAndFormatter.getFormattedDistance(ri.distance, ctx))) {
textView.setText((directionInfo + 1) + ". " + ri.getDescriptionRoutePart() + " " + OsmAndFormatter.getFormattedDistance(ri.distance, ctx));
} else {
textView.setText((directionInfo + 1) + ". " + ri.getDescriptionRoutePart());
}
} else {
TextView distanceText = (TextView) mainView.findViewById(R.id.DistanceText);
TextView durationText = (TextView) mainView.findViewById(R.id.DurationText);
distanceText.setText(OsmAndFormatter.getFormattedDistance(ctx.getRoutingHelper().getLeftDistance(), ctx));
durationText.setText(OsmAndFormatter.getFormattedDuration(ctx.getRoutingHelper().getLeftTime(), ctx));
}
}
Aggregations