Search in sources :

Example 1 with POIView

use of im.tny.segvault.disturbances.ui.widget.POIView 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);
        }
    });
}
Also used : Locale(java.util.Locale) POIView(im.tny.segvault.disturbances.ui.widget.POIView) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) POI(im.tny.segvault.subway.POI) Marker(com.google.android.gms.maps.model.Marker) MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) GoogleMap(com.google.android.gms.maps.GoogleMap) Network(im.tny.segvault.subway.Network) 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 POIView (im.tny.segvault.disturbances.ui.widget.POIView)1 Network (im.tny.segvault.subway.Network)1 POI (im.tny.segvault.subway.POI)1 Station (im.tny.segvault.subway.Station)1 Locale (java.util.Locale)1