/[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 906 by torben, Fri Jun 25 23:59:58 2010 UTC revision 984 by torben, Sun Jul 11 15:29:13 2010 UTC
# Line 19  import android.os.Bundle; Line 19  import android.os.Bundle;
19  import android.os.Handler;  import android.os.Handler;
20  import android.os.Message;  import android.os.Message;
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;
# Line 48  public class StationList extends ListAct Line 47  public class StationList extends ListAct
47                    
48          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
49          public static final int OPTIONS_GPSINFO = 2004;          public static final int OPTIONS_GPSINFO = 2004;
   
           
   
50                    
51          public static final int DLG_PROGRESS = 3001;          public static final int DLG_PROGRESS = 3001;
52          public static final int DLG_STATIONNAME = 3002;          public static final int DLG_STATIONNAME = 3002;
53                    
54            
55            public static final int GPS_TIMEOUT_MS = 17500; //how long are we willing to wait for gps fix -in milliseconds
56            
57            
58          static enum LookupMethod {          static enum LookupMethod {
59                  ByLocation,                  ByLocation,
60                  ByName,                  ByName,
# Line 122  public class StationList extends ListAct Line 122  public class StationList extends ListAct
122                          case ListNearest:                          case ListNearest:
123                                  startLookup();                                  startLookup();
124                                  break;                                  break;
125                          case ListSearch:                          case ListSearch:                                
126                                  this.showDialogSafe(DLG_STATIONNAME);                                  showDialog(DLG_STATIONNAME); //TODO: this.showDialogSafe(DLG_STATIONNAME);
127                                  break;                                  break;
128                          case ListFavorites:                          case ListFavorites:
129                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 139  public class StationList extends ListAct Line 139  public class StationList extends ListAct
139                  }                  }
140                                    
141          }          }
142            
143    
144            @Override
145            protected void onDestroy() {
146                    super.onDestroy();
147                    
148                    if (findStationsTask != null) {
149                            findStationsTask.cancel(true);
150                    }
151                    if (locationLookup != null) {
152                            locationLookup.stopSearch();
153                    }
154                    isRunning = false;
155            }
156    
157            
158          protected void setTitle() {          protected void setTitle() {
159                  String dialogTitle = getResources().getString(app_name);                  String dialogTitle = getResources().getString(app_name);
160                  switch (listType) {                  switch (listType) {
# Line 165  public class StationList extends ListAct Line 181  public class StationList extends ListAct
181           * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?           * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?
182           * - java.lang.IllegalArgumentException: View not attached to window manager           * - java.lang.IllegalArgumentException: View not attached to window manager
183           */           */
184            
185            /*
186          public void showDialogSafe(int id) {          public void showDialogSafe(int id) {
187                  try {                  try {
188                          showDialog(id);                          showDialog(id);
# Line 196  public class StationList extends ListAct Line 213  public class StationList extends ListAct
213                          Log.e("StationList", "builder.show() failed", e);                          Log.e("StationList", "builder.show() failed", e);
214                  }                  }
215                                    
216          }          }*/
217            
218          /* EOF rude and ugly dialog hack */          /* EOF rude and ugly dialog hack */
219                    
220    
# Line 376  public class StationList extends ListAct Line 394  public class StationList extends ListAct
394          public void startLookup() {          public void startLookup() {
395                  isRunning = true;                                isRunning = true;              
396                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
397                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
398                                    
399                  locationLookup.locateStations();                  locationLookup.locateStations();
400                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS);
401          }          }
402                    
403          void startNameSearch(String name) {          void startNameSearch(String name) {
404                  dialogMessage = getString( stationlist_findbyname );                  dialogMessage = getString( stationlist_findbyname );
405                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
406    
407                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
408                  findStationsTask.searchByName(name);                  findStationsTask.searchByName(name);
# Line 396  public class StationList extends ListAct Line 414  public class StationList extends ListAct
414                                    
415                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
416                          dialogMessage = getString( stationlist_loadfavorites );                          dialogMessage = getString( stationlist_loadfavorites );
417                          showDialogSafe(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
418    
419                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
420                          findStationsTask.searchByIds( favorites.toString() );                          findStationsTask.searchByIds( favorites.toString() );
# Line 411  public class StationList extends ListAct Line 429  public class StationList extends ListAct
429          void startLocatorTask()          void startLocatorTask()
430          {          {
431                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
432                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
433                                    
434                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
435                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
# Line 428  public class StationList extends ListAct Line 446  public class StationList extends ListAct
446    
447                          switch (msg.what) {                          switch (msg.what) {
448                          case GOTLOCATION:                          case GOTLOCATION:
449                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
450                                                                    
451                                  startLocatorTask();                                  startLocatorTask();
452                                  location = GeoPair.fromLocation( locationLookup.getLocation() );                                  location = GeoPair.fromLocation( locationLookup.getLocation() );
# Line 436  public class StationList extends ListAct Line 454  public class StationList extends ListAct
454                                  break;                                  break;
455    
456                          case NOPROVIDER:                          case NOPROVIDER:
457                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
458                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
459                                  //StationList.this.finish();                                  //StationList.this.finish();
460                                  break;                                  break;
# Line 446  public class StationList extends ListAct Line 464  public class StationList extends ListAct
464                                          if (locationLookup.hasLocation()) {                                          if (locationLookup.hasLocation()) {
465                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );
466                                          } else {                                                                                          } else {                                                
467                                                  dismissDialogSafe(DLG_PROGRESS);                                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
468                                                                                                    
469                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
470                                                  builder.setMessage(  getString( stationlist_gpstimeout) );                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
# Line 463  public class StationList extends ListAct Line 481  public class StationList extends ListAct
481                                                                  dialog.dismiss();                                                                  dialog.dismiss();
482                                                          }                                                                                                                }                                                      
483                                                  });                                                  });
484                                                  builderShowSafe(builder); // builder.show()                                                  builder.show();//TODO:builderShowSafe(builder);
485    
486                                          }                                          }
487                                  }                                  }
# Line 531  public class StationList extends ListAct Line 549  public class StationList extends ListAct
549                  @Override                  @Override
550                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
551                          super.onPostExecute(result);                          super.onPostExecute(result);
552                          dismissDialogSafe(dialog);                          dialog.dismiss();//TODO:dismissDialogSafe(dialog);
553                                                    
554                                                    
555                          if (success) {                                                    if (success) {                          
# Line 539  public class StationList extends ListAct Line 557  public class StationList extends ListAct
557                                          showMessageAndClose(getString(stationlist_nostations));                                          showMessageAndClose(getString(stationlist_nostations));
558                                  }                                  }
559                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
560    
561                                    StationList.this.getListView().invalidateViews();
562                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
563                                                                    
564                                    
565                          } else { //communication or parse errors                          } else { //communication or parse errors
566                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
567                                  builder.setMessage(getString(stationlist_fetcherror));                                                            builder.setMessage(getString(stationlist_fetcherror));                          
# Line 587  public class StationList extends ListAct Line 608  public class StationList extends ListAct
608                                          }                                                                                                }                                                      
609                                  });                                  });
610                                                                    
611                                  builderShowSafe(builder); // builder.show()                                  builder.show();//TODO:builderShowSafe(builder);
612                          }                          }
613                  }                  }
614          }          }

Legend:
Removed from v.906  
changed lines
  Added in v.984

  ViewVC Help
Powered by ViewVC 1.1.20