--- android/TrainInfo/src/dk/thoerup/traininfo/TrainInfoList.java 2009/08/09 09:09:16 239 +++ android/TrainInfo/src/dk/thoerup/traininfo/TrainInfoList.java 2009/08/09 12:12:33 243 @@ -6,6 +6,7 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -24,6 +25,7 @@ /** Called when the activity is first created. */ ProgressDialog dialog; StationLocator locator = null; + LocatorTask locatorTask = new LocatorTask(); boolean isRunning; @@ -33,6 +35,8 @@ super.onCreate(savedInstanceState); setContentView(R.layout.main); + //StationLocator.injectMockLocation(this); + adapter = new StationListAdapter(this); setListAdapter(adapter); @@ -41,6 +45,13 @@ startLookup(); } + @Override + public void onSaveInstanceState(Bundle outState) + { + if (dialog.isShowing()) + dialog.dismiss(); + } + @Override @@ -59,7 +70,6 @@ - @Override protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); @@ -70,19 +80,9 @@ } } - - - public void progressDialog() { - dialog = new ProgressDialog(this); - dialog.setMessage("Wait for location fix"); - dialog.setCancelable(false); - dialog.show(); - } - public void startLookup() { isRunning = true; showDialog(DLG_PROGRESS); - //progressDialog(); locator.locateStations(); stationsFetched.sendEmptyMessageDelayed(FIXTIMEOUT, 20000); @@ -96,6 +96,7 @@ switch (msg.what) { case GOTLOCATION: dialog.setMessage("Finding nearby stations"); + locatorTask.execute(); break; case GOTSTATIONLIST: dialog.dismiss(); @@ -103,7 +104,7 @@ break; case NOPROVIDER: dialog.dismiss(); - showMessageBox("No Location provider enabled. Plase enabled gps."); + showMessageBox("No location provider enabled. Plase enable gps."); break; case FIXTIMEOUT: dialog.dismiss(); @@ -152,4 +153,22 @@ .show(); } + + class LocatorTask extends AsyncTask { + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected Void doInBackground(Void... params) { + locator.findNearestStations(); + return null; + } + + @Override + protected void onPostExecute(Void result) { + super.onPostExecute(result); + } + } } \ No newline at end of file