18 |
import android.os.Handler; |
import android.os.Handler; |
19 |
import android.os.Message; |
import android.os.Message; |
20 |
|
|
21 |
|
import android.util.Log; |
22 |
import android.view.ContextMenu; |
import android.view.ContextMenu; |
23 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
24 |
import android.view.Menu; |
import android.view.Menu; |
335 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
336 |
|
|
337 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
338 |
findStationsTask.searchByName(name, locationLookup.getLocation()); |
findStationsTask.searchByName(name); |
339 |
findStationsTask.execute(); |
findStationsTask.execute(); |
340 |
|
|
341 |
} |
} |
347 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
348 |
|
|
349 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
350 |
findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); |
findStationsTask.searchByIds( favorites.toString() ); |
351 |
findStationsTask.execute(); |
findStationsTask.execute(); |
352 |
} else { |
} else { |
353 |
showMessageAndClose( getString( stationlist_nofavorites ) ); |
showMessageAndClose( getString( stationlist_nofavorites ) ); |
365 |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
366 |
findStationsTask.execute(); |
findStationsTask.execute(); |
367 |
} |
} |
|
|
|
|
|
|
|
/* TODO: Remove this no longer needed function |
|
|
String lookupAddress(double latitude, double longitude) { |
|
368 |
|
|
|
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(); |
|
|
}*/ |
|
|
|
|
369 |
|
|
370 |
//////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////// |
371 |
// Inner classes |
// Inner classes |
429 |
Location loc; |
Location loc; |
430 |
String ids; |
String ids; |
431 |
|
|
432 |
public void searchByName(String n, Location l) { |
public void searchByName(String n) { |
433 |
|
|
434 |
method = LookupMethod.ByName; |
method = LookupMethod.ByName; |
|
loc = l; |
|
435 |
name = n; |
name = n; |
436 |
} |
} |
437 |
|
|
440 |
loc = l; |
loc = l; |
441 |
} |
} |
442 |
|
|
443 |
public void searchByIds(String id, Location l) { |
public void searchByIds(String id) { |
444 |
|
|
445 |
method = LookupMethod.ByList; |
method = LookupMethod.ByList; |
|
loc = l; |
|
446 |
ids = id; |
ids = id; |
447 |
} |
} |
448 |
|
|
472 |
} |
} |
473 |
|
|
474 |
|
|
|
Location dummy = new Location("gps"); |
|
|
List<StationBean> stations = stationProvider.getStations(); |
|
|
|
|
|
for (StationBean station : stations) { |
|
|
|
|
|
if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) { |
|
|
if (loc != null) { //only do the distance calc if we have a location |
|
|
dummy.setLatitude(station.getLatitude()); |
|
|
dummy.setLongitude(station.getLongitude()); |
|
|
station.setDistance( (int)loc.distanceTo(dummy) ); |
|
|
} else { |
|
|
station.setDistance(0); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
475 |
return null; |
return null; |
476 |
} |
} |
477 |
|
|
482 |
|
|
483 |
|
|
484 |
if (success) { |
if (success) { |
485 |
if (stationProvider.getStations().size() == 0) |
if (stationProvider.getStations().size() == 0) { |
486 |
MessageBox.showMessage(StationList.this, getString(stationlist_nostations) ); // this should not be possible !?! |
showMessageAndClose(getString(stationlist_nostations)); |
487 |
|
} |
488 |
stations = stationProvider.getStations(); |
stations = stationProvider.getStations(); |
489 |
adapter.setStations( stations ); |
adapter.setStations( stations ); |
490 |
|
|
508 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
509 |
dialog.dismiss(); |
dialog.dismiss(); |
510 |
} |
} |
511 |
}); |
}); |
512 |
builder.show(); |
try { |
513 |
|
builder.show(); |
514 |
|
} catch (android.view.WindowManager.BadTokenException e) { |
515 |
|
Log.i("StationList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |
516 |
|
} |
517 |
} |
} |
518 |
} |
} |
519 |
} |
} |