63 |
|
|
64 |
String dialogMessage = ""; |
String dialogMessage = ""; |
65 |
ProgressDialog dialog; |
ProgressDialog dialog; |
66 |
LocationLookup locator = null; |
LocationLookup locationLookup = null; |
67 |
FindStationsTask findStationsTask; |
FindStationsTask findStationsTask; |
68 |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
StationsFetchedHandler stationsFetched = new StationsFetchedHandler(); |
69 |
|
|
80 |
IntSet favorites = new IntSet(); |
IntSet favorites = new IntSet(); |
81 |
|
|
82 |
WelcomeScreen.ListType listType; |
WelcomeScreen.ListType listType; |
|
String dialogTitle; |
|
83 |
SharedPreferences prefs; |
SharedPreferences prefs; |
84 |
|
|
85 |
/////////////////////////////////////////////////////////////////////////////////////////// |
/////////////////////////////////////////////////////////////////////////////////////////// |
98 |
ListView lv = getListView(); |
ListView lv = getListView(); |
99 |
lv.setOnCreateContextMenuListener(contextMenu); |
lv.setOnCreateContextMenuListener(contextMenu); |
100 |
|
|
101 |
locator = new LocationLookup(this, stationsFetched); |
locationLookup = new LocationLookup(this, stationsFetched); |
102 |
|
|
103 |
|
|
104 |
prefs = getSharedPreferences("TrainStation", 0); |
prefs = getSharedPreferences("TrainStation", 0); |
107 |
favorites.fromString(favoriteString); |
favorites.fromString(favoriteString); |
108 |
} |
} |
109 |
|
|
110 |
|
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
111 |
|
setTitle(); |
112 |
|
|
113 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
114 |
listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type"); |
|
115 |
|
|
116 |
switch (listType) { |
switch (listType) { |
117 |
case ListNearest: |
case ListNearest: |
118 |
startLookup(); |
startLookup(); |
131 |
stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations"); |
stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations"); |
132 |
adapter.setStations(stations); |
adapter.setStations(stations); |
133 |
location = (GeoPair) savedInstanceState.getSerializable("location"); |
location = (GeoPair) savedInstanceState.getSerializable("location"); |
|
dialogTitle = savedInstanceState.getString("title"); |
|
|
setTitle(dialogTitle); |
|
134 |
} |
} |
135 |
|
|
136 |
|
} |
137 |
|
protected void setTitle() { |
138 |
|
String dialogTitle = getResources().getString(R.string.app_name); |
139 |
|
switch (listType) { |
140 |
|
case ListNearest: |
141 |
|
dialogTitle += " - Nearby stations"; |
142 |
|
break; |
143 |
|
case ListSearch: |
144 |
|
dialogTitle += " - Search"; |
145 |
|
break; |
146 |
|
case ListFavorites: |
147 |
|
dialogTitle += " - Favorites"; |
148 |
|
break; |
149 |
|
default: |
150 |
|
dialogTitle = "";//not possible |
151 |
|
} |
152 |
|
|
153 |
|
setTitle(dialogTitle); |
154 |
} |
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
@Override |
@Override |
163 |
dialog.dismiss(); |
dialog.dismiss(); |
164 |
outState.putSerializable("stations", (ArrayList<StationBean>) stations); |
outState.putSerializable("stations", (ArrayList<StationBean>) stations); |
165 |
outState.putSerializable("location", location); |
outState.putSerializable("location", location); |
166 |
outState.putString("title", dialogTitle); |
|
167 |
} |
} |
168 |
|
|
169 |
|
|
190 |
case OPTIONS_MAP: |
case OPTIONS_MAP: |
191 |
|
|
192 |
Intent intent = new Intent(this,StationMapView.class); |
Intent intent = new Intent(this,StationMapView.class); |
|
intent.putExtra("userlocation", location ); |
|
193 |
|
|
194 |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>(); |
195 |
for (StationBean st : stations ) { |
for (StationBean st : stations ) { |
201 |
startActivity(intent); |
startActivity(intent); |
202 |
break; |
break; |
203 |
case OPTIONS_GPSINFO: |
case OPTIONS_GPSINFO: |
204 |
Location loc = locator.getLocation(); |
Location loc = locationLookup.getLocation(); |
205 |
StringBuffer message = new StringBuffer(); |
StringBuffer message = new StringBuffer(); |
206 |
message.append("Location info:\n"); |
message.append("Location info:\n"); |
207 |
message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n"); |
message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n"); |
315 |
dialogMessage = "Wait for location fix"; |
dialogMessage = "Wait for location fix"; |
316 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
317 |
|
|
318 |
locator.locateStations(); |
locationLookup.locateStations(); |
319 |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000); |
320 |
} |
} |
321 |
|
|
324 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
325 |
|
|
326 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
327 |
findStationsTask.searchByName(name, locator.getLocation()); |
findStationsTask.searchByName(name, locationLookup.getLocation()); |
328 |
findStationsTask.execute(); |
findStationsTask.execute(); |
329 |
|
|
330 |
} |
} |
336 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
337 |
|
|
338 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
339 |
findStationsTask.searchByIds(favorites.toString(), locator.getLocation()); |
findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation()); |
340 |
findStationsTask.execute(); |
findStationsTask.execute(); |
341 |
} else { |
} else { |
342 |
MessageBox.showMessage(this, "Favorite list is empty"); |
MessageBox.showMessage(this, "Favorite list is empty"); |
351 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
352 |
|
|
353 |
findStationsTask = new FindStationsTask(); |
findStationsTask = new FindStationsTask(); |
354 |
findStationsTask.searchByLocation( locator.getLocation() ); |
findStationsTask.searchByLocation( locationLookup.getLocation() ); |
355 |
findStationsTask.execute(); |
findStationsTask.execute(); |
356 |
} |
} |
357 |
|
|
395 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
396 |
|
|
397 |
startLocatorTask(); |
startLocatorTask(); |
398 |
location = GeoPair.fromLocation( locator.getLocation() ); |
location = GeoPair.fromLocation( locationLookup.getLocation() ); |
399 |
|
|
400 |
break; |
break; |
401 |
|
|
405 |
break; |
break; |
406 |
case LOCATIONFIXTIMEOUT: |
case LOCATIONFIXTIMEOUT: |
407 |
if (isRunning) { |
if (isRunning) { |
408 |
locator.stopSearch(); |
locationLookup.stopSearch(); |
409 |
if (locator.hasLocation()) { |
if (locationLookup.hasLocation()) { |
410 |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
stationsFetched.sendEmptyMessage( GOTLOCATION ); |
411 |
} else { |
} else { |
412 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
518 |
super.onPostExecute(result); |
super.onPostExecute(result); |
519 |
dialog.dismiss(); |
dialog.dismiss(); |
520 |
|
|
|
//set title |
|
|
switch (method) { |
|
|
case ByLocation: |
|
|
dialogTitle = "Traininfo DK - Nearby stations"; |
|
|
break; |
|
|
case ByName: |
|
|
dialogTitle = "Traininfo DK - Search"; |
|
|
break; |
|
|
case ByList: |
|
|
dialogTitle = "Traininfo DK - Favorites"; |
|
|
break; |
|
|
default: |
|
|
dialogTitle = "";//not possible |
|
|
} |
|
|
|
|
|
StationList.this.setTitle(dialogTitle); |
|
|
//set title end |
|
521 |
|
|
522 |
if (success) { |
if (success) { |
523 |
if (stationProvider.getStations().size() == 0) |
if (stationProvider.getStations().size() == 0) |