30 |
import static dk.thoerup.traininfo.R.string.stationlist_stationsearch; |
import static dk.thoerup.traininfo.R.string.stationlist_stationsearch; |
31 |
import static dk.thoerup.traininfo.R.string.stationlist_twocharmin; |
import static dk.thoerup.traininfo.R.string.stationlist_twocharmin; |
32 |
import static dk.thoerup.traininfo.R.string.stationlist_waitforlocation; |
import static dk.thoerup.traininfo.R.string.stationlist_waitforlocation; |
33 |
|
import static dk.thoerup.traininfo.R.string.stationlist_satellitecount; |
34 |
|
|
35 |
import java.util.ArrayList; |
import java.util.ArrayList; |
36 |
|
|
|
|
|
37 |
import android.app.Activity; |
import android.app.Activity; |
38 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
39 |
import android.app.Dialog; |
import android.app.Dialog; |
48 |
import android.os.Bundle; |
import android.os.Bundle; |
49 |
import android.os.Handler; |
import android.os.Handler; |
50 |
import android.os.Message; |
import android.os.Message; |
51 |
|
import android.util.Log; |
52 |
import android.view.ContextMenu; |
import android.view.ContextMenu; |
53 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
54 |
import android.view.Menu; |
import android.view.Menu; |
70 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
71 |
|
|
72 |
public class StationList extends ListActivity { |
public class StationList extends ListActivity { |
73 |
public static final int GOTLOCATION = 1001; |
public enum LookupStates { |
74 |
public static final int GOTSTATIONLIST = 1002; |
GOTLOCATION, |
75 |
public static final int NOPROVIDER = 1003; |
GOTSTATIONLIST, |
76 |
public static final int LOCATIONFIXTIMEOUT = 1004; |
NOPROVIDER, |
77 |
|
LOCATIONFIXTIMEOUT, |
78 |
|
GPS_SAT_COUNT |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
public static final int OPTIONS_MAP = 2003; |
public static final int OPTIONS_MAP = 2003; |
83 |
public static final int OPTIONS_GPSINFO = 2004; |
public static final int OPTIONS_GPSINFO = 2004; |
396 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
397 |
|
|
398 |
locationLookup.locateStations(); |
locationLookup.locateStations(); |
399 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS); |
stationsFetched.sendEmptyMessageDelayed(LookupStates.LOCATIONFIXTIMEOUT.ordinal(), GPS_TIMEOUT_MS); |
400 |
} |
} |
401 |
|
|
402 |
void startNameSearch(String name) { |
void startNameSearch(String name) { |
442 |
class StationsFetchedHandler extends Handler { |
class StationsFetchedHandler extends Handler { |
443 |
@Override |
@Override |
444 |
public void handleMessage(Message msg) { |
public void handleMessage(Message msg) { |
445 |
|
Log.e("Handler", "WHAT:" + msg.what); |
446 |
|
|
447 |
|
LookupStates state = LookupStates.values()[msg.what]; |
448 |
|
|
449 |
switch (msg.what) { |
switch (state) { |
450 |
case GOTLOCATION: |
case GOTLOCATION: |
451 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
452 |
|
|
460 |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
461 |
//StationList.this.finish(); |
//StationList.this.finish(); |
462 |
break; |
break; |
463 |
|
case GPS_SAT_COUNT: |
464 |
|
int count = msg.arg1; |
465 |
|
String dialogMessage = getString( stationlist_waitforlocation ) + "\n" + getString( stationlist_satellitecount ) + ": " + count; |
466 |
|
dialog.setMessage( dialogMessage ); |
467 |
|
return; //abort immediately |
468 |
case LOCATIONFIXTIMEOUT: |
case LOCATIONFIXTIMEOUT: |
469 |
if (isRunning) { |
if (isRunning) { |
470 |
locationLookup.stopSearch(); |
locationLookup.stopSearch(); |
471 |
if (locationLookup.hasLocation()) { |
if (locationLookup.hasLocation()) { |
472 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( LookupStates.GOTLOCATION.ordinal() ); |
473 |
} else { |
} else { |
474 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
475 |
|
|