52 |
public static final int DLG_STATIONNAME = 3002; |
public static final int DLG_STATIONNAME = 3002; |
53 |
|
|
54 |
|
|
55 |
public static final int GPS_TIMEOUT_MS = 17500; //how long are we willing to wait for gps fix -in milliseconds |
public static final int GPS_TIMEOUT_MS = 15000; //how long are we willing to wait for gps fix -in milliseconds |
56 |
|
|
57 |
|
|
58 |
static enum LookupMethod { |
static enum LookupMethod { |
123 |
startLookup(); |
startLookup(); |
124 |
break; |
break; |
125 |
case ListSearch: |
case ListSearch: |
126 |
showDialog(DLG_STATIONNAME); //TODO: this.showDialogSafe(DLG_STATIONNAME); |
showDialog(DLG_STATIONNAME); |
127 |
break; |
break; |
128 |
case ListFavorites: |
case ListFavorites: |
129 |
startFavoriteLookup(); |
startFavoriteLookup(); |
140 |
|
|
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@Override |
147 |
|
protected void onStart() { |
148 |
|
super.onStart(); |
149 |
|
ProviderFactory.purgeOldEntries(); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
@Override |
@Override |
156 |
protected void onDestroy() { |
protected void onDestroy() { |
157 |
super.onDestroy(); |
super.onDestroy(); |
158 |
|
|
159 |
if (findStationsTask != null) { |
isRunning = false; |
160 |
findStationsTask.cancel(true); |
|
|
} |
|
161 |
if (locationLookup != null) { |
if (locationLookup != null) { |
162 |
locationLookup.stopSearch(); |
locationLookup.stopSearch(); |
163 |
} |
} |
164 |
isRunning = false; |
if (findStationsTask != null) { |
165 |
|
findStationsTask.cancel(true); |
166 |
|
} |
167 |
} |
} |
168 |
|
|
169 |
|
|
187 |
|
|
188 |
} |
} |
189 |
|
|
|
|
|
|
/* these 3 dialogs helper functions are very rude and ugly hack |
|
|
* to remove these auto-reported exceptions |
|
|
* - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running? |
|
|
* - java.lang.IllegalArgumentException: View not attached to window manager |
|
|
*/ |
|
|
|
|
|
/* |
|
|
public void showDialogSafe(int id) { |
|
|
try { |
|
|
showDialog(id); |
|
|
} catch (Exception e) { |
|
|
Log.e("StationList", "showDialog failed", e); |
|
|
} |
|
|
} |
|
|
|
|
|
public void dismissDialogSafe(int id) { |
|
|
try { |
|
|
dismissDialog(id); |
|
|
} catch (Exception e) { |
|
|
Log.e("StationList", "dismissDialog failed", e); |
|
|
} |
|
|
} |
|
|
public void dismissDialogSafe(Dialog dlg) { |
|
|
try { |
|
|
dlg.dismiss(); |
|
|
} catch (Exception e) { |
|
|
Log.e("StationList", "dismissDialog failed", e); |
|
|
} |
|
|
} |
|
|
|
|
|
public void builderShowSafe(AlertDialog.Builder builder) { |
|
|
try { |
|
|
builder.show(); |
|
|
} catch (Exception e) { |
|
|
Log.e("StationList", "builder.show() failed", e); |
|
|
} |
|
190 |
|
|
|
}*/ |
|
|
|
|
|
/* EOF rude and ugly dialog hack */ |
|
|
|
|
|
|
|
191 |
|
|
192 |
@Override |
@Override |
193 |
public void onSaveInstanceState(Bundle outState) |
public void onSaveInstanceState(Bundle outState) |
364 |
public void startLookup() { |
public void startLookup() { |
365 |
isRunning = true; |
isRunning = true; |
366 |
dialogMessage = getString( stationlist_waitforlocation ); |
dialogMessage = getString( stationlist_waitforlocation ); |
367 |
showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
368 |
|
|
369 |
locationLookup.locateStations(); |
locationLookup.locateStations(); |
370 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS); |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS); |
372 |
|
|
373 |
void startNameSearch(String name) { |
void startNameSearch(String name) { |
374 |
dialogMessage = getString( stationlist_findbyname ); |
dialogMessage = getString( stationlist_findbyname ); |
375 |
showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
376 |
|
|
377 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
378 |
findStationsTask.searchByName(name); |
findStationsTask.searchByName(name); |
384 |
|
|
385 |
if (favorites.size() > 0) { |
if (favorites.size() > 0) { |
386 |
dialogMessage = getString( stationlist_loadfavorites ); |
dialogMessage = getString( stationlist_loadfavorites ); |
387 |
showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
388 |
|
|
389 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
390 |
findStationsTask.searchByIds( favorites.toString() ); |
findStationsTask.searchByIds( favorites.toString() ); |
399 |
void startLocatorTask() |
void startLocatorTask() |
400 |
{ |
{ |
401 |
dialogMessage = getString( stationlist_findingnearby ); |
dialogMessage = getString( stationlist_findingnearby ); |
402 |
showDialog(DLG_PROGRESS);//TODO:showDialogSafe(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
403 |
|
|
404 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
405 |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
416 |
|
|
417 |
switch (msg.what) { |
switch (msg.what) { |
418 |
case GOTLOCATION: |
case GOTLOCATION: |
419 |
dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
420 |
|
|
421 |
startLocatorTask(); |
startLocatorTask(); |
422 |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
424 |
break; |
break; |
425 |
|
|
426 |
case NOPROVIDER: |
case NOPROVIDER: |
427 |
dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
428 |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true ); |
429 |
//StationList.this.finish(); |
//StationList.this.finish(); |
430 |
break; |
break; |
434 |
if (locationLookup.hasLocation()) { |
if (locationLookup.hasLocation()) { |
435 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
436 |
} else { |
} else { |
437 |
dismissDialog(DLG_PROGRESS);//TODO:dismissDialogSafe(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
438 |
|
|
439 |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this); |
440 |
builder.setMessage( getString( stationlist_gpstimeout) ); |
builder.setMessage( getString( stationlist_gpstimeout) ); |
451 |
dialog.dismiss(); |
dialog.dismiss(); |
452 |
} |
} |
453 |
}); |
}); |
454 |
builder.show();//TODO:builderShowSafe(builder); |
builder.show(); |
455 |
|
|
456 |
} |
} |
457 |
} |
} |
518 |
@Override |
@Override |
519 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
520 |
super.onPostExecute(result); |
super.onPostExecute(result); |
521 |
dialog.dismiss();//TODO:dismissDialogSafe(dialog); |
dialog.dismiss(); |
522 |
|
|
523 |
|
|
524 |
if (stations != null) { |
if (stations != null) { |
576 |
} |
} |
577 |
}); |
}); |
578 |
|
|
579 |
builder.show();//TODO:builderShowSafe(builder); |
builder.show(); |
580 |
} |
} |
581 |
} |
} |
582 |
} |
} |