/[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 713 by torben, Fri May 7 15:13:07 2010 UTC revision 983 by torben, Sun Jul 11 15:15:04 2010 UTC
# Line 4  import java.util.ArrayList; Line 4  import java.util.ArrayList;
4  import java.util.List;  import java.util.List;
5    
6    
7    import android.app.Activity;
8  import android.app.AlertDialog;  import android.app.AlertDialog;
9  import android.app.Dialog;  import android.app.Dialog;
10  import android.app.ListActivity;  import android.app.ListActivity;
# Line 47  public class StationList extends ListAct Line 48  public class StationList extends ListAct
48                    
49          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
50          public static final int OPTIONS_GPSINFO = 2004;          public static final int OPTIONS_GPSINFO = 2004;
   
           
   
51                    
52          public static final int DLG_PROGRESS = 3001;          public static final int DLG_PROGRESS = 3001;
53          public static final int DLG_STATIONNAME = 3002;          public static final int DLG_STATIONNAME = 3002;
54                    
55            
56            public static final int GPS_TIMEOUT_MS = 17500; //how long are we willing to wait for gps fix -in milliseconds
57            
58            
59          static enum LookupMethod {          static enum LookupMethod {
60                  ByLocation,                  ByLocation,
61                  ByName,                  ByName,
# Line 69  public class StationList extends ListAct Line 71  public class StationList extends ListAct
71          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();
72                    
73          GeoPair location = new GeoPair();          GeoPair location = new GeoPair();
74            
75            boolean isLaunchedforShortcut;
76          boolean isRunning = false;          boolean isRunning = false;
77          List<StationBean> stations = new ArrayList<StationBean>();          List<StationBean> stations = new ArrayList<StationBean>();
78                    
# Line 111  public class StationList extends ListAct Line 114  public class StationList extends ListAct
114                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");
115                  setTitle();                  setTitle();
116                                    
117                    isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false);
118                    
119                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
120    
121                                                    
# Line 118  public class StationList extends ListAct Line 123  public class StationList extends ListAct
123                          case ListNearest:                          case ListNearest:
124                                  startLookup();                                  startLookup();
125                                  break;                                  break;
126                          case ListSearch:                          case ListSearch:                                
127                                  this.showDialogSafe(DLG_STATIONNAME);                                  showDialog(DLG_STATIONNAME); //TODO: this.showDialogSafe(DLG_STATIONNAME);
128                                  break;                                  break;
129                          case ListFavorites:                          case ListFavorites:
130                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 135  public class StationList extends ListAct Line 140  public class StationList extends ListAct
140                  }                  }
141                                    
142          }          }
143            
144    
145            @Override
146            protected void onDestroy() {
147                    super.onDestroy();
148                    
149                    if (findStationsTask != null) {
150                            findStationsTask.cancel(true);
151                    }
152                    if (locationLookup != null) {
153                            locationLookup.stopSearch();
154                    }
155                    isRunning = false;
156            }
157    
158            
159          protected void setTitle() {          protected void setTitle() {
160                  String dialogTitle = getResources().getString(app_name);                  String dialogTitle = getResources().getString(app_name);
161                  switch (listType) {                  switch (listType) {
# Line 161  public class StationList extends ListAct Line 182  public class StationList extends ListAct
182           * - 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?
183           * - java.lang.IllegalArgumentException: View not attached to window manager           * - java.lang.IllegalArgumentException: View not attached to window manager
184           */           */
185            
186            /*
187          public void showDialogSafe(int id) {          public void showDialogSafe(int id) {
188                  try {                  try {
189                          showDialog(id);                          showDialog(id);
# Line 177  public class StationList extends ListAct Line 199  public class StationList extends ListAct
199                          Log.e("StationList", "dismissDialog failed", e);                          Log.e("StationList", "dismissDialog failed", e);
200                  }                  }
201          }          }
202            public void dismissDialogSafe(Dialog dlg) {
203                    try {
204                            dlg.dismiss();
205                    } catch (Exception e) {
206                            Log.e("StationList", "dismissDialog failed", e);
207                    }
208            }
209                    
210          public void builderShowSafe(AlertDialog.Builder builder) {          public void builderShowSafe(AlertDialog.Builder builder) {
211                  try {                  try {
# Line 185  public class StationList extends ListAct Line 214  public class StationList extends ListAct
214                          Log.e("StationList", "builder.show() failed", e);                          Log.e("StationList", "builder.show() failed", e);
215                  }                  }
216                                    
217          }          }*/
218            
219          /* EOF rude and ugly dialog hack */          /* EOF rude and ugly dialog hack */
220                    
221    
# Line 247  public class StationList extends ListAct Line 277  public class StationList extends ListAct
277                                  message.append( getString(stationlist_nolocation) );                                  message.append( getString(stationlist_nolocation) );
278                          }                                                }                      
279                                                    
280                          MessageBox.showMessage(this, message.toString());                          MessageBox.showMessage(this, message.toString(), false);
281                          break;                          break;
282                  default:                  default:
283                          retval = super.onOptionsItemSelected(item);                          retval = super.onOptionsItemSelected(item);
# Line 347  public class StationList extends ListAct Line 377  public class StationList extends ListAct
377                                                                    
378                  StationBean station = stations.get(position);                  StationBean station = stations.get(position);
379                                    
380                  Intent intent = new Intent(this, DepartureList.class);                  if (isLaunchedforShortcut == true) {
381                  intent.putExtra("stationbean", station);                          Intent i = new Intent();
382                  startActivity(intent);                          i.putExtra("station", station);
383                            setResult(Activity.RESULT_OK, i);
384                            finish();
385                    } else {                
386                            Intent intent = new Intent(this, DepartureList.class);
387                            intent.putExtra("stationbean", station);
388                            startActivity(intent);
389                    }
390          }          }
391    
392          /////////////////////////////////////////////////////////////          /////////////////////////////////////////////////////////////
# Line 358  public class StationList extends ListAct Line 395  public class StationList extends ListAct
395          public void startLookup() {          public void startLookup() {
396                  isRunning = true;                                isRunning = true;              
397                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
398                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
399                                    
400                  locationLookup.locateStations();                  locationLookup.locateStations();
401                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS);
402          }          }
403                    
404          void startNameSearch(String name) {          void startNameSearch(String name) {
405                  dialogMessage = getString( stationlist_findbyname );                  dialogMessage = getString( stationlist_findbyname );
406                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
407    
408                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
409                  findStationsTask.searchByName(name);                  findStationsTask.searchByName(name);
# Line 378  public class StationList extends ListAct Line 415  public class StationList extends ListAct
415                                    
416                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
417                          dialogMessage = getString( stationlist_loadfavorites );                          dialogMessage = getString( stationlist_loadfavorites );
418                          showDialogSafe(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
419    
420                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
421                          findStationsTask.searchByIds( favorites.toString() );                          findStationsTask.searchByIds( favorites.toString() );
# Line 393  public class StationList extends ListAct Line 430  public class StationList extends ListAct
430          void startLocatorTask()          void startLocatorTask()
431          {          {
432                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
433                  showDialogSafe(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS);
434                                    
435                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
436                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
# Line 410  public class StationList extends ListAct Line 447  public class StationList extends ListAct
447    
448                          switch (msg.what) {                          switch (msg.what) {
449                          case GOTLOCATION:                          case GOTLOCATION:
450                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
451                                                                    
452                                  startLocatorTask();                                  startLocatorTask();
453                                  location = GeoPair.fromLocation( locationLookup.getLocation() );                                  location = GeoPair.fromLocation( locationLookup.getLocation() );
# Line 418  public class StationList extends ListAct Line 455  public class StationList extends ListAct
455                                  break;                                  break;
456    
457                          case NOPROVIDER:                          case NOPROVIDER:
458                                  dismissDialogSafe(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
459                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
460                                    //StationList.this.finish();
461                                  break;                                  break;
462                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
463                                  if (isRunning) {                                  if (isRunning) {
# Line 427  public class StationList extends ListAct Line 465  public class StationList extends ListAct
465                                          if (locationLookup.hasLocation()) {                                          if (locationLookup.hasLocation()) {
466                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );
467                                          } else {                                                                                          } else {                                                
468                                                  dismissDialogSafe(DLG_PROGRESS);                                                  dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS);
469                                                                                                    
470                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
471                                                  builder.setMessage(  getString( stationlist_gpstimeout) );                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
# Line 444  public class StationList extends ListAct Line 482  public class StationList extends ListAct
482                                                                  dialog.dismiss();                                                                  dialog.dismiss();
483                                                          }                                                                                                                }                                                      
484                                                  });                                                  });
485                                                  builderShowSafe(builder); // builder.show()                                                  builder.show();//TODO:builderShowSafe(builder);
486    
487                                          }                                          }
488                                  }                                  }
# Line 512  public class StationList extends ListAct Line 550  public class StationList extends ListAct
550                  @Override                  @Override
551                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
552                          super.onPostExecute(result);                          super.onPostExecute(result);
553                          dialog.dismiss();                          dialog.dismiss();//TODO:dismissDialogSafe(dialog);
554                                                    
555                                                    
556                          if (success) {                                                    if (success) {                          
# Line 520  public class StationList extends ListAct Line 558  public class StationList extends ListAct
558                                          showMessageAndClose(getString(stationlist_nostations));                                          showMessageAndClose(getString(stationlist_nostations));
559                                  }                                  }
560                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
561    
562                                    StationList.this.getListView().invalidateViews();
563                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
564                                                                    
565                                    
566                          } else { //communication or parse errors                          } else { //communication or parse errors
567                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
568                                  builder.setMessage(getString(stationlist_nearbyerror));                                                          builder.setMessage(getString(stationlist_fetcherror));                          
569                                  builder.setCancelable(true);                                  builder.setCancelable(true);
570                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
571                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
# Line 564  public class StationList extends ListAct Line 605  public class StationList extends ListAct
605                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
606                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
607                                                  dialog.dismiss();                                                  dialog.dismiss();
608                                                    StationList.this.finish();
609                                          }                                                                                                }                                                      
610                                  });                                  });
611                                                                    
612                                  builderShowSafe(builder); // builder.show()                                  builder.show();//TODO:builderShowSafe(builder);
613                          }                          }
614                  }                  }
615          }          }

Legend:
Removed from v.713  
changed lines
  Added in v.983

  ViewVC Help
Powered by ViewVC 1.1.20