--- android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2011/05/03 20:30:12 1441 +++ android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java 2011/05/28 17:47:01 1487 @@ -14,10 +14,12 @@ import android.content.ActivityNotFoundException; import android.content.DialogInterface; import android.content.Intent; +import android.content.SharedPreferences; import android.graphics.Typeface; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -77,8 +79,8 @@ setContentView(R.layout.departurelist); adapter = new DepartureListAdapter(this); - setListAdapter(adapter); - + setListAdapter(adapter); + Intent launchedBy = getIntent(); station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); @@ -195,6 +197,8 @@ Log.e("Station", station.toCSV() ); + + if (station.isMetro() == false) { metroBtn.setVisibility( View.GONE ); } @@ -223,6 +227,16 @@ trainType = "STOG"; } + //Both enabled - use preferred from preferences + if (station.isRegional() == true && station.isStrain() == true ) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + trainType = prefs.getString("traintype", "REGIONAL"); //default value is gps + + if (trainType.equals("STOG") ) { + stogBtn.setBackgroundResource(R.drawable.custom_button_hilight); + regionalBtn.setBackgroundResource(R.drawable.custom_button); + } + } if (station.isRegional() == false && station.isStrain() == false) { @@ -263,6 +277,8 @@ } } + + boolean hasNotifications() { return (departures != null && departures.notifications.size() > 0); } @@ -298,6 +314,12 @@ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); + //how can this happen ?? + if (departures == null || departures.entries == null || departures.entries.size() == 0) { + Toast.makeText(this, "No departures in list ?!?", Toast.LENGTH_LONG).show(); //TODO: translate + return; + } + selectedItemId = position; DepartureEntry dep = departures.entries.get(selectedItemId); @@ -339,6 +361,17 @@ @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); + boolean notifEnabled = hasNotifications(); + item.setEnabled(notifEnabled); + + return true; + } + + @Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem item;