use of im.tny.segvault.s2ls.routing.NeutralWeighter in project underlx by underlx.
the class RouteFragment method tryPlanRoute.
private void tryPlanRoute() {
if (originPicker.getSelection() == null || destinationPicker.getSelection() == null) {
// not enough information
return;
}
Route realtimeRoute = Route.calculate(network, originPicker.getSelection(), destinationPicker.getSelection());
Route neutralRoute = Route.calculate(network, originPicker.getSelection(), destinationPicker.getSelection(), new NeutralWeighter(), new NeutralQualifier());
if (useRealtimeCheckbox.isChecked()) {
route = realtimeRoute;
} else {
route = neutralRoute;
}
showRoute(realtimeRoute.getPath().getEdgeList().equals(neutralRoute.getPath().getEdgeList()));
}
use of im.tny.segvault.s2ls.routing.NeutralWeighter 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);
}
}
Aggregations