/[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 1142 by torben, Tue Sep 28 14:58:45 2010 UTC revision 1143 by torben, Tue Sep 28 15:30:13 2010 UTC
# Line 70  import dk.thoerup.traininfo.util.IntSet; Line 70  import dk.thoerup.traininfo.util.IntSet;
70  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
71    
72  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
73          public enum LookupStates {  
                 GOTLOCATION,  
                 GOTSTATIONLIST,  
                 NOPROVIDER,  
                 LOCATIONFIXTIMEOUT,  
                 GPS_SAT_COUNT  
         }  
74                    
75                    
76          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
# Line 103  public class StationList extends ListAct Line 97  public class StationList extends ListAct
97          FindStationsTask findStationsTask;          FindStationsTask findStationsTask;
98          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();
99                    
100          GeoPair location = new GeoPair();          //GeoPair location = new GeoPair();
101    
102          boolean isLaunchedforShortcut;          boolean isLaunchedforShortcut;
103          boolean isRunning = false;  
104          StationBean stations = new StationBean();          StationBean stations = new StationBean();
105                    
106          StationProvider stationProvider = ProviderFactory.getStationProvider();          StationProvider stationProvider = ProviderFactory.getStationProvider();
# Line 118  public class StationList extends ListAct Line 112  public class StationList extends ListAct
112    
113          WelcomeScreen.ListType listType;          WelcomeScreen.ListType listType;
114          SharedPreferences prefs;          SharedPreferences prefs;
115                                    
116          ///////////////////////////////////////////////////////////////////////////////////////////          ///////////////////////////////////////////////////////////////////////////////////////////
117          //Activity call backs          //Activity call backs
118                    
# Line 135  public class StationList extends ListAct Line 129  public class StationList extends ListAct
129                  ListView lv = getListView();                  ListView lv = getListView();
130                  lv.setOnCreateContextMenuListener(contextMenu);                  lv.setOnCreateContextMenuListener(contextMenu);
131                                    
132                  locationLookup = new LocationLookup(this, stationsFetched);                  locationLookup = new LocationLookup(this);
133                                    
134    
135                  prefs = getSharedPreferences("TrainStation", 0);                  prefs = getSharedPreferences("TrainStation", 0);
# Line 171  public class StationList extends ListAct Line 165  public class StationList extends ListAct
165                  } else {                  } else {
166                          stations = (StationBean) savedInstanceState.getSerializable("stations");                          stations = (StationBean) savedInstanceState.getSerializable("stations");
167                          adapter.setStations(stations);                          adapter.setStations(stations);
                         location = (GeoPair) savedInstanceState.getSerializable("location");  
168                  }                  }
169                                    
170          }          }
# Line 185  public class StationList extends ListAct Line 178  public class StationList extends ListAct
178          protected void onDestroy() {          protected void onDestroy() {
179                  super.onDestroy();                  super.onDestroy();
180                                    
                 isRunning = false;  
181                                    
182                  if (locationLookup != null) {                  if (locationLookup != null) {
183                          locationLookup.stopSearch();                          locationLookup.stopSearch();
# Line 224  public class StationList extends ListAct Line 216  public class StationList extends ListAct
216          if (dialog != null && dialog.isShowing())          if (dialog != null && dialog.isShowing())
217                  dialog.dismiss();                  dialog.dismiss();
218          outState.putSerializable("stations", (StationBean) stations);          outState.putSerializable("stations", (StationBean) stations);
         outState.putSerializable("location", location);  
219                    
220      }      }
221                    
# Line 391  public class StationList extends ListAct Line 382  public class StationList extends ListAct
382          //          //
383    
384          public void startLookup() {          public void startLookup() {
                 isRunning = true;                
385                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
386                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
387                                    
388                  locationLookup.locateStations();                  locationLookup.locateStations();
389                  stationsFetched.sendEmptyMessageDelayed(LookupStates.LOCATIONFIXTIMEOUT.ordinal(), GPS_TIMEOUT_MS);                  stationsFetched.sendEmptyMessageDelayed(0, 500);
390          }          }
391                    
392          void startNameSearch(String name) {          void startNameSearch(String name) {
# Line 428  public class StationList extends ListAct Line 418  public class StationList extends ListAct
418          void startLocatorTask()          void startLocatorTask()
419          {          {
420                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
421                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);              
422                                    
423                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
424                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
# Line 443  public class StationList extends ListAct Line 433  public class StationList extends ListAct
433                  @Override                  @Override
434                  public void handleMessage(Message msg) {                  public void handleMessage(Message msg) {
435                          Log.e("Handler", "WHAT:" + msg.what);                          Log.e("Handler", "WHAT:" + msg.what);
436                            
437                          LookupStates state = LookupStates.values()[msg.what];                          LocationLookup.LookupStates state = locationLookup.getState();
438    
439    
440                          switch (state) {                          switch (state) {
441                          case GOTLOCATION:                          case GOTLOCATION:
442                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
443                                    
444                                  startLocatorTask();                                  startLocatorTask();
445                                  location = GeoPair.fromLocation( locationLookup.getLocation() );  
446                                                                    return;
                                 break;  
447    
448                          case NOPROVIDER:                          case NOPROVIDER:
449                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
450                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
451                                  //StationList.this.finish();                                  //StationList.this.finish();
452                                  break;                                  return;
453                          case GPS_SAT_COUNT:                          }
454                                  int count = msg.arg1;  
455                                  String dialogMessage = getString( stationlist_waitforlocation ) + "\n" + getString( stationlist_satellitecount ) + ": " + count;  
456                                  dialog.setMessage( dialogMessage );  
457                                  return; //abort immediately                          if (locationLookup.elapsedTime() >=  GPS_TIMEOUT_MS) {
458                          case LOCATIONFIXTIMEOUT:                                                                  dismissDialog(DLG_PROGRESS);
459                                  if (isRunning) {  
460                                          locationLookup.stopSearch();                                  locationLookup.stopSearch();
461                                          if (locationLookup.hasLocation()) {  
462                                                  stationsFetched.sendEmptyMessage(  LookupStates.GOTLOCATION.ordinal() );                                  if (locationLookup.hasLocation()) {
463                                          } else {                                                                                          startLocatorTask();
464                                                  dismissDialog(DLG_PROGRESS);                                  } else {                                                
465                                                                                            AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
466                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                          builder.setMessage(  getString( stationlist_gpstimeout) );
467                                                  builder.setMessage(  getString( stationlist_gpstimeout) );                                          builder.setCancelable(true);
468                                                  builder.setCancelable(true);                                          builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
469                                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                                  public void onClick(DialogInterface dialog, int id) {
470                                                          public void onClick(DialogInterface dialog, int id) {                                                          dialog.dismiss();
471                                                                  dialog.dismiss();                                                          startLookup();
472                                                                  startLookup();  
473                                                                                                                    }
474                                                          }                                          });
475                                                  });                                          builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
476                                                  builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {                                                  public void onClick(DialogInterface dialog, int id) {
477                                                          public void onClick(DialogInterface dialog, int id) {                                                          dialog.dismiss();
478                                                                  dialog.dismiss();                                                  }                                                      
479                                                          }                                                                                                });
480                                                  });                                          builder.show();
                                                 builder.show();  
481    
                                         }  
482                                  }                                  }
483                                  break;                          } else {
484                                    if (locationLookup.hasGps()) {
485                                            int count = locationLookup.getSatCount();
486                                            String dialogMessage = getString( stationlist_waitforlocation ) + "\n" + getString( stationlist_satellitecount ) + ": " + count;
487                                            dialog.setMessage( dialogMessage );
488                                    }
489                                    this.sendEmptyMessageDelayed(0, 500);
490                          }                          }
491                          isRunning = false;                          
492                  }                  }
493          };          }
494    
495    
496    
497                    
498          class FindStationsTask extends AsyncTask<Void,Void,Void> {          class FindStationsTask extends AsyncTask<Void,Void,Void> {

Legend:
Removed from v.1142  
changed lines
  Added in v.1143

  ViewVC Help
Powered by ViewVC 1.1.20