--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2010/01/26 21:17:26 552 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2010/05/19 16:27:41 742 @@ -13,12 +13,14 @@ import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.ListView; import android.widget.TextView; import dk.thoerup.traininfo.provider.DepartureProvider; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.util.MessageBox; +import static dk.thoerup.traininfo.R.string.*; public class DepartureList extends ListActivity { @@ -35,9 +37,8 @@ ProgressDialog pgDialog; DepartureFetcher fetcher; - int stationId; - - double latitude,longitude; + + StationBean station; @SuppressWarnings("unchecked") @Override @@ -49,32 +50,30 @@ setListAdapter(adapter); Intent launchedBy = getIntent(); + + station = (StationBean) launchedBy.getSerializableExtra("stationbean"); - latitude = launchedBy.getDoubleExtra("latitude", 0.0); - longitude = launchedBy.getDoubleExtra("longitude", 0.0); - - String name = launchedBy.getStringExtra("name"); - ((TextView) findViewById(R.id.stationName)).setText( name ); + ((TextView) findViewById(R.id.stationName)).setText( station.getName() ); + - String address = launchedBy.getStringExtra("address"); - ((TextView) findViewById(R.id.stationAddr)).setText( address ); + ((TextView) findViewById(R.id.stationAddr)).setText( station.getAddress() ); - stationId = launchedBy.getIntExtra("stationid", -1); findViewById(R.id.header).setOnClickListener( mapLauncher ); - NumberFormat format = NumberFormat.getNumberInstance(); - format.setMaximumFractionDigits(1); - format.setMinimumFractionDigits(1); - int distance = launchedBy.getIntExtra("distance", 0); - ((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); - - boolean isRegional = launchedBy.getBooleanExtra("isregional", false); - boolean isSTrain = launchedBy.getBooleanExtra("isstrain", false); - //boolean isMetro = launchedBy.getBooleanExtra("ismetro", false); // not currently used + int distance = station.getDistance(); + if (distance != 0) { + NumberFormat format = NumberFormat.getNumberInstance(); + format.setMaximumFractionDigits(1); + format.setMinimumFractionDigits(1); + + ((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); + } else { + ((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE); + } - if (isRegional == false && isSTrain == false) { + if (station.isRegional() == false && station.isSTrain() == false) { getListView().setVisibility( View.GONE ); findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); @@ -134,7 +133,7 @@ switch (id) { case DLG_PROGRESS: ProgressDialog dlg = new ProgressDialog(this); - dlg.setMessage("Fetch departure data"); + dlg.setMessage( getString(departurelist_fetchdata) ); dlg.setCancelable(true); return dlg; default: @@ -145,7 +144,7 @@ void startDepartureFetcher() { showDialog(DLG_PROGRESS); fetcher = new DepartureFetcher(); - fetcher.execute(stationId); + fetcher.execute(station.getId()); } class DialogDismisser implements View.OnClickListener { @@ -164,8 +163,8 @@ View.OnClickListener mapLauncher = new View.OnClickListener() { @Override - public void onClick(View v) { - Uri uri = Uri.parse("geo:" + latitude + "," + longitude); + public void onClick(View v) { + Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); startActivity( new Intent(Intent.ACTION_VIEW, uri)); } }; @@ -192,19 +191,24 @@ AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); builder.setMessage("Error finding departures"); builder.setCancelable(true); - builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { + builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); startDepartureFetcher(); } }); - builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { + builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } - }); - builder.show(); + }); + + try { + builder.show(); + } catch (android.view.WindowManager.BadTokenException e) { + Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running + } } }