--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/07/11 15:29:13 984 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/08/31 08:49:15 1025 @@ -52,7 +52,7 @@ public static final int DLG_STATIONNAME = 3002; - public static final int GPS_TIMEOUT_MS = 17500; //how long are we willing to wait for gps fix -in milliseconds + public static final int GPS_TIMEOUT_MS = 15000; //how long are we willing to wait for gps fix -in milliseconds static enum LookupMethod { @@ -123,7 +123,7 @@ startLookup(); break; case ListSearch: - showDialog(DLG_STATIONNAME); //TODO: this.showDialogSafe(DLG_STATIONNAME); + showDialog(DLG_STATIONNAME); break; case ListFavorites: startFavoriteLookup(); @@ -145,13 +145,14 @@ protected void onDestroy() { super.onDestroy(); - if (findStationsTask != null) { - findStationsTask.cancel(true); - } + isRunning = false; + if (locationLookup != null) { locationLookup.stopSearch(); } - isRunning = false; + if (findStationsTask != null) { + findStationsTask.cancel(true); + } } @@ -175,49 +176,7 @@ } - - /* 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 dismissDialogSafe(Dialog dlg) { - try { - dlg.dismiss(); - } 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 */ - - @Override public void onSaveInstanceState(Bundle outState) @@ -394,7 +353,7 @@ public void startLookup() { isRunning = true; dialogMessage = getString( stationlist_waitforlocation ); - showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); + showDialog(DLG_PROGRESS); locationLookup.locateStations(); stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS); @@ -402,7 +361,7 @@ void startNameSearch(String name) { dialogMessage = getString( stationlist_findbyname ); - showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); + showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); findStationsTask.searchByName(name); @@ -414,7 +373,7 @@ if (favorites.size() > 0) { dialogMessage = getString( stationlist_loadfavorites ); - showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); + showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); findStationsTask.searchByIds( favorites.toString() ); @@ -429,7 +388,7 @@ void startLocatorTask() { dialogMessage = getString( stationlist_findingnearby ); - showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); + showDialog(DLG_PROGRESS); findStationsTask = new FindStationsTask(); findStationsTask.searchByLocation( locationLookup.getLocation() ); @@ -446,7 +405,7 @@ switch (msg.what) { case GOTLOCATION: - dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); + dismissDialog(DLG_PROGRESS); startLocatorTask(); location = GeoPair.fromLocation( locationLookup.getLocation() ); @@ -454,7 +413,7 @@ break; case NOPROVIDER: - dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); + dismissDialog(DLG_PROGRESS); MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); //StationList.this.finish(); break; @@ -464,7 +423,7 @@ if (locationLookup.hasLocation()) { stationsFetched.sendEmptyMessage( GOTLOCATION ); } else { - dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); + dismissDialog(DLG_PROGRESS); AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); builder.setMessage( getString( stationlist_gpstimeout) ); @@ -481,7 +440,7 @@ dialog.dismiss(); } }); - builder.show();//TODO:builderShowSafe(builder); + builder.show(); } } @@ -495,7 +454,6 @@ class FindStationsTask extends AsyncTask { LookupMethod method = LookupMethod.MethodNone; - boolean success; String name; Location loc; String ids; @@ -530,16 +488,16 @@ switch (method) { case ByLocation: - success = stationProvider.lookupStations(loc); + stations = stationProvider.lookupStations(loc); break; case ByName: - success = stationProvider.lookupStationsByName(name); + stations = stationProvider.lookupStationsByName(name); break; case ByList: - success = stationProvider.lookupStationsByIds(ids); + stations = stationProvider.lookupStationsByIds(ids); break; default: - success = false; // not possible + stations = null; // not possible } @@ -549,14 +507,13 @@ @Override protected void onPostExecute(Void result) { super.onPostExecute(result); - dialog.dismiss();//TODO:dismissDialogSafe(dialog); + dialog.dismiss(); - if (success) { - if (stationProvider.getStations().size() == 0) { + if (stations != null) { + if (stations.size() == 0) { showMessageAndClose(getString(stationlist_nostations)); } - stations = stationProvider.getStations(); StationList.this.getListView().invalidateViews(); adapter.setStations( stations ); @@ -608,7 +565,7 @@ } }); - builder.show();//TODO:builderShowSafe(builder); + builder.show(); } } }