--- android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/05/03 13:41:04 701 +++ android/TrainInfo/src/dk/thoerup/traininfo/StationList.java 2010/06/26 11:06:12 919 @@ -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) { @@ -135,6 +139,22 @@ } } + + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (findStationsTask != null) { + findStationsTask.cancel(true); + } + if (locationLookup != null) { + locationLookup.stopSearch(); + } + isRunning = false; + } + + protected void setTitle() { String dialogTitle = getResources().getString(app_name); switch (listType) { @@ -177,6 +197,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 { @@ -247,7 +274,7 @@ message.append( getString(stationlist_nolocation) ); } - MessageBox.showMessage(this, message.toString()); + MessageBox.showMessage(this, message.toString(), false); break; default: retval = super.onOptionsItemSelected(item); @@ -304,8 +331,9 @@ public void onClick(DialogInterface dialog, int which) { EditText et = (EditText) rootView.findViewById(R.id.EditText); dialog.dismiss(); - if (et.getText().toString().length() >= 2) { - startNameSearch(et.getText().toString()); + String search = et.getText().toString().trim(); + if (search.length() >= 2) { + startNameSearch(search); } else { showMessageAndClose( getString(stationlist_twocharmin) ); } @@ -346,9 +374,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); + } } ///////////////////////////////////////////////////////////// @@ -418,7 +453,8 @@ case NOPROVIDER: dismissDialogSafe(DLG_PROGRESS); - MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) ); + MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); + //StationList.this.finish(); break; case LOCATIONFIXTIMEOUT: if (isRunning) { @@ -511,7 +547,7 @@ @Override protected void onPostExecute(Void result) { super.onPostExecute(result); - dialog.dismiss(); + dismissDialogSafe(dialog); if (success) { @@ -519,11 +555,14 @@ showMessageAndClose(getString(stationlist_nostations)); } stations = stationProvider.getStations(); + + StationList.this.getListView().invalidateViews(); adapter.setStations( stations ); + } 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) { @@ -563,6 +602,7 @@ builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); + StationList.this.finish(); } });