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.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; |
30 |
import android.widget.TableLayout; |
import android.widget.TableLayout; |
31 |
import android.widget.TableRow; |
import android.widget.TableRow; |
32 |
import android.widget.TextView; |
import android.widget.TextView; |
33 |
|
import android.widget.Toast; |
34 |
import dk.thoerup.android.traininfo.common.DepartureBean; |
import dk.thoerup.android.traininfo.common.DepartureBean; |
35 |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
36 |
import dk.thoerup.android.traininfo.common.MetroBean; |
import dk.thoerup.android.traininfo.common.MetroBean; |
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 |
|
|
47 |
public static final int DLG_PROGRESS = 1; |
public static final int DLG_PROGRESS = 1; |
48 |
static final int MENU_MAP = 100; |
static final int MENU_MAP = 100; |
49 |
static final int MENU_NOTIFICATIONS = 101; |
static final int MENU_NOTIFICATIONS = 101; |
50 |
static final int MENU_METROMAP= 102; |
static final int MENU_METROMAP = 102; |
51 |
|
static final int MENU_TOGGLEDETAILS= 103; |
52 |
|
|
53 |
|
|
54 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
70 |
|
|
71 |
String trainType = "REGIONAL"; |
String trainType = "REGIONAL"; |
72 |
|
|
73 |
boolean arrival = false; |
boolean arrival = false; |
74 |
|
|
75 |
int commFailCounter = 0; |
int commFailCounter = 0; |
76 |
|
|
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); |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
@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 |
@Override |
376 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
377 |
MenuItem item; |
MenuItem item; |
378 |
|
|
379 |
|
|
380 |
|
item = menu.add(0, MENU_TOGGLEDETAILS, 0, getString(R.string.departurelist_toggledetails)); |
381 |
|
item.setIcon(android.R.drawable.ic_menu_view); |
382 |
|
|
383 |
item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) ); |
item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) ); |
384 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
385 |
|
|
392 |
if (station.isMetro()) { |
if (station.isMetro()) { |
393 |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
394 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
395 |
} |
} |
|
|
|
396 |
|
|
397 |
return true; |
return true; |
398 |
} |
} |
399 |
|
|
400 |
@Override |
@Override |
401 |
public boolean onOptionsItemSelected(MenuItem item) { |
public boolean onOptionsItemSelected(MenuItem item) { |
402 |
boolean res; |
boolean res = true; |
403 |
switch(item.getItemId()) { |
switch(item.getItemId()) { |
404 |
case MENU_MAP: |
case MENU_MAP: |
405 |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
406 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
|
407 |
res = true; |
try { |
408 |
|
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 |
|
|
413 |
break; |
break; |
414 |
case MENU_NOTIFICATIONS: |
case MENU_NOTIFICATIONS: |
415 |
Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class); |
Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class); |
416 |
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
417 |
startActivity(i); |
startActivity(i); |
|
res = true; |
|
418 |
break; |
break; |
419 |
case MENU_METROMAP: |
case MENU_METROMAP: |
420 |
Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class); |
Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class); |
421 |
startActivity(metroMap); |
startActivity(metroMap); |
|
res = true; |
|
422 |
break; |
break; |
423 |
|
case MENU_TOGGLEDETAILS: |
424 |
|
adapter.toggleShowDetails(); |
425 |
|
break; |
426 |
default: |
default: |
427 |
res = super.onOptionsItemSelected(item); |
res = super.onOptionsItemSelected(item); |
428 |
} |
} |
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; |