Search in sources :

Example 1 with Stop

use of im.tny.segvault.subway.Stop in project underlx by underlx.

the class Trip method toConnectionPath.

public Path toConnectionPath(Network network) {
    List<Connection> edges = new LinkedList<>();
    List<Pair<Date, Date>> times = new ArrayList<>();
    List<Boolean> manualEntry = new ArrayList<>();
    Stop startVertex = null;
    List<Stop> previous = new ArrayList<>();
    for (StationUse use : path) {
        switch(use.getType()) {
            case INTERCHANGE:
                Stop source = null;
                Stop target = null;
                for (Stop s : network.getStation(use.getStation().getId()).getStops()) {
                    if (s.getLine().getId().equals(use.getSourceLine())) {
                        source = s;
                    }
                    if (s.getLine().getId().equals(use.getTargetLine())) {
                        target = s;
                    }
                }
                for (Stop s : previous) {
                    Connection e = network.getEdge(s, source);
                    if (e != null) {
                        edges.add(e);
                    }
                }
                Connection edge = network.getEdge(source, target);
                if (edge != null) {
                    edges.add(edge);
                    previous = new ArrayList<>();
                    previous.add(target);
                    // in a Path, there are originally two entries for an interchange
                    times.add(new Pair<>(use.getEntryDate(), use.getLeaveDate()));
                    times.add(new Pair<>(use.getEntryDate(), use.getLeaveDate()));
                    manualEntry.add(use.isManualEntry());
                    manualEntry.add(use.isManualEntry());
                }
                break;
            case NETWORK_ENTRY:
                previous = new ArrayList<>(network.getStation(use.getStation().getId()).getStops());
                times.add(new Pair<>(use.getEntryDate(), use.getLeaveDate()));
                manualEntry.add(use.isManualEntry());
                break;
            case NETWORK_EXIT:
            case GONE_THROUGH:
                for (Stop s : previous) {
                    for (Stop s2 : network.getStation(use.getStation().getId()).getStops()) {
                        Connection e = network.getEdge(s, s2);
                        // deal with our way of closing stations
                        // where closed stations only have their outbound edges
                        // (but the user may have travelled through a no longer existing
                        // inbound edge, before the station closed)
                        Connection otherDir = network.getEdge(s2, s);
                        if (e == null && otherDir != null) {
                            e = new Connection(true, s, s2, otherDir.getTimes(), otherDir.getWorldLength());
                        }
                        if (e != null) {
                            edges.add(e);
                            previous = new ArrayList<>();
                            previous.add(s2);
                            times.add(new Pair<>(use.getEntryDate(), use.getLeaveDate()));
                            manualEntry.add(use.isManualEntry());
                        }
                    }
                }
                break;
            case VISIT:
                times.add(new Pair<>(use.getEntryDate(), use.getLeaveDate()));
                manualEntry.add(use.isManualEntry());
                // a stop, any stop
                startVertex = network.getStation(use.getStation().getId()).getStops().iterator().next();
                break;
        }
    }
    if (startVertex == null) {
        startVertex = edges.get(0).getSource();
    }
    return new Path(network, startVertex, edges, times, manualEntry, 0);
}
Also used : Path(im.tny.segvault.s2ls.Path) Stop(im.tny.segvault.subway.Stop) Connection(im.tny.segvault.subway.Connection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Pair(android.util.Pair)

Example 2 with Stop

use of im.tny.segvault.subway.Stop in project underlx by underlx.

the class LineActivity method populateLineView.

public static void populateLineView(final Context context, final LayoutInflater inflater, final Line line, ViewGroup root) {
    root.removeAllViews();
    // TODO note: this doesn't work for circular lines
    List<Station> stations = new ArrayList<>();
    Stop s = line.getFirstStop();
    Set<Stop> visited = new HashSet<>();
    // terminus will only have one outgoing edge
    Connection c = line.outgoingEdgesOf(s).iterator().next();
    while (visited.add(c.getSource())) {
        stations.add(c.getSource().getStation());
        Stop curStop = c.getTarget();
        if (line.outDegreeOf(curStop) == 1) {
            // it's an end station
            stations.add(curStop.getStation());
            break;
        }
        boolean loop = true;
        for (Connection inedge : line.incomingEdgesOf(curStop)) {
            if (!visited.contains(inedge.getSource())) {
                c = new Connection(true, inedge.getTarget(), inedge.getSource(), null, 0);
                loop = false;
                break;
            }
        }
        if (!loop) {
            continue;
        }
        for (Connection outedge : line.outgoingEdgesOf(curStop)) {
            if (!visited.contains(outedge.getTarget())) {
                c = outedge;
                break;
            }
        }
    }
    int lineColor = line.getColor();
    for (int i = 0; i < stations.size(); i++) {
        final Station station = stations.get(i);
        View stepview = inflater.inflate(R.layout.path_station, root, false);
        TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
        timeView.setVisibility(View.INVISIBLE);
        FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
        FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
        FrameLayout leftLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.left_line_stripe_layout);
        FrameLayout rightLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.right_line_stripe_layout);
        if (i == 0) {
            prevLineStripeLayout.setVisibility(View.GONE);
            nextLineStripeLayout.setBackgroundColor(lineColor);
        } else if (i == stations.size() - 1) {
            prevLineStripeLayout.setBackgroundColor(lineColor);
            nextLineStripeLayout.setVisibility(View.GONE);
        } else {
            prevLineStripeLayout.setBackgroundColor(lineColor);
            nextLineStripeLayout.setBackgroundColor(lineColor);
        }
        if (station.getLines().size() > 1) {
            for (Stop stop : station.getStops()) {
                if (stop.getLine() != line) {
                    rightLineStripeLayout.setVisibility(View.VISIBLE);
                    GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, new int[] { 0, stop.getLine().getColor() });
                    gd.setCornerRadius(0f);
                    if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                        rightLineStripeLayout.setBackgroundDrawable(gd);
                    } else {
                        rightLineStripeLayout.setBackground(gd);
                    }
                    if (stop.getLine().outDegreeOf(stop) > 1) {
                        leftLineStripeLayout.setVisibility(View.VISIBLE);
                        gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[] { 0, stop.getLine().getColor() });
                        gd.setCornerRadius(0f);
                        if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
                            leftLineStripeLayout.setBackgroundDrawable(gd);
                        } else {
                            leftLineStripeLayout.setBackground(gd);
                        }
                    }
                    break;
                }
            }
        }
        ImageView crossView = (ImageView) stepview.findViewById(R.id.station_cross_image);
        if (station.isAlwaysClosed()) {
            crossView.setVisibility(View.VISIBLE);
        }
        stepview.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
                context.startActivity(intent);
            }
        });
        RouteFragment.populateStationView(context, station, stepview, true, false);
        root.addView(stepview);
    }
}
Also used : Stop(im.tny.segvault.subway.Stop) ArrayList(java.util.ArrayList) Connection(im.tny.segvault.subway.Connection) ServiceConnection(android.content.ServiceConnection) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) GradientDrawable(android.graphics.drawable.GradientDrawable) Station(im.tny.segvault.subway.Station) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HashSet(java.util.HashSet)

Example 3 with Stop

use of im.tny.segvault.subway.Stop in project underlx by underlx.

the class TripCorrectionActivity method removeVertex.

private void removeVertex(int i) {
    if (!canRemoveVertex(i)) {
        return;
    }
    List<StationUse> uses = trip.getPath();
    uses.get(i - 1).setLeaveDate(trip.getPath().get(i + 1).getLeaveDate());
    uses.remove(i);
    // the next one to remove might be an interchange, if yes, save its src/dest line as it may be needed later
    String srcLineId = uses.get(i).getSourceLine();
    String dstLineId = uses.get(i).getTargetLine();
    uses.remove(i);
    if (uses.size() == 1) {
        uses.get(0).setType(StationUse.UseType.VISIT);
    } else {
        uses.get(0).setType(StationUse.UseType.NETWORK_ENTRY);
        uses.get(trip.getPath().size() - 1).setType(StationUse.UseType.NETWORK_EXIT);
        if (i < uses.size() && i > 1) {
            Station src = network.getStation(uses.get(i - 2).getStation().getId());
            Station dst = network.getStation(uses.get(i).getStation().getId());
            boolean foundSameLine = false;
            for (Stop srcStop : src.getStops()) {
                for (Line dstLine : dst.getLines()) {
                    if (dstLine.containsVertex(srcStop)) {
                        foundSameLine = true;
                    }
                }
            }
            if (!foundSameLine) {
                if (uses.get(i - 1).getType() != StationUse.UseType.INTERCHANGE) {
                    uses.get(i - 1).setType(StationUse.UseType.INTERCHANGE);
                    uses.get(i - 1).setSourceLine(srcLineId);
                    uses.get(i - 1).setTargetLine(dstLineId);
                }
            } else {
                uses.get(i - 1).setType(StationUse.UseType.GONE_THROUGH);
            }
        }
    }
    originalPath = trip.toConnectionPath(network);
    partsDeleted = true;
    redrawPath();
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Station(im.tny.segvault.subway.Station) Line(im.tny.segvault.subway.Line) Stop(im.tny.segvault.subway.Stop)

Example 4 with Stop

use of im.tny.segvault.subway.Stop in project underlx by underlx.

the class WiFiLocator method updateCurrentBSSIDs.

public void updateCurrentBSSIDs(List<BSSID> bssids) {
    boolean prevInNetwork = inNetwork(network);
    List<Stop> prevLocation = getLocationOrdered(network);
    currentBSSIDs = bssids;
    boolean curInNetwork = inNetwork(network);
    List<Stop> curLocation = getLocationOrdered(network);
    List<Stop> stationsLeft = new ArrayList<>();
    for (Stop s : prevLocation) {
        if (!curLocation.contains(s)) {
            stationsLeft.add(s);
            blacklistedStations.remove(s);
            if (lastEntered == s) {
                lastEntered = null;
            }
        }
    }
    if (stationsLeft.size() > 0) {
        Stop[] stationsLeftArray = new Stop[stationsLeft.size()];
        listener.onLeftStations(this, stationsLeft.toArray(stationsLeftArray));
    }
    if (curInNetwork != prevInNetwork) {
        if (curInNetwork) {
            listener.onEnteredNetwork(this);
        } else {
            listener.onLeftNetwork(this);
        }
    }
    for (Stop s : curLocation) {
        if ((lastEntered != s || !prevLocation.contains(s)) && !blacklistedStations.contains(s)) {
            listener.onEnteredStations(this, s);
            lastEntered = s;
            blacklistedStations.add(s);
            break;
        }
    }
}
Also used : Stop(im.tny.segvault.subway.Stop) ArrayList(java.util.ArrayList)

Example 5 with Stop

use of im.tny.segvault.subway.Stop in project underlx by underlx.

the class WiFiLocator method getLocationOrdered.

private List<Stop> getLocationOrdered(Network network) {
    Set<Stop> stops = new HashSet<>();
    List<Stop> orderedStops = new ArrayList<>();
    for (Stop s : network.vertexSet()) {
        if (checkBSSIDs(s)) {
            stops.add(s);
        }
    }
    // assumes currentBSSIDs are sorted by decreasing signal strength
    for (BSSID b : currentBSSIDs) {
        for (Stop s : stops) {
            Object o = s.getMeta(STOP_META_WIFICHECKER_KEY);
            if (o == null || !(o instanceof List)) {
                continue;
            }
            List<BSSID> stationBSSID = (List<BSSID>) o;
            if (stationBSSID.contains(b)) {
                orderedStops.add(s);
            }
        }
    }
    return orderedStops;
}
Also used : Stop(im.tny.segvault.subway.Stop) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

Stop (im.tny.segvault.subway.Stop)15 ArrayList (java.util.ArrayList)8 Connection (im.tny.segvault.subway.Connection)6 Station (im.tny.segvault.subway.Station)5 Line (im.tny.segvault.subway.Line)4 Network (im.tny.segvault.subway.Network)4 Intent (android.content.Intent)3 S2LS (im.tny.segvault.s2ls.S2LS)3 HashSet (java.util.HashSet)3 SpannableString (android.text.SpannableString)2 View (android.view.View)2 TextView (android.widget.TextView)2 CacheException (im.tny.segvault.disturbances.exception.CacheException)2 Path (im.tny.segvault.s2ls.Path)2 BSSID (im.tny.segvault.s2ls.wifi.BSSID)2 Date (java.util.Date)2 PendingIntent (android.app.PendingIntent)1 ServiceConnection (android.content.ServiceConnection)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1