--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/05/07 15:13:07 713 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/06/13 14:52:49 844 @@ -4,6 +4,7 @@ import java.util.List; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ListActivity; @@ -69,7 +70,8 @@ StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); GeoPair location = new GeoPair(); - + + boolean isLaunchedforShortcut; boolean isRunning = false; List stations = new ArrayList(); @@ -111,6 +113,8 @@ listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); setTitle(); + isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false); + if (savedInstanceState == null) { @@ -177,6 +181,13 @@ Log.e("StationList", "dismissDialog failed", e); } } + public void dismissDialogSafe(Dialog dlg) { + try { + dlg.dismiss(); + } catch (Exception e) { + Log.e("StationList", "dismissDialog failed", e); + } + } public void builderShowSafe(AlertDialog.Builder builder) { try { @@ -347,9 +358,16 @@ StationBean station = stations.get(position); - Intent intent = new Intent(this, DepartureList.class); - intent.putExtra("stationbean", station); - startActivity(intent); + if (isLaunchedforShortcut == true) { + Intent i = new Intent(); + i.putExtra("station", station); + setResult(Activity.RESULT_OK, i); + finish(); + } else { + Intent intent = new Intent(this, DepartureList.class); + intent.putExtra("stationbean", station); + startActivity(intent); + } } ///////////////////////////////////////////////////////////// @@ -512,7 +530,7 @@ @Override protected void onPostExecute(Void result) { super.onPostExecute(result); - dialog.dismiss(); + dismissDialogSafe(dialog); if (success) { @@ -524,7 +542,7 @@ } else { //communication or parse errors AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); - builder.setMessage(getString(stationlist_nearbyerror)); + builder.setMessage(getString(stationlist_fetcherror)); builder.setCancelable(true); builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { @@ -564,6 +582,7 @@ builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); + StationList.this.finish(); } });