/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/DepartureList.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1434 by torben, Tue May 3 16:28:56 2011 UTC revision 1709 by torben, Tue Mar 6 11:02:04 2012 UTC
# Line 14  import android.app.ProgressDialog; Line 14  import android.app.ProgressDialog;
14  import android.content.ActivityNotFoundException;  import android.content.ActivityNotFoundException;
15  import android.content.DialogInterface;  import android.content.DialogInterface;
16  import android.content.Intent;  import android.content.Intent;
17    import android.content.SharedPreferences;
18  import android.graphics.Typeface;  import android.graphics.Typeface;
19  import android.net.Uri;  import android.net.Uri;
20  import android.os.AsyncTask;  import android.os.AsyncTask;
21  import android.os.Bundle;  import android.os.Bundle;
22    import android.preference.PreferenceManager;
23  import android.util.Log;  import android.util.Log;
24  import android.view.Menu;  import android.view.Menu;
25  import android.view.MenuItem;  import android.view.MenuItem;
# Line 37  import dk.thoerup.android.traininfo.comm Line 39  import dk.thoerup.android.traininfo.comm
39  import dk.thoerup.traininfo.provider.DepartureProvider;  import dk.thoerup.traininfo.provider.DepartureProvider;
40  import dk.thoerup.traininfo.provider.MetroProvider;  import dk.thoerup.traininfo.provider.MetroProvider;
41  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
42    
43    import dk.thoerup.traininfo.util.FavoritesHelper;
44  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
45    import dk.thoerup.traininfo.util.StationEntryCsv;
46    
47  public class DepartureList extends ListActivity {  public class DepartureList extends ListActivity {
48    
# Line 46  public class DepartureList extends ListA Line 51  public class DepartureList extends ListA
51          static final int MENU_NOTIFICATIONS = 101;          static final int MENU_NOTIFICATIONS = 101;
52          static final int MENU_METROMAP = 102;          static final int MENU_METROMAP = 102;
53          static final int MENU_TOGGLEDETAILS= 103;          static final int MENU_TOGGLEDETAILS= 103;
54    
55            static final int MENU_FAVORITES_ADD = 104;
56            static final int MENU_FAVORITES_REMOVE = 105;
57                    
58                    
59          DepartureListAdapter adapter;          DepartureListAdapter adapter;
# Line 56  public class DepartureList extends ListA Line 64  public class DepartureList extends ListA
64          MetroProvider metro;          MetroProvider metro;
65                    
66          int selectedItemId;          int selectedItemId;
67    
68            FavoritesHelper favorites;
69    
70          //DepartureBean currentDeparture;          //DepartureBean currentDeparture;
71                    
72          ProgressDialog pgDialog;          ProgressDialog pgDialog;
# Line 75  public class DepartureList extends ListA Line 86  public class DepartureList extends ListA
86          protected void onCreate(Bundle savedInstanceState) {          protected void onCreate(Bundle savedInstanceState) {
87                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
88                  setContentView(R.layout.departurelist);                  setContentView(R.layout.departurelist);
89                            
90                    favorites = new FavoritesHelper(this);
91            
92                  adapter = new DepartureListAdapter(this);                  adapter = new DepartureListAdapter(this);
93                  setListAdapter(adapter);                                                  setListAdapter(adapter);
94                                                    
95                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
96                    
97                  station = (StationEntry) launchedBy.getSerializableExtra("stationbean");                  station = (StationEntry) launchedBy.getSerializableExtra("stationbean");
# Line 193  public class DepartureList extends ListA Line 206  public class DepartureList extends ListA
206                    
207                  ProviderFactory.purgeOldEntries(); //cleanup before fetching more data                  ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
208                                    
209                  Log.e("Station", station.toCSV() );                  Log.e("Station", StationEntryCsv.toCSV(station) );
210                    
211                    
212                                    
213                  if (station.isMetro() == false) {                  if (station.isMetro() == false) {
214                          metroBtn.setVisibility( View.GONE );                          metroBtn.setVisibility( View.GONE );
# Line 223  public class DepartureList extends ListA Line 238  public class DepartureList extends ListA
238                          trainType = "STOG";                          trainType = "STOG";
239                                                    
240                  }                  }
241                    //Both enabled - use preferred from preferences
242                    if (station.isRegional() == true && station.isStrain() == true ) {
243                            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
244                            trainType = prefs.getString("traintype", "REGIONAL"); //default value is gps    
245                            
246                            if (trainType.equals("STOG") ) {
247                                    stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);
248                                    regionalBtn.setBackgroundResource(R.drawable.custom_button);
249                            }
250                    }
251                                                                    
252                                    
253                  if (station.isRegional() == false && station.isStrain() == false) {                  if (station.isRegional() == false && station.isStrain() == false) {
# Line 263  public class DepartureList extends ListA Line 288  public class DepartureList extends ListA
288                  }                  }
289          }          }
290                    
291            
292            
293          boolean hasNotifications() {          boolean hasNotifications() {
294                  return (departures != null && departures.notifications.size() > 0);                  return (departures != null && departures.notifications.size() > 0);
295          }          }
# Line 298  public class DepartureList extends ListA Line 325  public class DepartureList extends ListA
325          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
326                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
327                                    
328                    //how can this happen ??
329                    if (departures == null || departures.entries == null || departures.entries.size() == 0) {
330                            Toast.makeText(this, "No departures in list ?!?", Toast.LENGTH_LONG).show(); //TODO: translate
331                            return;
332                    }
333                    
334                  selectedItemId = position;                  selectedItemId = position;
335                                    
336                  DepartureEntry dep = departures.entries.get(selectedItemId);                  DepartureEntry dep = departures.entries.get(selectedItemId);
# Line 339  public class DepartureList extends ListA Line 372  public class DepartureList extends ListA
372                    
373    
374          @Override          @Override
375            public boolean onPrepareOptionsMenu(Menu menu) {                
376                    super.onPrepareOptionsMenu(menu);
377    
378                    ///////////////////////
379                    
380                    MenuItem item = menu.findItem( MENU_NOTIFICATIONS );
381                    boolean notifEnabled = hasNotifications();
382                    item.setEnabled(notifEnabled);
383    
384                    //////////////////////////
385    
386    
387                    
388                    
389                    return true;
390            }
391    
392            @Override
393          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
394                  MenuItem item;                  MenuItem item;
395                                    
# Line 354  public class DepartureList extends ListA Line 405  public class DepartureList extends ListA
405                                    
406                  boolean notifEnabled = hasNotifications();                  boolean notifEnabled = hasNotifications();
407                  item.setEnabled(notifEnabled);                  item.setEnabled(notifEnabled);
408    
409                    ///////////////////////////////////////
410                    if ( ! favorites.hasFavorite( this.station.getId() ) ) {
411                            item = menu.add(0, MENU_FAVORITES_ADD, 0, getString(dk.thoerup.traininfo.R.string.stationlist_addfavorite) );
412                    } else {
413                            item = menu.add(0, MENU_FAVORITES_REMOVE, 0, getString(dk.thoerup.traininfo.R.string.stationlist_removefavorite) );
414                    }
415                    /////////////////////////////
416                                    
417                  if (station.isMetro()) {                  if (station.isMetro()) {
418                          item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!                          item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!
# Line 389  public class DepartureList extends ListA Line 448  public class DepartureList extends ListA
448                  case MENU_TOGGLEDETAILS:                  case MENU_TOGGLEDETAILS:
449                          adapter.toggleShowDetails();                                                                      adapter.toggleShowDetails();                                            
450                          break;                          break;
451                    case MENU_FAVORITES_ADD:
452                            favorites.addFavorite( this.station.getId() );
453                            Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationadded), Toast.LENGTH_SHORT).show();
454                            break;
455                    case MENU_FAVORITES_REMOVE:
456                            favorites.removeFavorite( station.getId() );
457                            Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationremoved), Toast.LENGTH_SHORT).show();
458                            break;
459                  default:                  default:
460                          res = super.onOptionsItemSelected(item);                          res = super.onOptionsItemSelected(item);
461                  }                  }
# Line 447  public class DepartureList extends ListA Line 514  public class DepartureList extends ListA
514                                  DepartureList.this.getListView().setVisibility(View.VISIBLE);                                  DepartureList.this.getListView().setVisibility(View.VISIBLE);
515                                                                    
516                                                                    
517                                  // handle notification icon.                                                                                              // handle notification icon.
518                                  if ( hasNotifications() ) {                                  View notifIcon = findViewById(R.id.notifIcon);
519                                          View notifIcon = findViewById(R.id.notifIcon);                                  if ( hasNotifications() ) {                                    
520                                          notifIcon.setVisibility(View.VISIBLE);                                          notifIcon.setVisibility(View.VISIBLE);
521                                          notifIcon.setClickable(true);                                          notifIcon.setClickable(true);
522                                          notifIcon.setOnClickListener( new View.OnClickListener() {                                                                                        notifIcon.setOnClickListener( new View.OnClickListener() {                                              
# Line 460  public class DepartureList extends ListA Line 527  public class DepartureList extends ListA
527                                                          startActivity(i);                                                                                                                startActivity(i);                                                      
528                                                  }                                                  }
529                                          });                                          });
530                                  }                                                                } else {
531                                            notifIcon.setVisibility(View.INVISIBLE);
532                                    }
533                                                                    
534                                  if (departures.entries.size() == 0) {                                  if (departures.entries.size() == 0) {
535                                          int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals;                                          int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals;

Legend:
Removed from v.1434  
changed lines
  Added in v.1709

  ViewVC Help
Powered by ViewVC 1.1.20