use of im.tny.segvault.subway.Station in project underlx by underlx.
the class HomeFragment method refreshCurrentTrip.
private void refreshCurrentTrip() {
if (mListener == null)
return;
final MainService m = mListener.getMainService();
if (m == null)
return;
S2LS loc = m.getS2LS(MainService.PRIMARY_NETWORK_ID);
if (loc == null || loc.getCurrentTrip() == null) {
ongoingTripCard.setVisibility(View.GONE);
} else {
final Station station = loc.getCurrentTrip().getCurrentStop().getStation();
curStationNameView.setText(station.getName());
Stop direction = loc.getCurrentTrip().getDirection();
Stop next = loc.getCurrentTrip().getNextStop();
if (direction != null && next != null) {
directionView.setText(String.format(getString(R.string.frag_home_trip_direction), direction.getStation().getName()));
nextStationView.setText(String.format(getString(R.string.frag_home_trip_next_station), next.getStation().getName()));
Stop likelyExit = m.getLikelyNextExit(loc.getCurrentTrip().getEdgeList(), 1);
int resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Small;
if (next == likelyExit) {
resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Medium;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
nextStationView.setTextAppearance(resId);
} else {
nextStationView.setTextAppearance(getContext(), resId);
}
directionView.setVisibility(View.VISIBLE);
nextStationView.setVisibility(View.VISIBLE);
} else {
directionView.setVisibility(View.GONE);
nextStationView.setVisibility(View.GONE);
}
redrawCurrentStationLineIcons(station);
curStationLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getContext(), StationActivity.class);
intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
intent.putExtra(StationActivity.EXTRA_NETWORK_ID, MainService.PRIMARY_NETWORK_ID);
startActivity(intent);
}
});
curTripIncorrectLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FeedbackUtil.IncorrectLocation(getContext(), m, station).showReportWizard();
}
});
if (loc.canRequestEndOfTrip()) {
curTripEndButton.setVisibility(View.VISIBLE);
curTripIncorrectLocationButton.setVisibility(View.GONE);
} else {
curTripEndButton.setVisibility(View.GONE);
curTripIncorrectLocationButton.setVisibility(View.VISIBLE);
}
ongoingTripCard.setVisibility(View.VISIBLE);
}
}
use of im.tny.segvault.subway.Station 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;
}
}
}
}
use of im.tny.segvault.subway.Station 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();
}
use of im.tny.segvault.subway.Station in project underlx by underlx.
the class MainService method putNetwork.
private void putNetwork(final Network net) {
synchronized (lock) {
// create Realm stations for the network if they don't exist already
Realm realm = Application.getDefaultRealmInstance(this);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
for (Station s : net.getStations()) {
if (realm.where(RStation.class).equalTo("id", s.getId()).count() == 0) {
RStation rs = new RStation();
rs.setStop(s);
rs.setNetwork(net.getId());
realm.copyToRealm(rs);
}
}
}
});
realm.close();
net.setEdgeWeighter(cweighter);
networks.put(net.getId(), net);
S2LS loc = new S2LS(net, new S2LSChangeListener());
locServices.put(net.getId(), loc);
WiFiLocator wl = new WiFiLocator(net);
wfc.setLocatorForNetwork(net, wl);
loc.addNetworkDetector(wl);
loc.addProximityDetector(wl);
loc.addLocator(wl);
}
}
Aggregations