28 |
|
|
29 |
StationBean stations = new StationBean(); |
StationBean stations = new StationBean(); |
30 |
|
|
31 |
|
boolean statsByNameSend = false; |
32 |
|
|
33 |
public boolean hasStations() { |
public boolean hasStations() { |
34 |
return (stations != null && stations.entries.size() > 0); |
return (stations != null && stations.entries.size() > 0); |
35 |
} |
} |
38 |
public boolean loadStations(Context context) throws Exception { |
public boolean loadStations(Context context) throws Exception { |
39 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
40 |
|
|
41 |
stations.entries.clear(); //TODO: remove |
StationBean tmpStations = new StationBean(); |
42 |
|
|
43 |
File parent = context.getFilesDir(); |
File parent = context.getFilesDir(); |
44 |
File stationsFile = new File(parent, "stations.bin"); |
File stationsFile = new File(parent, "stations.bin"); |
64 |
for (int i=0; i<length; i++) { |
for (int i=0; i<length; i++) { |
65 |
StationEntry entry = (StationEntry) in.readObject(); |
StationEntry entry = (StationEntry) in.readObject(); |
66 |
updateSearchStrings(entry); |
updateSearchStrings(entry); |
67 |
stations.entries.add( entry ); |
tmpStations.entries.add( entry ); |
68 |
} |
} |
69 |
|
|
70 |
in.close(); |
in.close(); |
71 |
|
|
72 |
|
stations = tmpStations; // når indlæsningen er ok skifter vi over |
73 |
|
|
74 |
Log.e("OFFLINE", "loaded" + stations.entries.size()); |
Log.e("OFFLINE", "loaded" + tmpStations.entries.size()); |
75 |
logElapsedTime(start, "loadStations"); |
logElapsedTime(start, "loadStations"); |
76 |
|
|
77 |
return true; |
return true; |
86 |
File parent = context.getFilesDir(); |
File parent = context.getFilesDir(); |
87 |
File stationsFile = new File(parent, "stations.bin"); |
File stationsFile = new File(parent, "stations.bin"); |
88 |
|
|
89 |
|
long start = System.currentTimeMillis(); |
90 |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
byte data[] = HttpUtil.getContent(XmlUtil.SERVICE_BASE + "/LocateStations?dump=1", 5000); |
91 |
Serializer serializer = new Persister(); |
logElapsedTime(start, "download XML"); |
92 |
|
|
93 |
|
|
94 |
|
Serializer serializer = new Persister(); |
95 |
|
|
96 |
|
start = System.currentTimeMillis(); |
97 |
StationBean tmpStations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
StationBean tmpStations = serializer.read(StationBean.class, new String(data, "ISO-8859-1") ); |
98 |
|
logElapsedTime(start, "parse XML"); |
99 |
|
|
100 |
|
|
101 |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(stationsFile) ); |
181 |
|
|
182 |
@Override |
@Override |
183 |
public StationBean lookupStationsByName(String name) { |
public StationBean lookupStationsByName(String name) { |
184 |
|
|
185 |
|
statsByName(name); |
186 |
|
|
187 |
long start = System.currentTimeMillis(); |
long start = System.currentTimeMillis(); |
188 |
|
|
225 |
} |
} |
226 |
|
|
227 |
private void statsByName(String name) { |
private void statsByName(String name) { |
228 |
|
if (statsByNameSend == true) { |
229 |
|
return; |
230 |
|
} |
231 |
|
statsByNameSend = true; |
232 |
|
|
233 |
try { |
try { |
234 |
name = URLEncoder.encode(name, "ISO8859-1"); |
name = URLEncoder.encode(name, "ISO8859-1"); |