private VehicleActivity createActivity(VehicleStatusBean vehicleStatus, boolean onwardCalls) {

    if (vehicleStatus.getPhase().equals("DEADHEAD_AFTER")
        || vehicleStatus.getPhase().equals("DEADHEAD_BEFORE")
        || vehicleStatus.getPhase().equals("DEADHEAD_DURING")) {
      return null;
    }
    VehicleActivity activity = new VehicleActivity();

    Calendar time = Calendar.getInstance();
    time.setTime(new Date(vehicleStatus.getLastUpdateTime()));

    activity.RecordedAtTime = time;
    TripBean tripBean = vehicleStatus.getTrip();
    if (tripBean != null) {
      TripDetailsQueryBean query = new TripDetailsQueryBean();
      query.setTime(time.getTimeInMillis());
      query.setTripId(tripBean.getId());
      query.setVehicleId(vehicleStatus.getVehicleId());
      query.getInclusion().setIncludeTripStatus(true);
      TripStatusBean tripStatus = vehicleStatus.getTripStatus();
      query.setServiceDate(tripStatus.getServiceDate());
      TripDetailsBean tripDetails = _transitDataService.getSingleTripDetails(query);
      activity.MonitoredVehicleJourney =
          SiriUtils.getMonitoredVehicleJourney(
              tripDetails, new Date(tripStatus.getServiceDate()), vehicleStatus.getVehicleId());

      if (onwardCalls) {

        List<TripStopTimeBean> stopTimes = tripDetails.getSchedule().getStopTimes();

        long serviceDateMillis = tripStatus.getServiceDate();
        double distance = tripStatus.getDistanceAlongTrip();
        if (Double.isNaN(distance)) {
          distance = tripStatus.getScheduledDistanceAlongTrip();
        }
        activity.MonitoredVehicleJourney.OnwardCalls =
            SiriUtils.getOnwardCalls(
                stopTimes, serviceDateMillis, distance, tripStatus.getNextStop());
      }
    } else {
      activity.MonitoredVehicleJourney = new MonitoredVehicleJourney();
    }
    activity.MonitoredVehicleJourney.Monitored = true;

    activity.MonitoredVehicleJourney.VehicleRef = vehicleStatus.getVehicleId();

    activity.MonitoredVehicleJourney.ProgressRate =
        SiriUtils.getProgressRateForStatus(vehicleStatus.getStatus());

    VehicleLocation location = new VehicleLocation();
    location.Latitude = vehicleStatus.getLocation().getLat();
    location.Longitude = vehicleStatus.getLocation().getLon();

    activity.MonitoredVehicleJourney.VehicleLocation = location;
    return activity;
  }
  /** 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;
  }