use of im.tny.segvault.disturbances.MainService 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);
}
});
}
use of im.tny.segvault.disturbances.MainService in project underlx by underlx.
the class StationTriviaFragment 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;
Station station = net.getStation(stationId);
if (station == null)
return;
ExtraContentCache.getTrivia(getContext(), new ExtraContentCache.OnTriviaReadyListener() {
@Override
public void onSuccess(List<String> trivia) {
if (isAdded()) {
triviaView.setHtml(trivia.get(0));
}
}
@Override
public void onProgress(int current) {
}
@Override
public void onFailure() {
if (isAdded()) {
triviaView.setHtml(getString(R.string.frag_station_info_unavailable));
}
}
}, station);
}
use of im.tny.segvault.disturbances.MainService in project underlx by underlx.
the class HomeFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.menu_refresh:
refresh(true);
return true;
case R.id.menu_report_incorrect_location:
if (mListener == null)
return true;
MainService m = mListener.getMainService();
if (m == null)
return true;
new FeedbackUtil.IncorrectLocation(getContext(), m).showReportWizard();
return true;
}
return super.onOptionsItemSelected(item);
}
use of im.tny.segvault.disturbances.MainService in project underlx by underlx.
the class StationPOIFragment 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;
Locale l = Util.getCurrentLocale(getContext());
final String lang = l.getLanguage();
// POIs
pois = station.getPOIs();
Collections.sort(pois, new Comparator<POI>() {
@Override
public int compare(POI o1, POI o2) {
return o1.getNames(lang)[0].compareTo(o2.getNames(lang)[0]);
}
});
for (POI poi : pois) {
POIView v = new POIView(getContext(), poi);
v.setInteractionListener(new POIView.OnViewInteractionListener() {
@Override
public void onPOIClicked(POI poi) {
if (googleMap == null || !mapLayoutReady) {
return;
}
Marker marker = markers.get(poi);
if (marker != null) {
marker.showInfoWindow();
}
poiScrollView.fullScroll(NestedScrollView.FOCUS_UP);
googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(marker.getPosition(), googleMap.getCameraPosition().zoom)));
}
});
poisLayout.addView(v);
}
// Lobbies
final int[] lobbyColors = Util.lobbyColors.clone();
if (station.getLobbies().size() == 1) {
lobbyColors[0] = Color.BLACK;
}
final ViewTreeObserver vto = mapView.getViewTreeObserver();
if (vto.isAlive()) {
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
mapLayoutReady = true;
trySetupMap(station, pois, lobbyColors, lang);
// 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, pois, lobbyColors, lang);
}
});
}
use of im.tny.segvault.disturbances.MainService in project underlx by underlx.
the class HomeFragment method recomputeShortcutVisibility.
private void recomputeShortcutVisibility() {
if (disturbancesButton == null || mListener == null) {
return;
}
Layout layout = disturbancesButton.getLayout();
boolean littleSpace = false;
if (layout == null) {
return;
}
int lines = layout.getLineCount();
if (lines > 0) {
int ellipsisCount = layout.getEllipsisCount(lines - 1);
if (ellipsisCount > 0) {
littleSpace = true;
}
}
if (!littleSpace) {
disturbancesButton.setVisibility(View.VISIBLE);
tripHistoryButton.setVisibility(View.VISIBLE);
return;
}
MainService m = mListener.getMainService();
if (m == null) {
return;
}
if (m.getLineStatusCache().isDisturbanceOngoing()) {
disturbancesButton.setVisibility(View.VISIBLE);
tripHistoryButton.setVisibility(View.GONE);
} else {
disturbancesButton.setVisibility(View.GONE);
tripHistoryButton.setVisibility(View.VISIBLE);
}
}
Aggregations