Search in sources :

Example 1 with MainService

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

Example 2 with MainService

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);
}
Also used : MainService(im.tny.segvault.disturbances.MainService) Station(im.tny.segvault.subway.Station) ExtraContentCache(im.tny.segvault.disturbances.ExtraContentCache) Network(im.tny.segvault.subway.Network)

Example 3 with MainService

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);
}
Also used : MainService(im.tny.segvault.disturbances.MainService) FeedbackUtil(im.tny.segvault.disturbances.FeedbackUtil)

Example 4 with MainService

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

Example 5 with MainService

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);
    }
}
Also used : MainService(im.tny.segvault.disturbances.MainService) LinearLayout(android.widget.LinearLayout) FrameLayout(android.widget.FrameLayout) Layout(android.text.Layout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout)

Aggregations

MainService (im.tny.segvault.disturbances.MainService)10 Network (im.tny.segvault.subway.Network)5 Station (im.tny.segvault.subway.Station)5 View (android.view.View)4 TextView (android.widget.TextView)4 Intent (android.content.Intent)2 ViewTreeObserver (android.view.ViewTreeObserver)2 ImageView (android.widget.ImageView)2 LinearLayout (android.widget.LinearLayout)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 OnMapReadyCallback (com.google.android.gms.maps.OnMapReadyCallback)2 Marker (com.google.android.gms.maps.model.Marker)2 Realm (io.realm.Realm)2 Formatter (java.util.Formatter)2 DialogInterface (android.content.DialogInterface)1 Fragment (android.support.v4.app.Fragment)1 FragmentTransaction (android.support.v4.app.FragmentTransaction)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 AlertDialog (android.support.v7.app.AlertDialog)1 CardView (android.support.v7.widget.CardView)1