Search in sources :

Example 1 with Station

use of im.tny.segvault.subway.Station 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 2 with Station

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

the class TripCorrectionActivity method populateUI.

private void populateUI() {
    Realm realm = Application.getDefaultRealmInstance(this);
    trip = realm.where(Trip.class).equalTo("id", tripId).findFirst();
    if (trip == null) {
        finish();
        return;
    }
    trip = realm.copyFromRealm(trip);
    realm.close();
    originalPath = trip.toConnectionPath(network);
    if (!trip.canBeCorrected()) {
        finish();
        return;
    }
    List<Station> stations = new ArrayList<>(network.getStations());
    startPicker.setStations(stations);
    endPicker.setStations(stations);
    startPicker.setAllStationsSortStrategy(new StationPickerView.DistanceSortStrategy(network, originalPath.getStartVertex()));
    endPicker.setAllStationsSortStrategy(new StationPickerView.DistanceSortStrategy(network, originalPath.getEndVertex()));
    startPicker.setWeakSelection(originalPath.getStartVertex().getStation());
    endPicker.setWeakSelection(originalPath.getEndVertex().getStation());
    StationPickerView.OnStationSelectedListener onStationSelectedListener = new StationPickerView.OnStationSelectedListener() {

        @Override
        public void onStationSelected(Station station) {
            redrawPath();
        }
    };
    startPicker.setOnStationSelectedListener(onStationSelectedListener);
    endPicker.setOnStationSelectedListener(onStationSelectedListener);
    StationPickerView.OnSelectionLostListener onSelectionLostListener = new StationPickerView.OnSelectionLostListener() {

        @Override
        public void onSelectionLost() {
            redrawPath();
        }
    };
    startPicker.setOnSelectionLostListener(onSelectionLostListener);
    endPicker.setOnSelectionLostListener(onSelectionLostListener);
    redrawPath();
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveChanges();
        }
    });
}
Also used : Trip(im.tny.segvault.disturbances.model.Trip) ArrayList(java.util.ArrayList) StationPickerView(im.tny.segvault.disturbances.ui.widget.StationPickerView) View(android.view.View) Station(im.tny.segvault.subway.Station) StationPickerView(im.tny.segvault.disturbances.ui.widget.StationPickerView) Realm(io.realm.Realm)

Example 3 with Station

use of im.tny.segvault.subway.Station 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 Station

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

the class Route method getShortestPath.

public static GraphPath getShortestPath(final Network network, Station source, Station target, @Nullable IEdgeWeighter weighter, @Nullable IAlternativeQualifier qualifier) {
    if (qualifier == null) {
        qualifier = new IAlternativeQualifier() {

            @Override
            public boolean acceptable(Station station) {
                return !station.isAlwaysClosed() && !station.isExceptionallyClosed(network, new Date());
            }
        };
    }
    List<Stop> possibleSources = new ArrayList<>();
    if (!qualifier.acceptable(source)) {
        for (Station neighbor : source.getAlternatives(qualifier, 1)) {
            possibleSources.addAll(neighbor.getStops());
        }
    } else {
        possibleSources.addAll(source.getStops());
    }
    List<Stop> possibleTargets = new ArrayList<>();
    if (!qualifier.acceptable(target)) {
        for (Station neighbor : target.getAlternatives(qualifier, 1)) {
            possibleTargets.addAll(neighbor.getStops());
        }
    } else {
        possibleTargets.addAll(target.getStops());
    }
    return getShortestPath(network, possibleSources, possibleTargets, weighter);
}
Also used : Station(im.tny.segvault.subway.Station) Stop(im.tny.segvault.subway.Stop) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 5 with Station

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

the class StationLobbyFragment method update.

private void update() {
    if (mListener == null)
        return;
    MainService service = mListener.getMainService();
    if (service == null)
        return;
    Network net = service.getNetwork(networkId);
    if (net == null)
        return;
    final Station station = net.getStation(stationId);
    if (station == null)
        return;
    // Lobbies
    final int[] lobbyColors = Util.lobbyColors.clone();
    if (station.getLobbies().size() == 1) {
        lobbyColors[0] = Color.BLACK;
    }
    int curLobbyColorIdx = 0;
    for (Lobby lobby : station.getLobbies()) {
        LobbyView v = new LobbyView(getContext(), lobby, lobbyColors[curLobbyColorIdx]);
        v.setInteractionListener(new LobbyView.OnViewInteractionListener() {

            @Override
            public void onExitClicked(Lobby.Exit exit) {
                if (googleMap == null || !mapLayoutReady) {
                    return;
                }
                Marker marker = markers.get(exit);
                if (marker != null) {
                    marker.showInfoWindow();
                }
                lobbyScrollView.fullScroll(NestedScrollView.FOCUS_UP);
                googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(marker.getPosition(), googleMap.getCameraPosition().zoom)));
            }
        });
        lobbiesLayout.addView(v);
        curLobbyColorIdx = (curLobbyColorIdx + 1) % lobbyColors.length;
    }
    final int preselExit = mListener.getPreselectedExitId();
    final ViewTreeObserver vto = mapView.getViewTreeObserver();
    if (vto.isAlive()) {
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            public void onGlobalLayout() {
                mapLayoutReady = true;
                trySetupMap(station, lobbyColors, preselExit);
                // remove the listener... or we'll be doing this a lot.
                ViewTreeObserver obs = mapView.getViewTreeObserver();
                obs.removeGlobalOnLayoutListener(this);
            }
        });
    }
    mapView.getMapAsync(new OnMapReadyCallback() {

        @Override
        public void onMapReady(GoogleMap mMap) {
            googleMap = mMap;
            trySetupMap(station, lobbyColors, preselExit);
        }
    });
}
Also used : OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) Marker(com.google.android.gms.maps.model.Marker) MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) Lobby(im.tny.segvault.subway.Lobby) GoogleMap(com.google.android.gms.maps.GoogleMap) Network(im.tny.segvault.subway.Network) LobbyView(im.tny.segvault.disturbances.ui.widget.LobbyView) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

Station (im.tny.segvault.subway.Station)19 View (android.view.View)7 Network (im.tny.segvault.subway.Network)7 TextView (android.widget.TextView)6 MainService (im.tny.segvault.disturbances.MainService)5 Stop (im.tny.segvault.subway.Stop)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)4 ImageView (android.widget.ImageView)4 Line (im.tny.segvault.subway.Line)4 Lobby (im.tny.segvault.subway.Lobby)4 Realm (io.realm.Realm)4 Connection (im.tny.segvault.subway.Connection)3 POI (im.tny.segvault.subway.POI)3 Location (android.location.Location)2 ViewTreeObserver (android.view.ViewTreeObserver)2 FrameLayout (android.widget.FrameLayout)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)2 Marker (com.google.android.gms.maps.model.Marker)2