19 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
20 |
import android.os.Bundle; |
import android.os.Bundle; |
21 |
import android.util.Log; |
import android.util.Log; |
22 |
|
import android.view.Menu; |
23 |
|
import android.view.MenuItem; |
24 |
import android.view.View; |
import android.view.View; |
25 |
import android.view.View.OnClickListener; |
import android.view.View.OnClickListener; |
26 |
import android.widget.Button; |
import android.widget.Button; |
33 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
34 |
|
|
35 |
public static final int DLG_PROGRESS = 1; |
public static final int DLG_PROGRESS = 1; |
36 |
|
static final int MENU_MAP = 100; |
37 |
|
static final int MENU_NOTIFICATIONS = 101; |
38 |
|
|
39 |
|
|
40 |
DepartureListAdapter adapter; |
DepartureListAdapter adapter; |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
// findViewById(R.id.header).setOnClickListener( mapLauncher ); |
99 |
|
|
100 |
int distance = station.getDistance(); |
int distance = station.getDistance(); |
101 |
if (distance != 0) { |
if (distance != 0) { |
122 |
startDepartureFetcher(); |
startDepartureFetcher(); |
123 |
} else { |
} else { |
124 |
departures = (DepartureBean) savedInstanceState.getSerializable("departures"); |
departures = (DepartureBean) savedInstanceState.getSerializable("departures"); |
125 |
adapter.setDepartures(departures.entries); |
|
126 |
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
if ( (departures != null) && (departures.entries != null) ) { |
127 |
|
adapter.setDepartures(departures.entries); |
128 |
|
} |
129 |
|
selectedItemId = savedInstanceState.getInt("selectedItemId"); |
130 |
|
|
131 |
|
if ( hasNotifications() ) { |
132 |
|
findViewById(R.id.notifIcon).setVisibility(View.VISIBLE); |
133 |
|
} |
134 |
|
|
135 |
} |
} |
136 |
} |
} |
137 |
} |
} |
138 |
|
|
139 |
|
boolean hasNotifications() { |
140 |
|
return (departures != null && departures.notifications.size() > 0); |
141 |
|
} |
142 |
|
|
143 |
@Override |
@Override |
144 |
public void onSaveInstanceState(Bundle outState) |
public void onSaveInstanceState(Bundle outState) |
145 |
{ |
{ |
203 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
204 |
} |
} |
205 |
} |
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
@Override |
212 |
|
public boolean onCreateOptionsMenu(Menu menu) { |
213 |
|
MenuItem item; |
214 |
|
|
215 |
|
item = menu.add(0, MENU_MAP, 0, getString(R.string.departurelist_showonmap) ); |
216 |
|
item.setIcon(android.R.drawable.ic_menu_mapmode); |
217 |
|
|
218 |
|
item = menu.add(0, MENU_NOTIFICATIONS, 0, getString(R.string.departurelist_notifications) ); |
219 |
|
item.setIcon(android.R.drawable.ic_menu_info_details); |
220 |
|
|
221 |
|
|
222 |
|
boolean notifEnabled = hasNotifications(); |
223 |
|
item.setEnabled(notifEnabled); |
224 |
|
|
225 |
|
|
226 |
|
return true; |
227 |
|
} |
228 |
|
|
229 |
|
@Override |
230 |
|
public boolean onOptionsItemSelected(MenuItem item) { |
231 |
|
boolean res; |
232 |
|
switch(item.getItemId()) { |
233 |
|
case MENU_MAP: |
234 |
|
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); |
235 |
|
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
236 |
|
res = true; |
237 |
|
break; |
238 |
|
case MENU_NOTIFICATIONS: |
239 |
|
Intent i = new Intent(this,dk.thoerup.traininfo.NotificationList.class); |
240 |
|
i.putExtra(NotificationList.EXTRA_NOTIFICATIONS, departures.notifications); |
241 |
|
startActivity(i); |
242 |
|
res = true; |
243 |
|
break; |
244 |
|
default: |
245 |
|
res = super.onOptionsItemSelected(item); |
246 |
|
} |
247 |
|
return res; |
248 |
|
} |
249 |
|
|
250 |
void startDepartureFetcher() { |
void startDepartureFetcher() { |
251 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
267 |
} |
} |
268 |
} |
} |
269 |
|
|
270 |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
/*View.OnClickListener mapLauncher = new View.OnClickListener() { |
271 |
@Override |
@Override |
272 |
public void onClick(View v) { |
public void onClick(View v) { |
273 |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); |
274 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
275 |
} |
} |
276 |
}; |
};*/ |
277 |
|
|
278 |
|
|
279 |
|
|
293 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
294 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
295 |
|
|
296 |
|
|
297 |
|
if ( hasNotifications() ) { |
298 |
|
findViewById(R.id.notifIcon).setVisibility(View.VISIBLE); |
299 |
|
} |
300 |
|
|
301 |
if (departures.entries.size() == 0) { |
if (departures.entries.size() == 0) { |
302 |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
303 |
} |
} |