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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1562 - (hide annotations) (download)
Fri Jul 8 16:26:09 2011 UTC (12 years, 10 months ago) by torben
File size: 19808 byte(s)
Flesh out all logic from TrainInfoCommon so it just contains simple beans
1 torben 237 package dk.thoerup.traininfo;
2    
3 torben 1053 import static dk.thoerup.traininfo.R.string.departurelist_fetcharrivals;
4 torben 835 import static dk.thoerup.traininfo.R.string.departurelist_fetchdepartures;
5     import static dk.thoerup.traininfo.R.string.generic_cancel;
6     import static dk.thoerup.traininfo.R.string.generic_retry;
7    
8 torben 237 import java.text.NumberFormat;
9    
10 torben 336 import android.app.AlertDialog;
11 torben 237 import android.app.Dialog;
12     import android.app.ListActivity;
13     import android.app.ProgressDialog;
14 torben 1433 import android.content.ActivityNotFoundException;
15 torben 336 import android.content.DialogInterface;
16 torben 237 import android.content.Intent;
17 torben 1446 import android.content.SharedPreferences;
18 torben 1053 import android.graphics.Typeface;
19 torben 239 import android.net.Uri;
20 torben 237 import android.os.AsyncTask;
21     import android.os.Bundle;
22 torben 1446 import android.preference.PreferenceManager;
23 torben 630 import android.util.Log;
24 torben 982 import android.view.Menu;
25     import android.view.MenuItem;
26 torben 237 import android.view.View;
27 torben 835 import android.view.View.OnClickListener;
28     import android.widget.Button;
29 torben 237 import android.widget.ListView;
30 torben 1053 import android.widget.TableLayout;
31     import android.widget.TableRow;
32 torben 237 import android.widget.TextView;
33 torben 1433 import android.widget.Toast;
34 torben 1066 import dk.thoerup.android.traininfo.common.DepartureBean;
35     import dk.thoerup.android.traininfo.common.DepartureEntry;
36     import dk.thoerup.android.traininfo.common.MetroBean;
37     import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry;
38 torben 1408 import dk.thoerup.android.traininfo.common.StationEntry;
39 torben 255 import dk.thoerup.traininfo.provider.DepartureProvider;
40 torben 1053 import dk.thoerup.traininfo.provider.MetroProvider;
41 torben 253 import dk.thoerup.traininfo.provider.ProviderFactory;
42 torben 245 import dk.thoerup.traininfo.util.MessageBox;
43 torben 1562 import dk.thoerup.traininfo.util.StationEntryCsv;
44 torben 237
45     public class DepartureList extends ListActivity {
46    
47     public static final int DLG_PROGRESS = 1;
48 torben 982 static final int MENU_MAP = 100;
49     static final int MENU_NOTIFICATIONS = 101;
50 torben 1434 static final int MENU_METROMAP = 102;
51     static final int MENU_TOGGLEDETAILS= 103;
52 torben 237
53 torben 362
54 torben 237 DepartureListAdapter adapter;
55     DepartureProvider provider;
56 torben 981 DepartureBean departures;
57 torben 237
58 torben 1053 MetroBean metroBean;
59     MetroProvider metro;
60    
61 torben 257 int selectedItemId;
62     //DepartureBean currentDeparture;
63 torben 237
64     ProgressDialog pgDialog;
65 torben 362
66 torben 238 DepartureFetcher fetcher;
67 torben 1053 MetroFetcher metroFetcher;
68 torben 557
69 torben 1066 StationEntry station;
70 torben 238
71 torben 1250 String trainType = "REGIONAL";
72    
73 torben 1434 boolean arrival = false;
74 torben 981
75 torben 1017 int commFailCounter = 0;
76    
77 torben 237 @Override
78     protected void onCreate(Bundle savedInstanceState) {
79     super.onCreate(savedInstanceState);
80     setContentView(R.layout.departurelist);
81    
82     adapter = new DepartureListAdapter(this);
83 torben 1446 setListAdapter(adapter);
84    
85 torben 237 Intent launchedBy = getIntent();
86 torben 557
87 torben 1066 station = (StationEntry) launchedBy.getSerializableExtra("stationbean");
88 torben 239
89 torben 557 ((TextView) findViewById(R.id.stationName)).setText( station.getName() );
90 torben 317
91 torben 557
92     ((TextView) findViewById(R.id.stationAddr)).setText( station.getAddress() );
93 torben 237
94 torben 835 final Button departureBtn = (Button) findViewById(R.id.departurebtn);
95     final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn);
96 torben 1044 final Button metroBtn = (Button) findViewById(R.id.metrobtn);
97 torben 1250 final Button regionalBtn = (Button) findViewById(R.id.regionalbtn);
98     final Button stogBtn = (Button) findViewById(R.id.stogbtn);
99 torben 294
100 torben 1053 final View metroView = findViewById(R.id.metroonly);
101    
102 torben 835 departureBtn.setOnClickListener( new OnClickListener() {
103     @Override
104     public void onClick(View arg0) {
105     arrivalBtn.setBackgroundResource(R.drawable.custom_button);
106     departureBtn.setBackgroundResource(R.drawable.custom_button_hilight);
107 torben 1044 metroBtn.setBackgroundResource(R.drawable.custom_button);
108 torben 1053
109     getListView().setVisibility( View.VISIBLE );
110     metroView.setVisibility( View.GONE );
111 torben 835 arrival = false;
112     startDepartureFetcher();
113     }
114     });
115     arrivalBtn.setOnClickListener( new OnClickListener() {
116     @Override
117     public void onClick(View arg0) {
118     arrivalBtn.setBackgroundResource(R.drawable.custom_button_hilight);
119     departureBtn.setBackgroundResource(R.drawable.custom_button);
120 torben 1044 metroBtn.setBackgroundResource(R.drawable.custom_button);
121 torben 1053
122     getListView().setVisibility( View.VISIBLE );
123     metroView.setVisibility( View.GONE );
124 torben 835 arrival = true;
125     startDepartureFetcher();
126     }
127     });
128    
129 torben 1250 regionalBtn.setOnClickListener( new OnClickListener() {
130     @Override
131     public void onClick(View arg0) {
132     regionalBtn.setBackgroundResource(R.drawable.custom_button_hilight);
133     stogBtn.setBackgroundResource(R.drawable.custom_button);
134     metroBtn.setBackgroundResource(R.drawable.custom_button);
135    
136     departureBtn.setVisibility( View.VISIBLE );
137     arrivalBtn.setVisibility( View.VISIBLE );
138    
139     getListView().setVisibility( View.VISIBLE );
140     metroView.setVisibility( View.GONE );
141     trainType = "REGIONAL";
142     startDepartureFetcher();
143     }
144     });
145     stogBtn.setOnClickListener( new OnClickListener() {
146     @Override
147     public void onClick(View arg0) {
148     regionalBtn.setBackgroundResource(R.drawable.custom_button);
149     stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);
150     metroBtn.setBackgroundResource(R.drawable.custom_button);
151    
152    
153     departureBtn.setVisibility( View.VISIBLE );
154     arrivalBtn.setVisibility( View.VISIBLE );
155    
156     getListView().setVisibility( View.VISIBLE );
157     metroView.setVisibility( View.GONE );
158     trainType = "STOG";
159     startDepartureFetcher();
160     }
161     });
162    
163    
164    
165 torben 1044 metroBtn.setOnClickListener( new OnClickListener() {
166     @Override
167     public void onClick(View v) {
168 torben 1250 regionalBtn.setBackgroundResource(R.drawable.custom_button);
169     stogBtn.setBackgroundResource(R.drawable.custom_button);
170 torben 1044 metroBtn.setBackgroundResource(R.drawable.custom_button_hilight);
171 torben 1053
172 torben 1250 departureBtn.setVisibility( View.GONE );
173     arrivalBtn.setVisibility( View.GONE );
174    
175 torben 1053 getListView().setVisibility( View.GONE );
176     metroView.setVisibility( View.VISIBLE );
177     startMetroFetcher();
178 torben 1044 }
179     });
180 torben 835
181    
182    
183 torben 1044
184 torben 982 // findViewById(R.id.header).setOnClickListener( mapLauncher );
185 torben 237
186 torben 1066 int distance = station.getCalcdist();
187 torben 742 if (distance != 0) {
188     NumberFormat format = NumberFormat.getNumberInstance();
189     format.setMaximumFractionDigits(1);
190     format.setMinimumFractionDigits(1);
191 torben 575
192 torben 742 ((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." );
193     } else {
194     ((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE);
195     }
196 torben 552
197 torben 1028 ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
198 torben 1044
199 torben 1562 Log.e("Station", StationEntryCsv.toCSV(station) );
200 torben 1044
201 torben 1446
202    
203 torben 1044 if (station.isMetro() == false) {
204     metroBtn.setVisibility( View.GONE );
205     }
206 torben 1028
207 torben 1053 metro = ProviderFactory.getMetroProvider();
208    
209 torben 1250 if (station.isRegional() == false ) {
210     regionalBtn.setVisibility(View.GONE);
211     }
212    
213     if (station.isStrain() == false ) {
214     stogBtn.setVisibility(View.GONE);
215     }
216    
217     if (station.isRegional() == true && station.isStrain() == false ) {
218     if ( station.isMetro() == false )
219     regionalBtn.setVisibility(View.GONE);
220     trainType = "REGIONAL";
221     }
222    
223     if (station.isRegional() == false && station.isStrain() == true) {
224     if (station.isMetro() == false)
225     stogBtn.setVisibility(View.GONE);
226    
227     stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);
228     trainType = "STOG";
229    
230     }
231 torben 1446 //Both enabled - use preferred from preferences
232     if (station.isRegional() == true && station.isStrain() == true ) {
233     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
234     trainType = prefs.getString("traintype", "REGIONAL"); //default value is gps
235    
236     if (trainType.equals("STOG") ) {
237     stogBtn.setBackgroundResource(R.drawable.custom_button_hilight);
238     regionalBtn.setBackgroundResource(R.drawable.custom_button);
239     }
240     }
241 torben 1250
242    
243 torben 1066 if (station.isRegional() == false && station.isStrain() == false) {
244 torben 552 getListView().setVisibility( View.GONE );
245 torben 1053 metroView.setVisibility( View.VISIBLE );
246    
247 torben 835 departureBtn.setVisibility( View.GONE );
248     arrivalBtn.setVisibility(View.GONE);
249 torben 1250 metroBtn.setVisibility( View.GONE );
250 torben 552
251 torben 1250
252    
253 torben 1053 if (savedInstanceState == null) {
254     startMetroFetcher();
255     } else {
256     metroBean = (MetroBean) savedInstanceState.getSerializable("metro");
257     loadMetroData();
258     }
259    
260 torben 257 } else {
261 torben 552 provider = ProviderFactory.getDepartureProvider();
262    
263     if (savedInstanceState == null) {
264     startDepartureFetcher();
265     } else {
266 torben 981 departures = (DepartureBean) savedInstanceState.getSerializable("departures");
267 torben 990
268     if ( (departures != null) && (departures.entries != null) ) {
269     adapter.setDepartures(departures.entries);
270     }
271 torben 982 selectedItemId = savedInstanceState.getInt("selectedItemId");
272    
273     if ( hasNotifications() ) {
274     findViewById(R.id.notifIcon).setVisibility(View.VISIBLE);
275     }
276    
277 torben 552 }
278 torben 257 }
279 torben 237 }
280    
281 torben 1446
282    
283 torben 982 boolean hasNotifications() {
284     return (departures != null && departures.notifications.size() > 0);
285     }
286    
287 torben 243 @Override
288     public void onSaveInstanceState(Bundle outState)
289     {
290 torben 257 if (pgDialog != null && pgDialog.isShowing())
291     dismissDialog(DLG_PROGRESS);
292 torben 362
293 torben 257 outState.putInt("selectedItemId", selectedItemId);
294    
295 torben 981 outState.putSerializable("departures", departures);
296 torben 1053 outState.putSerializable("metro", metroBean);
297 torben 243 }
298 torben 918
299    
300 torben 243
301 torben 237 @Override
302 torben 918 protected void onDestroy() {
303     super.onDestroy();
304    
305     if (fetcher != null) {
306     fetcher.cancel(true);
307     }
308 torben 1053
309     if (metroFetcher != null) {
310     metroFetcher.cancel(true);
311     }
312 torben 918 }
313    
314     @Override
315 torben 237 protected void onListItemClick(ListView l, View v, int position, long id) {
316     super.onListItemClick(l, v, position, id);
317 torben 362
318 torben 1487 //how can this happen ??
319     if (departures == null || departures.entries == null || departures.entries.size() == 0) {
320     Toast.makeText(this, "No departures in list ?!?", Toast.LENGTH_LONG).show(); //TODO: translate
321     return;
322     }
323    
324 torben 362 selectedItemId = position;
325 torben 364
326 torben 981 DepartureEntry dep = departures.entries.get(selectedItemId);
327 torben 237
328 torben 362 Intent intent = new Intent(this, TimetableList.class);
329 torben 364 intent.putExtra("departure", dep);
330 torben 362
331     startActivity(intent);
332    
333 torben 237 }
334    
335    
336     @Override
337     protected void onPrepareDialog(int id, Dialog dialog) {
338     super.onPrepareDialog(id, dialog);
339 torben 257
340 torben 237 switch (id) {
341     case DLG_PROGRESS:
342     pgDialog = (ProgressDialog) dialog;
343 torben 835 int messageId = arrival == false ? departurelist_fetchdepartures : departurelist_fetcharrivals;
344     pgDialog.setMessage( getString(messageId) );
345 torben 237 break;
346     }
347     }
348    
349     @Override
350     protected Dialog onCreateDialog(int id) {
351     switch (id) {
352     case DLG_PROGRESS:
353 torben 835
354 torben 237 ProgressDialog dlg = new ProgressDialog(this);
355     dlg.setCancelable(true);
356 torben 362 return dlg;
357 torben 237 default:
358     return super.onCreateDialog(id);
359     }
360     }
361 torben 982
362    
363 torben 336
364 torben 982 @Override
365 torben 1442 public boolean onPrepareOptionsMenu(Menu menu) {
366     super.onPrepareOptionsMenu(menu);
367    
368     MenuItem item = menu.findItem( MENU_NOTIFICATIONS );
369     boolean notifEnabled = hasNotifications();
370     item.setEnabled(notifEnabled);
371    
372     return true;
373     }
374    
375     @Override
376 torben 982 public boolean onCreateOptionsMenu(Menu menu) {
377     MenuItem item;
378 torben 985
379 torben 1434
380     item = menu.add(0, MENU_TOGGLEDETAILS, 0, getString(R.string.departurelist_toggledetails));
381     item.setIcon(android.R.drawable.ic_menu_view);
382    
383 torben 985 item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) );
384 torben 982 item.setIcon(android.R.drawable.ic_menu_mapmode);
385    
386 torben 985 item = menu.add(0, MENU_NOTIFICATIONS, 0, getString(R.string.departurelist_notifications) );
387 torben 1057 item.setIcon(android.R.drawable.ic_menu_info_details);
388 torben 982
389     boolean notifEnabled = hasNotifications();
390     item.setEnabled(notifEnabled);
391    
392 torben 1057 if (station.isMetro()) {
393     item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?!
394     item.setIcon(android.R.drawable.ic_menu_mapmode);
395 torben 1434 }
396 torben 982
397     return true;
398     }
399    
400     @Override
401     public boolean onOptionsItemSelected(MenuItem item) {
402 torben 1434 boolean res = true;
403 torben 982 switch(item.getItemId()) {
404     case MENU_MAP:
405 torben 1434 Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16");
406    
407     try {
408 torben 1432 startActivity( new Intent(Intent.ACTION_VIEW, uri));
409     } catch (ActivityNotFoundException anfe) {
410     Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show();
411     }
412 torben 1434
413 torben 982 break;
414     case MENU_NOTIFICATIONS:
415     Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class);
416     i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
417 torben 1434 startActivity(i);
418 torben 982 break;
419 torben 1057 case MENU_METROMAP:
420     Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class);
421 torben 1434 startActivity(metroMap);
422 torben 1057 break;
423 torben 1434 case MENU_TOGGLEDETAILS:
424     adapter.toggleShowDetails();
425     break;
426 torben 982 default:
427     res = super.onOptionsItemSelected(item);
428     }
429     return res;
430     }
431    
432 torben 336 void startDepartureFetcher() {
433     showDialog(DLG_PROGRESS);
434     fetcher = new DepartureFetcher();
435 torben 557 fetcher.execute(station.getId());
436 torben 336 }
437 torben 316
438 torben 1053 void startMetroFetcher() {
439     showDialog(DLG_PROGRESS);
440     metroFetcher = new MetroFetcher();
441     metroFetcher.execute(station.getId());
442     }
443    
444 torben 237 class DialogDismisser implements View.OnClickListener {
445    
446     Dialog dlg;
447     public DialogDismisser(Dialog d) {
448     dlg = d;
449     }
450    
451     @Override
452     public void onClick(View v) {
453     if (dlg.isShowing())
454     dlg.dismiss();
455 torben 365 }
456     }
457 torben 238
458 torben 982 /*View.OnClickListener mapLauncher = new View.OnClickListener() {
459 torben 239 @Override
460 torben 557 public void onClick(View v) {
461     Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude());
462 torben 239 startActivity( new Intent(Intent.ACTION_VIEW, uri));
463     }
464 torben 982 };*/
465 torben 336
466    
467 torben 238
468 torben 310 class DepartureFetcher extends AsyncTask<Integer, Void, Void> {
469 torben 238
470     @Override
471     protected void onPostExecute(Void result) {
472     super.onPostExecute(result);
473    
474 torben 336
475 torben 238 pgDialog.dismiss();
476 torben 1423
477 torben 1373 if (departures != null && departures.errorCode == null) {
478 torben 1017 commFailCounter = 0;
479 torben 917 DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html
480 torben 981 adapter.setDepartures(departures.entries);
481 torben 917 DepartureList.this.getListView().setVisibility(View.VISIBLE);
482    
483 torben 982
484 torben 1441 // handle notification icon.
485     View notifIcon = findViewById(R.id.notifIcon);
486     if ( hasNotifications() ) {
487 torben 1261 notifIcon.setVisibility(View.VISIBLE);
488     notifIcon.setClickable(true);
489     notifIcon.setOnClickListener( new View.OnClickListener() {
490     @Override
491     public void onClick(View v) {
492     Intent i = new Intent(DepartureList.this, dk.thoerup.traininfo.NotificationList.class);
493     i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications);
494     startActivity(i);
495     }
496     });
497 torben 1441 } else {
498     notifIcon.setVisibility(View.INVISIBLE);
499     }
500 torben 982
501 torben 1264 if (departures.entries.size() == 0) {
502 torben 1262 int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals;
503     MessageBox.showMessage(DepartureList.this, getString(msgId), false);
504 torben 319 }
505     } else { // communication or parse error
506 torben 1017 commFailCounter++;
507 torben 1373 AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);
508    
509     if (departures != null && departures.errorCode != null ) { //got an error xml back
510     commFailCounter = 10;
511     builder.setMessage( getString(R.string.no_backend) );
512     } else {
513     builder.setMessage( getString(R.string.departurelist_fetcherror) );
514     }
515 torben 336 builder.setCancelable(true);
516 torben 1373
517 torben 1017 if (commFailCounter < 3) {
518     builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
519     public void onClick(DialogInterface dialog, int id) {
520     dialog.dismiss();
521     startDepartureFetcher();
522    
523     }
524     });
525     }
526 torben 561 builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
527 torben 336 public void onClick(DialogInterface dialog, int id) {
528     dialog.dismiss();
529 torben 843 DepartureList.this.finish();
530 torben 336 }
531 torben 630 });
532    
533 torben 1263 try { //TODO: is this still necessary after the 0.9.4.1 fix ?
534 torben 630 builder.show();
535     } catch (android.view.WindowManager.BadTokenException e) {
536     Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
537     }
538 torben 319 }
539 torben 238 }
540    
541     @Override
542 torben 310 protected Void doInBackground(Integer... params) {
543 torben 1250 departures = provider.lookupDepartures(params[0], DepartureList.this.arrival, trainType);
544 torben 238 return null;
545     }
546    
547     }
548 torben 1053
549     public void loadMetroData() {
550     ((TextView) findViewById(R.id.operations)).setText( metroBean.operationInfo );
551     ((TextView) findViewById(R.id.plan)).setText( metroBean.plan );
552    
553    
554     TableLayout table = (TableLayout) findViewById(R.id.metrotable);
555     table.removeAllViews();
556    
557     TableRow head = new TableRow(this);
558    
559     TextView h1 = new TextView(this);
560     h1.setText("Metro");
561 torben 1072 h1.setTextSize(16);
562 torben 1053 h1.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
563    
564    
565     TableRow.LayoutParams params = new TableRow.LayoutParams();
566     params.span = 2;
567     head.addView(h1, params);
568    
569 torben 1055
570    
571 torben 1053 TextView h2 = new TextView(this);
572 torben 1072 h2.setTextSize(16);
573 torben 1053 h2.setTypeface( Typeface.defaultFromStyle(Typeface.BOLD));
574 torben 1055 h2.setText("Om minutter");
575    
576 torben 1072 params = new TableRow.LayoutParams();
577     params.weight = 2;
578 torben 1055 head.addView(h2,params);
579 torben 1053
580    
581    
582     table.addView(head);
583    
584     for (MetroEntry entry : metroBean.entries) {
585     TableRow row = new TableRow(this);
586    
587     Log.e("Test", "" + entry.destination);
588    
589     TextView v1 = new TextView(this);
590 torben 1072 v1.setTextSize(16);
591     v1.setText( entry.metro );
592 torben 1053 row.addView(v1);
593    
594     TextView v2 = new TextView(this);
595 torben 1072 v2.setTextSize(16);
596 torben 1053 v2.setText( entry.destination );
597     row.addView(v2);
598 torben 1055
599 torben 1053 TextView v3 = new TextView(this);
600 torben 1072 v3.setTextSize(16);
601 torben 1053 v3.setText( entry.minutes );
602     row.addView(v3);
603    
604     table.addView(row);
605    
606     }
607     findViewById(R.id.rootView).requestLayout();
608     }
609    
610     class MetroFetcher extends AsyncTask<Integer, Void, Void> {
611    
612     @Override
613     protected void onPostExecute(Void result) {
614     super.onPostExecute(result);
615    
616    
617    
618     pgDialog.dismiss();
619    
620     if (metroBean != null) {
621     loadMetroData();
622     } else { // communication or parse error
623     commFailCounter++;
624     AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this);
625     builder.setMessage("Error finding metro data");
626     builder.setCancelable(true);
627     if (commFailCounter < 3) {
628     builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
629     public void onClick(DialogInterface dialog, int id) {
630     dialog.dismiss();
631     startMetroFetcher();
632    
633     }
634     });
635     }
636     builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
637     public void onClick(DialogInterface dialog, int id) {
638     dialog.dismiss();
639 torben 1263 DepartureList.this.finish(); //TODO: should we really close the activity ??
640 torben 1053 }
641     });
642    
643 torben 1263 try { //TODO: is this still necessary after the 0.9.4.1 fix ?
644 torben 1053 builder.show();
645     } catch (android.view.WindowManager.BadTokenException e) {
646     Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
647     }
648     }
649     }
650    
651     @Override
652     protected Void doInBackground(Integer... params) {
653     metroBean = metro.lookupMetroInfo(params[0]);
654     return null;
655     }
656    
657     }
658    
659 torben 237 }

  ViewVC Help
Powered by ViewVC 1.1.20