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