Search in sources :

Example 1 with LobbyView

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);
        }
    });
}
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

ViewTreeObserver (android.view.ViewTreeObserver)1 GoogleMap (com.google.android.gms.maps.GoogleMap)1 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)1 Marker (com.google.android.gms.maps.model.Marker)1 MainService (im.tny.segvault.disturbances.MainService)1 LobbyView (im.tny.segvault.disturbances.ui.widget.LobbyView)1 Lobby (im.tny.segvault.subway.Lobby)1 Network (im.tny.segvault.subway.Network)1 Station (im.tny.segvault.subway.Station)1