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; |
import android.graphics.Typeface; |
28 |
import android.widget.TableLayout; |
import android.widget.TableLayout; |
29 |
import android.widget.TableRow; |
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; |
import dk.thoerup.android.traininfo.common.DepartureBean; |
33 |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
34 |
import dk.thoerup.android.traininfo.common.MetroBean; |
import dk.thoerup.android.traininfo.common.MetroBean; |
35 |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
36 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
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; |
import dk.thoerup.traininfo.provider.MetroProvider; |
39 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
366 |
boolean res; |
boolean res; |
367 |
switch(item.getItemId()) { |
switch(item.getItemId()) { |
368 |
case MENU_MAP: |
case MENU_MAP: |
369 |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
try { |
370 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
371 |
|
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
372 |
|
} catch (ActivityNotFoundException anfe) { |
373 |
|
Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show(); |
374 |
|
} |
375 |
res = true; |
res = true; |
376 |
break; |
break; |
377 |
case MENU_NOTIFICATIONS: |
case MENU_NOTIFICATIONS: |
435 |
|
|
436 |
|
|
437 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
438 |
|
|
439 |
if (departures != null) { |
if (departures != null && departures.errorCode == null) { |
440 |
commFailCounter = 0; |
commFailCounter = 0; |
441 |
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 |
442 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
458 |
}); |
}); |
459 |
} |
} |
460 |
|
|
461 |
if (departures.entries.size() != 0) { |
if (departures.entries.size() == 0) { |
462 |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
463 |
MessageBox.showMessage(DepartureList.this, getString(msgId), false); |
MessageBox.showMessage(DepartureList.this, getString(msgId), false); |
464 |
} |
} |
465 |
} else { // communication or parse error |
} else { // communication or parse error |
466 |
commFailCounter++; |
commFailCounter++; |
467 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
468 |
builder.setMessage("Error finding departures"); |
|
469 |
|
if (departures != null && departures.errorCode != null ) { //got an error xml back |
470 |
|
commFailCounter = 10; |
471 |
|
builder.setMessage( getString(R.string.no_backend) ); |
472 |
|
} else { |
473 |
|
builder.setMessage( getString(R.string.departurelist_fetcherror) ); |
474 |
|
} |
475 |
builder.setCancelable(true); |
builder.setCancelable(true); |
476 |
|
|
477 |
if (commFailCounter < 3) { |
if (commFailCounter < 3) { |
478 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
479 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
490 |
} |
} |
491 |
}); |
}); |
492 |
|
|
493 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
494 |
builder.show(); |
builder.show(); |
495 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
496 |
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 |
596 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
597 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
598 |
dialog.dismiss(); |
dialog.dismiss(); |
599 |
DepartureList.this.finish(); |
DepartureList.this.finish(); //TODO: should we really close the activity ?? |
600 |
} |
} |
601 |
}); |
}); |
602 |
|
|
603 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
604 |
builder.show(); |
builder.show(); |
605 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
606 |
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 |