/[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 906 by torben, Fri Jun 25 23:59:58 2010 UTC revision 1434 by torben, Tue May 3 16:28:56 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;
 import java.util.ArrayList;  
 import java.util.List;  
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;
21  import android.util.Log;  import android.util.Log;
22    import android.view.Menu;
23    import android.view.MenuItem;
24  import android.view.View;  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    
42  public class DepartureList extends ListActivity {  public class DepartureList extends ListActivity {
43    
44          public static final int DLG_PROGRESS = 1;          public static final int DLG_PROGRESS = 1;
45            static final int MENU_MAP = 100;
46            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          List<DepartureBean> departures;          DepartureBean departures;
54            
55            MetroBean metroBean;
56            MetroProvider metro;
57                    
58          int selectedItemId;          int selectedItemId;
59          //DepartureBean currentDeparture;          //DepartureBean currentDeparture;
# Line 44  public class DepartureList extends ListA Line 61  public class DepartureList extends ListA
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          @SuppressWarnings("unchecked")          boolean arrival = false;        
71    
72            int commFailCounter = 0;
73    
74          @Override          @Override
75          protected void onCreate(Bundle savedInstanceState) {          protected void onCreate(Bundle savedInstanceState) {
76                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
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 69  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 84  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 104  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 118  public class DepartureList extends ListA Line 248  public class DepartureList extends ListA
248                          if (savedInstanceState == null) {                          if (savedInstanceState == null) {
249                                  startDepartureFetcher();                                  startDepartureFetcher();
250                          } else {                          } else {
251                                  departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures");                                  departures = (DepartureBean) savedInstanceState.getSerializable("departures");
252                                  adapter.setDepartures(departures);                                  
253                                  selectedItemId = savedInstanceState.getInt("selectedItemId");                                    if ( (departures != null) && (departures.entries != null) ) {
254                                            adapter.setDepartures(departures.entries);
255                                    }
256                                    selectedItemId = savedInstanceState.getInt("selectedItemId");
257                                    
258                                    if ( hasNotifications() ) {
259                                            findViewById(R.id.notifIcon).setVisibility(View.VISIBLE);
260                                    }
261                                    
262                          }                          }
263                  }                  }
264          }          }
265                    
266            boolean hasNotifications() {
267                    return (departures != null && departures.notifications.size() > 0);
268            }
269            
270      @Override      @Override
271      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
272      {      {
# Line 133  public class DepartureList extends ListA Line 275  public class DepartureList extends ListA
275    
276          outState.putInt("selectedItemId", selectedItemId);          outState.putInt("selectedItemId", selectedItemId);
277                    
278          outState.putSerializable("departures", (ArrayList<DepartureBean>) departures);          outState.putSerializable("departures",  departures);
279            outState.putSerializable("metro", metroBean);
280      }      }
281        
282        
283                    
284          @Override          @Override
285            protected void onDestroy() {
286                    super.onDestroy();
287                    
288                    if (fetcher != null) {
289                            fetcher.cancel(true);
290                    }
291                    
292                    if (metroFetcher != null) {
293                            metroFetcher.cancel(true);
294                    }
295            }
296    
297            @Override
298          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
299                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
300                                    
301                  selectedItemId = position;                  selectedItemId = position;
302                                    
303                  DepartureBean dep = departures.get(selectedItemId);                  DepartureEntry dep = departures.entries.get(selectedItemId);
304                    
305                  Intent intent = new Intent(this, TimetableList.class);                  Intent intent = new Intent(this, TimetableList.class);
306                  intent.putExtra("departure", dep);                  intent.putExtra("departure", dep);
# Line 177  public class DepartureList extends ListA Line 335  public class DepartureList extends ListA
335                          return super.onCreateDialog(id);                                          return super.onCreateDialog(id);                
336                  }                  }
337          }          }
338            
339            
340    
341            @Override
342            public boolean onCreateOptionsMenu(Menu menu) {
343                    MenuItem item;
344                    
345                    
346                    item = menu.add(0, MENU_TOGGLEDETAILS, 0, getString(R.string.departurelist_toggledetails));
347                    item.setIcon(android.R.drawable.ic_menu_view);
348                    
349                    item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) );
350                    item.setIcon(android.R.drawable.ic_menu_mapmode);
351                    
352                    item = menu.add(0, MENU_NOTIFICATIONS, 0, getString(R.string.departurelist_notifications) );
353                    item.setIcon(android.R.drawable.ic_menu_info_details);                  
354                    
355                    boolean notifEnabled = hasNotifications();
356                    item.setEnabled(notifEnabled);
357                    
358                    if (station.isMetro()) {
359                            item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!
360                            item.setIcon(android.R.drawable.ic_menu_mapmode);                      
361                    }                                              
362    
363                    return true;
364            }
365    
366            @Override
367            public boolean onOptionsItemSelected(MenuItem item) {          
368                    boolean res = true;
369                    switch(item.getItemId()) {
370                    case MENU_MAP:
371                            Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16");
372                            
373                            try {                          
374                                    startActivity( new Intent(Intent.ACTION_VIEW, uri));
375                            } catch (ActivityNotFoundException anfe) {
376                                     Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show();
377                            }
378                            
379                            break;
380                    case MENU_NOTIFICATIONS:
381                            Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class);
382                            i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
383                            startActivity(i);                      
384                            break;
385                    case MENU_METROMAP:
386                            Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class);
387                            startActivity(metroMap);                        
388                            break;                  
389                    case MENU_TOGGLEDETAILS:
390                            adapter.toggleShowDetails();                                            
391                            break;
392                    default:
393                            res = super.onOptionsItemSelected(item);
394                    }
395                    return res;
396            }
397    
398          void startDepartureFetcher() {          void startDepartureFetcher() {
399                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
# Line 184  public class DepartureList extends ListA Line 401  public class DepartureList extends ListA
401                  fetcher.execute(station.getId());                  fetcher.execute(station.getId());
402          }          }
403                    
404            void startMetroFetcher() {
405                    showDialog(DLG_PROGRESS);
406                    metroFetcher = new MetroFetcher();
407                    metroFetcher.execute(station.getId());          
408            }
409            
410          class DialogDismisser implements View.OnClickListener {          class DialogDismisser implements View.OnClickListener {
411    
412                  Dialog dlg;                  Dialog dlg;
# Line 198  public class DepartureList extends ListA Line 421  public class DepartureList extends ListA
421                  }                        }      
422          }          }
423                    
424          View.OnClickListener mapLauncher = new View.OnClickListener() {          /*View.OnClickListener mapLauncher = new View.OnClickListener() {
425                  @Override                  @Override
426                  public void onClick(View v) {                                    public void onClick(View v) {                  
427                          Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude());                          Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude());
428                          startActivity( new Intent(Intent.ACTION_VIEW, uri));                          startActivity( new Intent(Intent.ACTION_VIEW, uri));
429                  }                  }
430          };          };*/
431    
432    
433                    
434          class DepartureFetcher extends AsyncTask<Integer, Void, Void> {          class DepartureFetcher extends AsyncTask<Integer, Void, Void> {
435    
                 boolean success;  
   
436                  @Override                  @Override
437                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
438                          super.onPostExecute(result);                          super.onPostExecute(result);
439                                                    
440                                                    
441                          pgDialog.dismiss();                          pgDialog.dismiss();
442                            
443                          if (success) {                          if (departures != null && departures.errorCode == null) {
444                                  adapter.setDepartures(departures);                                  commFailCounter = 0;
445                                  if (departures.size() == 0) {                                  DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html
446                                          MessageBox.showMessage(DepartureList.this, "No departures found", true);                                  adapter.setDepartures(departures.entries);
447                                    DepartureList.this.getListView().setVisibility(View.VISIBLE);
448                                    
449                                    
450                                    // handle notification icon.                                                            
451                                    if ( hasNotifications() ) {
452                                            View notifIcon = findViewById(R.id.notifIcon);
453                                            notifIcon.setVisibility(View.VISIBLE);
454                                            notifIcon.setClickable(true);
455                                            notifIcon.setOnClickListener( new View.OnClickListener() {                                              
456                                                    @Override
457                                                    public void onClick(View v) {
458                                                            Intent i = new Intent(DepartureList.this, dk.thoerup.traininfo.NotificationList.class);
459                                                            i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
460                                                            startActivity(i);                                                      
461                                                    }
462                                            });
463                                    }                              
464                                    
465                                    if (departures.entries.size() == 0) {
466                                            int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals;
467                                            MessageBox.showMessage(DepartureList.this, getString(msgId), false);
468                                  }                                  }
469                          } else { // communication or parse error                          } else { // communication or parse error
470                                  AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);                                                                                commFailCounter++;
471                                  builder.setMessage("Error finding departures");                                  AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);
472                                    
473                                    if (departures != null && departures.errorCode != null ) { //got an error xml back
474                                            commFailCounter = 10;
475                                            builder.setMessage( getString(R.string.no_backend) );
476                                    } else {                                        
477                                            builder.setMessage( getString(R.string.departurelist_fetcherror) );            
478                                    }
479                                  builder.setCancelable(true);                                  builder.setCancelable(true);
480                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  
481                                    if (commFailCounter < 3) {
482                                            builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
483                                                    public void onClick(DialogInterface dialog, int id) {
484                                                            dialog.dismiss();
485                                                            startDepartureFetcher();
486                                                            
487                                                    }
488                                            });
489                                    }
490                                    builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
491                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
492                                                  dialog.dismiss();                                                  dialog.dismiss();
493                                                  startDepartureFetcher();                                                  DepartureList.this.finish();
494                                                                                            }                                                      
                                         }  
495                                  });                                  });
496                                    
497                                    try { //TODO: is this still necessary after the 0.9.4.1 fix ?
498                                            builder.show();
499                                    } catch (android.view.WindowManager.BadTokenException e) {                                      
500                                            Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
501                                    }                              
502                            }
503                    }
504    
505                    @Override
506                    protected Void doInBackground(Integer... params) {
507                            departures = provider.lookupDepartures(params[0], DepartureList.this.arrival, trainType);
508                            return null;
509                    }
510                    
511            }
512            
513            public void loadMetroData() {
514                    ((TextView) findViewById(R.id.operations)).setText( metroBean.operationInfo );
515                    ((TextView) findViewById(R.id.plan)).setText( metroBean.plan );
516                    
517                    
518                    TableLayout table = (TableLayout) findViewById(R.id.metrotable);
519                    table.removeAllViews();
520                    
521                    TableRow head = new TableRow(this);
522                    
523                    TextView h1 = new TextView(this);
524                    h1.setText("Metro");
525                    h1.setTextSize(16);
526                    h1.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
527                    
528                    
529                    TableRow.LayoutParams params = new TableRow.LayoutParams();
530                    params.span = 2;
531                    head.addView(h1, params);
532                    
533                    
534                    
535                    TextView h2 = new TextView(this);
536                    h2.setTextSize(16);
537                    h2.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
538                    h2.setText("Om minutter");
539                    
540                    params = new TableRow.LayoutParams();
541                    params.weight = 2;
542                    head.addView(h2,params);
543    
544                    
545                    
546                    table.addView(head);
547    
548                    for (MetroEntry entry : metroBean.entries) {
549                            TableRow row = new TableRow(this);
550                            
551                            Log.e("Test", "" + entry.destination);
552                            
553                            TextView v1 = new TextView(this);
554                            v1.setTextSize(16);
555                            v1.setText( entry.metro );                      
556                            row.addView(v1);
557                            
558                            TextView v2 = new TextView(this);
559                            v2.setTextSize(16);
560                            v2.setText( entry.destination );
561                            row.addView(v2);
562                    
563                            TextView v3 = new TextView(this);
564                            v3.setTextSize(16);
565                            v3.setText( entry.minutes );
566                            row.addView(v3);
567                            
568                            table.addView(row);
569                            
570                    }
571                    findViewById(R.id.rootView).requestLayout();
572            }
573            
574            class MetroFetcher extends AsyncTask<Integer, Void, Void> {
575                    
576                    @Override
577                    protected void onPostExecute(Void result) {
578                            super.onPostExecute(result);
579                            
580                            
581                            
582                            pgDialog.dismiss();
583                            
584                            if (metroBean != null) {
585                                    loadMetroData();
586                            } else { // communication or parse error
587                                    commFailCounter++;
588                                    AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);                                              
589                                    builder.setMessage("Error finding metro data");
590                                    builder.setCancelable(true);
591                                    if (commFailCounter < 3) {
592                                            builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
593                                                    public void onClick(DialogInterface dialog, int id) {
594                                                            dialog.dismiss();
595                                                            startMetroFetcher();
596                                                            
597                                                    }
598                                            });
599                                    }
600                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
601                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
602                                                  dialog.dismiss();                                                  dialog.dismiss();
603                                                  DepartureList.this.finish();                                                  DepartureList.this.finish(); //TODO: should we really close the activity ??
604                                          }                                                                                                }                                                      
605                                  });                                  });
606                                                                    
607                                  try {                                  try { //TODO: is this still necessary after the 0.9.4.1 fix ?
608                                          builder.show();                                          builder.show();
609                                  } catch (android.view.WindowManager.BadTokenException e) {                                                                        } catch (android.view.WindowManager.BadTokenException e) {                                      
610                                          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 251  public class DepartureList extends ListA Line 613  public class DepartureList extends ListA
613                  }                  }
614    
615                  @Override                  @Override
616                  protected Void doInBackground(Integer... params) {                  protected Void doInBackground(Integer... params) {                      
617                          success = provider.lookupDepartures(params[0], DepartureList.this.arrival);                          metroBean = metro.lookupMetroInfo(params[0]);
                         departures = provider.getDepartures(params[0], DepartureList.this.arrival);  
618                          return null;                          return null;
619                  }                  }
620                                    
621          }          }
622    
623  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.20