More fixes for end-of-line stations
This commit is contained in:
parent
742837f654
commit
a12884cdcb
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.dougkeen.bart"
|
||||
android:versionCode="15"
|
||||
android:versionName="1.2.2" >
|
||||
android:versionCode="16"
|
||||
android:versionName="1.2.3" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
@ -360,9 +360,28 @@ public class ViewDeparturesActivity extends ListActivity {
|
||||
Departure departure = mDeparturesAdapter.getItem(departureIndex);
|
||||
for (int i = lastSearchIndex; i < tripCount; i++) {
|
||||
ScheduleItem trip = mLatestScheduleInfo.getTrips().get(i);
|
||||
if (!departure.getDestination().abbreviation.equals(trip
|
||||
.getTrainHeadStation())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
long departTimeDiff = Math.abs(trip.getDepartureTime()
|
||||
- departure.getMeanEstimate());
|
||||
if (departTimeDiff <= (60000 + departure
|
||||
final long millisUntilTripDeparture = trip.getDepartureTime()
|
||||
- System.currentTimeMillis();
|
||||
final int equalityTolerance = (departure.getOrigin() != null) ? departure
|
||||
.getOrigin().departureEqualityTolerance
|
||||
: Station.DEFAULT_DEPARTURE_EQUALITY_TOLERANCE;
|
||||
if (departure.getOrigin() != null
|
||||
&& departure.getOrigin().longStationLinger
|
||||
&& departure.hasDeparted()
|
||||
&& millisUntilTripDeparture > 0
|
||||
&& millisUntilTripDeparture < equalityTolerance) {
|
||||
departure.setArrivalTimeOverride(trip.getArrivalTime());
|
||||
lastSearchIndex = i;
|
||||
departureUpdated = true;
|
||||
break;
|
||||
} else if (departTimeDiff <= (equalityTolerance + departure
|
||||
.getUncertaintySeconds() * 1000)
|
||||
&& departure.getEstimatedTripTime() != trip
|
||||
.getTripLength()) {
|
||||
@ -427,11 +446,18 @@ public class ViewDeparturesActivity extends ListActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private long mLastAutoUpdate = 0;
|
||||
|
||||
private void runAutoUpdate() {
|
||||
long now = System.currentTimeMillis();
|
||||
if (now - mLastAutoUpdate < 950) {
|
||||
return;
|
||||
}
|
||||
if (mIsAutoUpdating && mDeparturesAdapter != null) {
|
||||
mDeparturesAdapter.incrementRefreshCounter();
|
||||
mDeparturesAdapter.notifyDataSetChanged();
|
||||
}
|
||||
mLastAutoUpdate = now;
|
||||
if (hasWindowFocus()) {
|
||||
mListTitleView.postDelayed(AUTO_UPDATE_RUNNABLE, 1000);
|
||||
} else {
|
||||
|
@ -8,8 +8,6 @@ import android.os.Parcelable;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
public class Departure implements Parcelable, Comparable<Departure> {
|
||||
private static final int ESTIMATE_EQUALS_TOLERANCE_MILLIS = 59999;
|
||||
private static final int ESTIMATE_EQUALS_TOLERANCE_LONG_LINGER_MILLIS = 719999;
|
||||
private static final int MINIMUM_MERGE_OVERLAP_MILLIS = 10000;
|
||||
|
||||
public Departure() {
|
||||
@ -201,6 +199,14 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
||||
return (getMinEstimate() + getMaxEstimate()) / 2;
|
||||
}
|
||||
|
||||
public long getArrivalTimeOverride() {
|
||||
return arrivalTimeOverride;
|
||||
}
|
||||
|
||||
public void setArrivalTimeOverride(long arrivalTimeOverride) {
|
||||
this.arrivalTimeOverride = arrivalTimeOverride;
|
||||
}
|
||||
|
||||
public long getEstimatedArrivalTime() {
|
||||
if (arrivalTimeOverride > 0) {
|
||||
return arrivalTimeOverride;
|
||||
@ -209,7 +215,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
||||
}
|
||||
|
||||
public String getEstimatedArrivalTimeText(Context context) {
|
||||
if (getEstimatedTripTime() > 0) {
|
||||
if (getEstimatedTripTime() > 0 || arrivalTimeOverride > 0) {
|
||||
return DateFormat.getTimeFormat(context).format(
|
||||
new Date(getEstimatedArrivalTime()));
|
||||
} else {
|
||||
@ -326,10 +332,10 @@ public class Departure implements Parcelable, Comparable<Departure> {
|
||||
}
|
||||
|
||||
private int getEqualsTolerance() {
|
||||
if (origin != null && origin.longStationLinger && hasDeparted()) {
|
||||
return ESTIMATE_EQUALS_TOLERANCE_LONG_LINGER_MILLIS;
|
||||
if (origin != null) {
|
||||
return origin.departureEqualityTolerance;
|
||||
} else {
|
||||
return ESTIMATE_EQUALS_TOLERANCE_MILLIS;
|
||||
return Station.DEFAULT_DEPARTURE_EQUALITY_TOLERANCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,10 @@ public enum Line {
|
||||
Station.BALB, Station.GLEN, Station._24TH, Station._16TH,
|
||||
Station.CIVC, Station.POWL, Station.MONT, Station.EMBR,
|
||||
Station.WOAK, Station.ASHB, Station.DBRK, Station.NBRK,
|
||||
Station.PLZA, Station.DELN, Station.RICH);
|
||||
Station.PLZA, Station.DELN, Station.RICH),
|
||||
ORANGE_BLUE_SCHEDULED_TRANSFER(true, ORANGE, BLUE, Station.FRMT,
|
||||
Station.UCTY, Station.SHAY, Station.HAYW, Station.BAYF,
|
||||
Station.CAST, Station.WDUB, Station.DUBL);
|
||||
|
||||
public final List<Station> stations;
|
||||
|
||||
|
@ -20,30 +20,33 @@ public enum Station {
|
||||
CONC("conc", "Concord", true, false, false, "mcar"),
|
||||
DALY("daly", "Daly City", false, false, false),
|
||||
DBRK("dbrk", "Downtown Berkeley", true, false, false, "mcar"),
|
||||
DUBL("dubl", "Dublin/Pleasanton", true, false, true, "bayf"),
|
||||
DUBL("dubl", "Dublin/Pleasanton", true, false, true, "bayf", "bayf", true,
|
||||
719999),
|
||||
DELN("deln", "El Cerrito del Norte", true, false, false, "mcar"),
|
||||
PLZA("plza", "El Cerrito Plaza", true, false, false, "mcar"),
|
||||
EMBR("embr", "Embarcadero", false, false, false),
|
||||
FRMT("frmt", "Fremont", true, true, false, "bayf"),
|
||||
FRMT("frmt", "Fremont", true, true, true, "bayf", "bayf", true, 299999),
|
||||
FTVL("ftvl", "Fruitvale", true, true, false, "mcar"),
|
||||
GLEN("glen", "Glen Park", false, false, false),
|
||||
HAYW("hayw", "Hayward", true, true, false, "bayf"),
|
||||
LAFY("lafy", "Lafayette", true, false, false, "mcar"),
|
||||
LAKE("lake", "Lake Merritt", true, true, false, "mcar"),
|
||||
MCAR("mcar", "MacArthur", true, false, false, "bayf"),
|
||||
MLBR("mlbr", "Millbrae", true, false, true, "balb", "balb"),
|
||||
MLBR("mlbr", "Millbrae", true, false, true, "balb", "balb", true, 719999),
|
||||
MONT("mont", "Montgomery St.", false, false, false),
|
||||
NBRK("nbrk", "North Berkeley", true, false, false, "mcar"),
|
||||
NCON("ncon", "North Concord/Martinez", true, false, false, "mcar"),
|
||||
ORIN("orin", "Orinda", true, false, false, "mcar"),
|
||||
PITT("pitt", "Pittsburg/Bay Point", true, false, true, "mcar"),
|
||||
PITT("pitt", "Pittsburg/Bay Point", true, false, true, "mcar", "mcar",
|
||||
true, 719999),
|
||||
PHIL("phil", "Pleasant Hill", true, false, false, "mcar"),
|
||||
POWL("powl", "Powell St.", false, false, false),
|
||||
RICH("rich", "Richmond", true, false, true, "mcar"),
|
||||
RICH("rich", "Richmond", true, false, true, "mcar", "mcar", true, 299999),
|
||||
ROCK("rock", "Rockridge", true, false, false, "mcar"),
|
||||
SBRN("sbrn", "San Bruno", true, false, false, "balb", "balb"),
|
||||
SANL("sanl", "San Leandro", true, true, false, "mcar"),
|
||||
SFIA("sfia", "SFO Airport", true, false, false, "sbrn", "balb", true),
|
||||
SFIA("sfia", "SFO Airport", true, false, false, "sbrn", "balb", true,
|
||||
719999),
|
||||
SHAY("shay", "South Hayward", true, true, false, "bayf"),
|
||||
SSAN("ssan", "South San Francisco", true, false, false, "balb", "balb"),
|
||||
UCTY("ucty", "Union City", true, true, false, "bayf"),
|
||||
@ -60,30 +63,35 @@ public enum Station {
|
||||
protected final String outboundTransferStation;
|
||||
public final boolean endOfLine;
|
||||
public final boolean longStationLinger;
|
||||
public final int departureEqualityTolerance;
|
||||
|
||||
public final static int DEFAULT_DEPARTURE_EQUALITY_TOLERANCE = 59999;
|
||||
|
||||
private Station(String abbreviation, String name, boolean transferFriendly,
|
||||
boolean invertDirection, boolean endOfLine) {
|
||||
this(abbreviation, name, transferFriendly, invertDirection, endOfLine,
|
||||
null, null, false);
|
||||
null, null, false, DEFAULT_DEPARTURE_EQUALITY_TOLERANCE);
|
||||
}
|
||||
|
||||
private Station(String abbreviation, String name, boolean transferFriendly,
|
||||
boolean invertDirection, boolean endOfLine, String transferStation) {
|
||||
this(abbreviation, name, transferFriendly, invertDirection, endOfLine,
|
||||
transferStation, null, false);
|
||||
transferStation, null, false,
|
||||
DEFAULT_DEPARTURE_EQUALITY_TOLERANCE);
|
||||
}
|
||||
|
||||
private Station(String abbreviation, String name, boolean transferFriendly,
|
||||
boolean invertDirection, boolean endOfLine,
|
||||
String inboundTransferStation, String outboundTransferStation) {
|
||||
this(abbreviation, name, transferFriendly, invertDirection, endOfLine,
|
||||
inboundTransferStation, outboundTransferStation, false);
|
||||
inboundTransferStation, outboundTransferStation, false,
|
||||
DEFAULT_DEPARTURE_EQUALITY_TOLERANCE);
|
||||
}
|
||||
|
||||
private Station(String abbreviation, String name, boolean transferFriendly,
|
||||
boolean invertDirection, boolean endOfLine,
|
||||
String inboundTransferStation, String outboundTransferStation,
|
||||
boolean longStationLinger) {
|
||||
boolean longStationLinger, int departureEqualityTolerance) {
|
||||
this.abbreviation = abbreviation;
|
||||
this.name = name;
|
||||
this.invertDirection = invertDirection;
|
||||
@ -92,6 +100,7 @@ public enum Station {
|
||||
this.outboundTransferStation = outboundTransferStation;
|
||||
this.endOfLine = endOfLine;
|
||||
this.longStationLinger = longStationLinger;
|
||||
this.departureEqualityTolerance = departureEqualityTolerance;
|
||||
}
|
||||
|
||||
public static Station getByAbbreviation(String abbr) {
|
||||
|
@ -25,7 +25,7 @@ public class ScheduleContentHandler extends DefaultHandler {
|
||||
}
|
||||
|
||||
private final static List<String> TAGS = Arrays.asList("date", "time",
|
||||
"trip");
|
||||
"trip", "leg");
|
||||
|
||||
private final static DateFormat TRIP_DATE_FORMAT;
|
||||
private final static DateFormat REQUEST_DATE_FORMAT;
|
||||
@ -53,6 +53,8 @@ public class ScheduleContentHandler extends DefaultHandler {
|
||||
private String requestDate;
|
||||
private String requestTime;
|
||||
|
||||
private ScheduleItem currentTrip;
|
||||
|
||||
@Override
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
@ -67,22 +69,23 @@ public class ScheduleContentHandler extends DefaultHandler {
|
||||
if (TAGS.contains(localName)) {
|
||||
isParsingTag = true;
|
||||
}
|
||||
final int numberOfAttributes = attributes.getLength();
|
||||
if (localName.equals("trip")) {
|
||||
ScheduleItem trip = new ScheduleItem();
|
||||
currentTrip = new ScheduleItem();
|
||||
String originDate = null;
|
||||
String originTime = null;
|
||||
String destinationDate = null;
|
||||
String destinationTime = null;
|
||||
for (int i = attributes.getLength() - 1; i >= 0; i--) {
|
||||
for (int i = 0; i < numberOfAttributes; i++) {
|
||||
if (attributes.getLocalName(i).equalsIgnoreCase("origin")) {
|
||||
trip.setOrigin(Station.getByAbbreviation(attributes
|
||||
currentTrip.setOrigin(Station.getByAbbreviation(attributes
|
||||
.getValue(i)));
|
||||
} else if (attributes.getLocalName(i).equalsIgnoreCase(
|
||||
"destination")) {
|
||||
trip.setDestination(Station.getByAbbreviation(attributes
|
||||
.getValue(i)));
|
||||
currentTrip.setDestination(Station
|
||||
.getByAbbreviation(attributes.getValue(i)));
|
||||
} else if (attributes.getLocalName(i).equalsIgnoreCase("fare")) {
|
||||
trip.setFare(attributes.getValue(i));
|
||||
currentTrip.setFare(attributes.getValue(i));
|
||||
} else if (attributes.getLocalName(i).equalsIgnoreCase(
|
||||
"origTimeMin")) {
|
||||
originTime = attributes.getValue(i);
|
||||
@ -97,24 +100,34 @@ public class ScheduleContentHandler extends DefaultHandler {
|
||||
destinationDate = attributes.getValue(i);
|
||||
} else if (attributes.getLocalName(i).equalsIgnoreCase(
|
||||
"bikeFlag")) {
|
||||
trip.setBikesAllowed(attributes.getValue(i).equals("1"));
|
||||
} else if (attributes.getLocalName(i).equalsIgnoreCase(
|
||||
"trainHeadStation")) {
|
||||
trip.setTrainHeadStation(attributes.getValue(i));
|
||||
currentTrip.setBikesAllowed(attributes.getValue(i).equals(
|
||||
"1"));
|
||||
}
|
||||
}
|
||||
|
||||
long departTime = parseDate(TRIP_DATE_FORMAT, originDate,
|
||||
originTime);
|
||||
if (departTime > 0)
|
||||
trip.setDepartureTime(departTime);
|
||||
currentTrip.setDepartureTime(departTime);
|
||||
|
||||
long arriveTime = parseDate(TRIP_DATE_FORMAT, destinationDate,
|
||||
destinationTime);
|
||||
if (arriveTime > 0)
|
||||
trip.setArrivalTime(arriveTime);
|
||||
currentTrip.setArrivalTime(arriveTime);
|
||||
|
||||
schedule.addTrip(trip);
|
||||
schedule.addTrip(currentTrip);
|
||||
}
|
||||
if (localName.equals("leg")) {
|
||||
String legNumber = null;
|
||||
for (int i = 0; i < numberOfAttributes; i++) {
|
||||
if (attributes.getLocalName(i).equals("order")) {
|
||||
legNumber = attributes.getValue(i);
|
||||
} else if (attributes.getLocalName(i)
|
||||
.equals("trainHeadStation") && "1".equals(legNumber)) {
|
||||
currentTrip.setTrainHeadStation(attributes.getValue(i)
|
||||
.toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user