2012-04-13 01:07:55 +00:00
|
|
|
package com.dougkeen.bart.model;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2012-04-29 16:42:54 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
2012-04-13 01:07:55 +00:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2011-05-27 21:06:58 +00:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2012-04-13 01:07:55 +00:00
|
|
|
import android.text.format.DateFormat;
|
2012-09-17 15:13:50 +00:00
|
|
|
import android.util.Log;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public class Departure implements Parcelable, Comparable<Departure> {
|
|
|
|
private static final int MINIMUM_MERGE_OVERLAP_MILLIS = 10000;
|
|
|
|
|
|
|
|
public Departure() {
|
2011-05-23 18:59:34 +00:00
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public Departure(String destinationAbbr, String destinationColor,
|
2011-05-23 18:59:34 +00:00
|
|
|
String platform, String direction, boolean bikeAllowed,
|
2011-11-21 16:57:16 +00:00
|
|
|
String trainLength, int minutes) {
|
2011-05-23 18:59:34 +00:00
|
|
|
super();
|
2012-09-18 17:11:52 +00:00
|
|
|
this.trainDestination = Station.getByAbbreviation(destinationAbbr);
|
2011-05-23 18:59:34 +00:00
|
|
|
this.destinationColor = destinationColor;
|
|
|
|
this.platform = platform;
|
|
|
|
this.direction = direction;
|
|
|
|
this.bikeAllowed = bikeAllowed;
|
|
|
|
this.trainLength = trainLength;
|
|
|
|
this.minutes = minutes;
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public Departure(Parcel in) {
|
2011-05-27 21:06:58 +00:00
|
|
|
readFromParcel(in);
|
|
|
|
}
|
|
|
|
|
2012-04-13 22:05:30 +00:00
|
|
|
private Station origin;
|
2012-09-18 17:11:52 +00:00
|
|
|
private Station trainDestination;
|
|
|
|
private Station passengerDestination;
|
2011-06-01 03:42:32 +00:00
|
|
|
private Line line;
|
2011-05-23 18:59:34 +00:00
|
|
|
private String destinationColor;
|
|
|
|
private String platform;
|
|
|
|
private String direction;
|
|
|
|
private boolean bikeAllowed;
|
2011-11-21 16:57:16 +00:00
|
|
|
private String trainLength;
|
2011-05-23 18:59:34 +00:00
|
|
|
private boolean requiresTransfer;
|
2012-09-05 17:34:00 +00:00
|
|
|
private boolean transferScheduled;
|
2011-05-23 18:59:34 +00:00
|
|
|
|
|
|
|
private int minutes;
|
|
|
|
|
|
|
|
private long minEstimate;
|
|
|
|
private long maxEstimate;
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
private int estimatedTripTime;
|
|
|
|
|
2012-04-13 22:05:30 +00:00
|
|
|
private boolean beganAsDeparted;
|
|
|
|
|
|
|
|
private long arrivalTimeOverride;
|
|
|
|
|
|
|
|
public Station getOrigin() {
|
|
|
|
return origin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOrigin(Station origin) {
|
|
|
|
this.origin = origin;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public Station getTrainDestination() {
|
|
|
|
return trainDestination;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public void setTrainDestination(Station destination) {
|
|
|
|
this.trainDestination = destination;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public String getTrainDestinationName() {
|
|
|
|
if (trainDestination != null)
|
|
|
|
return trainDestination.name;
|
2011-05-23 18:59:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public String getTrainDestinationAbbreviation() {
|
|
|
|
if (trainDestination != null)
|
|
|
|
return trainDestination.abbreviation;
|
2011-05-23 18:59:34 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public Station getPassengerDestination() {
|
|
|
|
return passengerDestination;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPassengerDestination(Station passengerDestination) {
|
|
|
|
this.passengerDestination = passengerDestination;
|
|
|
|
}
|
|
|
|
|
|
|
|
public StationPair getStationPair() {
|
|
|
|
if (passengerDestination != null) {
|
|
|
|
return new StationPair(origin, passengerDestination);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 03:42:32 +00:00
|
|
|
public Line getLine() {
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLine(Line line) {
|
|
|
|
this.line = line;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public String getTrainDestinationColor() {
|
2011-05-23 18:59:34 +00:00
|
|
|
return destinationColor;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:11:52 +00:00
|
|
|
public void setTrainDestinationColor(String destinationColor) {
|
2011-05-23 18:59:34 +00:00
|
|
|
this.destinationColor = destinationColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getPlatform() {
|
|
|
|
return platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPlatform(String platform) {
|
|
|
|
this.platform = platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDirection() {
|
|
|
|
return direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDirection(String direction) {
|
|
|
|
this.direction = direction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBikeAllowed() {
|
|
|
|
return bikeAllowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBikeAllowed(boolean bikeAllowed) {
|
|
|
|
this.bikeAllowed = bikeAllowed;
|
|
|
|
}
|
|
|
|
|
2011-11-21 16:57:16 +00:00
|
|
|
public String getTrainLength() {
|
2011-05-23 18:59:34 +00:00
|
|
|
return trainLength;
|
|
|
|
}
|
|
|
|
|
2011-11-21 16:57:16 +00:00
|
|
|
public void setTrainLength(String trainLength) {
|
2011-05-23 18:59:34 +00:00
|
|
|
this.trainLength = trainLength;
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
public String getTrainLengthText() {
|
|
|
|
return trainLength + " car train";
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public boolean getRequiresTransfer() {
|
|
|
|
return requiresTransfer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRequiresTransfer(boolean requiresTransfer) {
|
|
|
|
this.requiresTransfer = requiresTransfer;
|
|
|
|
}
|
|
|
|
|
2012-09-05 17:34:00 +00:00
|
|
|
public boolean isTransferScheduled() {
|
|
|
|
return transferScheduled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTransferScheduled(boolean transferScheduled) {
|
|
|
|
this.transferScheduled = transferScheduled;
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public int getMinutes() {
|
|
|
|
return minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMinutes(int minutes) {
|
|
|
|
this.minutes = minutes;
|
2012-04-13 22:05:30 +00:00
|
|
|
if (minutes == 0) {
|
|
|
|
beganAsDeparted = true;
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getMinEstimate() {
|
|
|
|
return minEstimate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMinEstimate(long minEstimate) {
|
|
|
|
this.minEstimate = minEstimate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMaxEstimate() {
|
|
|
|
return maxEstimate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMaxEstimate(long maxEstimate) {
|
|
|
|
this.maxEstimate = maxEstimate;
|
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
public int getEstimatedTripTime() {
|
|
|
|
return estimatedTripTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEstimatedTripTime(int estimatedTripTime) {
|
|
|
|
this.estimatedTripTime = estimatedTripTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasEstimatedTripTime() {
|
|
|
|
return this.estimatedTripTime > 0;
|
|
|
|
}
|
|
|
|
|
2012-04-29 16:42:54 +00:00
|
|
|
public boolean hasAnyArrivalEstimate() {
|
|
|
|
return this.estimatedTripTime > 0 || this.arrivalTimeOverride > 0;
|
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public int getUncertaintySeconds() {
|
|
|
|
return (int) (maxEstimate - minEstimate + 1000) / 2000;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMinSecondsLeft() {
|
|
|
|
return (int) ((getMinEstimate() - System.currentTimeMillis()) / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMaxSecondsLeft() {
|
|
|
|
return (int) ((getMaxEstimate() - System.currentTimeMillis()) / 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMeanSecondsLeft() {
|
2012-09-17 15:13:50 +00:00
|
|
|
return (int) getMeanSecondsLeft(getMinEstimate(), getMaxEstimate());
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getMeanSecondsLeft(long min, long max) {
|
|
|
|
return (int) ((getMeanEstimate(min, max) - System.currentTimeMillis()) / 1000);
|
2012-04-13 01:07:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public long getMeanEstimate() {
|
2012-09-17 15:13:50 +00:00
|
|
|
return getMeanEstimate(getMinEstimate(), getMaxEstimate());
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getMeanEstimate(long min, long max) {
|
|
|
|
return (min + max) / 2;
|
2012-04-13 01:07:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 15:44:53 +00:00
|
|
|
public long getArrivalTimeOverride() {
|
|
|
|
return arrivalTimeOverride;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setArrivalTimeOverride(long arrivalTimeOverride) {
|
|
|
|
this.arrivalTimeOverride = arrivalTimeOverride;
|
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
public long getEstimatedArrivalTime() {
|
2012-04-13 22:05:30 +00:00
|
|
|
if (arrivalTimeOverride > 0) {
|
|
|
|
return arrivalTimeOverride;
|
|
|
|
}
|
2012-04-13 01:07:55 +00:00
|
|
|
return getMeanEstimate() + getEstimatedTripTime();
|
|
|
|
}
|
|
|
|
|
2012-07-17 20:43:42 +00:00
|
|
|
public long getEstimatedArrivalMinutesLeft() {
|
|
|
|
long millisLeft = getEstimatedArrivalTime()
|
|
|
|
- System.currentTimeMillis();
|
|
|
|
if (millisLeft < 0) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
// Add ~30s to emulate rounding
|
|
|
|
return (millisLeft + 29999) / (60 * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 14:57:17 +00:00
|
|
|
public String getEstimatedArrivalMinutesLeftText(Context context) {
|
|
|
|
if (!hasAnyArrivalEstimate()) {
|
|
|
|
return "Estimated arrival unknown";
|
|
|
|
}
|
2012-07-17 20:43:42 +00:00
|
|
|
long minutesLeft = getEstimatedArrivalMinutesLeft();
|
|
|
|
if (minutesLeft < 0) {
|
2012-07-18 02:20:18 +00:00
|
|
|
return "Arrived at destination";
|
2012-07-17 20:43:42 +00:00
|
|
|
} else if (minutesLeft == 0) {
|
2012-07-22 14:57:17 +00:00
|
|
|
return "Arrives around " + getEstimatedArrivalTimeText(context)
|
|
|
|
+ " (<1 min)";
|
2012-07-17 20:43:42 +00:00
|
|
|
} else if (minutesLeft == 1) {
|
2012-07-22 14:57:17 +00:00
|
|
|
return "Arrives around " + getEstimatedArrivalTimeText(context)
|
|
|
|
+ " (1 min)";
|
2012-07-17 20:43:42 +00:00
|
|
|
} else {
|
2012-07-22 14:57:17 +00:00
|
|
|
return "Arrives around " + getEstimatedArrivalTimeText(context)
|
|
|
|
+ " (" + minutesLeft + " mins)";
|
2012-07-17 20:43:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-13 01:07:55 +00:00
|
|
|
public String getEstimatedArrivalTimeText(Context context) {
|
2012-04-28 15:44:53 +00:00
|
|
|
if (getEstimatedTripTime() > 0 || arrivalTimeOverride > 0) {
|
2012-04-13 01:07:55 +00:00
|
|
|
return DateFormat.getTimeFormat(context).format(
|
|
|
|
new Date(getEstimatedArrivalTime()));
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public boolean hasDeparted() {
|
2011-06-17 21:35:20 +00:00
|
|
|
return getMeanSecondsLeft() < 0;
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 18:59:34 +00:00
|
|
|
public void calculateEstimates(long originalEstimateTime) {
|
2011-06-05 18:13:21 +00:00
|
|
|
setMinEstimate(originalEstimateTime + (getMinutes() * 60 * 1000)
|
|
|
|
- (30000));
|
|
|
|
setMaxEstimate(getMinEstimate() + 60000);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mergeEstimate(Departure departure) {
|
2012-04-13 22:05:30 +00:00
|
|
|
if (departure.hasDeparted() && origin.longStationLinger
|
|
|
|
&& getMinEstimate() > 0 && !beganAsDeparted) {
|
2012-09-17 15:13:50 +00:00
|
|
|
/*
|
|
|
|
* This is probably not a true departure, but an indication that the
|
|
|
|
* train is in the station. Don't update the estimates.
|
|
|
|
*/
|
2012-04-13 22:05:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-17 15:13:50 +00:00
|
|
|
boolean wasDeparted = hasDeparted();
|
|
|
|
if (!hasAnyArrivalEstimate() && departure.hasAnyArrivalEstimate()) {
|
|
|
|
setArrivalTimeOverride(departure.getArrivalTimeOverride());
|
|
|
|
setEstimatedTripTime(departure.getEstimatedTripTime());
|
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
if ((getMaxEstimate() - departure.getMinEstimate()) < MINIMUM_MERGE_OVERLAP_MILLIS
|
|
|
|
|| departure.getMaxEstimate() - getMinEstimate() < MINIMUM_MERGE_OVERLAP_MILLIS) {
|
2012-09-17 15:13:50 +00:00
|
|
|
/*
|
|
|
|
* The estimate must have changed... just use the latest incoming
|
|
|
|
* values
|
|
|
|
*/
|
2011-06-05 18:13:21 +00:00
|
|
|
setMinEstimate(departure.getMinEstimate());
|
|
|
|
setMaxEstimate(departure.getMaxEstimate());
|
|
|
|
return;
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
|
2011-11-21 16:57:16 +00:00
|
|
|
final long newMin = Math.max(getMinEstimate(),
|
|
|
|
departure.getMinEstimate());
|
|
|
|
final long newMax = Math.min(getMaxEstimate(),
|
|
|
|
departure.getMaxEstimate());
|
2012-09-17 15:13:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the new departure would mark this as departed, and we have < 1
|
|
|
|
* minute left on a fairly accurate local estimate, ignore the incoming
|
|
|
|
* departure
|
|
|
|
*/
|
|
|
|
if (!wasDeparted && getMeanSecondsLeft(newMin, newMax) < 0
|
|
|
|
&& getMeanSecondsLeft() < 60 && getUncertaintySeconds() < 30) {
|
|
|
|
Log.d(Constants.TAG,
|
|
|
|
"Skipping estimate merge, since it would make this departure show as 'departed' prematurely");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
if (newMax > newMin) { // We can never have 0 or negative uncertainty
|
|
|
|
setMinEstimate(newMin);
|
|
|
|
setMaxEstimate(newMax);
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public int compareTo(Departure another) {
|
2012-09-11 22:49:36 +00:00
|
|
|
return (this.getMeanSecondsLeft() > another.getMeanSecondsLeft()) ? 1
|
|
|
|
: ((this.getMeanSecondsLeft() == another.getMeanSecondsLeft()) ? 0
|
|
|
|
: -1);
|
2011-11-21 16:57:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
|
|
|
final int prime = 31;
|
|
|
|
int result = 1;
|
|
|
|
result = prime * result + (bikeAllowed ? 1231 : 1237);
|
2012-09-18 17:11:52 +00:00
|
|
|
result = prime
|
|
|
|
* result
|
|
|
|
+ ((trainDestination == null) ? 0 : trainDestination.hashCode());
|
2011-11-21 16:57:16 +00:00
|
|
|
result = prime
|
|
|
|
* result
|
|
|
|
+ ((destinationColor == null) ? 0 : destinationColor.hashCode());
|
|
|
|
result = prime * result
|
|
|
|
+ ((direction == null) ? 0 : direction.hashCode());
|
|
|
|
result = prime * result + ((line == null) ? 0 : line.hashCode());
|
|
|
|
result = prime * result + (int) (maxEstimate ^ (maxEstimate >>> 32));
|
|
|
|
result = prime * result + (int) (minEstimate ^ (minEstimate >>> 32));
|
|
|
|
result = prime * result + minutes;
|
|
|
|
result = prime * result
|
|
|
|
+ ((platform == null) ? 0 : platform.hashCode());
|
|
|
|
result = prime * result + (requiresTransfer ? 1231 : 1237);
|
|
|
|
result = prime * result
|
|
|
|
+ ((trainLength == null) ? 0 : trainLength.hashCode());
|
|
|
|
return result;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
if (this == obj)
|
|
|
|
return true;
|
|
|
|
if (obj == null)
|
|
|
|
return false;
|
|
|
|
if (getClass() != obj.getClass())
|
|
|
|
return false;
|
2011-06-05 18:13:21 +00:00
|
|
|
Departure other = (Departure) obj;
|
2011-05-23 18:59:34 +00:00
|
|
|
if (bikeAllowed != other.bikeAllowed)
|
|
|
|
return false;
|
2012-09-18 17:11:52 +00:00
|
|
|
if (trainDestination != other.trainDestination)
|
2011-05-23 18:59:34 +00:00
|
|
|
return false;
|
|
|
|
if (destinationColor == null) {
|
|
|
|
if (other.destinationColor != null)
|
|
|
|
return false;
|
|
|
|
} else if (!destinationColor.equals(other.destinationColor))
|
|
|
|
return false;
|
|
|
|
if (direction == null) {
|
|
|
|
if (other.direction != null)
|
|
|
|
return false;
|
|
|
|
} else if (!direction.equals(other.direction))
|
|
|
|
return false;
|
2011-11-21 16:57:16 +00:00
|
|
|
if (line != other.line)
|
|
|
|
return false;
|
2012-04-13 22:05:30 +00:00
|
|
|
if (Math.abs(maxEstimate - other.maxEstimate) > getEqualsTolerance())
|
2011-11-21 16:57:16 +00:00
|
|
|
return false;
|
2011-05-23 18:59:34 +00:00
|
|
|
if (platform == null) {
|
|
|
|
if (other.platform != null)
|
|
|
|
return false;
|
|
|
|
} else if (!platform.equals(other.platform))
|
|
|
|
return false;
|
2011-11-21 16:57:16 +00:00
|
|
|
if (requiresTransfer != other.requiresTransfer)
|
2011-05-23 18:59:34 +00:00
|
|
|
return false;
|
2011-11-21 16:57:16 +00:00
|
|
|
if (trainLength == null) {
|
|
|
|
if (other.trainLength != null)
|
|
|
|
return false;
|
|
|
|
} else if (!trainLength.equals(other.trainLength))
|
|
|
|
return false;
|
|
|
|
return true;
|
2011-05-23 18:59:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 22:05:30 +00:00
|
|
|
private int getEqualsTolerance() {
|
2012-04-28 15:44:53 +00:00
|
|
|
if (origin != null) {
|
|
|
|
return origin.departureEqualityTolerance;
|
2012-04-13 22:05:30 +00:00
|
|
|
} else {
|
2012-04-28 15:44:53 +00:00
|
|
|
return Station.DEFAULT_DEPARTURE_EQUALITY_TOLERANCE;
|
2012-04-13 22:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:06:58 +00:00
|
|
|
public String getCountdownText() {
|
2011-05-23 18:59:34 +00:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
int secondsLeft = getMeanSecondsLeft();
|
2011-06-05 18:13:21 +00:00
|
|
|
if (hasDeparted()) {
|
2012-04-24 23:13:23 +00:00
|
|
|
if (origin != null && origin.longStationLinger && beganAsDeparted) {
|
2012-04-13 22:05:30 +00:00
|
|
|
builder.append("At station");
|
|
|
|
} else {
|
|
|
|
builder.append("Departed");
|
|
|
|
}
|
2011-05-23 18:59:34 +00:00
|
|
|
} else {
|
|
|
|
builder.append(secondsLeft / 60);
|
|
|
|
builder.append("m, ");
|
|
|
|
builder.append(secondsLeft % 60);
|
|
|
|
builder.append("s");
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
2011-05-27 21:06:58 +00:00
|
|
|
|
|
|
|
public String getUncertaintyText() {
|
2011-06-05 18:13:21 +00:00
|
|
|
if (hasDeparted()) {
|
2011-05-27 21:06:58 +00:00
|
|
|
return "";
|
|
|
|
} else {
|
2012-09-07 05:47:27 +00:00
|
|
|
return "(±" + getUncertaintySeconds() + "s)";
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2012-04-29 16:42:54 +00:00
|
|
|
java.text.DateFormat format = SimpleDateFormat.getTimeInstance();
|
2011-05-27 21:06:58 +00:00
|
|
|
StringBuilder builder = new StringBuilder();
|
2012-09-18 17:11:52 +00:00
|
|
|
builder.append(trainDestination);
|
2011-05-27 21:06:58 +00:00
|
|
|
if (requiresTransfer) {
|
|
|
|
builder.append(" (w/ xfer)");
|
|
|
|
}
|
|
|
|
builder.append(", ");
|
|
|
|
builder.append(getCountdownText());
|
2012-04-29 16:42:54 +00:00
|
|
|
builder.append(", ");
|
|
|
|
builder.append(format.format(new Date(getMeanEstimate())));
|
2011-05-27 21:06:58 +00:00
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
2012-09-17 15:13:50 +00:00
|
|
|
dest.writeString(origin.abbreviation);
|
2012-09-18 17:11:52 +00:00
|
|
|
dest.writeString(trainDestination.abbreviation);
|
|
|
|
dest.writeString(passengerDestination == null ? null
|
|
|
|
: passengerDestination.abbreviation);
|
2011-05-27 21:06:58 +00:00
|
|
|
dest.writeString(destinationColor);
|
|
|
|
dest.writeString(platform);
|
|
|
|
dest.writeString(direction);
|
|
|
|
dest.writeByte((byte) (bikeAllowed ? 1 : 0));
|
2011-11-21 16:57:16 +00:00
|
|
|
dest.writeString(trainLength);
|
2011-05-27 21:06:58 +00:00
|
|
|
dest.writeByte((byte) (requiresTransfer ? 1 : 0));
|
|
|
|
dest.writeInt(minutes);
|
|
|
|
dest.writeLong(minEstimate);
|
|
|
|
dest.writeLong(maxEstimate);
|
2012-09-17 15:13:50 +00:00
|
|
|
dest.writeLong(arrivalTimeOverride);
|
|
|
|
dest.writeInt(estimatedTripTime);
|
|
|
|
dest.writeInt(line.ordinal());
|
|
|
|
dest.writeBooleanArray(new boolean[] { beganAsDeparted, bikeAllowed,
|
|
|
|
requiresTransfer, transferScheduled });
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void readFromParcel(Parcel in) {
|
2012-09-17 15:13:50 +00:00
|
|
|
origin = Station.getByAbbreviation(in.readString());
|
2012-09-18 17:11:52 +00:00
|
|
|
trainDestination = Station.getByAbbreviation(in.readString());
|
|
|
|
passengerDestination = Station.getByAbbreviation(in.readString());
|
2011-05-27 21:06:58 +00:00
|
|
|
destinationColor = in.readString();
|
|
|
|
platform = in.readString();
|
|
|
|
direction = in.readString();
|
|
|
|
bikeAllowed = in.readByte() != 0;
|
2011-11-21 16:57:16 +00:00
|
|
|
trainLength = in.readString();
|
2011-05-27 21:06:58 +00:00
|
|
|
requiresTransfer = in.readByte() != 0;
|
|
|
|
minutes = in.readInt();
|
|
|
|
minEstimate = in.readLong();
|
|
|
|
maxEstimate = in.readLong();
|
2012-09-17 15:13:50 +00:00
|
|
|
arrivalTimeOverride = in.readLong();
|
|
|
|
estimatedTripTime = in.readInt();
|
|
|
|
line = Line.values()[in.readInt()];
|
|
|
|
boolean[] bools = new boolean[4];
|
|
|
|
in.readBooleanArray(bools);
|
|
|
|
beganAsDeparted = bools[0];
|
|
|
|
bikeAllowed = bools[1];
|
|
|
|
requiresTransfer = bools[2];
|
|
|
|
transferScheduled = bools[3];
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public static final Parcelable.Creator<Departure> CREATOR = new Parcelable.Creator<Departure>() {
|
|
|
|
public Departure createFromParcel(Parcel in) {
|
|
|
|
return new Departure(in);
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2011-06-05 18:13:21 +00:00
|
|
|
public Departure[] newArray(int size) {
|
|
|
|
return new Departure[size];
|
2011-05-27 21:06:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|