119 |
startLookup(); |
startLookup(); |
120 |
break; |
break; |
121 |
case ListSearch: |
case ListSearch: |
122 |
this.showDialog(DLG_STATIONNAME); |
this.showDialogSafe(DLG_STATIONNAME); |
123 |
break; |
break; |
124 |
case ListFavorites: |
case ListFavorites: |
125 |
startFavoriteLookup(); |
startFavoriteLookup(); |
152 |
} |
} |
153 |
|
|
154 |
setTitle(dialogTitle); |
setTitle(dialogTitle); |
155 |
|
|
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
/* these 3 dialogs helper functions are very rude and ugly hack |
160 |
|
* to remove these auto-reported exceptions |
161 |
|
* - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running? |
162 |
|
* - java.lang.IllegalArgumentException: View not attached to window manager |
163 |
|
*/ |
164 |
|
|
165 |
|
public void showDialogSafe(int id) { |
166 |
|
try { |
167 |
|
showDialog(id); |
168 |
|
} catch (Exception e) { |
169 |
|
Log.e("StationList", "showDialog failed", e); |
170 |
|
} |
171 |
|
} |
172 |
|
|
173 |
|
public void dismissDialogSafe(int id) { |
174 |
|
try { |
175 |
|
dismissDialog(id); |
176 |
|
} catch (Exception e) { |
177 |
|
Log.e("StationList", "dismissDialog failed", e); |
178 |
|
} |
179 |
} |
} |
180 |
|
|
181 |
|
public void builderShowSafe(AlertDialog.Builder builder) { |
182 |
|
try { |
183 |
|
builder.show(); |
184 |
|
} catch (Exception e) { |
185 |
|
Log.e("StationList", "builder.show() failed", e); |
186 |
|
} |
187 |
|
|
188 |
|
} |
189 |
|
/* EOF rude and ugly dialog hack */ |
190 |
|
|
191 |
|
|
192 |
|
|
304 |
public void onClick(DialogInterface dialog, int which) { |
public void onClick(DialogInterface dialog, int which) { |
305 |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
EditText et = (EditText) rootView.findViewById(R.id.EditText); |
306 |
dialog.dismiss(); |
dialog.dismiss(); |
307 |
if (et.getText().toString().length() >= 2) { |
String search = et.getText().toString().trim(); |
308 |
startNameSearch(et.getText().toString()); |
if (search.length() >= 2) { |
309 |
|
startNameSearch(search); |
310 |
} else { |
} else { |
311 |
showMessageAndClose( getString(stationlist_twocharmin) ); |
showMessageAndClose( getString(stationlist_twocharmin) ); |
312 |
} |
} |
358 |
public void startLookup() { |
public void startLookup() { |
359 |
isRunning = true; |
isRunning = true; |
360 |
dialogMessage = getString( stationlist_waitforlocation ); |
dialogMessage = getString( stationlist_waitforlocation ); |
361 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
362 |
|
|
363 |
locationLookup.locateStations(); |
locationLookup.locateStations(); |
364 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
366 |
|
|
367 |
void startNameSearch(String name) { |
void startNameSearch(String name) { |
368 |
dialogMessage = getString( stationlist_findbyname ); |
dialogMessage = getString( stationlist_findbyname ); |
369 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
370 |
|
|
371 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
372 |
findStationsTask.searchByName(name); |
findStationsTask.searchByName(name); |
378 |
|
|
379 |
if (favorites.size() > 0) { |
if (favorites.size() > 0) { |
380 |
dialogMessage = getString( stationlist_loadfavorites ); |
dialogMessage = getString( stationlist_loadfavorites ); |
381 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
382 |
|
|
383 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
384 |
findStationsTask.searchByIds( favorites.toString() ); |
findStationsTask.searchByIds( favorites.toString() ); |
393 |
void startLocatorTask() |
void startLocatorTask() |
394 |
{ |
{ |
395 |
dialogMessage = getString( stationlist_findingnearby ); |
dialogMessage = getString( stationlist_findingnearby ); |
396 |
showDialog(DLG_PROGRESS); |
showDialogSafe(DLG_PROGRESS); |
397 |
|
|
398 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
399 |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
410 |
|
|
411 |
switch (msg.what) { |
switch (msg.what) { |
412 |
case GOTLOCATION: |
case GOTLOCATION: |
413 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
414 |
|
|
415 |
startLocatorTask(); |
startLocatorTask(); |
416 |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
418 |
break; |
break; |
419 |
|
|
420 |
case NOPROVIDER: |
case NOPROVIDER: |
421 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
422 |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) ); |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) ); |
423 |
break; |
break; |
424 |
case LOCATIONFIXTIMEOUT: |
case LOCATIONFIXTIMEOUT: |
427 |
if (locationLookup.hasLocation()) { |
if (locationLookup.hasLocation()) { |
428 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
429 |
} else { |
} else { |
430 |
dismissDialog(DLG_PROGRESS); |
dismissDialogSafe(DLG_PROGRESS); |
431 |
|
|
432 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
433 |
builder.setMessage( getString( stationlist_gpstimeout) ); |
builder.setMessage( getString( stationlist_gpstimeout) ); |
443 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
444 |
dialog.dismiss(); |
dialog.dismiss(); |
445 |
} |
} |
446 |
}); |
}); |
447 |
builder.show(); |
builderShowSafe(builder); // builder.show() |
448 |
|
|
449 |
} |
} |
450 |
} |
} |
565 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
566 |
dialog.dismiss(); |
dialog.dismiss(); |
567 |
} |
} |
568 |
}); |
}); |
569 |
try { |
|
570 |
builder.show(); |
builderShowSafe(builder); // builder.show() |
|
} catch (android.view.WindowManager.BadTokenException e) { |
|
|
Log.i("StationList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |
|
|
} |
|
571 |
} |
} |
572 |
} |
} |
573 |
} |
} |