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

View File

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

View File

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

View File

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

View File

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

View File

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