use of im.tny.segvault.disturbances.ui.widget.LobbyView 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);
}
});
}
Aggregations