--- android/TrainInfo/src/dk/thoerup/traininfo/TrainInfoList.java 2009/08/08 19:02:20 237 +++ android/TrainInfo/src/dk/thoerup/traininfo/TrainInfoList.java 2009/08/09 11:21:30 241 @@ -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); @@ -59,7 +63,6 @@ - @Override protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); @@ -70,19 +73,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 +89,7 @@ switch (msg.what) { case GOTLOCATION: dialog.setMessage("Finding nearby stations"); + locatorTask.execute(); break; case GOTSTATIONLIST: dialog.dismiss(); @@ -135,6 +129,8 @@ intent.putExtra("name", station.getName()); intent.putExtra("address", station.getAddress()); intent.putExtra("distance", station.getDistance()); + intent.putExtra("latitude", station.getLatitude()); + intent.putExtra("longitude", station.getLongitude()); startActivity(intent); } @@ -150,4 +146,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