Search in sources :

Example 1 with Line

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

the class TripCorrectionActivity method removeVertex.

private void removeVertex(int i) {
    if (!canRemoveVertex(i)) {
        return;
    }
    List<StationUse> uses = trip.getPath();
    uses.get(i - 1).setLeaveDate(trip.getPath().get(i + 1).getLeaveDate());
    uses.remove(i);
    // the next one to remove might be an interchange, if yes, save its src/dest line as it may be needed later
    String srcLineId = uses.get(i).getSourceLine();
    String dstLineId = uses.get(i).getTargetLine();
    uses.remove(i);
    if (uses.size() == 1) {
        uses.get(0).setType(StationUse.UseType.VISIT);
    } else {
        uses.get(0).setType(StationUse.UseType.NETWORK_ENTRY);
        uses.get(trip.getPath().size() - 1).setType(StationUse.UseType.NETWORK_EXIT);
        if (i < uses.size() && i > 1) {
            Station src = network.getStation(uses.get(i - 2).getStation().getId());
            Station dst = network.getStation(uses.get(i).getStation().getId());
            boolean foundSameLine = false;
            for (Stop srcStop : src.getStops()) {
                for (Line dstLine : dst.getLines()) {
                    if (dstLine.containsVertex(srcStop)) {
                        foundSameLine = true;
                    }
                }
            }
            if (!foundSameLine) {
                if (uses.get(i - 1).getType() != StationUse.UseType.INTERCHANGE) {
                    uses.get(i - 1).setType(StationUse.UseType.INTERCHANGE);
                    uses.get(i - 1).setSourceLine(srcLineId);
                    uses.get(i - 1).setTargetLine(dstLineId);
                }
            } else {
                uses.get(i - 1).setType(StationUse.UseType.GONE_THROUGH);
            }
        }
    }
    originalPath = trip.toConnectionPath(network);
    partsDeleted = true;
    redrawPath();
}
Also used : StationUse(im.tny.segvault.disturbances.model.StationUse) Station(im.tny.segvault.subway.Station) Line(im.tny.segvault.subway.Line) Stop(im.tny.segvault.subway.Stop)

Example 2 with Line

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

the class StationLobbyFragment method trySetupMap.

private void trySetupMap(final Station station, final int[] lobbyColors, final int preselExit) {
    if (googleMap == null || !mapLayoutReady) {
        return;
    }
    if (!station.getFeatures().train) {
        googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.no_train_stations_map_style));
    }
    markers.clear();
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    int curLobbyColorIdx = 0;
    Marker focusMarker = null;
    for (Lobby lobby : station.getLobbies()) {
        for (Lobby.Exit exit : lobby.getExits()) {
            LatLng pos = new LatLng(exit.worldCoord[0], exit.worldCoord[1]);
            builder.include(pos);
            Marker marker = googleMap.addMarker(new MarkerOptions().position(pos).title(String.format(getString(R.string.frag_station_lobby_name), lobby.getName())).snippet(exit.getExitsString()).icon(Util.createMapMarker(getContext(), Util.getDrawableResourceIdForExitType(exit.type, lobby.isAlwaysClosed()), lobbyColors[curLobbyColorIdx])).alpha(lobby.isAlwaysClosed() ? 0.5f : 1));
            if (exit.id == preselExit) {
                marker.showInfoWindow();
                focusMarker = marker;
            }
            markers.put(exit, marker);
        }
        curLobbyColorIdx = (curLobbyColorIdx + 1) % lobbyColors.length;
    }
    for (Line line : station.getNetwork().getLines()) {
        for (WorldPath path : line.getPaths()) {
            PolylineOptions options = new PolylineOptions().width(5).color(line.getColor()).geodesic(true);
            for (float[] point : path.getPath()) {
                options.add(new LatLng(point[0], point[1]));
            }
            googleMap.addPolyline(options);
        }
    }
    LatLngBounds bounds = builder.build();
    // offset from edges of the map in pixels
    int padding = 100;
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    googleMap.moveCamera(cu);
    if (focusMarker != null) {
        googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.fromLatLngZoom(focusMarker.getPosition(), googleMap.getCameraPosition().zoom)));
    }
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) Marker(com.google.android.gms.maps.model.Marker) WorldPath(im.tny.segvault.subway.WorldPath) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions) Line(im.tny.segvault.subway.Line) Lobby(im.tny.segvault.subway.Lobby) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 3 with Line

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

the class StationPOIFragment method trySetupMap.

private void trySetupMap(final Station station, final List<POI> pois, final int[] lobbyColors, final String lang) {
    if (googleMap == null || !mapLayoutReady) {
        return;
    }
    if (!station.getFeatures().train) {
        googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.no_train_stations_map_style));
    }
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    int curLobbyColorIdx = 0;
    for (Lobby lobby : station.getLobbies()) {
        if (lobby.isAlwaysClosed()) {
            continue;
        }
        for (Lobby.Exit exit : lobby.getExits()) {
            LatLng pos = new LatLng(exit.worldCoord[0], exit.worldCoord[1]);
            builder.include(pos);
            googleMap.addMarker(new MarkerOptions().position(pos).title(String.format(getString(R.string.frag_station_lobby_name), lobby.getName())).snippet(exit.getExitsString()).icon(Util.createMapMarker(getContext(), Util.getDrawableResourceIdForExitType(exit.type, lobby.isAlwaysClosed()), lobbyColors[curLobbyColorIdx])).alpha(lobby.isAlwaysClosed() ? 0.5f : 1));
        }
        curLobbyColorIdx = (curLobbyColorIdx + 1) % lobbyColors.length;
    }
    markers.clear();
    for (POI poi : pois) {
        LatLng pos = new LatLng(poi.getWorldCoord()[0], poi.getWorldCoord()[1]);
        builder.include(pos);
        Marker marker = googleMap.addMarker(new MarkerOptions().position(pos).icon(getMarkerIcon(Util.getColorForPOIType(poi.getType(), getContext()))).title(poi.getNames(lang)[0]));
        markers.put(poi, marker);
    }
    for (Line line : station.getNetwork().getLines()) {
        for (WorldPath path : line.getPaths()) {
            PolylineOptions options = new PolylineOptions().width(5).color(line.getColor()).geodesic(true);
            for (float[] point : path.getPath()) {
                options.add(new LatLng(point[0], point[1]));
            }
            googleMap.addPolyline(options);
        }
    }
    googleMap.setOnInfoWindowClickListener(this);
    LatLngBounds bounds = builder.build();
    // offset from edges of the map in pixels
    int padding = 64;
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    googleMap.moveCamera(cu);
}
Also used : MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) POI(im.tny.segvault.subway.POI) Marker(com.google.android.gms.maps.model.Marker) WorldPath(im.tny.segvault.subway.WorldPath) PolylineOptions(com.google.android.gms.maps.model.PolylineOptions) Line(im.tny.segvault.subway.Line) Lobby(im.tny.segvault.subway.Lobby) LatLng(com.google.android.gms.maps.model.LatLng) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 4 with Line

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

the class HomeFragment method redrawCurrentStationLineIcons.

private void redrawCurrentStationLineIcons(Station station) {
    curStationIconsLayout.removeAllViews();
    List<Line> lines = new ArrayList<>(station.getLines());
    Collections.sort(lines, new Comparator<Line>() {

        @Override
        public int compare(Line l1, Line l2) {
            return Integer.valueOf(l1.getOrder()).compareTo(l2.getOrder());
        }
    });
    for (Line l : lines) {
        Drawable drawable = ContextCompat.getDrawable(getContext(), Util.getDrawableResourceIdForLineId(l.getId()));
        drawable.setColorFilter(l.getColor(), PorterDuff.Mode.SRC_ATOP);
        int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics());
        FrameLayout iconFrame = new FrameLayout(getContext());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(height, height);
        int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            params.setMarginEnd(margin);
        }
        int marginTop = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics());
        params.setMargins(0, marginTop, margin, 0);
        iconFrame.setLayoutParams(params);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            iconFrame.setBackgroundDrawable(drawable);
        } else {
            iconFrame.setBackground(drawable);
        }
        curStationIconsLayout.addView(iconFrame);
    }
}
Also used : Line(im.tny.segvault.subway.Line) FrameLayout(android.widget.FrameLayout) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) LinearLayout(android.widget.LinearLayout)

Example 5 with Line

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

Aggregations

Line (im.tny.segvault.subway.Line)18 Network (im.tny.segvault.subway.Network)8 Intent (android.content.Intent)5 Connection (im.tny.segvault.subway.Connection)5 SharedPreferences (android.content.SharedPreferences)4 Lobby (im.tny.segvault.subway.Lobby)4 Station (im.tny.segvault.subway.Station)4 Stop (im.tny.segvault.subway.Stop)4 ArrayList (java.util.ArrayList)4 View (android.view.View)3 FrameLayout (android.widget.FrameLayout)3 LinearLayout (android.widget.LinearLayout)3 TextView (android.widget.TextView)3 POI (im.tny.segvault.subway.POI)3 WorldPath (im.tny.segvault.subway.WorldPath)3 FileInputStream (java.io.FileInputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3