Fixed SFIA, arrival estimate issues

--HG--
branch : estarrival
This commit is contained in:
dkeen@dkeen-laptop 2012-04-13 15:05:30 -07:00
parent 58f623b1cf
commit 64f576c36d
6 changed files with 123 additions and 65 deletions

View File

@ -2,6 +2,8 @@ package com.dougkeen.bart;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
@ -20,6 +22,8 @@ import com.dougkeen.bart.model.Departure;
public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
public static int refreshCounter = 0;
public DepartureArrayAdapter(Context context, int textViewResourceId,
Departure[] objects) {
super(context, textViewResourceId, objects);
@ -49,8 +53,6 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
super(context, textViewResourceId);
}
private String currentViewSwitcherText;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
@ -69,20 +71,23 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
.findViewById(R.id.trainLengthText);
initTextSwitcher(textSwitcher);
if (System.currentTimeMillis() % 6000 > 3000) {
final String estimatedArrivalTimeText = departure
.getEstimatedArrivalTimeText(getContext());
String arrivalText = "Est. arrival " + estimatedArrivalTimeText;
if (StringUtils.isBlank(estimatedArrivalTimeText)) {
textSwitcher.setCurrentText(departure.getTrainLengthText());
} else if (refreshCounter % 6 < 3) {
String trainLengthText = departure.getTrainLengthText();
if (currentViewSwitcherText == null
|| !currentViewSwitcherText.equals(trainLengthText)) {
if (refreshCounter % 6 == 0) {
textSwitcher.setText(trainLengthText);
currentViewSwitcherText = trainLengthText;
} else {
textSwitcher.setCurrentText(trainLengthText);
}
} else {
String arrivalText = "Est. arrival "
+ departure.getEstimatedArrivalTimeText(getContext());
if (currentViewSwitcherText == null
|| !currentViewSwitcherText.equals(arrivalText)) {
if (refreshCounter % 6 == 3) {
textSwitcher.setText(arrivalText);
currentViewSwitcherText = arrivalText;
} else {
textSwitcher.setCurrentText(arrivalText);
}
}
ImageView colorBar = (ImageView) view
@ -121,9 +126,7 @@ public class DepartureArrayAdapter extends ArrayAdapter<Departure> {
});
textSwitcher.setInAnimation(AnimationUtils.loadAnimation(
getContext(), android.R.anim.slide_in_left));
textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(
getContext(), android.R.anim.slide_out_right));
getContext(), android.R.anim.fade_in));
}
}
}

View File

@ -430,6 +430,7 @@ public class ViewDeparturesActivity extends ListActivity {
private void runAutoUpdate() {
if (mIsAutoUpdating && mDeparturesAdapter != null) {
DepartureArrayAdapter.refreshCounter++;
mDeparturesAdapter.notifyDataSetChanged();
}
if (hasWindowFocus()) {

View File

@ -9,6 +9,7 @@ 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() {
@ -32,6 +33,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
readFromParcel(in);
}
private Station origin;
private Station destination;
private Line line;
private String destinationColor;
@ -48,6 +50,18 @@ public class Departure implements Parcelable, Comparable<Departure> {
private int estimatedTripTime;
private boolean beganAsDeparted;
private long arrivalTimeOverride;
public Station getOrigin() {
return origin;
}
public void setOrigin(Station origin) {
this.origin = origin;
}
public Station getDestination() {
return destination;
}
@ -134,6 +148,9 @@ public class Departure implements Parcelable, Comparable<Departure> {
public void setMinutes(int minutes) {
this.minutes = minutes;
if (minutes == 0) {
beganAsDeparted = true;
}
}
public long getMinEstimate() {
@ -185,6 +202,9 @@ public class Departure implements Parcelable, Comparable<Departure> {
}
public long getEstimatedArrivalTime() {
if (arrivalTimeOverride > 0) {
return arrivalTimeOverride;
}
return getMeanEstimate() + getEstimatedTripTime();
}
@ -208,6 +228,13 @@ public class Departure implements Parcelable, Comparable<Departure> {
}
public void mergeEstimate(Departure departure) {
if (departure.hasDeparted() && origin.longStationLinger
&& getMinEstimate() > 0 && !beganAsDeparted) {
// This is probably not a true departure, but an indication that
// the train is in the station. Don't update the estimates.
return;
}
if ((getMaxEstimate() - departure.getMinEstimate()) < MINIMUM_MERGE_OVERLAP_MILLIS
|| departure.getMaxEstimate() - getMinEstimate() < MINIMUM_MERGE_OVERLAP_MILLIS) {
// The estimate must have changed... just use the latest incoming
@ -281,7 +308,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
return false;
if (line != other.line)
return false;
if (Math.abs(maxEstimate - other.maxEstimate) > ESTIMATE_EQUALS_TOLERANCE_MILLIS)
if (Math.abs(maxEstimate - other.maxEstimate) > getEqualsTolerance())
return false;
if (platform == null) {
if (other.platform != null)
@ -298,11 +325,23 @@ public class Departure implements Parcelable, Comparable<Departure> {
return true;
}
private int getEqualsTolerance() {
if (origin.longStationLinger && hasDeparted()) {
return ESTIMATE_EQUALS_TOLERANCE_LONG_LINGER_MILLIS;
} else {
return ESTIMATE_EQUALS_TOLERANCE_MILLIS;
}
}
public String getCountdownText() {
StringBuilder builder = new StringBuilder();
int secondsLeft = getMeanSecondsLeft();
if (hasDeparted()) {
if (origin.longStationLinger && beganAsDeparted) {
builder.append("At station");
} else {
builder.append("Departed");
}
} else {
builder.append(secondsLeft / 60);
builder.append("m, ");

View File

@ -37,6 +37,12 @@ public enum Line {
Station.COLS, Station.SANL, Station.BAYF, Station.HAYW,
Station.SHAY, Station.UCTY, Station.FRMT),
YELLOW_ORANGE_SCHEDULED_TRANSFER(YELLOW, ORANGE, Station.MLBR,
Station.SFIA, Station.SBRN, Station.SSAN, Station.COLM,
Station.DALY, 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),
YELLOW_RED_SCHEDULED_TRANSFER(YELLOW, RED, Station.MLBR,
Station.SFIA, Station.SBRN, Station.SSAN, Station.COLM,
Station.DALY, Station.BALB, Station.GLEN, Station._24TH,
Station._16TH, Station.CIVC, Station.POWL, Station.MONT,

View File

@ -6,43 +6,51 @@ import java.util.List;
import android.util.Log;
public enum Station {
_12TH("12th", "12th St./Oakland City Center", false, false, "bayf"), _16TH(
"16th", "16th St. Mission", false, false), _19TH("19th",
"19th St./Oakland", false, false, "bayf"), _24TH("24th",
"24th St. Mission", false, false), ASHB("ashb", "Ashby", false,
false, "mcar"), BALB("balb", "Balboa Park", false, false), BAYF(
"bayf", "Bay Fair", true, false, "mcar"), CAST("cast",
"Castro Valley", false, false, "bayf"), CIVC("civc",
"Civic Center", false, false), COLS("cols",
"Coliseum/Oakland Airport", true, false, "mcar"), COLM("colm",
"Colma", false, false, "balb", "balb"), CONC("conc", "Concord",
false, false, "mcar"), DALY("daly", "Daly City", false, false), DBRK(
"dbrk", "Downtown Berkeley", false, false, "mcar"), DUBL("dubl",
"Dublin/Pleasanton", false, true, "bayf"), DELN("deln",
"El Cerrito del Norte", false, false, "mcar"), PLZA("plza",
"El Cerrito Plaza", false, false, "mcar"), EMBR("embr",
"Embarcadero", false, false), FRMT("frmt", "Fremont", true, false,
"bayf"), FTVL("ftvl", "Fruitvale", true, false, "mcar"), GLEN(
"glen", "Glen Park", false, false), HAYW("hayw", "Hayward", true,
false, "bayf"), LAFY("lafy", "Lafayette", false, false, "mcar"), LAKE(
"lake", "Lake Merritt", true, false, "mcar"), MCAR("mcar",
"MacArthur", false, false, "bayf"), MLBR("mlbr", "Millbrae", false,
true, "balb", "balb"), MONT("mont", "Montgomery St.", false, false), NBRK(
"nbrk", "North Berkeley", false, false, "mcar"), NCON("ncon",
"North Concord/Martinez", false, false, "mcar"), ORIN("orin",
"Orinda", false, false, "mcar"), PITT("pitt",
"Pittsburg/Bay Point", false, true, "mcar"), PHIL("phil",
"Pleasant Hill", false, false, "mcar"), POWL("powl", "Powell St.",
false, false), RICH("rich", "Richmond", false, true, "mcar"), ROCK(
"rock", "Rockridge", false, false, "mcar"), SBRN("sbrn",
"San Bruno", false, false, "balb", "balb"), SANL("sanl",
"San Leandro", true, false, "mcar"), SFIA("sfia", "SFO Airport",
false, false, "sbrn", "balb"), SHAY("shay", "South Hayward", true,
false, "bayf"), SSAN("ssan", "South San Francisco", false, false,
"balb", "balb"), UCTY("ucty", "Union City", true, false, "bayf"), WCRK(
"wcrk", "Walnut Creek", false, false, "mcar"), WDUB("wdub",
"West Dublin/Pleasanton", false, false, "bayf"), WOAK("woak",
"West Oakland", false, false), SPCL("spcl", "Special", false, false);
_12TH("12th", "12th St./Oakland City Center", false, false, "bayf"),
_16TH("16th", "16th St. Mission", false, false),
_19TH("19th", "19th St./Oakland", false, false, "bayf"),
_24TH("24th", "24th St. Mission", false, false),
ASHB("ashb", "Ashby", false, false, "mcar"),
BALB("balb", "Balboa Park", false, false),
BAYF("bayf", "Bay Fair", true, false, "mcar"),
CAST("cast", "Castro Valley", false, false, "bayf"),
CIVC("civc", "Civic Center", false, false),
COLS("cols", "Coliseum/Oakland Airport", true, false, "mcar"),
COLM("colm", "Colma", false, false, "balb", "balb"),
CONC("conc", "Concord", false, false, "mcar"),
DALY("daly", "Daly City", false, false),
DBRK("dbrk", "Downtown Berkeley", false, false, "mcar"),
DUBL("dubl", "Dublin/Pleasanton", false, true, "bayf"),
DELN("deln", "El Cerrito del Norte", false, false, "mcar"),
PLZA("plza", "El Cerrito Plaza", false, false, "mcar"),
EMBR("embr", "Embarcadero", false, false),
FRMT("frmt", "Fremont", true, false, "bayf"),
FTVL("ftvl", "Fruitvale", true, false, "mcar"),
GLEN("glen", "Glen Park", false, false),
HAYW("hayw", "Hayward", true, false, "bayf"),
LAFY("lafy", "Lafayette", false, false, "mcar"),
LAKE("lake", "Lake Merritt", true, false, "mcar"),
MCAR("mcar", "MacArthur", false, false, "bayf"),
MLBR("mlbr", "Millbrae", false, true, "balb", "balb"),
MONT("mont", "Montgomery St.", false, false),
NBRK("nbrk", "North Berkeley", false, false, "mcar"),
NCON("ncon", "North Concord/Martinez", false, false, "mcar"),
ORIN("orin", "Orinda", false, false, "mcar"),
PITT("pitt", "Pittsburg/Bay Point", false, true, "mcar"),
PHIL("phil", "Pleasant Hill", false, false, "mcar"),
POWL("powl", "Powell St.", false, false),
RICH("rich", "Richmond", false, true, "mcar"),
ROCK("rock", "Rockridge", false, false, "mcar"),
SBRN("sbrn", "San Bruno", false, false, "balb", "balb"),
SANL("sanl", "San Leandro", true, false, "mcar"),
SFIA("sfia", "SFO Airport", false, false, "sbrn", "balb", true),
SHAY("shay", "South Hayward", true, false, "bayf"),
SSAN("ssan", "South San Francisco", false, false, "balb", "balb"),
UCTY("ucty", "Union City", true, false, "bayf"),
WCRK("wcrk", "Walnut Creek", false, false, "mcar"),
WDUB("wdub", "West Dublin/Pleasanton", false, false, "bayf"),
WOAK("woak", "West Oakland", false, false),
SPCL("spcl", "Special", false, false);
public final String abbreviation;
public final String name;
@ -50,36 +58,36 @@ public enum Station {
protected final String inboundTransferStation;
protected final String outboundTransferStation;
public final boolean endOfLine;
public final boolean longStationLinger;
private Station(String abbreviation, String name, boolean invertDirection,
boolean endOfLine) {
this.abbreviation = abbreviation;
this.name = name;
this.invertDirection = invertDirection;
this.inboundTransferStation = null;
this.outboundTransferStation = null;
this.endOfLine = endOfLine;
this(abbreviation, name, invertDirection, endOfLine, null, null, false);
}
private Station(String abbreviation, String name, boolean invertDirection,
boolean endOfLine, String transferStation) {
this.abbreviation = abbreviation;
this.name = name;
this.invertDirection = invertDirection;
this.inboundTransferStation = transferStation;
this.outboundTransferStation = null;
this.endOfLine = endOfLine;
this(abbreviation, name, invertDirection, endOfLine, transferStation,
null, false);
}
private Station(String abbreviation, String name, boolean invertDirection,
boolean endOfLine, String inboundTransferStation,
String outboundTransferStation) {
this(abbreviation, name, invertDirection, endOfLine,
inboundTransferStation, outboundTransferStation, false);
}
private Station(String abbreviation, String name, boolean invertDirection,
boolean endOfLine, String inboundTransferStation,
String outboundTransferStation, boolean longStationLinger) {
this.abbreviation = abbreviation;
this.name = name;
this.invertDirection = invertDirection;
this.inboundTransferStation = inboundTransferStation;
this.outboundTransferStation = outboundTransferStation;
this.endOfLine = endOfLine;
this.longStationLinger = longStationLinger;
}
public static Station getByAbbreviation(String abbr) {

View File

@ -59,6 +59,7 @@ public class EtdContentHandler extends DefaultHandler {
currentDeparture = new Departure();
currentDeparture.setDestination(Station
.getByAbbreviation(currentDestination));
currentDeparture.setOrigin(realTimeDepartures.getOrigin());
}
}