Permalink
Browse files

Made TransitData classes parcelable.

  • Loading branch information...
codebutler committed Dec 4, 2011
1 parent dae0219 commit c30e4f20533f6ba4f98a87b3cbe07e859c24ffb6
@@ -39,7 +39,7 @@
{
private long mSerialNumber;
private short mBalance;
- private Trip[] mTrips;
+ private ClipperTrip[] mTrips;
private ClipperRefill[] mRefills;
private static final int RECORD_LENGTH = 32;
@@ -64,6 +64,7 @@
put(AGENCY_FERRY, "Golden Gate Ferry");
}
};
+
private static Map<Integer, String> sShortAgencies = new HashMap<Integer, String>() {
{
put(AGENCY_ACTRAN, "ACTransit");
@@ -115,12 +116,21 @@
}
};
-
public static boolean check (Card card)
{
return (card instanceof DesfireCard) && (((DesfireCard) card).getApplication(0x9011f2) != null);
}
+ public static Creator<ClipperTransitData> CREATOR = new Creator<ClipperTransitData>() {
+ public ClipperTransitData createFromParcel(Parcel parcel) {
+ return new ClipperTransitData(parcel);
+ }
+
+ public ClipperTransitData[] newArray(int size) {
+ return new ClipperTransitData[size];
+ }
+ };
+
public static TransitIdentity parseTransitIdentity (Card card)
{
try {
@@ -131,6 +141,18 @@ public static TransitIdentity parseTransitIdentity (Card card)
}
}
+
+ public ClipperTransitData(Parcel parcel) {
+ mSerialNumber = parcel.readLong();
+ mBalance = (short) parcel.readLong();
+
+ mTrips = new ClipperTrip[parcel.readInt()];
+ parcel.readTypedArray(mTrips, ClipperTrip.CREATOR);
+
+ mRefills = new ClipperRefill[parcel.readInt()];
+ parcel.readTypedArray(mRefills, ClipperRefill.CREATOR);
+ }
+
public ClipperTransitData (Card card)
{
DesfireCard desfireCard = (DesfireCard) card;
@@ -190,7 +212,7 @@ public String getSerialNumber () {
return mRefills;
}
- private Trip[] parseTrips (DesfireCard card)
+ private ClipperTrip[] parseTrips (DesfireCard card)
{
DesfireFile file = card.getApplication(0x9011f2).getFile(0x0e);
@@ -229,7 +251,7 @@ public String getSerialNumber () {
}
pos -= RECORD_LENGTH;
}
- Trip[] useLog = new Trip[result.size()];
+ ClipperTrip[] useLog = new ClipperTrip[result.size()];
result.toArray(useLog);
return useLog;
}
@@ -333,6 +355,17 @@ public static String getShortAgencyName (int agency) {
return "UNK(0x" + Long.toString(agency, 16) + ")";
}
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeLong(mSerialNumber);
+ parcel.writeLong(mBalance);
+
+ parcel.writeInt(mTrips.length);
+ parcel.writeTypedArray(mTrips, flags);
+
+ parcel.writeInt(mRefills.length);
+ parcel.writeTypedArray(mRefills, flags);
+ }
+
public static class ClipperTrip extends Trip
{
private final long mTimestamp;
@@ -508,13 +541,22 @@ public int describeContents() {
}
}
- public static class ClipperRefill extends Refill
- {
+ public static class ClipperRefill extends Refill {
private final long mTimestamp;
private final long mAmount;
private final long mMachineID;
private final long mAgency;
+ public static Creator<ClipperRefill> CREATOR = new Creator<ClipperRefill>() {
+ public ClipperRefill createFromParcel(Parcel parcel) {
+ return new ClipperRefill(parcel);
+ }
+
+ public ClipperRefill[] newArray(int size) {
+ return new ClipperRefill[size];
+ }
+ };
+
public ClipperRefill (long timestamp, long amount, long agency, long machineid)
{
mTimestamp = timestamp;
@@ -523,6 +565,13 @@ public ClipperRefill (long timestamp, long amount, long agency, long machineid)
mAgency = agency;
}
+ public ClipperRefill(Parcel parcel) {
+ mTimestamp = parcel.readLong();
+ mAmount = parcel.readLong();
+ mMachineID = parcel.readLong();
+ mAgency = parcel.readLong();
+ }
+
@Override
public long getTimestamp () {
return mTimestamp;
@@ -551,5 +600,12 @@ public String getAgencyName () {
public String getShortAgencyName () {
return ClipperTransitData.getShortAgencyName((int)mAgency);
}
+
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeLong(mTimestamp);
+ parcel.writeLong(mAmount);
+ parcel.writeLong(mMachineID);
+ parcel.writeLong(mAgency);
+ }
}
}
@@ -35,9 +35,9 @@
public class EZLinkTransitData extends TransitData
{
- private String mSerialNumber;
- private double mBalance;
- private Trip[] mTrips;
+ private String mSerialNumber;
+ private double mBalance;
+ private EZLinkTrip[] mTrips;
private static HashSet<String> sbsBuses = new HashSet<String> () {
/**
@@ -430,6 +430,24 @@ public static TransitIdentity parseTransitIdentity(Card card)
return new TransitIdentity("EZ-Link", Utils.getHexString(((CEPASCard) card).getPurse(3).getCAN(), "<Error>"));
}
+ public Creator<EZLinkTransitData> CREATOR = new Creator<EZLinkTransitData>() {
+ public EZLinkTransitData createFromParcel(Parcel parcel) {
+ return new EZLinkTransitData(parcel);
+ }
+
+ public EZLinkTransitData[] newArray(int size) {
+ return new EZLinkTransitData[size];
+ }
+ };
+
+ public EZLinkTransitData(Parcel parcel) {
+ mSerialNumber = parcel.readString();
+ mBalance = parcel.readDouble();
+
+ mTrips = new EZLinkTrip[parcel.readInt()];
+ parcel.readTypedArray(mTrips, EZLinkTrip.CREATOR);
+ }
+
public EZLinkTransitData (Card card)
{
CEPASCard cepasCard = (CEPASCard) card;
@@ -464,20 +482,23 @@ public String getSerialNumber () {
return null;
}
- private Trip[] parseTrips (CEPASCard card)
+ private EZLinkTrip[] parseTrips (CEPASCard card)
{
CEPASTransaction[] transactions = card.getHistory(3).getTransactions();
- Trip[] trips = new Trip[transactions.length];
+ EZLinkTrip[] trips = new EZLinkTrip[transactions.length];
for (int i = 0; i < trips.length; i++)
- trips[i] = createTrip(transactions[i]);
+ trips[i] = new EZLinkTrip(transactions[i]);
return trips;
}
- private Trip createTrip (CEPASTransaction record)
- {
- return new EZLinkTrip(record);
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeString(mSerialNumber);
+ parcel.writeDouble(mBalance);
+
+ parcel.writeInt(mTrips.length);
+ parcel.writeTypedArray(mTrips, flags);
}
public static class EZLinkTrip extends Trip
@@ -38,9 +38,9 @@
public class OrcaTransitData extends TransitData
{
- private int mSerialNumber;
- private double mBalance;
- private Trip[] mTrips;
+ private int mSerialNumber;
+ private double mBalance;
+ private OrcaTrip[] mTrips;
public static boolean check (Card card)
{
@@ -57,6 +57,14 @@ public static TransitIdentity parseTransitIdentity(Card card)
}
}
+ public OrcaTransitData (Parcel parcel) {
+ mSerialNumber = parcel.readInt();
+ mBalance = parcel.readDouble();
+
+ mTrips = new OrcaTrip[parcel.readInt()];
+ parcel.readTypedArray(mTrips, OrcaTrip.CREATOR);
+ }
+
public OrcaTransitData (Card card)
{
DesfireCard desfireCard = (DesfireCard) card;
@@ -109,7 +117,7 @@ public String getSerialNumber () {
return null;
}
- private Trip[] parseTrips (DesfireCard card)
+ private OrcaTrip[] parseTrips (DesfireCard card)
{
DesfireFile file = card.getApplication(0x3010f2).getFile(0x02);
@@ -118,7 +126,7 @@ public String getSerialNumber () {
List<Trip> result = new ArrayList<Trip>();
- Trip[] useLog = new Trip[recordFile.getRecords().length];
+ OrcaTrip[] useLog = new OrcaTrip[recordFile.getRecords().length];
for (int i = 0; i < useLog.length; i++) {
useLog[i] = new OrcaTrip(recordFile.getRecords()[i]);
}
@@ -134,6 +142,14 @@ public int compare(Trip trip, Trip trip1) {
return null;
}
+ public void writeToParcel(Parcel parcel, int flags) {
+ parcel.writeInt(mSerialNumber);
+ parcel.writeDouble(mBalance);
+
+ parcel.writeInt(mTrips.length);
+ parcel.writeTypedArray(mTrips, flags);
+ }
+
public static class OrcaTrip extends Trip
{
private final long mTimestamp;
@@ -22,13 +22,18 @@
package com.codebutler.farebot.transit;
-public abstract class Refill
-{
+import android.os.Parcelable;
+
+public abstract class Refill implements Parcelable {
public abstract long getTimestamp ();
public abstract String getAgencyName ();
public abstract String getShortAgencyName ();
public abstract long getAmount ();
public abstract String getAmountString ();
+
+ public final int describeContents() {
+ return 0;
+ }
}
Oops, something went wrong.

0 comments on commit c30e4f2

Please sign in to comment.