31 |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
32 |
import dk.thoerup.android.traininfo.common.MetroBean; |
import dk.thoerup.android.traininfo.common.MetroBean; |
33 |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
34 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
import dk.thoerup.android.traininfo.common.StationEntry; |
35 |
import dk.thoerup.traininfo.provider.DepartureProvider; |
import dk.thoerup.traininfo.provider.DepartureProvider; |
36 |
import dk.thoerup.traininfo.provider.MetroProvider; |
import dk.thoerup.traininfo.provider.MetroProvider; |
37 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
62 |
|
|
63 |
StationEntry station; |
StationEntry station; |
64 |
|
|
65 |
|
String trainType = "REGIONAL"; |
66 |
|
|
67 |
boolean arrival = false; |
boolean arrival = false; |
68 |
|
|
69 |
int commFailCounter = 0; |
int commFailCounter = 0; |
88 |
final Button departureBtn = (Button) findViewById(R.id.departurebtn); |
final Button departureBtn = (Button) findViewById(R.id.departurebtn); |
89 |
final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn); |
final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn); |
90 |
final Button metroBtn = (Button) findViewById(R.id.metrobtn); |
final Button metroBtn = (Button) findViewById(R.id.metrobtn); |
91 |
|
final Button regionalBtn = (Button) findViewById(R.id.regionalbtn); |
92 |
|
final Button stogBtn = (Button) findViewById(R.id.stogbtn); |
93 |
|
|
94 |
final View metroView = findViewById(R.id.metroonly); |
final View metroView = findViewById(R.id.metroonly); |
95 |
|
|
120 |
} |
} |
121 |
}); |
}); |
122 |
|
|
123 |
|
regionalBtn.setOnClickListener( new OnClickListener() { |
124 |
|
@Override |
125 |
|
public void onClick(View arg0) { |
126 |
|
regionalBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
127 |
|
stogBtn.setBackgroundResource(R.drawable.custom_button); |
128 |
|
metroBtn.setBackgroundResource(R.drawable.custom_button); |
129 |
|
|
130 |
|
departureBtn.setVisibility( View.VISIBLE ); |
131 |
|
arrivalBtn.setVisibility( View.VISIBLE ); |
132 |
|
|
133 |
|
getListView().setVisibility( View.VISIBLE ); |
134 |
|
metroView.setVisibility( View.GONE ); |
135 |
|
trainType = "REGIONAL"; |
136 |
|
startDepartureFetcher(); |
137 |
|
} |
138 |
|
}); |
139 |
|
stogBtn.setOnClickListener( new OnClickListener() { |
140 |
|
@Override |
141 |
|
public void onClick(View arg0) { |
142 |
|
regionalBtn.setBackgroundResource(R.drawable.custom_button); |
143 |
|
stogBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
144 |
|
metroBtn.setBackgroundResource(R.drawable.custom_button); |
145 |
|
|
146 |
|
|
147 |
|
departureBtn.setVisibility( View.VISIBLE ); |
148 |
|
arrivalBtn.setVisibility( View.VISIBLE ); |
149 |
|
|
150 |
|
getListView().setVisibility( View.VISIBLE ); |
151 |
|
metroView.setVisibility( View.GONE ); |
152 |
|
trainType = "STOG"; |
153 |
|
startDepartureFetcher(); |
154 |
|
} |
155 |
|
}); |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
metroBtn.setOnClickListener( new OnClickListener() { |
metroBtn.setOnClickListener( new OnClickListener() { |
160 |
@Override |
@Override |
161 |
public void onClick(View v) { |
public void onClick(View v) { |
162 |
arrivalBtn.setBackgroundResource(R.drawable.custom_button); |
regionalBtn.setBackgroundResource(R.drawable.custom_button); |
163 |
departureBtn.setBackgroundResource(R.drawable.custom_button); |
stogBtn.setBackgroundResource(R.drawable.custom_button); |
164 |
metroBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
metroBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
165 |
|
|
166 |
|
departureBtn.setVisibility( View.GONE ); |
167 |
|
arrivalBtn.setVisibility( View.GONE ); |
168 |
|
|
169 |
getListView().setVisibility( View.GONE ); |
getListView().setVisibility( View.GONE ); |
170 |
metroView.setVisibility( View.VISIBLE ); |
metroView.setVisibility( View.VISIBLE ); |
171 |
startMetroFetcher(); |
startMetroFetcher(); |
198 |
|
|
199 |
metro = ProviderFactory.getMetroProvider(); |
metro = ProviderFactory.getMetroProvider(); |
200 |
|
|
201 |
|
if (station.isRegional() == false ) { |
202 |
|
regionalBtn.setVisibility(View.GONE); |
203 |
|
} |
204 |
|
|
205 |
|
if (station.isStrain() == false ) { |
206 |
|
stogBtn.setVisibility(View.GONE); |
207 |
|
} |
208 |
|
|
209 |
|
if (station.isRegional() == true && station.isStrain() == false ) { |
210 |
|
if ( station.isMetro() == false ) |
211 |
|
regionalBtn.setVisibility(View.GONE); |
212 |
|
trainType = "REGIONAL"; |
213 |
|
} |
214 |
|
|
215 |
|
if (station.isRegional() == false && station.isStrain() == true) { |
216 |
|
if (station.isMetro() == false) |
217 |
|
stogBtn.setVisibility(View.GONE); |
218 |
|
|
219 |
|
stogBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
220 |
|
trainType = "STOG"; |
221 |
|
|
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
if (station.isRegional() == false && station.isStrain() == false) { |
if (station.isRegional() == false && station.isStrain() == false) { |
226 |
getListView().setVisibility( View.GONE ); |
getListView().setVisibility( View.GONE ); |
227 |
metroView.setVisibility( View.VISIBLE ); |
metroView.setVisibility( View.VISIBLE ); |
228 |
|
|
229 |
departureBtn.setVisibility( View.GONE ); |
departureBtn.setVisibility( View.GONE ); |
230 |
arrivalBtn.setVisibility(View.GONE); |
arrivalBtn.setVisibility(View.GONE); |
231 |
metroBtn.setVisibility( View.GONE ); |
metroBtn.setVisibility( View.GONE ); |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
236 |
startMetroFetcher(); |
startMetroFetcher(); |
364 |
boolean res; |
boolean res; |
365 |
switch(item.getItemId()) { |
switch(item.getItemId()) { |
366 |
case MENU_MAP: |
case MENU_MAP: |
367 |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); |
try { |
368 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
369 |
|
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
370 |
|
} catch (ActivityNotFoundException anfe) { |
371 |
|
Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show(); |
372 |
|
} |
373 |
res = true; |
res = true; |
374 |
break; |
break; |
375 |
case MENU_NOTIFICATIONS: |
case MENU_NOTIFICATIONS: |
433 |
|
|
434 |
|
|
435 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
436 |
|
|
437 |
if (departures != null) { |
if (departures != null && departures.errorCode == null) { |
438 |
commFailCounter = 0; |
commFailCounter = 0; |
439 |
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 |
440 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
441 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
442 |
|
|
443 |
|
|
444 |
|
// handle notification icon. |
445 |
if ( hasNotifications() ) { |
if ( hasNotifications() ) { |
446 |
findViewById(R.id.notifIcon).setVisibility(View.VISIBLE); |
View notifIcon = findViewById(R.id.notifIcon); |
447 |
} |
notifIcon.setVisibility(View.VISIBLE); |
448 |
|
notifIcon.setClickable(true); |
449 |
|
notifIcon.setOnClickListener( new View.OnClickListener() { |
450 |
|
@Override |
451 |
|
public void onClick(View v) { |
452 |
|
Intent i = new Intent(DepartureList.this, dk.thoerup.traininfo.NotificationList.class); |
453 |
|
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
454 |
|
startActivity(i); |
455 |
|
} |
456 |
|
}); |
457 |
|
} |
458 |
|
|
459 |
if (departures.entries.size() == 0) { |
if (departures.entries.size() == 0) { |
460 |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
461 |
|
MessageBox.showMessage(DepartureList.this, getString(msgId), false); |
462 |
} |
} |
463 |
} else { // communication or parse error |
} else { // communication or parse error |
464 |
commFailCounter++; |
commFailCounter++; |
465 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
466 |
builder.setMessage("Error finding departures"); |
|
467 |
|
if (departures != null && departures.errorCode != null ) { //got an error xml back |
468 |
|
commFailCounter = 10; |
469 |
|
builder.setMessage( getString(R.string.no_backend) ); |
470 |
|
} else { |
471 |
|
builder.setMessage( getString(R.string.departurelist_fetcherror) ); |
472 |
|
} |
473 |
builder.setCancelable(true); |
builder.setCancelable(true); |
474 |
|
|
475 |
if (commFailCounter < 3) { |
if (commFailCounter < 3) { |
476 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
477 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
488 |
} |
} |
489 |
}); |
}); |
490 |
|
|
491 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
492 |
builder.show(); |
builder.show(); |
493 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
494 |
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 |
498 |
|
|
499 |
@Override |
@Override |
500 |
protected Void doInBackground(Integer... params) { |
protected Void doInBackground(Integer... params) { |
501 |
departures = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
departures = provider.lookupDepartures(params[0], DepartureList.this.arrival, trainType); |
502 |
return null; |
return null; |
503 |
} |
} |
504 |
|
|
594 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
595 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
596 |
dialog.dismiss(); |
dialog.dismiss(); |
597 |
DepartureList.this.finish(); |
DepartureList.this.finish(); //TODO: should we really close the activity ?? |
598 |
} |
} |
599 |
}); |
}); |
600 |
|
|
601 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
602 |
builder.show(); |
builder.show(); |
603 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
604 |
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 |