use of im.tny.segvault.subway.Line in project underlx by underlx.
the class RouteFragment method showRoute.
private void showRoute(boolean realtimeEqualsNeutral) {
if (route == null) {
return;
}
layoutRoute.removeAllViews();
if (originPicker.getSelection().isAlwaysClosed()) {
viewOriginStationClosed.setText(String.format(getString(R.string.frag_route_station_closed_extended), originPicker.getSelection().getName()));
layoutOriginStationClosed.setVisibility(View.VISIBLE);
} else if (originPicker.getSelection().isExceptionallyClosed(network, new Date()) && useRealtimeCheckbox.isChecked()) {
viewOriginStationClosed.setText(String.format(getString(R.string.frag_route_station_closed_schedule), originPicker.getSelection().getName()));
layoutOriginStationClosed.setVisibility(View.VISIBLE);
} else {
layoutOriginStationClosed.setVisibility(View.GONE);
}
if (destinationPicker.getSelection().isAlwaysClosed()) {
viewDestinationStationClosed.setText(String.format(getString(R.string.frag_route_station_closed_extended), destinationPicker.getSelection().getName()));
layoutDestinationStationClosed.setVisibility(View.VISIBLE);
} else if (destinationPicker.getSelection().isExceptionallyClosed(network, new Date()) && useRealtimeCheckbox.isChecked()) {
viewDestinationStationClosed.setText(String.format(getString(R.string.frag_route_station_closed_schedule), destinationPicker.getSelection().getName()));
layoutDestinationStationClosed.setVisibility(View.VISIBLE);
} else {
layoutDestinationStationClosed.setVisibility(View.GONE);
}
for (Step step : route) {
View view = null;
if (step instanceof EnterStep) {
view = getActivity().getLayoutInflater().inflate(R.layout.step_enter_network, layoutRoute, false);
final Line line = step.getLine();
int lineColor = line.getColor();
FrameLayout lineStripeLayout = (FrameLayout) view.findViewById(R.id.line_stripe_layout);
lineStripeLayout.setBackgroundColor(lineColor);
populateStationView(getActivity(), step.getStation(), view);
if (step.getStation().getLines().size() > 1) {
Drawable drawable = ContextCompat.getDrawable(getContext(), Util.getDrawableResourceIdForLineId(line.getId()));
drawable.setColorFilter(lineColor, PorterDuff.Mode.SRC_ATOP);
FrameLayout iconFrame = (FrameLayout) view.findViewById(R.id.frame_icon);
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
iconFrame.setBackgroundDrawable(drawable);
} else {
iconFrame.setBackground(drawable);
}
TextView lineView = (TextView) view.findViewById(R.id.line_name_view);
lineView.setText(String.format(getString(R.string.frag_route_line_name), Util.getLineNames(getContext(), line)[0]));
lineView.setTextColor(lineColor);
LinearLayout lineLayout = (LinearLayout) view.findViewById(R.id.line_layout);
lineLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), LineActivity.class);
intent.putExtra(LineActivity.EXTRA_LINE_ID, line.getId());
intent.putExtra(LineActivity.EXTRA_NETWORK_ID, network.getId());
startActivity(intent);
}
});
lineLayout.setVisibility(View.VISIBLE);
}
TextView directionView = (TextView) view.findViewById(R.id.direction_view);
directionView.setText(Util.fromHtml(String.format(getString(R.string.frag_route_direction), ((EnterStep) step).getDirection().getName())));
if (line.getUsualCarCount() < network.getUsualCarCount()) {
LinearLayout carsWarningLayout = (LinearLayout) view.findViewById(R.id.cars_warning_layout);
carsWarningLayout.setVisibility(View.VISIBLE);
}
if (mListener != null && mListener.getMainService() != null) {
Map<String, LineStatusCache.Status> statuses = mListener.getLineStatusCache().getLineStatus();
if (statuses.get(line.getId()) != null && statuses.get(line.getId()).down) {
LinearLayout disturbancesWarningLayout = (LinearLayout) view.findViewById(R.id.disturbances_warning_layout);
disturbancesWarningLayout.setVisibility(View.VISIBLE);
}
}
} else if (step instanceof ChangeLineStep) {
final ChangeLineStep lStep = (ChangeLineStep) step;
view = getActivity().getLayoutInflater().inflate(R.layout.step_change_line, layoutRoute, false);
int prevLineColor = lStep.getLine().getColor();
FrameLayout prevLineStripeLayout = (FrameLayout) view.findViewById(R.id.prev_line_stripe_layout);
prevLineStripeLayout.setBackgroundColor(prevLineColor);
int nextLineColor = lStep.getTarget().getColor();
FrameLayout nextLineStripeLayout = (FrameLayout) view.findViewById(R.id.next_line_stripe_layout);
nextLineStripeLayout.setBackgroundColor(nextLineColor);
populateStationView(getActivity(), lStep.getStation(), view);
Drawable drawable = ContextCompat.getDrawable(getContext(), Util.getDrawableResourceIdForLineId(lStep.getTarget().getId()));
drawable.setColorFilter(nextLineColor, PorterDuff.Mode.SRC_ATOP);
FrameLayout iconFrame = (FrameLayout) view.findViewById(R.id.frame_icon);
if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
iconFrame.setBackgroundDrawable(drawable);
} else {
iconFrame.setBackground(drawable);
}
TextView lineView = (TextView) view.findViewById(R.id.line_name_view);
lineView.setText(String.format(getString(R.string.frag_route_line_name), Util.getLineNames(getContext(), lStep.getTarget())[0]));
lineView.setTextColor(nextLineColor);
LinearLayout lineLayout = (LinearLayout) view.findViewById(R.id.line_layout);
lineLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), LineActivity.class);
intent.putExtra(LineActivity.EXTRA_LINE_ID, lStep.getTarget().getId());
intent.putExtra(LineActivity.EXTRA_NETWORK_ID, network.getId());
startActivity(intent);
}
});
lineLayout.setVisibility(View.VISIBLE);
TextView directionView = (TextView) view.findViewById(R.id.direction_view);
directionView.setText(Util.fromHtml(String.format(getString(R.string.frag_route_direction), lStep.getDirection().getName())));
if (lStep.getTarget().getUsualCarCount() < network.getUsualCarCount()) {
LinearLayout carsWarningLayout = (LinearLayout) view.findViewById(R.id.cars_warning_layout);
carsWarningLayout.setVisibility(View.VISIBLE);
}
if (mListener != null && mListener.getMainService() != null) {
Map<String, LineStatusCache.Status> statuses = mListener.getLineStatusCache().getLineStatus();
if (statuses.get(lStep.getTarget().getId()) != null && statuses.get(lStep.getTarget().getId()).down) {
LinearLayout disturbancesWarningLayout = (LinearLayout) view.findViewById(R.id.disturbances_warning_layout);
disturbancesWarningLayout.setVisibility(View.VISIBLE);
}
}
} else if (step instanceof ExitStep) {
view = getActivity().getLayoutInflater().inflate(R.layout.step_exit_network, layoutRoute, false);
int lineColor = step.getLine().getColor();
FrameLayout lineStripeLayout = (FrameLayout) view.findViewById(R.id.line_stripe_layout);
lineStripeLayout.setBackgroundColor(lineColor);
populateStationView(getActivity(), step.getStation(), view);
}
layoutRoute.addView(view);
}
if (layoutRoute.getChildCount() == 0) {
View view = getActivity().getLayoutInflater().inflate(R.layout.step_already_there, layoutRoute, false);
populateStationView(getActivity(), originPicker.getSelection(), view);
// TODO maybe revive this
/*if (originPicker.getSelection().getLine().getUsualCarCount() < network.getUsualCarCount() ||
destinationPicker.getSelection().getLine().getUsualCarCount() < network.getUsualCarCount()) {
LinearLayout carsWarningLayout = (LinearLayout) view.findViewById(R.id.cars_warning_layout);
carsWarningLayout.setVisibility(View.VISIBLE);
}*/
layoutRoute.addView(view);
}
if (network.isAboutToClose() && route.hasLineChange()) {
Formatter f = new Formatter();
DateUtils.formatDateRange(getContext(), f, network.getNextCloseTime(), network.getNextCloseTime(), DateUtils.FORMAT_SHOW_TIME, network.getTimezone().getID());
viewNetworkClosed.setText(String.format(getString(R.string.warning_network_about_to_close_transfers), f.toString(), destinationPicker.getSelection().getName()));
layoutNetworkClosed.setVisibility(View.VISIBLE);
} else
updateClosedWarning();
layoutInstructions.setVisibility(View.GONE);
layoutRoute.setVisibility(View.VISIBLE);
swapButton.setVisibility(View.VISIBLE);
if (realtimeEqualsNeutral) {
useRealtimeCheckbox.setVisibility(View.GONE);
} else {
useRealtimeCheckbox.setVisibility(View.VISIBLE);
}
int length = 0;
double realWeight = 0;
// TODO: switch to using route.getPath().getWeight() directly once DisturbanceAwareWeighter
// can actually provide proper weights for lines with disturbances, and not just some
// extremely large number
NeutralWeighter weighter = new NeutralWeighter();
for (Connection c : route.getPath().getEdgeList()) {
length += c.getWorldLength();
realWeight += weighter.getEdgeWeight(network, c);
}
if (length < 1000) {
routeEtaView.setText(String.format("%s (%d m)", DateUtils.formatElapsedTime((int) realWeight), length));
} else {
routeEtaView.setText(String.format("%s (%.01f km)", DateUtils.formatElapsedTime((int) realWeight), length / 1000.0));
}
SharedPreferences sharedPref = getContext().getSharedPreferences("settings", MODE_PRIVATE);
boolean locationEnabled = sharedPref.getBoolean(PreferenceNames.LocationEnable, true);
if (locationEnabled) {
layoutBottomSheet.setVisibility(View.VISIBLE);
}
}
use of im.tny.segvault.subway.Line 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;
}
use of im.tny.segvault.subway.Line in project underlx by underlx.
the class HomeStatsFragment method redraw.
private void redraw(Context context) {
if (mListener == null || mListener.getMainService() == null) {
return;
}
StatsCache cache = mListener.getMainService().getStatsCache();
if (cache == null) {
return;
}
StatsCache.Stats stats = cache.getNetworkStats(networkId);
if (stats == null) {
return;
}
// Calculate days difference like the website
Calendar today = Calendar.getInstance();
today.setTime(new Date());
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
Calendar lastDisturbance = Calendar.getInstance();
lastDisturbance.setTime(stats.lastDisturbance);
lastDisturbance.set(Calendar.HOUR_OF_DAY, 0);
lastDisturbance.set(Calendar.MINUTE, 0);
lastDisturbance.set(Calendar.SECOND, 0);
lastDisturbance.set(Calendar.MILLISECOND, 0);
SharedPreferences sharedPref = context.getSharedPreferences("settings", MODE_PRIVATE);
boolean locationEnabled = sharedPref.getBoolean(PreferenceNames.LocationEnable, true);
if (locationEnabled) {
if (stats.curOnInTransit == 0) {
usersOnlineView.setText(R.string.frag_stats_few_users_in_network);
} else {
usersOnlineView.setText(String.format(getString(R.string.frag_stats_users_in_network), stats.curOnInTransit));
}
usersOnlineView.setVisibility(View.VISIBLE);
} else {
usersOnlineView.setVisibility(View.GONE);
}
long days = (today.getTime().getTime() - lastDisturbance.getTime().getTime()) / (24 * 60 * 60 * 1000);
if (days < 2) {
long hours = (new Date().getTime() - stats.lastDisturbance.getTime()) / (60 * 60 * 1000);
lastDisturbanceView.setHtml(String.format(getString(R.string.frag_stats_last_disturbance_hours), hours));
} else {
lastDisturbanceView.setHtml(String.format(getString(R.string.frag_stats_last_disturbance_days), days));
}
Network net = mListener.getMainService().getNetwork(networkId);
if (net == null) {
return;
}
List<Line> lines = new ArrayList<>(net.getLines());
Collections.sort(lines, new Comparator<Line>() {
@Override
public int compare(Line t0, Line t1) {
return Integer.valueOf(t0.getOrder()).compareTo(t1.getOrder());
}
});
lineStatsLayout.removeAllViews();
TableRow header = (TableRow) getActivity().getLayoutInflater().inflate(R.layout.line_stats_header, lineStatsLayout, false);
lineStatsLayout.addView(header);
for (Line line : lines) {
double weekAvail;
if (stats.weekLineStats.get(line.getId()) == null) {
continue;
} else {
weekAvail = stats.weekLineStats.get(line.getId()).availability;
}
double monthAvail;
if (stats.monthLineStats.get(line.getId()) == null) {
continue;
} else {
monthAvail = stats.monthLineStats.get(line.getId()).availability;
}
TableRow row = (TableRow) getActivity().getLayoutInflater().inflate(R.layout.line_stats_row, lineStatsLayout, false);
TextView lineNameView = (TextView) row.findViewById(R.id.line_name_view);
lineNameView.setText(Util.getLineNames(getContext(), line)[0]);
lineNameView.setTextColor(line.getColor());
((TextView) row.findViewById(R.id.week_availability_view)).setText(String.format("%.3f%%", weekAvail * 100));
((TextView) row.findViewById(R.id.month_availability_view)).setText(String.format("%.3f%%", monthAvail * 100));
lineStatsLayout.addView(row);
}
if (new Date().getTime() - stats.updated.getTime() > java.util.concurrent.TimeUnit.MINUTES.toMillis(5)) {
lineStatsLayout.setAlpha(0.6f);
lastDisturbanceView.setAlpha(0.6f);
usersOnlineView.setAlpha(0.6f);
updateInformationView.setTypeface(null, Typeface.BOLD);
} else {
lineStatsLayout.setAlpha(1f);
lastDisturbanceView.setAlpha(1f);
usersOnlineView.setAlpha(1f);
updateInformationView.setTypeface(null, Typeface.NORMAL);
}
updateInformationView.setText(String.format(getString(R.string.frag_stats_updated), DateUtils.getRelativeTimeSpanString(context, stats.updated.getTime(), true)));
}
use of im.tny.segvault.subway.Line in project underlx by underlx.
the class TripFragment method populatePathView.
public static void populatePathView(final Context context, final LayoutInflater inflater, final Path path, ViewGroup root, boolean showInfoIcons) {
root.removeAllViews();
List<Connection> el = path.getEdgeList();
final int stepviewPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, context.getResources().getDisplayMetrics());
if (el.size() == 0) {
View stepview = inflater.inflate(R.layout.path_station, root, false);
FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
prevLineStripeLayout.setVisibility(View.GONE);
nextLineStripeLayout.setVisibility(View.GONE);
TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
if (path.getManualEntry(0)) {
timeView.setVisibility(View.INVISIBLE);
} else {
timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(0).getTime(), DateUtils.FORMAT_SHOW_TIME));
}
final Station station = path.getStartVertex().getStation();
stepview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, StationActivity.class);
intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
context.startActivity(intent);
}
});
RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
root.addView(stepview);
return;
}
boolean isFirst = true;
Connection c = el.get(0);
int i = 0;
for (; i < el.size(); i++) {
c = el.get(i);
if (i == 0 && c instanceof Transfer) {
// starting with a line change? ignore
continue;
}
View stepview = inflater.inflate(R.layout.path_station, root, false);
FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
if (isFirst) {
Line line = c.getSource().getLine();
int lineColor = line.getColor();
prevLineStripeLayout.setVisibility(View.GONE);
nextLineStripeLayout.setBackgroundColor(lineColor);
TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
if (path.getManualEntry(i)) {
timeView.setVisibility(View.INVISIBLE);
} else {
timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
}
isFirst = false;
} else {
Line targetLine = c.getTarget().getLine();
int prevLineColor = c.getSource().getLine().getColor();
int nextLineColor = targetLine.getColor();
prevLineStripeLayout.setBackgroundColor(prevLineColor);
nextLineStripeLayout.setBackgroundColor(nextLineColor);
TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
// start of the path was extended with the first step getting replaced by a transfer
if (path.getManualEntry(i) && !(c instanceof Transfer && !path.getManualEntry(i + 1))) {
timeView.setVisibility(View.INVISIBLE);
} else {
timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
}
}
final Station station = c.getSource().getStation();
stepview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, StationActivity.class);
intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
context.startActivity(intent);
}
});
RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
ImageView crossView = (ImageView) stepview.findViewById(R.id.station_cross_image);
if (c.getSource().getStation().isAlwaysClosed()) {
crossView.setVisibility(View.VISIBLE);
}
stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
root.addView(stepview);
if (c instanceof Transfer && i != el.size() - 1) {
c = el.get(++i);
}
}
View stepview = inflater.inflate(R.layout.path_station, root, false);
int lineColor = c.getSource().getLine().getColor();
FrameLayout prevLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.prev_line_stripe_layout);
FrameLayout nextLineStripeLayout = (FrameLayout) stepview.findViewById(R.id.next_line_stripe_layout);
prevLineStripeLayout.setBackgroundColor(lineColor);
nextLineStripeLayout.setVisibility(View.GONE);
TextView timeView = (TextView) stepview.findViewById(R.id.time_view);
if (path.getManualEntry(i)) {
timeView.setVisibility(View.INVISIBLE);
} else {
timeView.setText(DateUtils.formatDateTime(context, path.getEntryTime(i).getTime(), DateUtils.FORMAT_SHOW_TIME));
}
ImageView crossView = (ImageView) stepview.findViewById(R.id.station_cross_image);
if (c.getTarget().getStation().isAlwaysClosed()) {
crossView.setVisibility(View.VISIBLE);
}
final Station station = c.getTarget().getStation();
stepview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, StationActivity.class);
intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
intent.putExtra(StationActivity.EXTRA_NETWORK_ID, station.getNetwork().getId());
context.startActivity(intent);
}
});
RouteFragment.populateStationView(context, station, stepview, showInfoIcons, false);
stepview.setPadding(stepviewPadding, 0, stepviewPadding, 0);
root.addView(stepview);
}
use of im.tny.segvault.subway.Line in project underlx by underlx.
the class LineStatusCache method readLineStatus.
private HashMap<String, Status> readLineStatus() {
HashMap<String, Status> info;
try {
FileInputStream fis = new FileInputStream(new File(context.getCacheDir(), LINE_STATUS_CACHE_FILENAME));
ObjectInputStream is = new ObjectInputStream(fis);
info = (HashMap) is.readObject();
is.close();
fis.close();
Map<String, Line> lines = new HashMap<>();
for (Line l : mainService.getAllLines()) {
lines.put(l.getId(), l);
}
for (Status s : info.values()) {
if (!(s instanceof Status)) {
throw new Exception();
}
s.line = lines.get(s.id);
}
} catch (Exception e) {
// caching is best-effort
return null;
}
return info;
}
Aggregations