/[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 1442 by torben, Tue May 3 20:36:16 2011 UTC revision 1798 by torben, Wed Apr 18 17:38:54 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 239  public class DepartureList extends ListA Line 264  public class DepartureList extends ListA
264                                  startMetroFetcher();                                  startMetroFetcher();
265                          } else {                          } else {
266                                  metroBean = (MetroBean) savedInstanceState.getSerializable("metro");                                  metroBean = (MetroBean) savedInstanceState.getSerializable("metro");
267                                  loadMetroData();                                  if (metroBean != null) { // Avoid reported NPE
268                                            loadMetroData();
269                                    } else {
270                                            startMetroFetcher();    
271                                    }
272                          }                          }
273                                                    
274                  } else {                  } else {
# Line 263  public class DepartureList extends ListA Line 292  public class DepartureList extends ListA
292                  }                  }
293          }          }
294                    
295            
296            
297          boolean hasNotifications() {          boolean hasNotifications() {
298                  return (departures != null && departures.notifications.size() > 0);                  return (departures != null && departures.notifications.size() > 0);
299          }          }
# Line 298  public class DepartureList extends ListA Line 329  public class DepartureList extends ListA
329          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
330                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
331                                    
332                    //how can this happen ??
333                    if (departures == null || departures.entries == null || departures.entries.size() == 0) {
334                            Toast.makeText(this, "No departures in list ?!?", Toast.LENGTH_LONG).show(); //TODO: translate
335                            return;
336                    }
337                    
338                  selectedItemId = position;                  selectedItemId = position;
339                                    
340                  DepartureEntry dep = departures.entries.get(selectedItemId);                  DepartureEntry dep = departures.entries.get(selectedItemId);
# Line 341  public class DepartureList extends ListA Line 378  public class DepartureList extends ListA
378          @Override          @Override
379          public boolean onPrepareOptionsMenu(Menu menu) {                          public boolean onPrepareOptionsMenu(Menu menu) {                
380                  super.onPrepareOptionsMenu(menu);                  super.onPrepareOptionsMenu(menu);
381    
382                    ///////////////////////
383                                    
384                  MenuItem item = menu.findItem( MENU_NOTIFICATIONS );                  MenuItem item = menu.findItem( MENU_NOTIFICATIONS );
385                  boolean notifEnabled = hasNotifications();                  boolean notifEnabled = hasNotifications();
386                  item.setEnabled(notifEnabled);                  item.setEnabled(notifEnabled);
387    
388                    //////////////////////////
389    
390    
391                    
392                                    
393                  return true;                  return true;
394          }          }
# Line 365  public class DepartureList extends ListA Line 409  public class DepartureList extends ListA
409                                    
410                  boolean notifEnabled = hasNotifications();                  boolean notifEnabled = hasNotifications();
411                  item.setEnabled(notifEnabled);                  item.setEnabled(notifEnabled);
412    
413                    ///////////////////////////////////////
414                    if ( ! favorites.hasFavorite( this.station.getId() ) ) {
415                            item = menu.add(0, MENU_FAVORITES_ADD, 0, getString(dk.thoerup.traininfo.R.string.stationlist_addfavorite) );
416                    } else {
417                            item = menu.add(0, MENU_FAVORITES_REMOVE, 0, getString(dk.thoerup.traininfo.R.string.stationlist_removefavorite) );
418                    }
419                    item.setIcon(android.R.drawable.ic_menu_save);                  
420                    /////////////////////////////
421                                    
422                  if (station.isMetro()) {                  if (station.isMetro()) {
423                          item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!                          item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!
# Line 400  public class DepartureList extends ListA Line 453  public class DepartureList extends ListA
453                  case MENU_TOGGLEDETAILS:                  case MENU_TOGGLEDETAILS:
454                          adapter.toggleShowDetails();                                                                      adapter.toggleShowDetails();                                            
455                          break;                          break;
456                    case MENU_FAVORITES_ADD:
457                            favorites.addFavorite( this.station.getId() );
458                            Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationadded), Toast.LENGTH_SHORT).show();
459                            break;
460                    case MENU_FAVORITES_REMOVE:
461                            favorites.removeFavorite( station.getId() );
462                            Toast.makeText(this, getString(dk.thoerup.traininfo.R.string.stationlist_stationremoved), Toast.LENGTH_SHORT).show();
463                            break;
464                  default:                  default:
465                          res = super.onOptionsItemSelected(item);                          res = super.onOptionsItemSelected(item);
466                  }                  }

Legend:
Removed from v.1442  
changed lines
  Added in v.1798

  ViewVC Help
Powered by ViewVC 1.1.20