--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/01/28 09:16:33 564
+++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/04/20 14:17:34 652
@@ -18,6 +18,7 @@
import android.os.Handler;
import android.os.Message;
+import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -334,7 +335,7 @@
showDialog(DLG_PROGRESS);
findStationsTask = new FindStationsTask();
- findStationsTask.searchByName(name, locationLookup.getLocation());
+ findStationsTask.searchByName(name);
findStationsTask.execute();
}
@@ -346,7 +347,7 @@
showDialog(DLG_PROGRESS);
findStationsTask = new FindStationsTask();
- findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());
+ findStationsTask.searchByIds( favorites.toString() );
findStationsTask.execute();
} else {
showMessageAndClose( getString( stationlist_nofavorites ) );
@@ -364,35 +365,7 @@
findStationsTask.searchByLocation( locationLookup.getLocation() );
findStationsTask.execute();
}
-
-
- /* TODO: Remove this no longer needed function
- 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
addressList = coder.getFromLocation(latitude, longitude, 1);
- Address addr = addressList.get(0);
-
-
- int max = addr.getMaxAddressLineIndex();
- for (int i=0; i0)
- sb.append(", ");
-
- sb.append(addr.getAddressLine(i));
- }
-
-
- } catch (Exception e) {
- Log.e("DepartureList", "geocoder failed", e);
- }
-
- return sb.toString();
- }*/
-
////////////////////////////////////////////////////////////////////////////
// Inner classes
@@ -456,10 +429,9 @@
Location loc;
String ids;
- public void searchByName(String n, Location l) {
+ public void searchByName(String n) {
method = LookupMethod.ByName;
- loc = l;
name = n;
}
@@ -468,10 +440,9 @@
loc = l;
}
- public void searchByIds(String id, Location l) {
+ public void searchByIds(String id) {
method = LookupMethod.ByList;
- loc = l;
ids = id;
}
@@ -501,23 +472,6 @@
}
- Location dummy = new Location("gps");
- List 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);
- }
- }
-
- }
-
return null;
}
@@ -528,8 +482,9 @@
if (success) {
- if (stationProvider.getStations().size() == 0)
- MessageBox.showMessage(StationList.this, getString(stationlist_nostations) ); // this should not be possible !?!
+ if (stationProvider.getStations().size() == 0) {
+ showMessageAndClose(getString(stationlist_nostations));
+ }
stations = stationProvider.getStations();
adapter.setStations( stations );
@@ -541,20 +496,47 @@
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
- stationsFetched.post( new Runnable() {
- @Override
- public void run() {
- startLocatorTask();
- }
- });
+ Runnable runner = null;
+ switch (method) {
+ case ByLocation:
+ runner = new Runnable() {
+ @Override
+ public void run() {
+ startLocatorTask();
+ }
+ };
+ break;
+ case ByName:
+ runner = new Runnable() {
+ @Override
+ public void run() {
+ startNameSearch( FindStationsTask.this.name );
+ }
+ };
+ break;
+ case ByList:
+ runner = new Runnable() {
+ @Override
+ public void run() {
+ startFavoriteLookup();
+ }
+ };
+ break;
+ }
+
+ stationsFetched.post( runner );
}
});
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
- });
- builder.show();
+ });
+ try {
+ builder.show();
+ } catch (android.view.WindowManager.BadTokenException e) {
+ Log.i("StationList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
+ }
}
}
}