18 |
import android.os.Handler; |
import android.os.Handler; |
19 |
import android.os.Message; |
import android.os.Message; |
20 |
import android.util.Log; |
import android.util.Log; |
21 |
|
import android.view.Menu; |
22 |
|
import android.view.MenuItem; |
23 |
import android.view.View; |
import android.view.View; |
24 |
import android.widget.ListView; |
import android.widget.ListView; |
25 |
|
|
26 |
|
|
27 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
28 |
import dk.thoerup.traininfo.provider.StationProvider; |
import dk.thoerup.traininfo.provider.StationProvider; |
29 |
|
import dk.thoerup.traininfo.stationmap.GeoPair; |
30 |
|
import dk.thoerup.traininfo.stationmap.StationMapView; |
31 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
32 |
|
|
33 |
public class StationList extends ListActivity { |
public class StationList extends ListActivity { |
35 |
public static final int GOTSTATIONLIST = 1002; |
public static final int GOTSTATIONLIST = 1002; |
36 |
public static final int NOPROVIDER = 1003; |
public static final int NOPROVIDER = 1003; |
37 |
public static final int LOCATIONFIXTIMEOUT = 1004; |
public static final int LOCATIONFIXTIMEOUT = 1004; |
38 |
|
|
39 |
|
public static final int OPTIONS_MAP = 2001; |
40 |
|
public static final int OPTIONS_ABOUT = 2002; |
41 |
|
|
42 |
|
|
43 |
public static final int DLG_PROGRESS = 1001; |
public static final int DLG_PROGRESS = 1001; |
48 |
LocationLookup locator = null; |
LocationLookup locator = null; |
49 |
LocatorTask locatorTask; |
LocatorTask locatorTask; |
50 |
|
|
51 |
|
GeoPair location = new GeoPair(); |
52 |
|
|
53 |
boolean isRunning = false; |
boolean isRunning = false; |
54 |
List<StationBean> stations = new ArrayList<StationBean>(); |
List<StationBean> stations = new ArrayList<StationBean>(); |
55 |
|
|
63 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
64 |
setContentView(R.layout.main); |
setContentView(R.layout.main); |
65 |
|
|
|
LocationLookup.removeMockLocation(this); |
|
|
//LocationLookup.injectMockLocation(this); |
|
66 |
|
|
67 |
adapter = new StationListAdapter(this); |
adapter = new StationListAdapter(this); |
68 |
setListAdapter(adapter); |
setListAdapter(adapter); |
73 |
} else { |
} else { |
74 |
stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations"); |
stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations"); |
75 |
adapter.setStations(stations); |
adapter.setStations(stations); |
76 |
|
location = (GeoPair) savedInstanceState.getSerializable("location"); |
77 |
} |
} |
78 |
} |
} |
79 |
|
|
80 |
|
|
81 |
@Override |
@Override |
82 |
public void onSaveInstanceState(Bundle outState) |
public void onSaveInstanceState(Bundle outState) |
83 |
{ |
{ |
84 |
if (dialog != null && dialog.isShowing()) |
if (dialog != null && dialog.isShowing()) |
85 |
dialog.dismiss(); |
dialog.dismiss(); |
86 |
outState.putSerializable("stations", (ArrayList<StationBean>) stations); |
outState.putSerializable("stations", (ArrayList<StationBean>) stations); |
87 |
|
outState.putSerializable("location", location); |
88 |
} |
} |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
@Override |
@Override |
93 |
|
public boolean onCreateOptionsMenu(Menu menu) { |
94 |
|
menu.add(0, OPTIONS_MAP, 0, "Show station map"); |
95 |
|
menu.add(0, OPTIONS_ABOUT, 0, "About"); |
96 |
|
|
97 |
|
return true; |
98 |
|
} |
99 |
|
|
100 |
|
@Override |
101 |
|
public boolean onOptionsItemSelected(MenuItem item) { |
102 |
|
boolean retval; |
103 |
|
|
104 |
|
switch (item.getItemId()) { |
105 |
|
case OPTIONS_MAP: |
106 |
|
|
107 |
|
Intent intent = new Intent(this,StationMapView.class); |
108 |
|
intent.putExtra("userlocation", location ); |
109 |
|
|
110 |
|
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
111 |
|
for (StationBean st : stations ) { |
112 |
|
stationPoints.add( new GeoPair(st.getLatitude(), st.getLongitude(), st.getName()) ); |
113 |
|
} |
114 |
|
|
115 |
|
intent.putExtra("stations", stationPoints); |
116 |
|
|
117 |
|
startActivity(intent); |
118 |
|
retval = true; |
119 |
|
break; |
120 |
|
case OPTIONS_ABOUT: |
121 |
|
String ver = this.getResources().getString(R.string.app_version); |
122 |
|
|
123 |
|
StringBuffer message = new StringBuffer(); |
124 |
|
message.append("TrainInfo DK v").append(ver).append("\n"); |
125 |
|
message.append("By Torben Nielsen\n"); |
126 |
|
|
127 |
|
MessageBox.showMessage(this, message.toString()); |
128 |
|
retval = true; |
129 |
|
break; |
130 |
|
default: |
131 |
|
retval = super.onOptionsItemSelected(item); |
132 |
|
} |
133 |
|
|
134 |
|
return retval; |
135 |
|
} |
136 |
|
|
137 |
|
@Override |
138 |
protected Dialog onCreateDialog(int id) { |
protected Dialog onCreateDialog(int id) { |
139 |
switch (id) { |
switch (id) { |
140 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
182 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
183 |
|
|
184 |
startLocatorTask(); |
startLocatorTask(); |
185 |
|
location = GeoPair.fromLocation( locator.getLocation() ); |
186 |
|
|
187 |
break; |
break; |
188 |
|
|