3 |
import java.util.ArrayList; |
import java.util.ArrayList; |
4 |
import java.util.List; |
import java.util.List; |
5 |
import java.util.Locale; |
import java.util.Locale; |
|
import java.util.prefs.Preferences; |
|
6 |
|
|
7 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
8 |
import android.app.Dialog; |
import android.app.Dialog; |
11 |
import android.content.DialogInterface; |
import android.content.DialogInterface; |
12 |
import android.content.Intent; |
import android.content.Intent; |
13 |
import android.content.SharedPreferences; |
import android.content.SharedPreferences; |
14 |
|
import android.content.SharedPreferences.Editor; |
15 |
import android.location.Address; |
import android.location.Address; |
16 |
import android.location.Geocoder; |
import android.location.Geocoder; |
17 |
import android.location.Location; |
import android.location.Location; |
55 |
public static final int DLG_PROGRESS = 3001; |
public static final int DLG_PROGRESS = 3001; |
56 |
public static final int DLG_STATIONNAME = 3002; |
public static final int DLG_STATIONNAME = 3002; |
57 |
|
|
58 |
/** Called when the activity is first created. */ |
static enum LookupMethod { |
59 |
|
ByLocation, |
60 |
|
ByName, |
61 |
|
ByList, |
62 |
|
MethodNone |
63 |
|
} |
64 |
|
|
65 |
|
|
66 |
String dialogMessage = ""; |
String dialogMessage = ""; |
67 |
ProgressDialog dialog; |
ProgressDialog dialog; |
68 |
LocationLookup locator = null; |
LocationLookup locator = null; |
69 |
LocatorTask locatorTask; |
FindStationsTask findStationsTask; |
70 |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
71 |
|
|
72 |
GeoPair location = new GeoPair(); |
GeoPair location = new GeoPair(); |
81 |
FavoritesMenu contextMenu = new FavoritesMenu(); |
FavoritesMenu contextMenu = new FavoritesMenu(); |
82 |
IntSet favorites = new IntSet(); |
IntSet favorites = new IntSet(); |
83 |
|
|
84 |
static enum LookupMethod { |
|
|
ByLocation, |
|
|
ByName, |
|
|
ByList, |
|
|
MethodNone |
|
|
} |
|
85 |
|
|
86 |
SharedPreferences prefs; |
SharedPreferences prefs; |
87 |
|
|
135 |
public boolean onCreateOptionsMenu(Menu menu) { |
public boolean onCreateOptionsMenu(Menu menu) { |
136 |
MenuItem item; |
MenuItem item; |
137 |
|
|
138 |
item = menu.add(0, OPTIONS_RESCAN, 0, "Find nearest stations"); |
item = menu.add(0, OPTIONS_RESCAN, 0, "Nearest stations"); |
139 |
item.setIcon(android.R.drawable.ic_menu_mylocation); |
item.setIcon(android.R.drawable.ic_menu_mylocation); |
140 |
|
|
141 |
item = menu.add(0, OPTIONS_NAMESEARCH, 0, "Search for station"); |
item = menu.add(0, OPTIONS_NAMESEARCH, 0, "Search for station"); |
144 |
item = menu.add(0, OPTIONS_FAVORITES, 0, "Favorites"); |
item = menu.add(0, OPTIONS_FAVORITES, 0, "Favorites"); |
145 |
item.setIcon(android.R.drawable.ic_menu_agenda); |
item.setIcon(android.R.drawable.ic_menu_agenda); |
146 |
|
|
147 |
item = menu.add(0, OPTIONS_MAP, 0, "Show station map"); |
item = menu.add(0, OPTIONS_MAP, 0, "Station map"); |
148 |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
item.setIcon(android.R.drawable.ic_menu_mapmode); |
149 |
|
|
150 |
item = menu.add(0, OPTIONS_ABOUT, 0, "About"); |
item = menu.add(0, OPTIONS_ABOUT, 0, "About"); |
309 |
dialogMessage = "Finding stations by name"; |
dialogMessage = "Finding stations by name"; |
310 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
311 |
|
|
312 |
locatorTask = new LocatorTask(); |
findStationsTask = new FindStationsTask(); |
313 |
locatorTask.searchByName(name, locator.getLocation()); |
findStationsTask.searchByName(name, locator.getLocation()); |
314 |
locatorTask.execute(); |
findStationsTask.execute(); |
315 |
|
|
316 |
} |
} |
317 |
|
|
318 |
public void startFavoriteLookup() { |
public void startFavoriteLookup() { |
319 |
|
|
320 |
if (favorites.toString().length() > 0) { |
if (favorites.size() > 0) { |
321 |
dialogMessage = "Loading favorites"; |
dialogMessage = "Loading favorites"; |
322 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
323 |
|
|
324 |
locatorTask = new LocatorTask(); |
findStationsTask = new FindStationsTask(); |
325 |
locatorTask.searchByIds(favorites.toString(), locator.getLocation()); |
findStationsTask.searchByIds(favorites.toString(), locator.getLocation()); |
326 |
locatorTask.execute(); |
findStationsTask.execute(); |
327 |
} else { |
} else { |
328 |
MessageBox.showMessage(this, "Favorite list is empty"); |
MessageBox.showMessage(this, "Favorite list is empty"); |
329 |
} |
} |
336 |
dialogMessage = "Finding nearby stations"; |
dialogMessage = "Finding nearby stations"; |
337 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
338 |
|
|
339 |
locatorTask = new LocatorTask(); |
findStationsTask = new FindStationsTask(); |
340 |
locatorTask.searchByLocation( locator.getLocation() ); |
findStationsTask.searchByLocation( locator.getLocation() ); |
341 |
locatorTask.execute(); |
findStationsTask.execute(); |
342 |
} |
} |
343 |
|
|
344 |
|
|
423 |
}; |
}; |
424 |
|
|
425 |
|
|
426 |
class LocatorTask extends AsyncTask<Void,Void,Void> { |
class FindStationsTask extends AsyncTask<Void,Void,Void> { |
427 |
|
|
428 |
LookupMethod method = LookupMethod.MethodNone; |
LookupMethod method = LookupMethod.MethodNone; |
429 |
boolean success; |
boolean success; |
558 |
favorites.remove(stationID); |
favorites.remove(stationID); |
559 |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show(); |
560 |
} |
} |
561 |
|
Editor ed = prefs.edit(); |
562 |
prefs.edit().putString("favorites", favorites.toString()); |
ed.putString("favorites", favorites.toString()); |
563 |
|
ed.commit(); |
564 |
} |
} |
565 |
} |
} |
566 |
} |
} |