2 |
|
|
3 |
import java.util.ArrayList; |
import java.util.ArrayList; |
4 |
import java.util.List; |
import java.util.List; |
|
import java.util.Locale; |
|
5 |
|
|
6 |
|
|
7 |
|
import android.app.Activity; |
8 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
9 |
import android.app.Dialog; |
import android.app.Dialog; |
10 |
import android.app.ListActivity; |
import android.app.ListActivity; |
13 |
import android.content.Intent; |
import android.content.Intent; |
14 |
import android.content.SharedPreferences; |
import android.content.SharedPreferences; |
15 |
import android.content.SharedPreferences.Editor; |
import android.content.SharedPreferences.Editor; |
|
import android.location.Address; |
|
|
import android.location.Geocoder; |
|
16 |
import android.location.Location; |
import android.location.Location; |
17 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
18 |
import android.os.Bundle; |
import android.os.Bundle; |
19 |
import android.os.Handler; |
import android.os.Handler; |
20 |
import android.os.Message; |
import android.os.Message; |
21 |
|
|
22 |
import android.util.Log; |
import android.util.Log; |
23 |
import android.view.ContextMenu; |
import android.view.ContextMenu; |
24 |
import android.view.LayoutInflater; |
import android.view.LayoutInflater; |
38 |
import dk.thoerup.traininfo.util.IntSet; |
import dk.thoerup.traininfo.util.IntSet; |
39 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
40 |
|
|
41 |
|
import static dk.thoerup.traininfo.R.string.*; |
42 |
|
|
43 |
public class StationList extends ListActivity { |
public class StationList extends ListActivity { |
44 |
public static final int GOTLOCATION = 1001; |
public static final int GOTLOCATION = 1001; |
45 |
public static final int GOTSTATIONLIST = 1002; |
public static final int GOTSTATIONLIST = 1002; |
70 |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
71 |
|
|
72 |
GeoPair location = new GeoPair(); |
GeoPair location = new GeoPair(); |
73 |
|
|
74 |
|
boolean isLaunchedforShortcut; |
75 |
boolean isRunning = false; |
boolean isRunning = false; |
76 |
List<StationBean> stations = new ArrayList<StationBean>(); |
List<StationBean> stations = new ArrayList<StationBean>(); |
77 |
|
|
113 |
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
114 |
setTitle(); |
setTitle(); |
115 |
|
|
116 |
|
isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false); |
117 |
|
|
118 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
119 |
|
|
120 |
|
|
123 |
startLookup(); |
startLookup(); |
124 |
break; |
break; |
125 |
case ListSearch: |
case ListSearch: |
126 |
this.showDialog(DLG_STATIONNAME); |
this.showDialogSafe(DLG_STATIONNAME); |
127 |
break; |
break; |
128 |
case ListFavorites: |
case ListFavorites: |
129 |
startFavoriteLookup(); |
startFavoriteLookup(); |
139 |
} |
} |
140 |
|
|
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
|
@Override |
145 |
|
protected void onDestroy() { |
146 |
|
super.onDestroy(); |
147 |
|
|
148 |
|
if (findStationsTask != null) { |
149 |
|
findStationsTask.cancel(true); |
150 |
|
} |
151 |
|
if (locationLookup != null) { |
152 |
|
locationLookup.stopSearch(); |
153 |
|
} |
154 |
|
isRunning = false; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
protected void setTitle() { |
protected void setTitle() { |
159 |
String dialogTitle; |
String dialogTitle = getResources().getString(app_name); |
160 |
switch (listType) { |
switch (listType) { |
161 |
case ListNearest: |
case ListNearest: |
162 |
dialogTitle = "TrainInfo DK - Nearby stations"; |
dialogTitle += " - " + getString(stationlist_nearbystations); |
163 |
break; |
break; |
164 |
case ListSearch: |
case ListSearch: |
165 |
dialogTitle = "TrainInfo DK - Search"; |
dialogTitle += " - " + getString(stationlist_search); |
166 |
break; |
break; |
167 |
case ListFavorites: |
case ListFavorites: |
168 |
dialogTitle = "TrainInfo DK - Favorites"; |
dialogTitle += " - " + getString(stationlist_favorites); |
169 |
break; |
break; |
170 |
default: |
default: |
171 |
dialogTitle = "";//not possible |
dialogTitle = "";//not possible |
172 |
} |
} |
173 |
|
|
174 |
setTitle(dialogTitle); |
setTitle(dialogTitle); |
175 |
|
|
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
/* these 3 dialogs helper functions are very rude and ugly hack |
180 |
|
* to remove these auto-reported exceptions |
181 |
|
* - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running? |
182 |
|
* - java.lang.IllegalArgumentException: View not attached to window manager |
183 |
|
*/ |
184 |
|
|
185 |
|
public void showDialogSafe(int id) { |
186 |
|
try { |
187 |
|
showDialog(id); |
188 |
|
} catch (Exception e) { |
189 |
|
Log.e("StationList", "showDialog failed", e); |
190 |
|
} |
191 |
} |
} |
192 |
|
|
193 |
|
public void dismissDialogSafe(int id) { |
194 |
|
try { |
195 |
|
dismissDialog(id); |
196 |
|
} catch (Exception e) { |
197 |
|
Log.e("StationList", "dismissDialog failed", e); |
198 |
|
} |
199 |
|
} |
200 |
|
public void dismissDialogSafe(Dialog dlg) { |
201 |
|
try { |
202 |
|
dlg.dismiss(); |
203 |
|
} catch (Exception e) { |
204 |
|
Log.e("StationList", "dismissDialog failed", e); |
205 |
|
} |
206 |
|
} |
207 |
|
|
208 |
|
public void builderShowSafe(AlertDialog.Builder builder) { |
209 |
|
try { |
210 |
|
builder.show(); |
211 |
|
} catch (Exception e) { |
212 |
|
Log.e("StationList", "builder.show() failed", e); |
213 |
|
} |
214 |
|
|
215 |
|
} |
216 |
|
/* EOF rude and ugly dialog hack */ |
217 |
|
|
218 |
|
|
219 |
|
|
232 |
@Override |
@Override |
233 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
234 |
MenuItem item; |
MenuItem item; |
235 |
|
|
236 |
item = menu.add(0, OPTIONS_MAP, 0, "Station map"); |
item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap)); |
237 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
238 |
|
|
239 |
item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info"); |
item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo)); |
240 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
241 |
|
|
242 |
return true; |
return true; |
251 |
case OPTIONS_MAP: |
case OPTIONS_MAP: |
252 |
|
|
253 |
Intent intent = new Intent(this,StationMapView.class); |
Intent intent = new Intent(this,StationMapView.class); |
|
intent.putExtra("userlocation", location ); |
|
254 |
|
|
255 |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
256 |
for (StationBean st : stations ) { |
for (StationBean st : stations ) { |
264 |
case OPTIONS_GPSINFO: |
case OPTIONS_GPSINFO: |
265 |
Location loc = locationLookup.getLocation(); |
Location loc = locationLookup.getLocation(); |
266 |
StringBuffer message = new StringBuffer(); |
StringBuffer message = new StringBuffer(); |
267 |
message.append("Location info:\n"); |
message.append( getString(stationlist_locationinfo) ).append(":\n"); |
268 |
message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n"); |
if (loc != null) { |
269 |
message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n"); |
message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); |
270 |
|
message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); |
271 |
MessageBox.showMessage(this, message.toString()); |
message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); |
272 |
|
message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); |
273 |
|
} else { |
274 |
|
message.append( getString(stationlist_nolocation) ); |
275 |
|
} |
276 |
|
|
277 |
|
MessageBox.showMessage(this, message.toString(), false); |
278 |
break; |
break; |
279 |
default: |
default: |
280 |
retval = super.onOptionsItemSelected(item); |
retval = super.onOptionsItemSelected(item); |
292 |
|
|
293 |
|
|
294 |
} |
} |
295 |
|
|
296 |
|
public void showMessageAndClose(String message) { |
297 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
298 |
|
builder.setMessage(message) |
299 |
|
.setCancelable(false) |
300 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
301 |
|
public void onClick(DialogInterface dialog, int id) { |
302 |
|
dialog.dismiss(); |
303 |
|
StationList.this.finish(); |
304 |
|
} |
305 |
|
}) |
306 |
|
.show(); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
314 |
switch (id) { |
switch (id) { |
315 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
316 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
317 |
dlg.setMessage("Wait for location fix"); |
dlg.setMessage( getString(stationlist_waitforlocation) ); |
318 |
dlg.setCancelable(false); |
dlg.setCancelable(false); |
319 |
return dlg; |
return dlg; |
320 |
case DLG_STATIONNAME: |
case DLG_STATIONNAME: |
324 |
|
|
325 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
326 |
|
|
327 |
builder.setTitle("Station search"); |
builder.setTitle( getString(stationlist_stationsearch) ); |
328 |
builder.setView(rootView); |
builder.setView(rootView); |
329 |
builder.setCancelable(true); |
builder.setCancelable(true); |
330 |
builder.setPositiveButton("Search", new DialogInterface.OnClickListener() { |
builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() { |
331 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
332 |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
333 |
dialog.dismiss(); |
dialog.dismiss(); |
334 |
if (et.getText().toString().length() >= 2) { |
String search = et.getText().toString().trim(); |
335 |
startNameSearch(et.getText().toString()); |
if (search.length() >= 2) { |
336 |
|
startNameSearch(search); |
337 |
} else { |
} else { |
338 |
MessageBox.showMessage(StationList.this, "Two characters minimum" ); |
showMessageAndClose( getString(stationlist_twocharmin) ); |
339 |
} |
} |
340 |
} |
} |
341 |
}); |
}); |
342 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
343 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
344 |
dialog.dismiss(); |
dialog.dismiss(); |
345 |
|
StationList.this.finish(); // Close this Activity |
346 |
} |
} |
347 |
}); |
}); |
348 |
return builder.create(); |
return builder.create(); |
373 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
374 |
|
|
375 |
StationBean station = stations.get(position); |
StationBean station = stations.get(position); |
|
|
|
|
double latitude = station.getLatitude(); |
|
|
double longitude = station.getLongitude(); |
|
|
|
|
|
|
|
376 |
|
|
377 |
Intent intent = new Intent(this, DepartureList.class); |
if (isLaunchedforShortcut == true) { |
378 |
intent.putExtra("name", station.getName()); |
Intent i = new Intent(); |
379 |
intent.putExtra("distance", station.getDistance()); |
i.putExtra("station", station); |
380 |
intent.putExtra("latitude", latitude); |
setResult(Activity.RESULT_OK, i); |
381 |
intent.putExtra("longitude", longitude); |
finish(); |
382 |
intent.putExtra("stationid", station.getId()); |
} else { |
383 |
intent.putExtra("address", station.getAddress()); |
Intent intent = new Intent(this, DepartureList.class); |
384 |
startActivity(intent); |
intent.putExtra("stationbean", station); |
385 |
|
startActivity(intent); |
386 |
|
} |
387 |
} |
} |
388 |
|
|
389 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
390 |
// |
// |
391 |
|
|
392 |
public void startLookup() { |
public void startLookup() { |
393 |
isRunning = true; |
isRunning = true; |
394 |
dialogMessage = "Wait for location fix"; |
dialogMessage = getString( stationlist_waitforlocation ); |
395 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
396 |
|
|
397 |
locationLookup.locateStations(); |
locationLookup.locateStations(); |
398 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
399 |
} |
} |
400 |
|
|
401 |
void startNameSearch(String name) { |
void startNameSearch(String name) { |
402 |
dialogMessage = "Finding stations by name"; |
dialogMessage = getString( stationlist_findbyname ); |
403 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
404 |
|
|
405 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
406 |
findStationsTask.searchByName(name, locationLookup.getLocation()); |
findStationsTask.searchByName(name); |
407 |
findStationsTask.execute(); |
findStationsTask.execute(); |
408 |
|
|
409 |
} |
} |
411 |
public void startFavoriteLookup() { |
public void startFavoriteLookup() { |
412 |
|
|
413 |
if (favorites.size() > 0) { |
if (favorites.size() > 0) { |
414 |
dialogMessage = "Loading favorites"; |
dialogMessage = getString( stationlist_loadfavorites ); |
415 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
416 |
|
|
417 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
418 |
findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); |
findStationsTask.searchByIds( favorites.toString() ); |
419 |
findStationsTask.execute(); |
findStationsTask.execute(); |
420 |
} else { |
} else { |
421 |
MessageBox.showMessage(this, "Favorite list is empty"); |
showMessageAndClose( getString( stationlist_nofavorites ) ); |
422 |
} |
} |
423 |
} |
} |
424 |
|
|
426 |
|
|
427 |
void startLocatorTask() |
void startLocatorTask() |
428 |
{ |
{ |
429 |
dialogMessage = "Finding nearby stations"; |
dialogMessage = getString( stationlist_findingnearby ); |
430 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
431 |
|
|
432 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
433 |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
434 |
findStationsTask.execute(); |
findStationsTask.execute(); |
435 |
} |
} |
|
|
|
|
|
|
|
String lookupAddress(double latitude, double longitude) { |
|
436 |
|
|
|
Geocoder coder = new Geocoder(this, new Locale("da")); |
|
|
StringBuilder sb = new StringBuilder(); |
|
|
Log.i("lookupaddr", "" + latitude + "/" + longitude); |
|
|
try { |
|
|
List<Address> addressList = coder.getFromLocation(latitude, longitude, 1); |
|
|
Address addr = addressList.get(0); |
|
|
|
|
|
|
|
|
int max = addr.getMaxAddressLineIndex(); |
|
|
for (int i=0; i<max; i++) { |
|
|
if (i>0) |
|
|
sb.append(", "); |
|
|
|
|
|
sb.append(addr.getAddressLine(i)); |
|
|
} |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
Log.e("DepartureList", "geocoder failed", e); |
|
|
} |
|
|
|
|
|
return sb.toString(); |
|
|
} |
|
|
|
|
437 |
|
|
438 |
//////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////// |
439 |
// Inner classes |
// Inner classes |
444 |
|
|
445 |
switch (msg.what) { |
switch (msg.what) { |
446 |
case GOTLOCATION: |
case GOTLOCATION: |
447 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
448 |
|
|
449 |
startLocatorTask(); |
startLocatorTask(); |
450 |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
452 |
break; |
break; |
453 |
|
|
454 |
case NOPROVIDER: |
case NOPROVIDER: |
455 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
456 |
MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps."); |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
457 |
|
//StationList.this.finish(); |
458 |
break; |
break; |
459 |
case LOCATIONFIXTIMEOUT: |
case LOCATIONFIXTIMEOUT: |
460 |
if (isRunning) { |
if (isRunning) { |
462 |
if (locationLookup.hasLocation()) { |
if (locationLookup.hasLocation()) { |
463 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
464 |
} else { |
} else { |
465 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
466 |
|
|
467 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
468 |
builder.setMessage("Location fix timed out"); |
builder.setMessage( getString( stationlist_gpstimeout) ); |
469 |
builder.setCancelable(true); |
builder.setCancelable(true); |
470 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
471 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
472 |
dialog.dismiss(); |
dialog.dismiss(); |
473 |
startLookup(); |
startLookup(); |
474 |
|
|
475 |
} |
} |
476 |
}); |
}); |
477 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() { |
478 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
479 |
dialog.dismiss(); |
dialog.dismiss(); |
480 |
} |
} |
481 |
}); |
}); |
482 |
builder.show(); |
builderShowSafe(builder); // builder.show() |
483 |
|
|
484 |
} |
} |
485 |
} |
} |
498 |
Location loc; |
Location loc; |
499 |
String ids; |
String ids; |
500 |
|
|
501 |
public void searchByName(String n, Location l) { |
public void searchByName(String n) { |
502 |
|
|
503 |
method = LookupMethod.ByName; |
method = LookupMethod.ByName; |
|
loc = l; |
|
504 |
name = n; |
name = n; |
505 |
} |
} |
506 |
|
|
509 |
loc = l; |
loc = l; |
510 |
} |
} |
511 |
|
|
512 |
public void searchByIds(String id, Location l) { |
public void searchByIds(String id) { |
513 |
|
|
514 |
method = LookupMethod.ByList; |
method = LookupMethod.ByList; |
|
loc = l; |
|
515 |
ids = id; |
ids = id; |
516 |
} |
} |
517 |
|
|
541 |
} |
} |
542 |
|
|
543 |
|
|
|
Location dummy = new Location("gps"); |
|
|
List<StationBean> stations = stationProvider.getStations(); |
|
|
|
|
|
for (StationBean station : stations) { |
|
|
String addr = lookupAddress(station.getLatitude(), station.getLongitude()); |
|
|
station.setAddress(addr); |
|
|
|
|
|
|
|
|
if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) { |
|
|
if (loc != null) { //only do the distance calc if we have a location |
|
|
dummy.setLatitude(station.getLatitude()); |
|
|
dummy.setLongitude(station.getLongitude()); |
|
|
station.setDistance( (int)loc.distanceTo(dummy) ); |
|
|
} else { |
|
|
station.setDistance(0); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
544 |
return null; |
return null; |
545 |
} |
} |
546 |
|
|
547 |
@Override |
@Override |
548 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
549 |
super.onPostExecute(result); |
super.onPostExecute(result); |
550 |
dialog.dismiss(); |
dismissDialogSafe(dialog); |
551 |
|
|
552 |
|
|
553 |
if (success) { |
if (success) { |
554 |
if (stationProvider.getStations().size() == 0) |
if (stationProvider.getStations().size() == 0) { |
555 |
MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?! |
showMessageAndClose(getString(stationlist_nostations)); |
556 |
|
} |
557 |
stations = stationProvider.getStations(); |
stations = stationProvider.getStations(); |
558 |
|
|
559 |
|
StationList.this.getListView().invalidateViews(); |
560 |
adapter.setStations( stations ); |
adapter.setStations( stations ); |
561 |
|
|
562 |
|
|
563 |
} else { //communication or parse errors |
} else { //communication or parse errors |
564 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
565 |
builder.setMessage("Error on finding nearby stations"); |
builder.setMessage(getString(stationlist_fetcherror)); |
566 |
builder.setCancelable(true); |
builder.setCancelable(true); |
567 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
568 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
569 |
dialog.dismiss(); |
dialog.dismiss(); |
570 |
|
|
571 |
stationsFetched.post( new Runnable() { |
Runnable runner = null; |
572 |
@Override |
switch (method) { |
573 |
public void run() { |
case ByLocation: |
574 |
startLocatorTask(); |
runner = new Runnable() { |
575 |
} |
@Override |
576 |
}); |
public void run() { |
577 |
|
startLocatorTask(); |
578 |
|
} |
579 |
|
}; |
580 |
|
break; |
581 |
|
case ByName: |
582 |
|
runner = new Runnable() { |
583 |
|
@Override |
584 |
|
public void run() { |
585 |
|
startNameSearch( FindStationsTask.this.name ); |
586 |
|
} |
587 |
|
}; |
588 |
|
break; |
589 |
|
case ByList: |
590 |
|
runner = new Runnable() { |
591 |
|
@Override |
592 |
|
public void run() { |
593 |
|
startFavoriteLookup(); |
594 |
|
} |
595 |
|
}; |
596 |
|
break; |
597 |
|
} |
598 |
|
|
599 |
|
stationsFetched.post( runner ); |
600 |
} |
} |
601 |
}); |
}); |
602 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
603 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
604 |
dialog.dismiss(); |
dialog.dismiss(); |
605 |
|
StationList.this.finish(); |
606 |
} |
} |
607 |
}); |
}); |
608 |
builder.show(); |
|
609 |
|
builderShowSafe(builder); // builder.show() |
610 |
} |
} |
611 |
} |
} |
612 |
} |
} |
627 |
int stationID = stations.get(selectedPosition).getId(); |
int stationID = stations.get(selectedPosition).getId(); |
628 |
|
|
629 |
if (!favorites.contains(stationID)) { |
if (!favorites.contains(stationID)) { |
630 |
menu.add(0, FAVORITES_ADD, 0, "Add to favorites"); |
menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) ); |
631 |
} else { |
} else { |
632 |
menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites"); |
menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) ); |
633 |
} |
} |
634 |
|
|
635 |
} |
} |
640 |
int stationID = sb.getId(); |
int stationID = sb.getId(); |
641 |
if (item.getItemId() == FAVORITES_ADD) { |
if (item.getItemId() == FAVORITES_ADD) { |
642 |
favorites.add(stationID); |
favorites.add(stationID); |
643 |
Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show(); |
644 |
} else { |
} else { |
645 |
|
|
646 |
favorites.remove(stationID); |
favorites.remove(stationID); |
647 |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show(); |
648 |
|
|
649 |
|
|
650 |
if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) { |
if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) { |