Search in sources :

Example 16 with Network

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

the class MainActivity method onStationLinkClicked.

public void onStationLinkClicked(String destination, String lobby, String exit) {
    if (locService != null) {
        for (Network network : locService.getNetworks()) {
            Station station;
            if ((station = network.getStation(destination)) != null) {
                Intent intent = new Intent(this, StationActivity.class);
                intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
                intent.putExtra(StationActivity.EXTRA_NETWORK_ID, network.getId());
                if (lobby != null && !lobby.isEmpty()) {
                    intent.putExtra(StationActivity.EXTRA_LOBBY_ID, lobby);
                }
                if (exit != null && !exit.isEmpty()) {
                    intent.putExtra(StationActivity.EXTRA_EXIT_ID, Integer.parseInt(exit));
                }
                startActivity(intent);
                return;
            }
        }
    }
}
Also used : Station(im.tny.segvault.subway.Station) Network(im.tny.segvault.subway.Network) Intent(android.content.Intent)

Example 17 with Network

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

the class MainActivity method onListFragmentInteraction.

@Override
public void onListFragmentInteraction(LineRecyclerViewAdapter.LineItem item) {
    if (locService != null) {
        for (Network network : locService.getNetworks()) {
            Line line;
            if ((line = network.getLine(item.id)) != null) {
                Intent intent = new Intent(this, LineActivity.class);
                intent.putExtra(LineActivity.EXTRA_LINE_ID, line.getId());
                intent.putExtra(LineActivity.EXTRA_NETWORK_ID, network.getId());
                startActivity(intent);
                return;
            }
        }
    }
}
Also used : Line(im.tny.segvault.subway.Line) Network(im.tny.segvault.subway.Network) Intent(android.content.Intent)

Example 18 with Network

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

the class StationGeneralFragment 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;
    if (station.isAlwaysClosed()) {
        LinearLayout closedLayout = (LinearLayout) view.findViewById(R.id.closed_info_layout);
        closedLayout.setVisibility(View.VISIBLE);
    } else if (station.isExceptionallyClosed(net, new Date())) {
        TextView closedView = (TextView) view.findViewById(R.id.closed_info_view);
        Formatter f = new Formatter();
        DateUtils.formatDateRange(getContext(), f, station.getNextOpenTime(net), station.getNextOpenTime(net), DateUtils.FORMAT_SHOW_TIME, net.getTimezone().getID());
        closedView.setText(String.format(getString(R.string.frag_station_closed_schedule), f.toString()));
        LinearLayout closedLayout = (LinearLayout) view.findViewById(R.id.closed_info_layout);
        closedLayout.setVisibility(View.VISIBLE);
    }
    // Connections
    TextView connectionsTitleView = (TextView) view.findViewById(R.id.connections_title_view);
    // buttons
    Button busButton = (Button) view.findViewById(R.id.connections_bus_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BUS)) {
        busButton.setVisibility(View.VISIBLE);
        busButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BUS, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    Button boatButton = (Button) view.findViewById(R.id.connections_boat_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BOAT)) {
        boatButton.setVisibility(View.VISIBLE);
        boatButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BOAT, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    Button trainButton = (Button) view.findViewById(R.id.connections_train_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_TRAIN)) {
        trainButton.setVisibility(View.VISIBLE);
        trainButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_TRAIN, station);
            }
        });
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    // icons
    LinearLayout busLayout = (LinearLayout) view.findViewById(R.id.feature_bus_layout);
    if (station.getFeatures().bus) {
        busLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout boatLayout = (LinearLayout) view.findViewById(R.id.feature_boat_layout);
    if (station.getFeatures().boat) {
        boatLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout trainLayout = (LinearLayout) view.findViewById(R.id.feature_train_layout);
    if (station.getFeatures().train) {
        trainLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout airportLayout = (LinearLayout) view.findViewById(R.id.feature_airport_layout);
    if (station.getFeatures().airport) {
        airportLayout.setVisibility(View.VISIBLE);
        connectionsTitleView.setVisibility(View.VISIBLE);
    }
    // Accessibility
    TextView accessibilityTitleView = (TextView) view.findViewById(R.id.accessibility_title_view);
    LinearLayout liftLayout = (LinearLayout) view.findViewById(R.id.feature_lift_layout);
    if (station.getFeatures().lift) {
        liftLayout.setVisibility(View.VISIBLE);
        accessibilityTitleView.setVisibility(View.VISIBLE);
    }
    // Services
    TextView servicesTitleView = (TextView) view.findViewById(R.id.services_title_view);
    Button parkButton = (Button) view.findViewById(R.id.connections_park_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_PARK)) {
        parkButton.setVisibility(View.VISIBLE);
        parkButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_PARK, station);
            }
        });
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    Button bikeButton = (Button) view.findViewById(R.id.connections_bike_button);
    if (station.hasConnectionUrl(Station.CONNECTION_TYPE_BIKE)) {
        bikeButton.setVisibility(View.VISIBLE);
        bikeButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ExtraContentCache.getConnectionInfo(getContext(), new ConnectionInfoReadyListener(), Station.CONNECTION_TYPE_BIKE, station);
            }
        });
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout wifiLayout = (LinearLayout) view.findViewById(R.id.service_wifi_layout);
    if (station.getFeatures().wifi) {
        wifiLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout parkLayout = (LinearLayout) view.findViewById(R.id.service_park_layout);
    if (station.getFeatures().parking) {
        parkLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    LinearLayout bikeLayout = (LinearLayout) view.findViewById(R.id.service_bike_layout);
    if (station.getFeatures().bike) {
        bikeLayout.setVisibility(View.VISIBLE);
        servicesTitleView.setVisibility(View.VISIBLE);
    }
    // Statistics
    Realm realm = Application.getDefaultRealmInstance(getContext());
    TextView statsEntryCountView = (TextView) view.findViewById(R.id.station_entry_count_view);
    long entryCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.NETWORK_ENTRY.name()).count();
    statsEntryCountView.setText(String.format(getString(R.string.frag_station_stats_entry), entryCount));
    TextView statsExitCountView = (TextView) view.findViewById(R.id.station_exit_count_view);
    long exitCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.NETWORK_EXIT.name()).count();
    statsExitCountView.setText(String.format(getString(R.string.frag_station_stats_exit), exitCount));
    TextView statsGoneThroughCountView = (TextView) view.findViewById(R.id.station_gone_through_count_view);
    long goneThroughCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.GONE_THROUGH.name()).count();
    statsGoneThroughCountView.setText(String.format(getString(R.string.frag_station_stats_gone_through), goneThroughCount));
    TextView statsTransferCountView = (TextView) view.findViewById(R.id.station_transfer_count_view);
    if (station.getLines().size() > 1) {
        long transferCount = realm.where(StationUse.class).equalTo("station.id", station.getId()).equalTo("type", StationUse.UseType.INTERCHANGE.name()).count();
        statsTransferCountView.setText(String.format(getString(R.string.frag_station_stats_transfer), transferCount));
        statsTransferCountView.setVisibility(View.VISIBLE);
    } else {
        statsTransferCountView.setVisibility(View.GONE);
    }
    realm.close();
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Formatter(java.util.Formatter) View(android.view.View) TextView(android.widget.TextView) Date(java.util.Date) MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) Button(android.widget.Button) Network(im.tny.segvault.subway.Network) TextView(android.widget.TextView) Realm(io.realm.Realm) LinearLayout(android.widget.LinearLayout)

Example 19 with Network

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

the class MainService method dumpDebugInfo.

// DEBUG:
public String dumpDebugInfo() {
    String s = "Service created on " + creationDate.toString();
    s += (wfc.isScanning() ? String.format(". WFC scanning every %d s", wfc.getScanInterval() / 1000) : ". WFC not scanning") + "\n";
    for (Network n : getNetworks()) {
        S2LS loc;
        synchronized (lock) {
            loc = locServices.get(n.getId());
        }
        s += "Network " + n.getNames("en")[0] + "\n";
        s += "State machine: " + loc.getState().toString() + "\n";
        s += String.format("\tIn network? %b\n\tNear network? %b\n", loc.inNetwork(), loc.nearNetwork());
        if (loc.getState() instanceof InNetworkState) {
            s += "\tPossible stops:\n";
            for (Stop stop : loc.getLocation().vertexSet()) {
                s += String.format("\t\t%s (%s)\n", stop.getStation().getName(), stop.getLine().getNames("en")[0]);
            }
            s += "\tPath:\n";
            if (loc.getCurrentTrip() != null) {
                for (Connection c : loc.getCurrentTrip().getEdgeList()) {
                    s += String.format("\t\t%s -> %s\n", c.getSource().toString(), c.getTarget().toString());
                }
                if (loc.getCurrentTargetRoute() != null) {
                    s += String.format("\t\tCurrent path complies? %b\n", loc.getCurrentTargetRoute().checkPathCompliance(loc.getCurrentTrip()));
                }
            }
        }
    }
    try {
        API.AuthTest authTest = API.getInstance().getAuthTest();
        s += "API auth test result: " + authTest.result + "\n";
        s += "API key as perceived by server: " + authTest.key + "\n";
    } catch (APIException e) {
        e.printStackTrace();
        s += "Error testing API authentication\n";
    }
    synchronizer.attemptSync();
    return s;
}
Also used : S2LS(im.tny.segvault.s2ls.S2LS) APIException(im.tny.segvault.disturbances.exception.APIException) Stop(im.tny.segvault.subway.Stop) Network(im.tny.segvault.subway.Network) Connection(im.tny.segvault.subway.Connection) SpannableString(android.text.SpannableString) InNetworkState(im.tny.segvault.s2ls.InNetworkState)

Aggregations

Network (im.tny.segvault.subway.Network)19 Line (im.tny.segvault.subway.Line)8 Station (im.tny.segvault.subway.Station)7 Intent (android.content.Intent)5 MainService (im.tny.segvault.disturbances.MainService)5 Stop (im.tny.segvault.subway.Stop)4 Realm (io.realm.Realm)4 SharedPreferences (android.content.SharedPreferences)3 SpannableString (android.text.SpannableString)3 Date (java.util.Date)3 PendingIntent (android.app.PendingIntent)2 View (android.view.View)2 ViewTreeObserver (android.view.ViewTreeObserver)2 Button (android.widget.Button)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)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 CacheException (im.tny.segvault.disturbances.exception.CacheException)2