14 |
import android.content.ActivityNotFoundException; |
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.content.SharedPreferences; |
18 |
import android.graphics.Typeface; |
import android.graphics.Typeface; |
19 |
import android.net.Uri; |
import android.net.Uri; |
20 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
21 |
import android.os.Bundle; |
import android.os.Bundle; |
22 |
|
import android.preference.PreferenceManager; |
23 |
import android.util.Log; |
import android.util.Log; |
24 |
import android.view.Menu; |
import android.view.Menu; |
25 |
import android.view.MenuItem; |
import android.view.MenuItem; |
40 |
import dk.thoerup.traininfo.provider.MetroProvider; |
import dk.thoerup.traininfo.provider.MetroProvider; |
41 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
42 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
43 |
|
import dk.thoerup.traininfo.util.StationEntryCsv; |
44 |
|
|
45 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
46 |
|
|
80 |
setContentView(R.layout.departurelist); |
setContentView(R.layout.departurelist); |
81 |
|
|
82 |
adapter = new DepartureListAdapter(this); |
adapter = new DepartureListAdapter(this); |
83 |
setListAdapter(adapter); |
setListAdapter(adapter); |
84 |
|
|
85 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
86 |
|
|
87 |
station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); |
station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); |
196 |
|
|
197 |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
198 |
|
|
199 |
Log.e("Station", station.toCSV() ); |
Log.e("Station", StationEntryCsv.toCSV(station) ); |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
if (station.isMetro() == false) { |
if (station.isMetro() == false) { |
204 |
metroBtn.setVisibility( View.GONE ); |
metroBtn.setVisibility( View.GONE ); |
228 |
trainType = "STOG"; |
trainType = "STOG"; |
229 |
|
|
230 |
} |
} |
231 |
|
//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 |
|
|
242 |
|
|
243 |
if (station.isRegional() == false && station.isStrain() == false) { |
if (station.isRegional() == false && station.isStrain() == false) { |
278 |
} |
} |
279 |
} |
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
boolean hasNotifications() { |
boolean hasNotifications() { |
284 |
return (departures != null && departures.notifications.size() > 0); |
return (departures != null && departures.notifications.size() > 0); |
285 |
} |
} |
315 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
316 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
317 |
|
|
318 |
|
//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 |
selectedItemId = position; |
selectedItemId = position; |
325 |
|
|
326 |
DepartureEntry dep = departures.entries.get(selectedItemId); |
DepartureEntry dep = departures.entries.get(selectedItemId); |
362 |
|
|
363 |
|
|
364 |
@Override |
@Override |
365 |
|
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 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
377 |
MenuItem item; |
MenuItem item; |
378 |
|
|
481 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
482 |
|
|
483 |
|
|
484 |
// handle notification icon. |
// handle notification icon. |
485 |
if ( hasNotifications() ) { |
View notifIcon = findViewById(R.id.notifIcon); |
486 |
View notifIcon = findViewById(R.id.notifIcon); |
if ( hasNotifications() ) { |
487 |
notifIcon.setVisibility(View.VISIBLE); |
notifIcon.setVisibility(View.VISIBLE); |
488 |
notifIcon.setClickable(true); |
notifIcon.setClickable(true); |
489 |
notifIcon.setOnClickListener( new View.OnClickListener() { |
notifIcon.setOnClickListener( new View.OnClickListener() { |
494 |
startActivity(i); |
startActivity(i); |
495 |
} |
} |
496 |
}); |
}); |
497 |
} |
} else { |
498 |
|
notifIcon.setVisibility(View.INVISIBLE); |
499 |
|
} |
500 |
|
|
501 |
if (departures.entries.size() == 0) { |
if (departures.entries.size() == 0) { |
502 |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |