--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/01/28 10:34:50 566 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/05/03 13:41:04 701 @@ -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; @@ -118,7 +119,7 @@ startLookup(); break; case ListSearch: - this.showDialog(DLG_STATIONNAME); + this.showDialogSafe(DLG_STATIONNAME); break; case ListFavorites: startFavoriteLookup(); @@ -151,8 +152,41 @@ } setTitle(dialogTitle); + + } + + + /* these 3 dialogs helper functions are very rude and ugly hack + * to remove these auto-reported exceptions + * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running? + * - java.lang.IllegalArgumentException: View not attached to window manager + */ + + public void showDialogSafe(int id) { + try { + showDialog(id); + } catch (Exception e) { + Log.e("StationList", "showDialog failed", e); + } } + public void dismissDialogSafe(int id) { + try { + dismissDialog(id); + } catch (Exception e) { + Log.e("StationList", "dismissDialog failed", e); + } + } + + public void builderShowSafe(AlertDialog.Builder builder) { + try { + builder.show(); + } catch (Exception e) { + Log.e("StationList", "builder.show() failed", e); + } + + } + /* EOF rude and ugly dialog hack */ @@ -323,7 +357,7 @@ public void startLookup() { isRunning = true; dialogMessage = getString( stationlist_waitforlocation ); - showDialog(DLG_PROGRESS); + showDialogSafe(DLG_PROGRESS); locationLookup.locateStations(); stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); @@ -331,10 +365,10 @@ void startNameSearch(String name) { dialogMessage = getString( stationlist_findbyname ); - showDialog(DLG_PROGRESS); + showDialogSafe(DLG_PROGRESS); findStationsTask = new FindStationsTask(); - findStationsTask.searchByName(name, locationLookup.getLocation()); + findStationsTask.searchByName(name); findStationsTask.execute(); } @@ -343,10 +377,10 @@ if (favorites.size() > 0) { dialogMessage = getString( stationlist_loadfavorites ); - showDialog(DLG_PROGRESS); + showDialogSafe(DLG_PROGRESS); findStationsTask = new FindStationsTask(); - findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); + findStationsTask.searchByIds( favorites.toString() ); findStationsTask.execute(); } else { showMessageAndClose( getString( stationlist_nofavorites ) ); @@ -358,41 +392,13 @@ void startLocatorTask() { dialogMessage = getString( stationlist_findingnearby ); - showDialog(DLG_PROGRESS); + showDialogSafe(DLG_PROGRESS); findStationsTask = new FindStationsTask(); 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; i