/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/provider/OfflineStationProvider.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/provider/OfflineStationProvider.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1628 by torben, Fri Nov 25 10:50:44 2011 UTC revision 1792 by torben, Wed Apr 11 10:43:06 2012 UTC
# Line 28  public class OfflineStationProvider impl Line 28  public class OfflineStationProvider impl
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          }          }
# Line 84  public class OfflineStationProvider impl Line 86  public class OfflineStationProvider impl
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) );
# Line 173  public class OfflineStationProvider impl Line 181  public class OfflineStationProvider impl
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                                    
# Line 182  public class OfflineStationProvider impl Line 192  public class OfflineStationProvider impl
192                          if (entry.nameLower.startsWith(name) || entry.nameInternational.startsWith(name) ) {                          if (entry.nameLower.startsWith(name) || entry.nameInternational.startsWith(name) ) {
193                                  tmpStations.entries.add(entry);                                  tmpStations.entries.add(entry);
194                          }                          }
195                            
196                            for(String alias : entry.getAliases()) {
197                                    if (alias.startsWith(name)) {
198                                            tmpStations.entries.add(entry);
199                                    }
200                            }
201                  }                  }
202                  logElapsedTime(start, "name");                                            logElapsedTime(start, "name");                          
203                  return tmpStations;                  return tmpStations;
# Line 215  public class OfflineStationProvider impl Line 231  public class OfflineStationProvider impl
231          }          }
232                    
233          private void statsByName(String name) {          private void statsByName(String name) {
234                    if (statsByNameSend == true) {
235                            return;
236                    }
237                    statsByNameSend = true;
238                                    
239                  try {                  try {
240                          name = URLEncoder.encode(name, "ISO8859-1");                              name = URLEncoder.encode(name, "ISO8859-1");    

Legend:
Removed from v.1628  
changed lines
  Added in v.1792

  ViewVC Help
Powered by ViewVC 1.1.20