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; |
46 |
public static final int DLG_PROGRESS = 1; |
public static final int DLG_PROGRESS = 1; |
47 |
static final int MENU_MAP = 100; |
static final int MENU_MAP = 100; |
48 |
static final int MENU_NOTIFICATIONS = 101; |
static final int MENU_NOTIFICATIONS = 101; |
49 |
static final int MENU_METROMAP= 102; |
static final int MENU_METROMAP = 102; |
50 |
|
static final int MENU_TOGGLEDETAILS= 103; |
51 |
|
|
52 |
|
|
53 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
69 |
|
|
70 |
String trainType = "REGIONAL"; |
String trainType = "REGIONAL"; |
71 |
|
|
72 |
boolean arrival = false; |
boolean arrival = false; |
73 |
|
|
74 |
int commFailCounter = 0; |
int commFailCounter = 0; |
75 |
|
|
80 |
|
|
81 |
adapter = new DepartureListAdapter(this); |
adapter = new DepartureListAdapter(this); |
82 |
setListAdapter(adapter); |
setListAdapter(adapter); |
83 |
|
|
84 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
85 |
|
|
86 |
station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); |
station = (StationEntry) launchedBy.getSerializableExtra("stationbean"); |
197 |
|
|
198 |
Log.e("Station", station.toCSV() ); |
Log.e("Station", station.toCSV() ); |
199 |
|
|
200 |
|
|
201 |
|
|
202 |
if (station.isMetro() == false) { |
if (station.isMetro() == false) { |
203 |
metroBtn.setVisibility( View.GONE ); |
metroBtn.setVisibility( View.GONE ); |
204 |
} |
} |
227 |
trainType = "STOG"; |
trainType = "STOG"; |
228 |
|
|
229 |
} |
} |
230 |
|
//Both enabled - use preferred from preferences |
231 |
|
if (station.isRegional() == true && station.isStrain() == true ) { |
232 |
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); |
233 |
|
trainType = prefs.getString("traintype", "REGIONAL"); //default value is gps |
234 |
|
|
235 |
|
if (trainType.equals("STOG") ) { |
236 |
|
stogBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
237 |
|
regionalBtn.setBackgroundResource(R.drawable.custom_button); |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
if (station.isRegional() == false && station.isStrain() == false) { |
if (station.isRegional() == false && station.isStrain() == false) { |
277 |
} |
} |
278 |
} |
} |
279 |
|
|
280 |
|
|
281 |
|
|
282 |
boolean hasNotifications() { |
boolean hasNotifications() { |
283 |
return (departures != null && departures.notifications.size() > 0); |
return (departures != null && departures.notifications.size() > 0); |
284 |
} |
} |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
@Override |
358 |
|
public boolean onPrepareOptionsMenu(Menu menu) { |
359 |
|
super.onPrepareOptionsMenu(menu); |
360 |
|
|
361 |
|
MenuItem item = menu.findItem( MENU_NOTIFICATIONS ); |
362 |
|
boolean notifEnabled = hasNotifications(); |
363 |
|
item.setEnabled(notifEnabled); |
364 |
|
|
365 |
|
return true; |
366 |
|
} |
367 |
|
|
368 |
@Override |
@Override |
369 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
370 |
MenuItem item; |
MenuItem item; |
371 |
|
|
372 |
|
|
373 |
|
item = menu.add(0, MENU_TOGGLEDETAILS, 0, getString(R.string.departurelist_toggledetails)); |
374 |
|
item.setIcon(android.R.drawable.ic_menu_view); |
375 |
|
|
376 |
item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) ); |
item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) ); |
377 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
378 |
|
|
385 |
if (station.isMetro()) { |
if (station.isMetro()) { |
386 |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
item = menu.add(0, MENU_METROMAP, 0, "Metro" ); //TODO:translate!?! |
387 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
388 |
} |
} |
|
|
|
389 |
|
|
390 |
return true; |
return true; |
391 |
} |
} |
392 |
|
|
393 |
@Override |
@Override |
394 |
public boolean onOptionsItemSelected(MenuItem item) { |
public boolean onOptionsItemSelected(MenuItem item) { |
395 |
boolean res; |
boolean res = true; |
396 |
switch(item.getItemId()) { |
switch(item.getItemId()) { |
397 |
case MENU_MAP: |
case MENU_MAP: |
398 |
try { |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
399 |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude() + "?z=16"); |
|
400 |
|
try { |
401 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
402 |
} catch (ActivityNotFoundException anfe) { |
} catch (ActivityNotFoundException anfe) { |
403 |
Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show(); |
Toast.makeText(this, "Could not launch google maps", Toast.LENGTH_LONG).show(); |
404 |
} |
} |
405 |
res = true; |
|
406 |
break; |
break; |
407 |
case MENU_NOTIFICATIONS: |
case MENU_NOTIFICATIONS: |
408 |
Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class); |
Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class); |
409 |
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
410 |
startActivity(i); |
startActivity(i); |
|
res = true; |
|
411 |
break; |
break; |
412 |
case MENU_METROMAP: |
case MENU_METROMAP: |
413 |
Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class); |
Intent metroMap = new Intent(this,dk.thoerup.traininfo.MetroMap.class); |
414 |
startActivity(metroMap); |
startActivity(metroMap); |
|
res = true; |
|
415 |
break; |
break; |
416 |
|
case MENU_TOGGLEDETAILS: |
417 |
|
adapter.toggleShowDetails(); |
418 |
|
break; |
419 |
default: |
default: |
420 |
res = super.onOptionsItemSelected(item); |
res = super.onOptionsItemSelected(item); |
421 |
} |
} |
474 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
475 |
|
|
476 |
|
|
477 |
// handle notification icon. |
// handle notification icon. |
478 |
if ( hasNotifications() ) { |
View notifIcon = findViewById(R.id.notifIcon); |
479 |
View notifIcon = findViewById(R.id.notifIcon); |
if ( hasNotifications() ) { |
480 |
notifIcon.setVisibility(View.VISIBLE); |
notifIcon.setVisibility(View.VISIBLE); |
481 |
notifIcon.setClickable(true); |
notifIcon.setClickable(true); |
482 |
notifIcon.setOnClickListener( new View.OnClickListener() { |
notifIcon.setOnClickListener( new View.OnClickListener() { |
487 |
startActivity(i); |
startActivity(i); |
488 |
} |
} |
489 |
}); |
}); |
490 |
} |
} else { |
491 |
|
notifIcon.setVisibility(View.INVISIBLE); |
492 |
|
} |
493 |
|
|
494 |
if (departures.entries.size() == 0) { |
if (departures.entries.size() == 0) { |
495 |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |