2 |
|
|
3 |
import java.util.ArrayList; |
import java.util.ArrayList; |
4 |
import java.util.List; |
import java.util.List; |
5 |
|
import java.util.Locale; |
6 |
|
|
7 |
import android.app.Dialog; |
import android.app.Dialog; |
8 |
import android.app.ListActivity; |
import android.app.ListActivity; |
9 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
10 |
import android.content.Intent; |
import android.content.Intent; |
11 |
|
import android.location.Address; |
12 |
|
import android.location.Geocoder; |
13 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
14 |
import android.os.Bundle; |
import android.os.Bundle; |
15 |
import android.os.Handler; |
import android.os.Handler; |
16 |
import android.os.Message; |
import android.os.Message; |
17 |
|
import android.util.Log; |
18 |
import android.view.View; |
import android.view.View; |
19 |
import android.widget.ListView; |
import android.widget.ListView; |
20 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
149 |
@Override |
@Override |
150 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
151 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
152 |
|
|
|
|
|
153 |
StationBean station = stations.get(position); |
StationBean station = stations.get(position); |
154 |
|
|
155 |
|
double latitude = station.getLatitude(); |
156 |
|
double longitude = station.getLongitude(); |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
Intent intent = new Intent(this, DepartureList.class); |
Intent intent = new Intent(this, DepartureList.class); |
161 |
intent.putExtra("name", station.getName()); |
intent.putExtra("name", station.getName()); |
|
intent.putExtra("address", station.getAddress()); |
|
162 |
intent.putExtra("distance", station.getDistance()); |
intent.putExtra("distance", station.getDistance()); |
163 |
intent.putExtra("latitude", station.getLatitude()); |
intent.putExtra("latitude", latitude); |
164 |
intent.putExtra("longitude", station.getLongitude()); |
intent.putExtra("longitude", longitude); |
165 |
|
intent.putExtra("stationid", station.getId()); |
166 |
|
intent.putExtra("address", station.getAddress()); |
167 |
startActivity(intent); |
startActivity(intent); |
168 |
} |
} |
169 |
|
|
170 |
|
String lookupAddress(double latitude, double longitude) { |
171 |
|
|
172 |
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
173 |
|
StringBuilder sb = new StringBuilder(); |
174 |
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
175 |
|
try { |
176 |
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
177 |
|
Address addr = addressList.get(0); |
178 |
|
|
179 |
|
|
180 |
|
int max = addr.getMaxAddressLineIndex(); |
181 |
|
for (int i=0; i<max; i++) { |
182 |
|
if (i>0) |
183 |
|
sb.append(", "); |
184 |
|
|
185 |
|
sb.append(addr.getAddressLine(i)); |
186 |
|
} |
187 |
|
|
188 |
|
|
189 |
|
} catch (Exception e) { |
190 |
|
Log.e("DepartureList", "geocoder failed", e); |
191 |
|
} |
192 |
|
|
193 |
|
return sb.toString(); |
194 |
|
} |
195 |
|
|
196 |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
197 |
@Override |
@Override |
204 |
protected Void doInBackground(Void... params) { |
protected Void doInBackground(Void... params) { |
205 |
locator.findNearestStations(); |
locator.findNearestStations(); |
206 |
|
|
207 |
|
List<StationBean> stations = locator.getStations(); |
208 |
|
for (StationBean station : stations) { |
209 |
|
String addr = lookupAddress(station.getLatitude(), station.getLongitude()); |
210 |
|
station.setAddress(addr); |
211 |
|
} |
212 |
|
|
213 |
return null; |
return null; |
214 |
} |
} |
215 |
|
|