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