1 |
package dk.thoerup.traininfo.provider; |
package dk.thoerup.traininfo.provider; |
2 |
|
|
3 |
|
|
4 |
|
import java.net.URLEncoder; |
5 |
import java.util.ArrayList; |
import java.util.ArrayList; |
6 |
import java.util.List; |
import java.util.List; |
7 |
|
|
25 |
return stations; |
return stations; |
26 |
} |
} |
27 |
|
|
28 |
|
|
29 |
@Override |
@Override |
30 |
public boolean lookupStations(Location location) { |
public boolean lookupStations(Location location) { |
31 |
boolean success = false; |
String url = XmlUtil.SERVICE_BASE + "/LocateStations?latitude=" + (float)location.getLatitude() + "&longitude=" + (float)location.getLongitude(); |
|
String url = XmlUtil.SERVICE_BASE + "/LocateStations?latitude=" + location.getLatitude() + "&longitude=" + location.getLongitude(); |
|
32 |
Log.i("url", url); |
Log.i("url", url); |
33 |
|
return lookupStationsWorker(url); |
34 |
|
} |
35 |
|
|
36 |
|
@Override |
37 |
|
public boolean lookupStationsByName(String name) { |
38 |
|
|
39 |
|
// String url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + Uri.encode(name); |
40 |
|
String url = ""; |
41 |
|
|
42 |
|
try { |
43 |
|
url = XmlUtil.SERVICE_BASE + "/LocateStations?name=" + URLEncoder.encode(name, "ISO8859-1"); |
44 |
|
} catch (Exception e) { |
45 |
|
Log.e("lookupStations", "Encoding failed", e); |
46 |
|
} |
47 |
|
|
48 |
|
Log.i("url", url); |
49 |
|
return lookupStationsWorker(url); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
@Override |
54 |
|
public boolean lookupStationsByIds(String ids) { |
55 |
|
String url = ""; |
56 |
|
url = XmlUtil.SERVICE_BASE + "/LocateStations?list=" + ids; |
57 |
|
|
58 |
|
Log.i("url", url); |
59 |
|
return lookupStationsWorker(url); |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
public boolean lookupStationsWorker(String url) { |
64 |
|
boolean success = false; |
65 |
|
|
66 |
try { |
try { |
67 |
stations.clear(); |
stations.clear(); |
68 |
|
|
102 |
station.setLatitude( Double.parseDouble(content) ); |
station.setLatitude( Double.parseDouble(content) ); |
103 |
|
|
104 |
if (nodeName.equals("longitude")) |
if (nodeName.equals("longitude")) |
105 |
station.setLongitude( Double.parseDouble(content) ); |
station.setLongitude( Double.parseDouble(content) ); |
|
|
|
|
if (nodeName.equals("stationcode")) |
|
|
station.setCode(content); |
|
106 |
|
|
107 |
if (nodeName.equals("calcdist")) |
if (nodeName.equals("calcdist")) |
108 |
station.setDistance( (int) Double.parseDouble(content) ); |
station.setDistance( (int) Double.parseDouble(content) ); |
109 |
|
|
110 |
|
if (nodeName.equals("address")) |
111 |
|
station.setAddress( content ); |
112 |
|
|
113 |
|
if (nodeName.equals("regional")) |
114 |
|
station.setRegional( Boolean.parseBoolean(content) ); |
115 |
|
|
116 |
|
if (nodeName.equals("strain")) |
117 |
|
station.setSTrain( Boolean.parseBoolean(content) ); |
118 |
|
|
119 |
|
if (nodeName.equals("metro")) |
120 |
|
station.setMetro( Boolean.parseBoolean(content) ); |
121 |
|
|
122 |
} |
} |
123 |
stations.add(station); |
stations.add(station); |