Search in sources :

Example 1 with Route

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()));
}
Also used : NeutralWeighter(im.tny.segvault.s2ls.routing.NeutralWeighter) Route(im.tny.segvault.s2ls.routing.Route) NeutralQualifier(im.tny.segvault.s2ls.routing.NeutralQualifier)

Example 2 with Route

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);
    }
}
Also used : Route(im.tny.segvault.s2ls.routing.Route)

Example 3 with Route

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());
}
Also used : Path(im.tny.segvault.s2ls.Path) ForegroundColorSpan(android.text.style.ForegroundColorSpan) Stop(im.tny.segvault.subway.Stop) ArrayList(java.util.ArrayList) EnterStep(im.tny.segvault.s2ls.routing.EnterStep) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ChangeLineStep(im.tny.segvault.s2ls.routing.ChangeLineStep) EnterStep(im.tny.segvault.s2ls.routing.EnterStep) ExitStep(im.tny.segvault.s2ls.routing.ExitStep) ChangeLineStep(im.tny.segvault.s2ls.routing.ChangeLineStep) Step(im.tny.segvault.s2ls.routing.Step) SpannableString(android.text.SpannableString) Date(java.util.Date) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) NotificationCompat(android.support.v4.app.NotificationCompat) ExitStep(im.tny.segvault.s2ls.routing.ExitStep) PendingIntent(android.app.PendingIntent) Route(im.tny.segvault.s2ls.routing.Route) Spannable(android.text.Spannable)

Aggregations

Route (im.tny.segvault.s2ls.routing.Route)3 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 StyleSpan (android.text.style.StyleSpan)1 Path (im.tny.segvault.s2ls.Path)1 ChangeLineStep (im.tny.segvault.s2ls.routing.ChangeLineStep)1 EnterStep (im.tny.segvault.s2ls.routing.EnterStep)1 ExitStep (im.tny.segvault.s2ls.routing.ExitStep)1 NeutralQualifier (im.tny.segvault.s2ls.routing.NeutralQualifier)1 NeutralWeighter (im.tny.segvault.s2ls.routing.NeutralWeighter)1 Step (im.tny.segvault.s2ls.routing.Step)1 Stop (im.tny.segvault.subway.Stop)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1