* Create a VehicleActivity for a given vehicle's trip.
*/
private VehicleActivity createActivity(TripDetailsBean trip,
boolean onwardCalls) {
VehicleActivity activity = new VehicleActivity();
TripStatusBean status = trip.getStatus();
if (status.getPhase().equals("DEADHEAD_AFTER")
|| status.getPhase().equals("DEADHEAD_BEFORE")
|| status.getPhase().equals("DEADHEAD_DURING")) {
return null;
}
Calendar time = Calendar.getInstance();
time.setTime(new Date(status.getLastUpdateTime()));
activity.RecordedAtTime = time;
activity.MonitoredVehicleJourney = SiriUtils.getMonitoredVehicleJourney(
trip, new Date(status.getServiceDate()), status.getVehicleId());
activity.MonitoredVehicleJourney.Monitored = true;
activity.MonitoredVehicleJourney.VehicleRef = status.getVehicleId();
activity.MonitoredVehicleJourney.ProgressRate = status.getStatus();
VehicleLocation location = new VehicleLocation();
location.Latitude = status.getLocation().getLat();
location.Longitude = status.getLocation().getLon();
activity.MonitoredVehicleJourney.VehicleLocation = location;
if (onwardCalls) {
List<TripStopTimeBean> stopTimes = trip.getSchedule().getStopTimes();
long serviceDateMillis = status.getServiceDate();
double distance = status.getDistanceAlongTrip();
if (Double.isNaN(distance)) {
distance = status.getScheduledDistanceAlongTrip();
}
activity.MonitoredVehicleJourney.OnwardCalls = SiriUtils.getOnwardCalls(
stopTimes, serviceDateMillis, distance, status.getNextStop());
}
return activity;
}