56 |
|
|
57 |
String name = launchedBy.getStringExtra("name"); |
String name = launchedBy.getStringExtra("name"); |
58 |
((TextView) findViewById(R.id.stationName)).setText( name ); |
((TextView) findViewById(R.id.stationName)).setText( name ); |
59 |
|
|
60 |
((TextView) findViewById(R.id.stationAddr)).setText( "searching..." ); |
String address = launchedBy.getStringExtra("address"); |
61 |
|
((TextView) findViewById(R.id.stationAddr)).setText( address ); |
62 |
|
|
63 |
int stationId = launchedBy.getIntExtra("stationid", -1); |
int stationId = launchedBy.getIntExtra("stationid", -1); |
64 |
|
|
157 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
158 |
} |
} |
159 |
} |
} |
|
|
|
|
String lookupAddress(double latitude, double longitude) { |
|
|
|
|
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
|
|
StringBuilder sb = new StringBuilder(); |
|
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
|
|
try { |
|
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
|
|
Address addr = addressList.get(0); |
|
|
|
|
|
|
|
|
int max = addr.getMaxAddressLineIndex(); |
|
|
for (int i=0; i<max; i++) { |
|
|
if (i>0) |
|
|
sb.append(", "); |
|
|
|
|
|
sb.append(addr.getAddressLine(i)); |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
Log.e("DepartureList", "geocoder failed", e); |
|
|
} |
|
|
|
|
|
return sb.toString(); |
|
|
} |
|
160 |
|
|
161 |
class DialogDismisser implements View.OnClickListener { |
class DialogDismisser implements View.OnClickListener { |
162 |
|
|
183 |
|
|
184 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
185 |
|
|
186 |
|
boolean success; |
187 |
String addr; |
String addr; |
188 |
@Override |
@Override |
189 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
192 |
adapter.setDepartures(departures); |
adapter.setDepartures(departures); |
193 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
194 |
|
|
195 |
|
if (success) { |
196 |
((TextView) findViewById(R.id.stationAddr)).setText( addr ); |
if (departures.size() == 0) { |
197 |
|
MessageBox.showMessage(DepartureList.this, "No departures found"); |
198 |
if (departures.size() == 0) |
} |
199 |
MessageBox.showMessage(DepartureList.this, "No departures found"); |
} else { // communication or parse error |
200 |
|
MessageBox.showMessage(DepartureList.this, "Error finding departures"); |
201 |
|
} |
202 |
} |
} |
203 |
|
|
204 |
@Override |
@Override |
205 |
protected Void doInBackground(Integer... params) { |
protected Void doInBackground(Integer... params) { |
206 |
addr = lookupAddress( latitude , longitude); |
success = provider.lookupDepartures(params[0]); |
207 |
provider.lookupDepartures(params[0]); |
departures = provider.getDepartures(params[0]); |
|
departures = provider.getDepartures(); |
|
208 |
return null; |
return null; |
209 |
} |
} |
210 |
|
|