コード例 #1
0
 /**
  * Computes the arrival status label from the delay (i.e., schedule deviation), where positive
  * means the bus is running late and negative means the bus is running ahead of schedule
  *
  * @param delay schedule deviation, in minutes, for this vehicle where positive means the bus is
  *     running late and negative means the bus is running ahead of schedule
  * @return the arrival status label based on the deviation
  */
 public static String computeArrivalLabelFromDelay(long delay) {
   StringBuilder sb = new StringBuilder();
   if (delay > 0) {
     // Delayed
     sb.append((int) delay);
     sb.append(Status.MINUTE_DELAY);
     return sb.toString();
   } else if (delay < 0) {
     // Early
     delay = -delay;
     sb.append((int) delay);
     if (delay < 2) {
       sb.append(MINUTE_EARLY);
     } else {
       sb.append(MINUTES_EARLY);
     }
     return sb.toString();
   } else {
     // On time
     return Status.ON_TIME;
   }
 }
コード例 #2
0
  private String computeLongDescription() {
    StringBuilder sb = new StringBuilder();
    sb.append(ROUTE);
    sb.append(SPACE);
    sb.append(mInfo.getShortName());
    sb.append(SPACE);
    sb.append(mInfo.getHeadsign());
    sb.append(SPACE);

    if (mEta < 0) {
      // Route just arrived or departed
      long invertEta = -mEta;
      if (mIsArrival) {
        sb.append(LongDescription.ARRIVED);
      } else {
        sb.append(LongDescription.DEPARTED);
      }
      sb.append(SPACE);
      sb.append(invertEta);
      sb.append(SPACE);
      if (invertEta < 2) {
        sb.append(MINUTE_AGO);
      } else {
        sb.append(MINUTES_AGO);
      }
    } else if (mEta == 0) {
      // Route is now arriving/departing
      if (mIsArrival) {
        sb.append(IS_NOW_ARRIVING);
      } else {
        sb.append(IS_NOW_DEPARTING);
      }
    } else {
      // Route is arriving or departing in future
      if (mIsArrival) {
        sb.append(IS_ARRIVING_IN);
      } else {
        sb.append(IS_DEPARTING_IN);
      }
      sb.append(SPACE);
      sb.append(mEta);
      sb.append(SPACE);
      if (mEta < 2) {
        sb.append(MINUTE);
      } else {
        sb.append(MINUTES);
      }
    }

    // If its not real-time info, add statement about schedule
    if (!mPredicted) {
      sb.append(SPACE);
      sb.append(BASED_ON_SCHEDULE);
    }
    return sb.toString();
  }
コード例 #3
0
  /**
   * @param info
   * @param now
   * @param predicted
   * @param scheduledMins
   * @param predictedMins
   * @param includeArrivalDeparture true if the arrival/departure label should be included, false if
   *     it should not
   * @return
   */
  private String computeStatusLabel(
      ObaArrivalInfo info,
      final long now,
      final long predicted,
      final long scheduledMins,
      final long predictedMins,
      boolean includeArrivalDeparture) {
    ObaArrivalInfo.Frequency frequency = info.getFrequency();

    StringBuilder sb = new StringBuilder();

    if (frequency != null) {

      int headwayAsMinutes = (int) (frequency.getHeadway() / 60);
      DateFormat formatter = DateFormat.getTimeInstance(DateFormat.SHORT);

      sb.append("Every ");
      sb.append(headwayAsMinutes);
      sb.append(" minutes ");
      long time = 0;

      if (now < frequency.getStartTime()) {
        time = frequency.getStartTime();
        sb.append("from ");
      } else {
        time = frequency.getEndTime();
        sb.append("until ");
      }
      String label = formatter.format(new Date(time));
      sb.append(label);

      return sb.toString();
    }

    if (predicted != 0) {
      long delay = predictedMins - scheduledMins;

      if (mEta >= 0) {
        // Bus hasn't yet arrived/departed
        return computeArrivalLabelFromDelay(delay);
      } else {
        /** Arrival/departure time has passed */
        if (!includeArrivalDeparture) {
          // Don't include "depart" or "arrive" in label
          if (delay > 0) {
            // Delayed
            sb.append((int) delay);
            sb.append(Status.MINUTE_DELAY);
            return sb.toString();
          } else if (delay < 0) {
            // Early
            delay = -delay;
            sb.append((int) delay);
            if (delay < 2) {
              sb.append(MINUTE_EARLY);
            } else {
              sb.append(MINUTES_EARLY);
            }
            return sb.toString();
          } else {
            // On time
            return Status.ON_TIME;
          }
        }

        if (mIsArrival) {
          // Is an arrival time
          if (delay > 0) {
            // Arrived late
            sb.append(Status.ARRIVED);
            sb.append((int) delay);
            if (delay < 2) {
              sb.append(MINUTE_LATE);
            } else {
              sb.append(MINUTES_LATE);
            }
            return sb.toString();
          } else if (delay < 0) {
            // Arrived early
            delay = -delay;
            sb.append(Status.ARRIVED);
            sb.append((int) delay);
            if (delay < 2) {
              sb.append(MINUTE_EARLY);
            } else {
              sb.append(MINUTES_EARLY);
            }
            return sb.toString();
          } else {
            // Arrived on time
            sb.append(Status.ARRIVED);
            sb.append(Status.ON_TIME.toLowerCase());
            return sb.toString();
          }
        } else {
          // Is a departure time
          if (delay > 0) {
            // Departed late
            sb.append(Status.DEPARTED);
            sb.append((int) delay);
            if (delay < 2) {
              sb.append(MINUTE_LATE);
            } else {
              sb.append(MINUTES_LATE);
            }
            return sb.toString();
          } else if (delay < 0) {
            // Departed early
            delay = -delay;
            sb.append(Status.DEPARTED);
            sb.append((int) delay);
            if (delay < 2) {
              sb.append(MINUTE_EARLY);
            } else {
              sb.append(MINUTES_EARLY);
            }
            return sb.toString();
          } else {
            // Departed on time
            sb.append(Status.DEPARTED);
            sb.append(Status.ON_TIME);
            return sb.toString();
          }
        }
      }
    } else {
      // Scheduled times
      if (!includeArrivalDeparture) {
        return SCHEDULED;
      }

      if (mIsArrival) {
        return SCHEDULED_ARRIVAL;
      } else {
        return SCHEDULED_DEPARTURE;
      }
    }
  }