Search in sources :

Example 1 with Network

use of im.tny.segvault.subway.Network 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 Network

use of im.tny.segvault.subway.Network in project underlx by underlx.

the class AboutFragment method refreshDatasetInfo.

private void refreshDatasetInfo() {
    if (mListener != null) {
        networksLayout.removeAllViews();
        for (Network n : mListener.getNetworks()) {
            DatasetInfoView d = new DatasetInfoView(getContext(), n, this);
            networksLayout.addView(d);
        }
    }
}
Also used : DatasetInfoView(im.tny.segvault.disturbances.ui.widget.DatasetInfoView) Network(im.tny.segvault.subway.Network)

Example 3 with Network

use of im.tny.segvault.subway.Network 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 4 with Network

use of im.tny.segvault.subway.Network in project underlx by underlx.

the class NotifPreferenceFragment method updateLinesPreference.

private void updateLinesPreference() {
    MultiSelectListPreference linesPreference;
    linesPreference = (MultiSelectListPreference) findPreference(PreferenceNames.NotifsLines);
    List<CharSequence> lineNames = new ArrayList<>();
    List<CharSequence> lineIDs = new ArrayList<>();
    List<Line> lines = new LinkedList<>();
    if (mListener != null && mListener.getMainService() != null) {
        for (Network n : mListener.getMainService().getNetworks()) {
            lines.addAll(n.getLines());
        }
        Collections.sort(lines, new Comparator<Line>() {

            @Override
            public int compare(Line line, Line t1) {
                return Integer.valueOf(line.getOrder()).compareTo(t1.getOrder());
            }
        });
        for (Line l : lines) {
            lineNames.add(Util.getLineNames(getContext(), l)[0]);
            lineIDs.add(l.getId());
        }
    }
    linesPreference.setEntries(lineNames.toArray(new CharSequence[lineNames.size()]));
    linesPreference.setEntryValues(lineIDs.toArray(new CharSequence[lineIDs.size()]));
    updateLinesPreferenceSummary(linesPreference, linesPreference.getValues());
    linesPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            MultiSelectListPreference multilistPreference = (MultiSelectListPreference) preference;
            @SuppressWarnings("unchecked") Set<String> values = (Set<String>) newValue;
            updateLinesPreferenceSummary(multilistPreference, values);
            return true;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) LinkedList(java.util.LinkedList) Line(im.tny.segvault.subway.Line) ListPreference(net.xpece.android.support.preference.ListPreference) MultiSelectListPreference(net.xpece.android.support.preference.MultiSelectListPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) SeekBarPreference(net.xpece.android.support.preference.SeekBarPreference) Preference(android.support.v7.preference.Preference) Network(im.tny.segvault.subway.Network)

Example 5 with Network

use of im.tny.segvault.subway.Network in project underlx by underlx.

the class DisturbancesIntroSlide method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.fragment_intro_disturbances, container, false);
    ((Button) view.findViewById(R.id.select_lines_button)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            List<Line> lines = new LinkedList<>();
            if (mListener != null && mListener.getMainService() != null) {
                for (Network n : mListener.getMainService().getNetworks()) {
                    lines.addAll(n.getLines());
                }
                Collections.sort(lines, new Comparator<Line>() {

                    @Override
                    public int compare(Line line, Line t1) {
                        return Integer.valueOf(line.getOrder()).compareTo(t1.getOrder());
                    }
                });
            }
            if (lines.size() == 0) {
                if (Connectivity.isConnected(getContext())) {
                    Snackbar.make(view, R.string.intro_disturbances_misc_error, Snackbar.LENGTH_LONG).show();
                } else {
                    Snackbar.make(view, R.string.intro_disturbances_connection_error, Snackbar.LENGTH_LONG).show();
                }
                return;
            }
            view.findViewById(R.id.description_layout).setVisibility(View.GONE);
            view.findViewById(R.id.select_lines_button).setVisibility(View.GONE);
            LinearLayout checkboxLayout = (LinearLayout) view.findViewById(R.id.checkbox_layout);
            SharedPreferences sharedPref = getContext().getSharedPreferences("notifsettings", Context.MODE_PRIVATE);
            Set<String> linePref = sharedPref.getStringSet(PreferenceNames.NotifsLines, null);
            for (final Line l : lines) {
                AppCompatCheckBox checkBox = new AppCompatCheckBox(view.getContext());
                checkBox.setText(Util.getLineNames(getContext(), l)[0]);
                checkBox.setTextColor(Color.WHITE);
                ColorStateList colorStateList = new ColorStateList(new int[][] { // unchecked
                new int[] { -android.R.attr.state_checked }, // checked
                new int[] { android.R.attr.state_checked } }, new int[] { l.getColor(), l.getColor() });
                CompoundButtonCompat.setButtonTintList(checkBox, colorStateList);
                checkBox.setChecked(linePref == null || linePref.contains(l.getId()));
                checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        updateShowLineNotifs(l.getId(), isChecked);
                    }
                });
                checkboxLayout.addView(checkBox);
            }
            view.findViewById(R.id.lines_layout).setVisibility(View.VISIBLE);
        }
    });
    return view;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SharedPreferences(android.content.SharedPreferences) ColorStateList(android.content.res.ColorStateList) View(android.view.View) Comparator(java.util.Comparator) AppCompatCheckBox(android.support.v7.widget.AppCompatCheckBox) Line(im.tny.segvault.subway.Line) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) Network(im.tny.segvault.subway.Network) ColorStateList(android.content.res.ColorStateList) LinkedList(java.util.LinkedList) List(java.util.List) LinearLayout(android.widget.LinearLayout) CompoundButton(android.widget.CompoundButton) Nullable(android.support.annotation.Nullable)

Aggregations

Network (im.tny.segvault.subway.Network)19 Line (im.tny.segvault.subway.Line)8 Station (im.tny.segvault.subway.Station)7 Intent (android.content.Intent)5 MainService (im.tny.segvault.disturbances.MainService)5 Stop (im.tny.segvault.subway.Stop)4 Realm (io.realm.Realm)4 SharedPreferences (android.content.SharedPreferences)3 SpannableString (android.text.SpannableString)3 Date (java.util.Date)3 PendingIntent (android.app.PendingIntent)2 View (android.view.View)2 ViewTreeObserver (android.view.ViewTreeObserver)2 Button (android.widget.Button)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)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 CacheException (im.tny.segvault.disturbances.exception.CacheException)2