use of im.tny.segvault.subway.Stop in project underlx by underlx.
the class HomeFragment method refreshCurrentTrip.
private void refreshCurrentTrip() {
if (mListener == null)
return;
final MainService m = mListener.getMainService();
if (m == null)
return;
S2LS loc = m.getS2LS(MainService.PRIMARY_NETWORK_ID);
if (loc == null || loc.getCurrentTrip() == null) {
ongoingTripCard.setVisibility(View.GONE);
} else {
final Station station = loc.getCurrentTrip().getCurrentStop().getStation();
curStationNameView.setText(station.getName());
Stop direction = loc.getCurrentTrip().getDirection();
Stop next = loc.getCurrentTrip().getNextStop();
if (direction != null && next != null) {
directionView.setText(String.format(getString(R.string.frag_home_trip_direction), direction.getStation().getName()));
nextStationView.setText(String.format(getString(R.string.frag_home_trip_next_station), next.getStation().getName()));
Stop likelyExit = m.getLikelyNextExit(loc.getCurrentTrip().getEdgeList(), 1);
int resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Small;
if (next == likelyExit) {
resId = android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Medium;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
nextStationView.setTextAppearance(resId);
} else {
nextStationView.setTextAppearance(getContext(), resId);
}
directionView.setVisibility(View.VISIBLE);
nextStationView.setVisibility(View.VISIBLE);
} else {
directionView.setVisibility(View.GONE);
nextStationView.setVisibility(View.GONE);
}
redrawCurrentStationLineIcons(station);
curStationLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getContext(), StationActivity.class);
intent.putExtra(StationActivity.EXTRA_STATION_ID, station.getId());
intent.putExtra(StationActivity.EXTRA_NETWORK_ID, MainService.PRIMARY_NETWORK_ID);
startActivity(intent);
}
});
curTripIncorrectLocationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new FeedbackUtil.IncorrectLocation(getContext(), m, station).showReportWizard();
}
});
if (loc.canRequestEndOfTrip()) {
curTripEndButton.setVisibility(View.VISIBLE);
curTripIncorrectLocationButton.setVisibility(View.GONE);
} else {
curTripEndButton.setVisibility(View.GONE);
curTripIncorrectLocationButton.setVisibility(View.VISIBLE);
}
ongoingTripCard.setVisibility(View.VISIBLE);
}
}
use of im.tny.segvault.subway.Stop in project underlx by underlx.
the class MainService method updateRouteNotification.
private void updateRouteNotification(S2LS loc, boolean highPriorityNotification) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(MainActivity.EXTRA_INITIAL_FRAGMENT, "nav_home");
PendingIntent pendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
Path currentPath = loc.getCurrentTrip();
Route currentRoute = loc.getCurrentTargetRoute();
if (currentPath == null && currentRoute == null) {
Log.e("MainService", "Attempt to create notification when there's no path or planned route");
return;
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
CharSequence title = "";
List<CharSequence> statusLines = new ArrayList<>();
int color = -1;
if (currentRoute != null) {
inboxStyle.setSummaryText(String.format(getString(R.string.notif_route_navigating_status), currentRoute.getTarget().getName()));
Step nextStep = currentRoute.getNextStep(currentPath);
if (nextStep instanceof EnterStep) {
if (currentPath != null && currentPath.getCurrentStop() != null && currentRoute.checkPathStartsRoute(currentPath)) {
title = String.format(getString(R.string.notif_route_catch_train_title), ((EnterStep) nextStep).getDirection().getName(12));
} else {
title = String.format(getString(R.string.notif_route_enter_station_title), nextStep.getStation().getName(15));
}
// TODO: show "encurtamentos" warnings here if applicable
statusLines.add(String.format(getString(R.string.notif_route_catch_train_status), ((EnterStep) nextStep).getDirection().getName()));
color = currentRoute.getSourceStop().getLine().getColor();
} else if (nextStep instanceof ChangeLineStep) {
ChangeLineStep clStep = (ChangeLineStep) nextStep;
String lineName = Util.getLineNames(this, clStep.getTarget())[0];
String titleStr;
if (currentPath != null && currentPath.getCurrentStop() != null && currentPath.getCurrentStop().getStation() == nextStep.getStation()) {
titleStr = String.format(getString(R.string.notif_route_catch_train_line_change_title), lineName);
} else {
titleStr = String.format(getString(R.string.notif_route_line_change_title), nextStep.getStation().getName(10), lineName);
}
int lStart = titleStr.indexOf(lineName);
int lEnd = lStart + lineName.length();
Spannable sb = new SpannableString(titleStr);
sb.setSpan(new ForegroundColorSpan(clStep.getTarget().getColor()), lStart, lEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
title = sb;
// TODO: show "encurtamentos" warnings here if applicable
sb = new SpannableString(String.format(getString(R.string.notif_route_catch_train_status), clStep.getDirection().getName()));
sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
statusLines.add(sb);
color = clStep.getTarget().getColor();
} else if (nextStep instanceof ExitStep) {
if (currentPath != null && currentPath.getCurrentStop().getStation() == nextStep.getStation()) {
title = getString(R.string.notif_route_leave_train_now);
} else if (currentPath != null && currentPath.getNextStop() != null && new Date().getTime() - currentPath.getCurrentStopEntryTime().getTime() > 30 * 1000 && nextStep.getStation() == currentPath.getNextStop().getStation()) {
title = getString(R.string.notif_route_leave_train_next);
} else {
title = String.format(getString(R.string.notif_route_leave_train), nextStep.getStation().getName(20));
}
}
}
if (currentPath != null) {
Stop curStop = currentPath.getCurrentStop();
if (color == -1) {
color = curStop.getLine().getColor();
}
if (currentRoute != null) {
statusLines.add(String.format(getString(R.string.notif_route_current_station), curStop.getStation().getName()));
} else {
title = curStop.getStation().getName();
}
if (currentPath.isWaitingFirstTrain()) {
statusLines.add(getString(R.string.notif_route_waiting));
} else {
Stop direction = currentPath.getDirection();
Stop next = currentPath.getNextStop();
if (direction != null && next != null) {
statusLines.add(String.format(getString(R.string.notif_route_next_station), next.getStation().getName()));
if (currentRoute == null) {
statusLines.add(String.format(getString(R.string.notif_route_direction), direction.getStation().getName()));
}
} else {
statusLines.add(getString(R.string.notif_route_left_station));
}
}
}
CharSequence singleLineStatus = "";
for (CharSequence s : statusLines) {
inboxStyle.addLine(s);
singleLineStatus = TextUtils.concat(singleLineStatus, s) + " | ";
}
singleLineStatus = singleLineStatus.subSequence(0, singleLineStatus.length() - 3);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this).setStyle(inboxStyle).setColor(color).setContentTitle(title).setContentText(singleLineStatus).setAutoCancel(false).setContentIntent(pendingIntent).setVisibility(Notification.VISIBILITY_PUBLIC).setOngoing(true);
if (highPriorityNotification) {
stopForeground(true);
notificationBuilder.setPriority(NotificationCompat.PRIORITY_HIGH);
notificationBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE);
}
if (currentRoute != null) {
notificationBuilder.setSmallIcon(R.drawable.ic_navigation_white_24dp);
Intent stopIntent = new Intent(this, MainService.class);
stopIntent.setAction(ACTION_END_NAVIGATION);
stopIntent.putExtra(EXTRA_NAVIGATION_NETWORK, loc.getNetwork().getId());
PendingIntent pendingStopIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), stopIntent, 0);
notificationBuilder.addAction(R.drawable.ic_close_black_24dp, getString(R.string.notif_route_end_navigation), pendingStopIntent);
} else {
notificationBuilder.setSmallIcon(R.drawable.ic_trip_notif);
if (loc.canRequestEndOfTrip()) {
Intent stopIntent = new Intent(this, MainService.class);
stopIntent.setAction(ACTION_END_TRIP);
stopIntent.putExtra(EXTRA_TRIP_NETWORK, loc.getNetwork().getId());
PendingIntent pendingStopIntent = PendingIntent.getService(this, (int) System.currentTimeMillis(), stopIntent, 0);
notificationBuilder.addAction(R.drawable.ic_stop_black_24dp, getString(R.string.notif_route_end_trip), pendingStopIntent);
}
}
startForeground(ROUTE_NOTIFICATION_ID, notificationBuilder.build());
}
use of im.tny.segvault.subway.Stop in project underlx by underlx.
the class MainService method getLikelyNextExit.
public Stop getLikelyNextExit(List<Connection> path, double threshold) {
if (path.size() == 0) {
return null;
}
// get the line for the latest connection
Connection last = path.get(path.size() - 1);
Line line = null;
for (Line l : getAllLines()) {
if (l.edgeSet().contains(last)) {
line = l;
break;
}
}
if (line == null) {
return null;
}
Set<Stop> alreadyVisited = new HashSet<>();
for (Connection c : path) {
alreadyVisited.add(c.getSource());
alreadyVisited.add(c.getTarget());
}
// get all the stops till the end of the line, after the given connection
// (or in the case of circular lines, all stops of the line)
Stop maxStop = null;
double max = 0;
Set<Stop> stops = new HashSet<>();
while (stops.add(last.getSource())) {
Stop curStop = last.getTarget();
if (!alreadyVisited.contains(curStop)) {
double r = getLeaveTrainFactorForStop(curStop);
if (maxStop == null || r > max) {
maxStop = curStop;
max = r;
}
}
if (line.outDegreeOf(curStop) == 1) {
break;
}
for (Connection outedge : line.outgoingEdgesOf(curStop)) {
if (!stops.contains(outedge.getTarget())) {
last = outedge;
break;
}
}
}
if (max < threshold) {
// most relevant station is not relevant enough
return null;
}
return maxStop;
}
use of im.tny.segvault.subway.Stop in project underlx by underlx.
the class MainService method dumpDebugInfo.
// DEBUG:
public String dumpDebugInfo() {
String s = "Service created on " + creationDate.toString();
s += (wfc.isScanning() ? String.format(". WFC scanning every %d s", wfc.getScanInterval() / 1000) : ". WFC not scanning") + "\n";
for (Network n : getNetworks()) {
S2LS loc;
synchronized (lock) {
loc = locServices.get(n.getId());
}
s += "Network " + n.getNames("en")[0] + "\n";
s += "State machine: " + loc.getState().toString() + "\n";
s += String.format("\tIn network? %b\n\tNear network? %b\n", loc.inNetwork(), loc.nearNetwork());
if (loc.getState() instanceof InNetworkState) {
s += "\tPossible stops:\n";
for (Stop stop : loc.getLocation().vertexSet()) {
s += String.format("\t\t%s (%s)\n", stop.getStation().getName(), stop.getLine().getNames("en")[0]);
}
s += "\tPath:\n";
if (loc.getCurrentTrip() != null) {
for (Connection c : loc.getCurrentTrip().getEdgeList()) {
s += String.format("\t\t%s -> %s\n", c.getSource().toString(), c.getTarget().toString());
}
if (loc.getCurrentTargetRoute() != null) {
s += String.format("\t\tCurrent path complies? %b\n", loc.getCurrentTargetRoute().checkPathCompliance(loc.getCurrentTrip()));
}
}
}
}
try {
API.AuthTest authTest = API.getInstance().getAuthTest();
s += "API auth test result: " + authTest.result + "\n";
s += "API key as perceived by server: " + authTest.key + "\n";
} catch (APIException e) {
e.printStackTrace();
s += "Error testing API authentication\n";
}
synchronizer.attemptSync();
return s;
}
use of im.tny.segvault.subway.Stop in project underlx by underlx.
the class MainService method mockLocation.
public void mockLocation(Station station) {
if (BuildConfig.DEBUG && station.getStops().size() > 0) {
List<BSSID> bssids = new ArrayList<>();
for (Stop s : station.getStops()) {
bssids.addAll(WiFiLocator.getBSSIDsForStop(s));
}
wfc.updateBSSIDsDebug(bssids);
}
}
Aggregations