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);
}
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);
}
}
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();
}
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;
}
}
}
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;
}
Aggregations