--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2010/01/27 10:04:28 557 +++ 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 { @@ -59,13 +61,16 @@ findViewById(R.id.header).setOnClickListener( mapLauncher ); - NumberFormat format = NumberFormat.getNumberInstance(); - format.setMaximumFractionDigits(1); - format.setMinimumFractionDigits(1); - - int distance = station.getDistance(); - ((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); + 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 (station.isRegional() == false && station.isSTrain() == false) { @@ -128,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: @@ -186,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 + } } }