use of im.tny.segvault.s2ls.routing.Route in project underlx by underlx.
the class RouteFragment method tryPlanRoute.
private void tryPlanRoute() {
if (originPicker.getSelection() == null || destinationPicker.getSelection() == null) {
// not enough information
return;
}
Route realtimeRoute = Route.calculate(network, originPicker.getSelection(), destinationPicker.getSelection());
Route neutralRoute = Route.calculate(network, originPicker.getSelection(), destinationPicker.getSelection(), new NeutralWeighter(), new NeutralQualifier());
if (useRealtimeCheckbox.isChecked()) {
route = realtimeRoute;
} else {
route = neutralRoute;
}
showRoute(realtimeRoute.getPath().getEdgeList().equals(neutralRoute.getPath().getEdgeList()));
}
use of im.tny.segvault.s2ls.routing.Route in project underlx by underlx.
the class S2LS method setCurrentTargetRoute.
public void setCurrentTargetRoute(Route route, boolean isReroute) {
if (route != null && route.size() == 0) {
// useless route
setCurrentTargetRoute(null, isReroute);
return;
}
Route prevRoute;
synchronized (this) {
prevRoute = targetRoute;
targetRoute = route;
if (route != null) {
if (isReroute) {
routePathChecker.onReroute();
} else {
routePathChecker.onNewTargetRoute();
listener.onRouteProgrammed(this, targetRoute);
}
}
}
if (route == null && prevRoute != null) {
listener.onRouteCancelled(this, prevRoute);
}
}
use of im.tny.segvault.s2ls.routing.Route in project underlx by underlx.
the class MainService method updateRouteNotification.
private void updateRouteNotification(S2LS loc, boolean highPriorityNotification) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_INITIAL_FRAGMENT, "nav_home");
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Path currentPath = loc.getCurrentTrip();
Route currentRoute = loc.getCurrentTargetRoute();
if (currentPath == null && currentRoute == null) {
Log.e("MainService", "Attempt to create notification when there's no path or planned route");
return;
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
CharSequence title = "";
List<CharSequence> statusLines = new ArrayList<>();
int color = -1;
if (currentRoute != null) {
inboxStyle.setSummaryText(String.format(getString(R.string.notif_route_navigating_status), currentRoute.getTarget().getName()));
Step nextStep = currentRoute.getNextStep(currentPath);
if (nextStep instanceof EnterStep) {
if (currentPath != null && currentPath.getCurrentStop() != null && currentRoute.checkPathStartsRoute(currentPath)) {
title = String.format(getString(R.string.notif_route_catch_train_title), ((EnterStep) nextStep).getDirection().getName(12));
} else {
title = String.format(getString(R.string.notif_route_enter_station_title), nextStep.getStation().getName(15));
}
// TODO: show "encurtamentos" warnings here if applicable
statusLines.add(String.format(getString(R.string.notif_route_catch_train_status), ((EnterStep) nextStep).getDirection().getName()));
color = currentRoute.getSourceStop().getLine().getColor();
} else if (nextStep instanceof ChangeLineStep) {
ChangeLineStep clStep = (ChangeLineStep) nextStep;
String lineName = Util.getLineNames(this, clStep.getTarget())[0];
String titleStr;
if (currentPath != null && currentPath.getCurrentStop() != null && currentPath.getCurrentStop().getStation() == nextStep.getStation()) {
titleStr = String.format(getString(R.string.notif_route_catch_train_line_change_title), lineName);
} else {
titleStr = String.format(getString(R.string.notif_route_line_change_title), nextStep.getStation().getName(10), lineName);
}
int lStart = titleStr.indexOf(lineName);
int lEnd = lStart + lineName.length();
Spannable sb = new SpannableString(titleStr);
sb.setSpan(new ForegroundColorSpan(clStep.getTarget().getColor()), lStart, lEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
title = sb;
// TODO: show "encurtamentos" warnings here if applicable
sb = new SpannableString(String.format(getString(R.string.notif_route_catch_train_status), clStep.getDirection().getName()));
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
statusLines.add(sb);
color = clStep.getTarget().getColor();
} else if (nextStep instanceof ExitStep) {
if (currentPath != null && currentPath.getCurrentStop().getStation() == nextStep.getStation()) {
title = getString(R.string.notif_route_leave_train_now);
} else if (currentPath != null && currentPath.getNextStop() != null && new Date().getTime() - currentPath.getCurrentStopEntryTime().getTime() > 30 * 1000 && nextStep.getStation() == currentPath.getNextStop().getStation()) {
title = getString(R.string.notif_route_leave_train_next);
} else {
title = String.format(getString(R.string.notif_route_leave_train), nextStep.getStation().getName(20));
}
}
}
if (currentPath != null) {
Stop curStop = currentPath.getCurrentStop();
if (color == -1) {
color = curStop.getLine().getColor();
}
if (currentRoute != null) {
statusLines.add(String.format(getString(R.string.notif_route_current_station), curStop.getStation().getName()));
} else {
title = curStop.getStation().getName();
}
if (currentPath.isWaitingFirstTrain()) {
statusLines.add(getString(R.string.notif_route_waiting));
} else {
Stop direction = currentPath.getDirection();
Stop next = currentPath.getNextStop();
if (direction != null && next != null) {
statusLines.add(String.format(getString(R.string.notif_route_next_station), next.getStation().getName()));
if (currentRoute == null) {
statusLines.add(String.format(getString(R.string.notif_route_direction), direction.getStation().getName()));
}
} else {
statusLines.add(getString(R.string.notif_route_left_station));
}
}
}
CharSequence singleLineStatus = "";
for (CharSequence s : statusLines) {
inboxStyle.addLine(s);
singleLineStatus = TextUtils.concat(singleLineStatus, s) + " | ";
}
singleLineStatus = singleLineStatus.subSequence(0, singleLineStatus.length() - 3);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setStyle(inboxStyle).setColor(color).setContentTitle(title).setContentText(singleLineStatus).setAutoCancel(false).setContentIntent(pendingIntent).setVisibility(Notification.VISIBILITY_PUBLIC).setOngoing(true);
if (highPriorityNotification) {
stopForeground(true);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
}
if (currentRoute != null) {
notificationBuilder.setSmallIcon(R.drawable.ic_navigation_white_24dp);
Intent stopIntent = new Intent(this, MainService.class);
stopIntent.setAction(ACTION_END_NAVIGATION);
stopIntent.putExtra(EXTRA_NAVIGATION_NETWORK, loc.getNetwork().getId());
PendingIntent pendingStopIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), stopIntent, 0);
notificationBuilder.addAction(R.drawable.ic_close_black_24dp, getString(R.string.notif_route_end_navigation), pendingStopIntent);
} else {
notificationBuilder.setSmallIcon(R.drawable.ic_trip_notif);
if (loc.canRequestEndOfTrip()) {
Intent stopIntent = new Intent(this, MainService.class);
stopIntent.setAction(ACTION_END_TRIP);
stopIntent.putExtra(EXTRA_TRIP_NETWORK, loc.getNetwork().getId());
PendingIntent pendingStopIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), stopIntent, 0);
notificationBuilder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.notif_route_end_trip), pendingStopIntent);
}
}
startForeground(ROUTE_NOTIFICATION_ID, notificationBuilder.build());
}
Aggregations