5 |
import java.util.List; |
import java.util.List; |
6 |
import java.util.Locale; |
import java.util.Locale; |
7 |
|
|
8 |
|
import android.app.AlertDialog; |
9 |
import android.app.Dialog; |
import android.app.Dialog; |
10 |
import android.app.ListActivity; |
import android.app.ListActivity; |
11 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
12 |
|
import android.content.DialogInterface; |
13 |
import android.content.Intent; |
import android.content.Intent; |
14 |
import android.location.Address; |
import android.location.Address; |
15 |
import android.location.Geocoder; |
import android.location.Geocoder; |
39 |
ProgressDialog pgDialog; |
ProgressDialog pgDialog; |
40 |
Dialog detailsDialog; |
Dialog detailsDialog; |
41 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
42 |
|
int stationId; |
43 |
|
|
44 |
double latitude,longitude; |
double latitude,longitude; |
45 |
|
|
63 |
String address = launchedBy.getStringExtra("address"); |
String address = launchedBy.getStringExtra("address"); |
64 |
((TextView) findViewById(R.id.stationAddr)).setText( address ); |
((TextView) findViewById(R.id.stationAddr)).setText( address ); |
65 |
|
|
66 |
int stationId = launchedBy.getIntExtra("stationid", -1); |
stationId = launchedBy.getIntExtra("stationid", -1); |
67 |
|
|
68 |
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
69 |
|
|
76 |
|
|
77 |
provider = ProviderFactory.getDepartureProvider(); |
provider = ProviderFactory.getDepartureProvider(); |
78 |
|
|
|
fetcher = new DepartureFetcher(); |
|
79 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
80 |
showDialog(DLG_PROGRESS); |
startDepartureFetcher(); |
|
fetcher.execute(stationId); |
|
81 |
} else { |
} else { |
82 |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
departures = (List<DepartureBean>) savedInstanceState.getSerializable("departures"); |
83 |
adapter.setDepartures(departures); |
adapter.setDepartures(departures); |
158 |
return super.onCreateDialog(id); |
return super.onCreateDialog(id); |
159 |
} |
} |
160 |
} |
} |
161 |
|
|
162 |
|
void startDepartureFetcher() { |
163 |
|
showDialog(DLG_PROGRESS); |
164 |
|
fetcher = new DepartureFetcher(); |
165 |
|
fetcher.execute(stationId); |
166 |
|
} |
167 |
|
|
168 |
class DialogDismisser implements View.OnClickListener { |
class DialogDismisser implements View.OnClickListener { |
169 |
|
|
177 |
if (dlg.isShowing()) |
if (dlg.isShowing()) |
178 |
dlg.dismiss(); |
dlg.dismiss(); |
179 |
} |
} |
180 |
} |
|
181 |
|
|
182 |
|
} |
183 |
|
|
184 |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
185 |
@Override |
@Override |
188 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
189 |
} |
} |
190 |
}; |
}; |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
195 |
|
|
199 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
200 |
super.onPostExecute(result); |
super.onPostExecute(result); |
201 |
|
|
202 |
adapter.setDepartures(departures); |
|
203 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
204 |
|
|
205 |
if (success) { |
if (success) { |
206 |
|
adapter.setDepartures(departures); |
207 |
if (departures.size() == 0) { |
if (departures.size() == 0) { |
208 |
MessageBox.showMessage(DepartureList.this, "No departures found"); |
MessageBox.showMessage(DepartureList.this, "No departures found"); |
209 |
} |
} |
210 |
} else { // communication or parse error |
} else { // communication or parse error |
211 |
MessageBox.showMessage(DepartureList.this, "Error finding departures"); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
212 |
|
builder.setMessage("Error finding departures"); |
213 |
|
builder.setCancelable(true); |
214 |
|
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
215 |
|
public void onClick(DialogInterface dialog, int id) { |
216 |
|
dialog.dismiss(); |
217 |
|
startDepartureFetcher(); |
218 |
|
|
219 |
|
} |
220 |
|
}); |
221 |
|
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
222 |
|
public void onClick(DialogInterface dialog, int id) { |
223 |
|
dialog.dismiss(); |
224 |
|
} |
225 |
|
}); |
226 |
|
builder.show(); |
227 |
} |
} |
228 |
} |
} |
229 |
|
|