Fixed change in API ("Arrived" became "Leaving")

Added commons lang dependency
This commit is contained in:
dkeen@dkeen-laptop 2011-11-21 08:57:16 -08:00
parent d732f0854a
commit 1df5c45160
5 changed files with 60 additions and 23 deletions

View File

@ -4,6 +4,7 @@
<classpathentry kind="src" path="gen"/> <classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/> <classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/>
<classpathentry kind="lib" path="libs/commons-lang3-3.1.jar"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dougkeen.bart" package="com.dougkeen.bart"
android:versionCode="7" android:versionCode="8"
android:versionName="1.0.2" > android:versionName="1.0.3" >
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

BIN
libs/commons-lang3-3.1.jar Normal file

Binary file not shown.

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
@ -67,17 +68,17 @@ public class EtdContentHandler extends DefaultHandler {
} else if (localName.equals("abbreviation")) { } else if (localName.equals("abbreviation")) {
currentDestination = currentValue; currentDestination = currentValue;
} else if (localName.equals("minutes")) { } else if (localName.equals("minutes")) {
if (currentValue.equalsIgnoreCase("arrived")) { if (StringUtils.isNumeric(currentValue)) {
currentDeparture.setMinutes(0);
} else {
currentDeparture.setMinutes(Integer.parseInt(currentValue)); currentDeparture.setMinutes(Integer.parseInt(currentValue));
} else {
currentDeparture.setMinutes(0);
} }
} else if (localName.equals("platform")) { } else if (localName.equals("platform")) {
currentDeparture.setPlatform(currentValue); currentDeparture.setPlatform(currentValue);
} else if (localName.equals("direction")) { } else if (localName.equals("direction")) {
currentDeparture.setDirection(currentValue); currentDeparture.setDirection(currentValue);
} else if (localName.equals("length")) { } else if (localName.equals("length")) {
currentDeparture.setTrainLength(Integer.parseInt(currentValue)); currentDeparture.setTrainLength(currentValue);
} else if (localName.equals("color")) { } else if (localName.equals("color")) {
try { try {
if (currentValue.equalsIgnoreCase("WHITE")) { if (currentValue.equalsIgnoreCase("WHITE")) {

View File

@ -15,7 +15,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
public Departure(String destinationAbbr, String destinationColor, public Departure(String destinationAbbr, String destinationColor,
String platform, String direction, boolean bikeAllowed, String platform, String direction, boolean bikeAllowed,
int trainLength, int minutes) { String trainLength, int minutes) {
super(); super();
this.destination = Station.getByAbbreviation(destinationAbbr); this.destination = Station.getByAbbreviation(destinationAbbr);
this.destinationColor = destinationColor; this.destinationColor = destinationColor;
@ -36,7 +36,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
private String platform; private String platform;
private String direction; private String direction;
private boolean bikeAllowed; private boolean bikeAllowed;
private int trainLength; private String trainLength;
private boolean requiresTransfer; private boolean requiresTransfer;
private int minutes; private int minutes;
@ -104,11 +104,11 @@ public class Departure implements Parcelable, Comparable<Departure> {
this.bikeAllowed = bikeAllowed; this.bikeAllowed = bikeAllowed;
} }
public int getTrainLength() { public String getTrainLength() {
return trainLength; return trainLength;
} }
public void setTrainLength(int trainLength) { public void setTrainLength(String trainLength) {
this.trainLength = trainLength; this.trainLength = trainLength;
} }
@ -185,10 +185,10 @@ public class Departure implements Parcelable, Comparable<Departure> {
return; return;
} }
final long newMin = Math final long newMin = Math.max(getMinEstimate(),
.max(getMinEstimate(), departure.getMinEstimate()); departure.getMinEstimate());
final long newMax = Math final long newMax = Math.min(getMaxEstimate(),
.min(getMaxEstimate(), departure.getMaxEstimate()); departure.getMaxEstimate());
if (newMax > newMin) { // We can never have 0 or negative uncertainty if (newMax > newMin) { // We can never have 0 or negative uncertainty
setMinEstimate(newMin); setMinEstimate(newMin);
setMaxEstimate(newMax); setMaxEstimate(newMax);
@ -196,8 +196,32 @@ public class Departure implements Parcelable, Comparable<Departure> {
} }
public int compareTo(Departure another) { public int compareTo(Departure another) {
return (this.getMinutes() > another.getMinutes()) ? 1 : ( return (this.getMinutes() > another.getMinutes()) ? 1 : ((this
(this.getMinutes() == another.getMinutes()) ? 0 : -1); .getMinutes() == another.getMinutes()) ? 0 : -1);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (bikeAllowed ? 1231 : 1237);
result = prime * result
+ ((destination == null) ? 0 : destination.hashCode());
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;
} }
@Override @Override
@ -223,16 +247,27 @@ public class Departure implements Parcelable, Comparable<Departure> {
return false; return false;
} else if (!direction.equals(other.direction)) } else if (!direction.equals(other.direction))
return false; return false;
if (line != other.line)
return false;
if (maxEstimate != other.maxEstimate)
return false;
if (minEstimate != other.minEstimate)
return false;
if (minutes != other.minutes)
return false;
if (platform == null) { if (platform == null) {
if (other.platform != null) if (other.platform != null)
return false; return false;
} else if (!platform.equals(other.platform)) } else if (!platform.equals(other.platform))
return false; return false;
if (trainLength != other.trainLength) if (requiresTransfer != other.requiresTransfer)
return false; return false;
if (trainLength == null) {
long delta = (getMinEstimate() - other.getMinEstimate()); if (other.trainLength != null)
return delta > -60000 && delta < 60000; return false;
} else if (!trainLength.equals(other.trainLength))
return false;
return true;
} }
public String getCountdownText() { public String getCountdownText() {
@ -279,7 +314,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
dest.writeString(platform); dest.writeString(platform);
dest.writeString(direction); dest.writeString(direction);
dest.writeByte((byte) (bikeAllowed ? 1 : 0)); dest.writeByte((byte) (bikeAllowed ? 1 : 0));
dest.writeInt(trainLength); dest.writeString(trainLength);
dest.writeByte((byte) (requiresTransfer ? 1 : 0)); dest.writeByte((byte) (requiresTransfer ? 1 : 0));
dest.writeInt(minutes); dest.writeInt(minutes);
dest.writeLong(minEstimate); dest.writeLong(minEstimate);
@ -292,7 +327,7 @@ public class Departure implements Parcelable, Comparable<Departure> {
platform = in.readString(); platform = in.readString();
direction = in.readString(); direction = in.readString();
bikeAllowed = in.readByte() != 0; bikeAllowed = in.readByte() != 0;
trainLength = in.readInt(); trainLength = in.readString();
requiresTransfer = in.readByte() != 0; requiresTransfer = in.readByte() != 0;
minutes = in.readInt(); minutes = in.readInt();
minEstimate = in.readLong(); minEstimate = in.readLong();