/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/StationList.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/StationList.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 630 by torben, Wed Mar 17 15:27:11 2010 UTC revision 725 by torben, Tue May 11 05:38:18 2010 UTC
# Line 119  public class StationList extends ListAct Line 119  public class StationList extends ListAct
119                                  startLookup();                                  startLookup();
120                                  break;                                  break;
121                          case ListSearch:                          case ListSearch:
122                                  this.showDialog(DLG_STATIONNAME);                                  this.showDialogSafe(DLG_STATIONNAME);
123                                  break;                                  break;
124                          case ListFavorites:                          case ListFavorites:
125                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 152  public class StationList extends ListAct Line 152  public class StationList extends ListAct
152                  }                  }
153                    
154                  setTitle(dialogTitle);                  setTitle(dialogTitle);
155                    
156          }          }
157                    
158                    
159            /* these 3 dialogs helper functions are very rude and ugly hack
160             * to remove these auto-reported exceptions
161             * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?
162             * - java.lang.IllegalArgumentException: View not attached to window manager
163             */
164            
165            public void showDialogSafe(int id) {
166                    try {
167                            showDialog(id);
168                    } catch (Exception e) {
169                            Log.e("StationList", "showDialog failed", e);
170                    }
171            }
172            
173            public void dismissDialogSafe(int id) {
174                    try {
175                            dismissDialog(id);
176                    } catch (Exception e) {
177                            Log.e("StationList", "dismissDialog failed", e);
178                    }
179            }
180            public void dismissDialogSafe(Dialog dlg) {
181                    try {
182                            dlg.dismiss();
183                    } catch (Exception e) {
184                            Log.e("StationList", "dismissDialog failed", e);
185                    }
186            }
187            
188            public void builderShowSafe(AlertDialog.Builder builder) {
189                    try {
190                            builder.show();
191                    } catch (Exception e) {
192                            Log.e("StationList", "builder.show() failed", e);
193                    }
194                    
195            }
196            /* EOF rude and ugly dialog hack */
197            
198    
199    
200      @Override      @Override
# Line 271  public class StationList extends ListAct Line 311  public class StationList extends ListAct
311                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
312                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
313                                          dialog.dismiss();                                          dialog.dismiss();
314                                          if (et.getText().toString().length() >= 2) {                                          String search = et.getText().toString().trim();
315                                                  startNameSearch(et.getText().toString());                                          if (search.length() >= 2) {
316                                                    startNameSearch(search);
317                                          } else {                                          } else {
318                                                  showMessageAndClose( getString(stationlist_twocharmin) );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
319                                          }                                          }
# Line 324  public class StationList extends ListAct Line 365  public class StationList extends ListAct
365          public void startLookup() {          public void startLookup() {
366                  isRunning = true;                                isRunning = true;              
367                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
368                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
369                                    
370                  locationLookup.locateStations();                  locationLookup.locateStations();
371                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);
# Line 332  public class StationList extends ListAct Line 373  public class StationList extends ListAct
373                    
374          void startNameSearch(String name) {          void startNameSearch(String name) {
375                  dialogMessage = getString( stationlist_findbyname );                  dialogMessage = getString( stationlist_findbyname );
376                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
377    
378                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
379                  findStationsTask.searchByName(name);                  findStationsTask.searchByName(name);
# Line 344  public class StationList extends ListAct Line 385  public class StationList extends ListAct
385                                    
386                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
387                          dialogMessage = getString( stationlist_loadfavorites );                          dialogMessage = getString( stationlist_loadfavorites );
388                          showDialog(DLG_PROGRESS);                          showDialogSafe(DLG_PROGRESS);
389    
390                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
391                          findStationsTask.searchByIds( favorites.toString() );                          findStationsTask.searchByIds( favorites.toString() );
# Line 359  public class StationList extends ListAct Line 400  public class StationList extends ListAct
400          void startLocatorTask()          void startLocatorTask()
401          {          {
402                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
403                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
404                                    
405                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
406                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
# Line 376  public class StationList extends ListAct Line 417  public class StationList extends ListAct
417    
418                          switch (msg.what) {                          switch (msg.what) {
419                          case GOTLOCATION:                          case GOTLOCATION:
420                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
421                                                                    
422                                  startLocatorTask();                                  startLocatorTask();
423                                  location = GeoPair.fromLocation( locationLookup.getLocation() );                                  location = GeoPair.fromLocation( locationLookup.getLocation() );
# Line 384  public class StationList extends ListAct Line 425  public class StationList extends ListAct
425                                  break;                                  break;
426    
427                          case NOPROVIDER:                          case NOPROVIDER:
428                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
429                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );
430                                  break;                                  break;
431                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
# Line 393  public class StationList extends ListAct Line 434  public class StationList extends ListAct
434                                          if (locationLookup.hasLocation()) {                                          if (locationLookup.hasLocation()) {
435                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );
436                                          } else {                                                                                          } else {                                                
437                                                  dismissDialog(DLG_PROGRESS);                                                  dismissDialogSafe(DLG_PROGRESS);
438                                                                                                    
439                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
440                                                  builder.setMessage(  getString( stationlist_gpstimeout) );                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
# Line 409  public class StationList extends ListAct Line 450  public class StationList extends ListAct
450                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
451                                                                  dialog.dismiss();                                                                  dialog.dismiss();
452                                                          }                                                                                                                }                                                      
453                                                  });                                                                                                                                              });
454                                                  builder.show();                                                  builderShowSafe(builder); // builder.show()
455    
456                                          }                                          }
457                                  }                                  }
# Line 478  public class StationList extends ListAct Line 519  public class StationList extends ListAct
519                  @Override                  @Override
520                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
521                          super.onPostExecute(result);                          super.onPostExecute(result);
522                          dialog.dismiss();                          dismissDialogSafe(dialog);
523                                                    
524                                                    
525                          if (success) {                                                    if (success) {                          
# Line 496  public class StationList extends ListAct Line 537  public class StationList extends ListAct
537                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
538                                                  dialog.dismiss();                                                  dialog.dismiss();
539                                                                                                    
540                                                  stationsFetched.post( new Runnable() {                                                  Runnable runner = null;
541                                                          @Override                                                  switch (method) {
542                                                          public void run() {                                                  case ByLocation:
543                                                                  startLocatorTask();                                                                                                                      runner = new Runnable() {
544                                                          }                                                                  @Override
545                                                  });                                                                  public void run() {
546                                                                            startLocatorTask();                                                            
547                                                                    }
548                                                            };
549                                                            break;
550                                                    case ByName:
551                                                            runner = new Runnable() {
552                                                                    @Override
553                                                                    public void run() {
554                                                                            startNameSearch( FindStationsTask.this.name );
555                                                                    }
556                                                            };
557                                                            break;
558                                                    case ByList:
559                                                            runner = new Runnable() {
560                                                                    @Override
561                                                                    public void run() {
562                                                                            startFavoriteLookup();
563                                                                    }
564                                                            };
565                                                            break;
566                                                    }
567                                                    
568                                                    stationsFetched.post( runner );
569                                          }                                          }
570                                  });                                  });
571                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
572                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
573                                                  dialog.dismiss();                                                  dialog.dismiss();
574                                          }                                                                                                }                                                      
575                                  });                                                      });
576                                  try {                                  
577                                          builder.show();                                  builderShowSafe(builder); // 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  
                                 }  
578                          }                          }
579                  }                  }
580          }          }

Legend:
Removed from v.630  
changed lines
  Added in v.725

  ViewVC Help
Powered by ViewVC 1.1.20