/[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 1007 by torben, Tue Aug 3 06:12:10 2010 UTC revision 1442 by torben, Tue May 3 20:36:16 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
 import static dk.thoerup.traininfo.R.string.departurelist_fetchdepartures;  
3  import static dk.thoerup.traininfo.R.string.departurelist_fetcharrivals;  import static dk.thoerup.traininfo.R.string.departurelist_fetcharrivals;
4    import static dk.thoerup.traininfo.R.string.departurelist_fetchdepartures;
5  import static dk.thoerup.traininfo.R.string.generic_cancel;  import static dk.thoerup.traininfo.R.string.generic_cancel;
6  import static dk.thoerup.traininfo.R.string.generic_retry;  import static dk.thoerup.traininfo.R.string.generic_retry;
7    
   
8  import java.text.NumberFormat;  import java.text.NumberFormat;
9    
   
10  import android.app.AlertDialog;  import android.app.AlertDialog;
11  import android.app.Dialog;  import android.app.Dialog;
12  import android.app.ListActivity;  import android.app.ListActivity;
13  import android.app.ProgressDialog;  import android.app.ProgressDialog;
14    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.graphics.Typeface;
18  import android.net.Uri;  import android.net.Uri;
19  import android.os.AsyncTask;  import android.os.AsyncTask;
20  import android.os.Bundle;  import android.os.Bundle;
# Line 25  import android.view.View; Line 25  import android.view.View;
25  import android.view.View.OnClickListener;  import android.view.View.OnClickListener;
26  import android.widget.Button;  import android.widget.Button;
27  import android.widget.ListView;  import android.widget.ListView;
28    import android.widget.TableLayout;
29    import android.widget.TableRow;
30  import android.widget.TextView;  import android.widget.TextView;
31    import android.widget.Toast;
32    import dk.thoerup.android.traininfo.common.DepartureBean;
33    import dk.thoerup.android.traininfo.common.DepartureEntry;
34    import dk.thoerup.android.traininfo.common.MetroBean;
35    import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry;
36    import dk.thoerup.android.traininfo.common.StationEntry;
37  import dk.thoerup.traininfo.provider.DepartureProvider;  import dk.thoerup.traininfo.provider.DepartureProvider;
38    import dk.thoerup.traininfo.provider.MetroProvider;
39  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
40  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
41    
# Line 35  public class DepartureList extends ListA Line 44  public class DepartureList extends ListA
44          public static final int DLG_PROGRESS = 1;          public static final int DLG_PROGRESS = 1;
45          static final int MENU_MAP = 100;          static final int MENU_MAP = 100;
46          static final int MENU_NOTIFICATIONS = 101;          static final int MENU_NOTIFICATIONS = 101;
47            static final int MENU_METROMAP = 102;
48            static final int MENU_TOGGLEDETAILS= 103;
49                    
50                    
51          DepartureListAdapter adapter;          DepartureListAdapter adapter;
52          DepartureProvider provider;          DepartureProvider provider;
53          DepartureBean departures;          DepartureBean departures;
54                    
55            MetroBean metroBean;
56            MetroProvider metro;
57            
58          int selectedItemId;          int selectedItemId;
59          //DepartureBean currentDeparture;          //DepartureBean currentDeparture;
60                    
61          ProgressDialog pgDialog;          ProgressDialog pgDialog;
62                    
63          DepartureFetcher fetcher;          DepartureFetcher fetcher;
64            MetroFetcher metroFetcher;
65    
66          StationBean station;          StationEntry station;
67                    
68          boolean arrival = false;          String trainType = "REGIONAL";
69                    
70            boolean arrival = false;        
71    
72            int commFailCounter = 0;
73    
74          @Override          @Override
75          protected void onCreate(Bundle savedInstanceState) {          protected void onCreate(Bundle savedInstanceState) {
# Line 59  public class DepartureList extends ListA Line 77  public class DepartureList extends ListA
77                  setContentView(R.layout.departurelist);                  setContentView(R.layout.departurelist);
78                                    
79                  adapter = new DepartureListAdapter(this);                  adapter = new DepartureListAdapter(this);
80                  setListAdapter(adapter);                  setListAdapter(adapter);                                
81                                    
82                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
83                    
84                  station = (StationBean) launchedBy.getSerializableExtra("stationbean");                  station = (StationEntry) launchedBy.getSerializableExtra("stationbean");
85                                    
86                  ((TextView) findViewById(R.id.stationName)).setText( station.getName() );                  ((TextView) findViewById(R.id.stationName)).setText( station.getName() );
87    
# Line 72  public class DepartureList extends ListA Line 90  public class DepartureList extends ListA
90                                    
91                  final Button departureBtn = (Button) findViewById(R.id.departurebtn);                  final Button departureBtn = (Button) findViewById(R.id.departurebtn);
92                  final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn);                  final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn);
93                    final Button metroBtn = (Button) findViewById(R.id.metrobtn);
94                    final Button regionalBtn = (Button) findViewById(R.id.regionalbtn);
95                    final Button stogBtn = (Button) findViewById(R.id.stogbtn);
96                    
97                    final View metroView = findViewById(R.id.metroonly);
98                                    
99                  departureBtn.setOnClickListener( new OnClickListener() {                  departureBtn.setOnClickListener( new OnClickListener() {
100                          @Override                          @Override
101                          public void onClick(View arg0) {                                  public void onClick(View arg0) {        
102                                  arrivalBtn.setBackgroundResource(R.drawable.custom_button);                                  arrivalBtn.setBackgroundResource(R.drawable.custom_button);
103                                  departureBtn.setBackgroundResource(R.drawable.custom_button_hilight);                                  departureBtn.setBackgroundResource(R.drawable.custom_button_hilight);
104                                    metroBtn.setBackgroundResource(R.drawable.custom_button);
105                                    
106                                    getListView().setVisibility( View.VISIBLE );            
107                                    metroView.setVisibility( View.GONE );
108                                  arrival = false;                                  arrival = false;
109                                  startDepartureFetcher();                                  startDepartureFetcher();
110                          }                          }
# Line 87  public class DepartureList extends ListA Line 114  public class DepartureList extends ListA
114                          public void onClick(View arg0) {                                  public void onClick(View arg0) {        
115                                  arrivalBtn.setBackgroundResource(R.drawable.custom_button_hilight);                                  arrivalBtn.setBackgroundResource(R.drawable.custom_button_hilight);
116                                  departureBtn.setBackgroundResource(R.drawable.custom_button);                                  departureBtn.setBackgroundResource(R.drawable.custom_button);
117                                    metroBtn.setBackgroundResource(R.drawable.custom_button);
118                                    
119                                    getListView().setVisibility( View.VISIBLE );            
120                                    metroView.setVisibility( View.GONE );
121                                  arrival = true;                                                  arrival = true;                
122                                  startDepartureFetcher();                                  startDepartureFetcher();
123                          }                          }
124                  });                  });
125                                    
126                    regionalBtn.setOnClickListener( new OnClickListener() {
127                            @Override
128                            public void onClick(View arg0) {        
129                                    regionalBtn.setBackgroundResource(R.drawable.custom_button_hilight);
130                                    stogBtn.setBackgroundResource(R.drawable.custom_button);                                
131                                    metroBtn.setBackgroundResource(R.drawable.custom_button);
132                                    
133                                    departureBtn.setVisibility( View.VISIBLE );
134                                    arrivalBtn.setVisibility( View.VISIBLE );
135                                    
136                                    getListView().setVisibility( View.VISIBLE );            
137                                    metroView.setVisibility( View.GONE );
138                                    trainType = "REGIONAL";
139                                    startDepartureFetcher();
140                            }
141                    });
142                    stogBtn.setOnClickListener( new OnClickListener() {
143                            @Override
144                            public void onClick(View arg0) {        
145                                    regionalBtn.setBackgroundResource(R.drawable.custom_button);
146                                    stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);                                
147                                    metroBtn.setBackgroundResource(R.drawable.custom_button);
148    
149    
150                                    departureBtn.setVisibility( View.VISIBLE );
151                                    arrivalBtn.setVisibility( View.VISIBLE );
152                                    
153                                    getListView().setVisibility( View.VISIBLE );            
154                                    metroView.setVisibility( View.GONE );
155                                    trainType = "STOG";                    
156                                    startDepartureFetcher();
157                            }
158                    });
159    
160                    
161                    
162                    metroBtn.setOnClickListener( new OnClickListener() {                    
163                            @Override
164                            public void onClick(View v) {
165                                    regionalBtn.setBackgroundResource(R.drawable.custom_button);
166                                    stogBtn.setBackgroundResource(R.drawable.custom_button);                                
167                                    metroBtn.setBackgroundResource(R.drawable.custom_button_hilight);
168                                    
169                                    departureBtn.setVisibility( View.GONE );
170                                    arrivalBtn.setVisibility( View.GONE );
171                                    
172                                    getListView().setVisibility( View.GONE );              
173                                    metroView.setVisibility( View.VISIBLE );
174                                    startMetroFetcher();
175                            }
176                    });
177                    
178                                    
179                                    
180                                    
181                  // findViewById(R.id.header).setOnClickListener( mapLauncher );                  // findViewById(R.id.header).setOnClickListener( mapLauncher );
182                                    
183                  int distance = station.getDistance();                  int distance = station.getCalcdist();
184                  if (distance != 0) {                  if (distance != 0) {
185                          NumberFormat format = NumberFormat.getNumberInstance();                          NumberFormat format = NumberFormat.getNumberInstance();
186                          format.setMaximumFractionDigits(1);                          format.setMaximumFractionDigits(1);
# Line 107  public class DepartureList extends ListA Line 190  public class DepartureList extends ListA
190                  } else {                  } else {
191                          ((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE);                          ((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE);
192                  }                  }
193            
194                    ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
195                    
196                    Log.e("Station", station.toCSV() );
197                                    
198                    if (station.isMetro() == false) {
199                            metroBtn.setVisibility( View.GONE );
200                    }
201                    
202                  if (station.isRegional() == false && station.isSTrain() == false) {                  metro = ProviderFactory.getMetroProvider();
203                    
204                    if (station.isRegional() == false ) {
205                            regionalBtn.setVisibility(View.GONE);
206                    }
207                    
208                    if (station.isStrain() == false ) {
209                            stogBtn.setVisibility(View.GONE);
210                    }
211                    
212                    if (station.isRegional() == true && station.isStrain() == false ) {
213                            if ( station.isMetro() == false )
214                                    regionalBtn.setVisibility(View.GONE);
215                            trainType = "REGIONAL";                
216                    }              
217    
218                    if (station.isRegional() == false  && station.isStrain() == true) {
219                            if (station.isMetro() == false)
220                                    stogBtn.setVisibility(View.GONE);
221    
222                            stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);
223                            trainType = "STOG";
224                            
225                    }
226                                    
227                    
228                    if (station.isRegional() == false && station.isStrain() == false) {
229                          getListView().setVisibility( View.GONE );                                        getListView().setVisibility( View.GONE );              
230                          findViewById(R.id.metroonly).setVisibility( View.VISIBLE );                          metroView.setVisibility( View.VISIBLE );
231                            
232                          departureBtn.setVisibility( View.GONE );                          departureBtn.setVisibility( View.GONE );
233                          arrivalBtn.setVisibility(View.GONE);                          arrivalBtn.setVisibility(View.GONE);
234                            metroBtn.setVisibility( View.GONE );            
235                            
236                            
237                            
238                            if (savedInstanceState == null) {
239                                    startMetroFetcher();
240                            } else {
241                                    metroBean = (MetroBean) savedInstanceState.getSerializable("metro");
242                                    loadMetroData();
243                            }
244                                                    
245                  } else {                  } else {
246                          provider = ProviderFactory.getDepartureProvider();                          provider = ProviderFactory.getDepartureProvider();
# Line 149  public class DepartureList extends ListA Line 276  public class DepartureList extends ListA
276          outState.putInt("selectedItemId", selectedItemId);          outState.putInt("selectedItemId", selectedItemId);
277                    
278          outState.putSerializable("departures",  departures);          outState.putSerializable("departures",  departures);
279            outState.putSerializable("metro", metroBean);
280      }      }
281            
282            
# Line 160  public class DepartureList extends ListA Line 288  public class DepartureList extends ListA
288                  if (fetcher != null) {                  if (fetcher != null) {
289                          fetcher.cancel(true);                          fetcher.cancel(true);
290                  }                  }
291                    
292                    if (metroFetcher != null) {
293                            metroFetcher.cancel(true);
294                    }
295          }          }
296    
297          @Override          @Override
# Line 206  public class DepartureList extends ListA Line 338  public class DepartureList extends ListA
338                    
339                    
340    
341            @Override
342            public boolean onPrepareOptionsMenu(Menu menu) {                
343                    super.onPrepareOptionsMenu(menu);
344                    
345                    MenuItem item = menu.findItem( MENU_NOTIFICATIONS );
346                    boolean notifEnabled = hasNotifications();
347                    item.setEnabled(notifEnabled);
348                    
349                    return true;
350            }
351    
352          @Override          @Override
353          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
354                  MenuItem item;                  MenuItem item;
355                                    
356                    
357                    item = menu.add(0, MENU_TOGGLEDETAILS, 0, getString(R.string.departurelist_toggledetails));
358                    item.setIcon(android.R.drawable.ic_menu_view);
359                    
360                  item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) );                  item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) );
361                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
362                                    
363                  item = menu.add(0, MENU_NOTIFICATIONS, 0, getString(R.string.departurelist_notifications) );                  item = menu.add(0, MENU_NOTIFICATIONS, 0, getString(R.string.departurelist_notifications) );
364                  item.setIcon(android.R.drawable.ic_menu_info_details);                  item.setIcon(android.R.drawable.ic_menu_info_details);                  
                   
365                                    
366                  boolean notifEnabled = hasNotifications();                  boolean notifEnabled = hasNotifications();
367                  item.setEnabled(notifEnabled);                  item.setEnabled(notifEnabled);
368                                    
369                    if (station.isMetro()) {
370                            item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!
371                            item.setIcon(android.R.drawable.ic_menu_mapmode);                      
372                    }                                              
373    
374                  return true;                  return true;
375          }          }
376    
377          @Override          @Override
378          public boolean onOptionsItemSelected(MenuItem item) {                    public boolean onOptionsItemSelected(MenuItem item) {          
379                  boolean res;                  boolean res = true;
380                  switch(item.getItemId()) {                  switch(item.getItemId()) {
381                  case MENU_MAP:                  case MENU_MAP:
382                          Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude());                          Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16");
383                          startActivity( new Intent(Intent.ACTION_VIEW, uri));                          
384                          res = true;                          try {                          
385                                    startActivity( new Intent(Intent.ACTION_VIEW, uri));
386                            } catch (ActivityNotFoundException anfe) {
387                                     Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show();
388                            }
389                            
390                          break;                          break;
391                  case MENU_NOTIFICATIONS:                  case MENU_NOTIFICATIONS:
392                          Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class);                          Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class);
393                          i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);                          i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
394                          startActivity(i);                          startActivity(i);                      
395                          res = true;                          break;
396                    case MENU_METROMAP:
397                            Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class);
398                            startActivity(metroMap);                        
399                            break;                  
400                    case MENU_TOGGLEDETAILS:
401                            adapter.toggleShowDetails();                                            
402                          break;                          break;
403                  default:                  default:
404                          res = super.onOptionsItemSelected(item);                          res = super.onOptionsItemSelected(item);
# Line 253  public class DepartureList extends ListA Line 412  public class DepartureList extends ListA
412                  fetcher.execute(station.getId());                  fetcher.execute(station.getId());
413          }          }
414                    
415            void startMetroFetcher() {
416                    showDialog(DLG_PROGRESS);
417                    metroFetcher = new MetroFetcher();
418                    metroFetcher.execute(station.getId());          
419            }
420            
421          class DialogDismisser implements View.OnClickListener {          class DialogDismisser implements View.OnClickListener {
422    
423                  Dialog dlg;                  Dialog dlg;
# Line 279  public class DepartureList extends ListA Line 444  public class DepartureList extends ListA
444                    
445          class DepartureFetcher extends AsyncTask<Integer, Void, Void> {          class DepartureFetcher extends AsyncTask<Integer, Void, Void> {
446    
   
447                  @Override                  @Override
448                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
449                          super.onPostExecute(result);                          super.onPostExecute(result);
450                                                    
451                                                    
452                          pgDialog.dismiss();                          pgDialog.dismiss();
453                            
454                          if (departures != null) {                          if (departures != null && departures.errorCode == null) {
455                                    commFailCounter = 0;
456                                  DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html                                  DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html
457                                  adapter.setDepartures(departures.entries);                                  adapter.setDepartures(departures.entries);
458                                  DepartureList.this.getListView().setVisibility(View.VISIBLE);                                  DepartureList.this.getListView().setVisibility(View.VISIBLE);
459                                                                    
460                                                                    
461                                  if ( hasNotifications() ) {                                  // handle notification icon.
462                                          findViewById(R.id.notifIcon).setVisibility(View.VISIBLE);                                  View notifIcon = findViewById(R.id.notifIcon);
463                                    if ( hasNotifications() ) {                                    
464                                            notifIcon.setVisibility(View.VISIBLE);
465                                            notifIcon.setClickable(true);
466                                            notifIcon.setOnClickListener( new View.OnClickListener() {                                              
467                                                    @Override
468                                                    public void onClick(View v) {
469                                                            Intent i = new Intent(DepartureList.this, dk.thoerup.traininfo.NotificationList.class);
470                                                            i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
471                                                            startActivity(i);                                                      
472                                                    }
473                                            });
474                                    } else {
475                                            notifIcon.setVisibility(View.INVISIBLE);
476                                  }                                  }
477                                                                    
478                                  if (departures.entries.size() == 0) {                                  if (departures.entries.size() == 0) {
479                                          MessageBox.showMessage(DepartureList.this, "No departures found", true);                                          int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals;
480                                            MessageBox.showMessage(DepartureList.this, getString(msgId), false);
481                                  }                                  }
482                          } else { // communication or parse error                          } else { // communication or parse error
483                                  AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);                                                                                commFailCounter++;
484                                  builder.setMessage("Error finding departures");                                  AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);
485                                    
486                                    if (departures != null && departures.errorCode != null ) { //got an error xml back
487                                            commFailCounter = 10;
488                                            builder.setMessage( getString(R.string.no_backend) );
489                                    } else {                                        
490                                            builder.setMessage( getString(R.string.departurelist_fetcherror) );            
491                                    }
492                                  builder.setCancelable(true);                                  builder.setCancelable(true);
493                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  
494                                    if (commFailCounter < 3) {
495                                            builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
496                                                    public void onClick(DialogInterface dialog, int id) {
497                                                            dialog.dismiss();
498                                                            startDepartureFetcher();
499                                                            
500                                                    }
501                                            });
502                                    }
503                                    builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
504                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
505                                                  dialog.dismiss();                                                  dialog.dismiss();
506                                                  startDepartureFetcher();                                                  DepartureList.this.finish();
507                                                                                            }                                                      
                                         }  
508                                  });                                  });
509                                    
510                                    try { //TODO: is this still necessary after the 0.9.4.1 fix ?
511                                            builder.show();
512                                    } catch (android.view.WindowManager.BadTokenException e) {                                      
513                                            Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
514                                    }                              
515                            }
516                    }
517    
518                    @Override
519                    protected Void doInBackground(Integer... params) {
520                            departures = provider.lookupDepartures(params[0], DepartureList.this.arrival, trainType);
521                            return null;
522                    }
523                    
524            }
525            
526            public void loadMetroData() {
527                    ((TextView) findViewById(R.id.operations)).setText( metroBean.operationInfo );
528                    ((TextView) findViewById(R.id.plan)).setText( metroBean.plan );
529                    
530                    
531                    TableLayout table = (TableLayout) findViewById(R.id.metrotable);
532                    table.removeAllViews();
533                    
534                    TableRow head = new TableRow(this);
535                    
536                    TextView h1 = new TextView(this);
537                    h1.setText("Metro");
538                    h1.setTextSize(16);
539                    h1.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
540                    
541                    
542                    TableRow.LayoutParams params = new TableRow.LayoutParams();
543                    params.span = 2;
544                    head.addView(h1, params);
545                    
546                    
547                    
548                    TextView h2 = new TextView(this);
549                    h2.setTextSize(16);
550                    h2.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
551                    h2.setText("Om minutter");
552                    
553                    params = new TableRow.LayoutParams();
554                    params.weight = 2;
555                    head.addView(h2,params);
556    
557                    
558                    
559                    table.addView(head);
560    
561                    for (MetroEntry entry : metroBean.entries) {
562                            TableRow row = new TableRow(this);
563                            
564                            Log.e("Test", "" + entry.destination);
565                            
566                            TextView v1 = new TextView(this);
567                            v1.setTextSize(16);
568                            v1.setText( entry.metro );                      
569                            row.addView(v1);
570                            
571                            TextView v2 = new TextView(this);
572                            v2.setTextSize(16);
573                            v2.setText( entry.destination );
574                            row.addView(v2);
575                    
576                            TextView v3 = new TextView(this);
577                            v3.setTextSize(16);
578                            v3.setText( entry.minutes );
579                            row.addView(v3);
580                            
581                            table.addView(row);
582                            
583                    }
584                    findViewById(R.id.rootView).requestLayout();
585            }
586            
587            class MetroFetcher extends AsyncTask<Integer, Void, Void> {
588                    
589                    @Override
590                    protected void onPostExecute(Void result) {
591                            super.onPostExecute(result);
592                            
593                            
594                            
595                            pgDialog.dismiss();
596                            
597                            if (metroBean != null) {
598                                    loadMetroData();
599                            } else { // communication or parse error
600                                    commFailCounter++;
601                                    AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);                                              
602                                    builder.setMessage("Error finding metro data");
603                                    builder.setCancelable(true);
604                                    if (commFailCounter < 3) {
605                                            builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
606                                                    public void onClick(DialogInterface dialog, int id) {
607                                                            dialog.dismiss();
608                                                            startMetroFetcher();
609                                                            
610                                                    }
611                                            });
612                                    }
613                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
614                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
615                                                  dialog.dismiss();                                                  dialog.dismiss();
616                                                  DepartureList.this.finish();                                                  DepartureList.this.finish(); //TODO: should we really close the activity ??
617                                          }                                                                                                }                                                      
618                                  });                                  });
619                                                                    
620                                  try {                                  try { //TODO: is this still necessary after the 0.9.4.1 fix ?
621                                          builder.show();                                          builder.show();
622                                  } catch (android.view.WindowManager.BadTokenException e) {                                                                        } catch (android.view.WindowManager.BadTokenException e) {                                      
623                                          Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running                                          Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
# Line 327  public class DepartureList extends ListA Line 626  public class DepartureList extends ListA
626                  }                  }
627    
628                  @Override                  @Override
629                  protected Void doInBackground(Integer... params) {                  protected Void doInBackground(Integer... params) {                      
630                          departures = provider.lookupDepartures(params[0], DepartureList.this.arrival);                          metroBean = metro.lookupMetroInfo(params[0]);
631                          return null;                          return null;
632                  }                  }
633                                    
634          }          }
635    
636  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20