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 |
|
} |
152 |
|
|
153 |
|
|
154 |
protected void setTitle() { |
protected void setTitle() { |
155 |
String dialogTitle = getResources().getString(R.string.app_name); |
String dialogTitle = getResources().getString(app_name); |
156 |
switch (listType) { |
switch (listType) { |
157 |
case ListNearest: |
case ListNearest: |
158 |
dialogTitle += " - Nearby stations"; |
dialogTitle += " - " + getString(stationlist_nearbystations); |
159 |
break; |
break; |
160 |
case ListSearch: |
case ListSearch: |
161 |
dialogTitle += " - Search"; |
dialogTitle += " - " + getString(stationlist_search); |
162 |
break; |
break; |
163 |
case ListFavorites: |
case ListFavorites: |
164 |
dialogTitle += " - Favorites"; |
dialogTitle += " - " + getString(stationlist_favorites); |
165 |
break; |
break; |
166 |
default: |
default: |
167 |
dialogTitle = "";//not possible |
dialogTitle = "";//not possible |
168 |
} |
} |
169 |
|
|
170 |
setTitle(dialogTitle); |
setTitle(dialogTitle); |
171 |
|
|
172 |
} |
} |
173 |
|
|
174 |
|
|
175 |
|
/* these 3 dialogs helper functions are very rude and ugly hack |
176 |
|
* to remove these auto-reported exceptions |
177 |
|
* - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running? |
178 |
|
* - java.lang.IllegalArgumentException: View not attached to window manager |
179 |
|
*/ |
180 |
|
|
181 |
|
public void showDialogSafe(int id) { |
182 |
|
try { |
183 |
|
showDialog(id); |
184 |
|
} catch (Exception e) { |
185 |
|
Log.e("StationList", "showDialog failed", e); |
186 |
|
} |
187 |
|
} |
188 |
|
|
189 |
|
public void dismissDialogSafe(int id) { |
190 |
|
try { |
191 |
|
dismissDialog(id); |
192 |
|
} catch (Exception e) { |
193 |
|
Log.e("StationList", "dismissDialog failed", e); |
194 |
|
} |
195 |
|
} |
196 |
|
public void dismissDialogSafe(Dialog dlg) { |
197 |
|
try { |
198 |
|
dlg.dismiss(); |
199 |
|
} catch (Exception e) { |
200 |
|
Log.e("StationList", "dismissDialog failed", e); |
201 |
|
} |
202 |
|
} |
203 |
|
|
204 |
|
public void builderShowSafe(AlertDialog.Builder builder) { |
205 |
|
try { |
206 |
|
builder.show(); |
207 |
|
} catch (Exception e) { |
208 |
|
Log.e("StationList", "builder.show() failed", e); |
209 |
|
} |
210 |
|
|
211 |
|
} |
212 |
|
/* EOF rude and ugly dialog hack */ |
213 |
|
|
214 |
|
|
215 |
|
|
216 |
@Override |
@Override |
228 |
@Override |
@Override |
229 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
230 |
MenuItem item; |
MenuItem item; |
231 |
|
|
232 |
item = menu.add(0, OPTIONS_MAP, 0, "Station map"); |
item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap)); |
233 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
234 |
|
|
235 |
item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info"); |
item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo)); |
236 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
237 |
|
|
238 |
return true; |
return true; |
247 |
case OPTIONS_MAP: |
case OPTIONS_MAP: |
248 |
|
|
249 |
Intent intent = new Intent(this,StationMapView.class); |
Intent intent = new Intent(this,StationMapView.class); |
|
intent.putExtra("userlocation", location ); |
|
250 |
|
|
251 |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
252 |
for (StationBean st : stations ) { |
for (StationBean st : stations ) { |
260 |
case OPTIONS_GPSINFO: |
case OPTIONS_GPSINFO: |
261 |
Location loc = locationLookup.getLocation(); |
Location loc = locationLookup.getLocation(); |
262 |
StringBuffer message = new StringBuffer(); |
StringBuffer message = new StringBuffer(); |
263 |
message.append("Location info:\n"); |
message.append( getString(stationlist_locationinfo) ).append(":\n"); |
264 |
message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n"); |
if (loc != null) { |
265 |
message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n"); |
message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n"); |
266 |
|
message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n"); |
267 |
MessageBox.showMessage(this, message.toString()); |
message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n"); |
268 |
|
message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n"); |
269 |
|
} else { |
270 |
|
message.append( getString(stationlist_nolocation) ); |
271 |
|
} |
272 |
|
|
273 |
|
MessageBox.showMessage(this, message.toString(), false); |
274 |
break; |
break; |
275 |
default: |
default: |
276 |
retval = super.onOptionsItemSelected(item); |
retval = super.onOptionsItemSelected(item); |
288 |
|
|
289 |
|
|
290 |
} |
} |
291 |
|
|
292 |
|
public void showMessageAndClose(String message) { |
293 |
|
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
294 |
|
builder.setMessage(message) |
295 |
|
.setCancelable(false) |
296 |
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
297 |
|
public void onClick(DialogInterface dialog, int id) { |
298 |
|
dialog.dismiss(); |
299 |
|
StationList.this.finish(); |
300 |
|
} |
301 |
|
}) |
302 |
|
.show(); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
310 |
switch (id) { |
switch (id) { |
311 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
312 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
313 |
dlg.setMessage("Wait for location fix"); |
dlg.setMessage( getString(stationlist_waitforlocation) ); |
314 |
dlg.setCancelable(false); |
dlg.setCancelable(false); |
315 |
return dlg; |
return dlg; |
316 |
case DLG_STATIONNAME: |
case DLG_STATIONNAME: |
320 |
|
|
321 |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
AlertDialog.Builder builder = new AlertDialog.Builder(this); |
322 |
|
|
323 |
builder.setTitle("Station search"); |
builder.setTitle( getString(stationlist_stationsearch) ); |
324 |
builder.setView(rootView); |
builder.setView(rootView); |
325 |
builder.setCancelable(true); |
builder.setCancelable(true); |
326 |
builder.setPositiveButton("Search", new DialogInterface.OnClickListener() { |
builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() { |
327 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
328 |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
329 |
dialog.dismiss(); |
dialog.dismiss(); |
330 |
if (et.getText().toString().length() >= 2) { |
String search = et.getText().toString().trim(); |
331 |
startNameSearch(et.getText().toString()); |
if (search.length() >= 2) { |
332 |
|
startNameSearch(search); |
333 |
} else { |
} else { |
334 |
MessageBox.showMessage(StationList.this, "Two characters minimum" ); |
showMessageAndClose( getString(stationlist_twocharmin) ); |
335 |
} |
} |
336 |
} |
} |
337 |
}); |
}); |
338 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
339 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
340 |
dialog.dismiss(); |
dialog.dismiss(); |
341 |
|
StationList.this.finish(); // Close this Activity |
342 |
} |
} |
343 |
}); |
}); |
344 |
return builder.create(); |
return builder.create(); |
369 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
370 |
|
|
371 |
StationBean station = stations.get(position); |
StationBean station = stations.get(position); |
|
|
|
|
double latitude = station.getLatitude(); |
|
|
double longitude = station.getLongitude(); |
|
|
|
|
|
|
|
372 |
|
|
373 |
Intent intent = new Intent(this, DepartureList.class); |
if (isLaunchedforShortcut == true) { |
374 |
intent.putExtra("name", station.getName()); |
Intent i = new Intent(); |
375 |
intent.putExtra("distance", station.getDistance()); |
i.putExtra("station", station); |
376 |
intent.putExtra("latitude", latitude); |
setResult(Activity.RESULT_OK, i); |
377 |
intent.putExtra("longitude", longitude); |
finish(); |
378 |
intent.putExtra("stationid", station.getId()); |
} else { |
379 |
intent.putExtra("address", station.getAddress()); |
Intent intent = new Intent(this, DepartureList.class); |
380 |
startActivity(intent); |
intent.putExtra("stationbean", station); |
381 |
|
startActivity(intent); |
382 |
|
} |
383 |
} |
} |
384 |
|
|
385 |
///////////////////////////////////////////////////////////// |
///////////////////////////////////////////////////////////// |
386 |
// |
// |
387 |
|
|
388 |
public void startLookup() { |
public void startLookup() { |
389 |
isRunning = true; |
isRunning = true; |
390 |
dialogMessage = "Wait for location fix"; |
dialogMessage = getString( stationlist_waitforlocation ); |
391 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
392 |
|
|
393 |
locationLookup.locateStations(); |
locationLookup.locateStations(); |
394 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
395 |
} |
} |
396 |
|
|
397 |
void startNameSearch(String name) { |
void startNameSearch(String name) { |
398 |
dialogMessage = "Finding stations by name"; |
dialogMessage = getString( stationlist_findbyname ); |
399 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
400 |
|
|
401 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
402 |
findStationsTask.searchByName(name, locationLookup.getLocation()); |
findStationsTask.searchByName(name); |
403 |
findStationsTask.execute(); |
findStationsTask.execute(); |
404 |
|
|
405 |
} |
} |
407 |
public void startFavoriteLookup() { |
public void startFavoriteLookup() { |
408 |
|
|
409 |
if (favorites.size() > 0) { |
if (favorites.size() > 0) { |
410 |
dialogMessage = "Loading favorites"; |
dialogMessage = getString( stationlist_loadfavorites ); |
411 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
412 |
|
|
413 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
414 |
findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); |
findStationsTask.searchByIds( favorites.toString() ); |
415 |
findStationsTask.execute(); |
findStationsTask.execute(); |
416 |
} else { |
} else { |
417 |
MessageBox.showMessage(this, "Favorite list is empty"); |
showMessageAndClose( getString( stationlist_nofavorites ) ); |
418 |
} |
} |
419 |
} |
} |
420 |
|
|
422 |
|
|
423 |
void startLocatorTask() |
void startLocatorTask() |
424 |
{ |
{ |
425 |
dialogMessage = "Finding nearby stations"; |
dialogMessage = getString( stationlist_findingnearby ); |
426 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
427 |
|
|
428 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
429 |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
430 |
findStationsTask.execute(); |
findStationsTask.execute(); |
431 |
} |
} |
|
|
|
|
|
|
|
String lookupAddress(double latitude, double longitude) { |
|
432 |
|
|
|
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(); |
|
|
} |
|
|
|
|
433 |
|
|
434 |
//////////////////////////////////////////////////////////////////////////// |
//////////////////////////////////////////////////////////////////////////// |
435 |
// Inner classes |
// Inner classes |
440 |
|
|
441 |
switch (msg.what) { |
switch (msg.what) { |
442 |
case GOTLOCATION: |
case GOTLOCATION: |
443 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
444 |
|
|
445 |
startLocatorTask(); |
startLocatorTask(); |
446 |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
448 |
break; |
break; |
449 |
|
|
450 |
case NOPROVIDER: |
case NOPROVIDER: |
451 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
452 |
MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps."); |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
453 |
|
//StationList.this.finish(); |
454 |
break; |
break; |
455 |
case LOCATIONFIXTIMEOUT: |
case LOCATIONFIXTIMEOUT: |
456 |
if (isRunning) { |
if (isRunning) { |
458 |
if (locationLookup.hasLocation()) { |
if (locationLookup.hasLocation()) { |
459 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
460 |
} else { |
} else { |
461 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
462 |
|
|
463 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
464 |
builder.setMessage("Location fix timed out"); |
builder.setMessage( getString( stationlist_gpstimeout) ); |
465 |
builder.setCancelable(true); |
builder.setCancelable(true); |
466 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
467 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
468 |
dialog.dismiss(); |
dialog.dismiss(); |
469 |
startLookup(); |
startLookup(); |
470 |
|
|
471 |
} |
} |
472 |
}); |
}); |
473 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() { |
474 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
475 |
dialog.dismiss(); |
dialog.dismiss(); |
476 |
} |
} |
477 |
}); |
}); |
478 |
builder.show(); |
builderShowSafe(builder); // builder.show() |
479 |
|
|
480 |
} |
} |
481 |
} |
} |
494 |
Location loc; |
Location loc; |
495 |
String ids; |
String ids; |
496 |
|
|
497 |
public void searchByName(String n, Location l) { |
public void searchByName(String n) { |
498 |
|
|
499 |
method = LookupMethod.ByName; |
method = LookupMethod.ByName; |
|
loc = l; |
|
500 |
name = n; |
name = n; |
501 |
} |
} |
502 |
|
|
505 |
loc = l; |
loc = l; |
506 |
} |
} |
507 |
|
|
508 |
public void searchByIds(String id, Location l) { |
public void searchByIds(String id) { |
509 |
|
|
510 |
method = LookupMethod.ByList; |
method = LookupMethod.ByList; |
|
loc = l; |
|
511 |
ids = id; |
ids = id; |
512 |
} |
} |
513 |
|
|
537 |
} |
} |
538 |
|
|
539 |
|
|
|
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); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
540 |
return null; |
return null; |
541 |
} |
} |
542 |
|
|
543 |
@Override |
@Override |
544 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
545 |
super.onPostExecute(result); |
super.onPostExecute(result); |
546 |
dialog.dismiss(); |
dismissDialogSafe(dialog); |
547 |
|
|
548 |
|
|
549 |
if (success) { |
if (success) { |
550 |
if (stationProvider.getStations().size() == 0) |
if (stationProvider.getStations().size() == 0) { |
551 |
MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?! |
showMessageAndClose(getString(stationlist_nostations)); |
552 |
|
} |
553 |
stations = stationProvider.getStations(); |
stations = stationProvider.getStations(); |
554 |
|
|
555 |
|
StationList.this.getListView().invalidateViews(); |
556 |
adapter.setStations( stations ); |
adapter.setStations( stations ); |
557 |
|
|
558 |
|
|
559 |
} else { //communication or parse errors |
} else { //communication or parse errors |
560 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
561 |
builder.setMessage("Error on finding nearby stations"); |
builder.setMessage(getString(stationlist_fetcherror)); |
562 |
builder.setCancelable(true); |
builder.setCancelable(true); |
563 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
564 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
565 |
dialog.dismiss(); |
dialog.dismiss(); |
566 |
|
|
567 |
stationsFetched.post( new Runnable() { |
Runnable runner = null; |
568 |
@Override |
switch (method) { |
569 |
public void run() { |
case ByLocation: |
570 |
startLocatorTask(); |
runner = new Runnable() { |
571 |
} |
@Override |
572 |
}); |
public void run() { |
573 |
|
startLocatorTask(); |
574 |
|
} |
575 |
|
}; |
576 |
|
break; |
577 |
|
case ByName: |
578 |
|
runner = new Runnable() { |
579 |
|
@Override |
580 |
|
public void run() { |
581 |
|
startNameSearch( FindStationsTask.this.name ); |
582 |
|
} |
583 |
|
}; |
584 |
|
break; |
585 |
|
case ByList: |
586 |
|
runner = new Runnable() { |
587 |
|
@Override |
588 |
|
public void run() { |
589 |
|
startFavoriteLookup(); |
590 |
|
} |
591 |
|
}; |
592 |
|
break; |
593 |
|
} |
594 |
|
|
595 |
|
stationsFetched.post( runner ); |
596 |
} |
} |
597 |
}); |
}); |
598 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
599 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
600 |
dialog.dismiss(); |
dialog.dismiss(); |
601 |
|
StationList.this.finish(); |
602 |
} |
} |
603 |
}); |
}); |
604 |
builder.show(); |
|
605 |
|
builderShowSafe(builder); // builder.show() |
606 |
} |
} |
607 |
} |
} |
608 |
} |
} |
623 |
int stationID = stations.get(selectedPosition).getId(); |
int stationID = stations.get(selectedPosition).getId(); |
624 |
|
|
625 |
if (!favorites.contains(stationID)) { |
if (!favorites.contains(stationID)) { |
626 |
menu.add(0, FAVORITES_ADD, 0, "Add to favorites"); |
menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) ); |
627 |
} else { |
} else { |
628 |
menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites"); |
menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) ); |
629 |
} |
} |
630 |
|
|
631 |
} |
} |
636 |
int stationID = sb.getId(); |
int stationID = sb.getId(); |
637 |
if (item.getItemId() == FAVORITES_ADD) { |
if (item.getItemId() == FAVORITES_ADD) { |
638 |
favorites.add(stationID); |
favorites.add(stationID); |
639 |
Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show(); |
640 |
} else { |
} else { |
641 |
|
|
642 |
favorites.remove(stationID); |
favorites.remove(stationID); |
643 |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show(); |
644 |
|
|
645 |
|
|
646 |
if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) { |
if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) { |