1 |
package dk.thoerup.traininfo; |
package dk.thoerup.traininfo; |
2 |
|
|
3 |
|
import static dk.thoerup.traininfo.R.string.departurelist_fetchdata; |
4 |
|
import static dk.thoerup.traininfo.R.string.generic_cancel; |
5 |
|
import static dk.thoerup.traininfo.R.string.generic_retry; |
6 |
|
|
7 |
import java.text.NumberFormat; |
import java.text.NumberFormat; |
8 |
import java.util.ArrayList; |
import java.util.ArrayList; |
9 |
import java.util.List; |
import java.util.List; |
17 |
import android.net.Uri; |
import android.net.Uri; |
18 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
19 |
import android.os.Bundle; |
import android.os.Bundle; |
20 |
|
import android.util.Log; |
21 |
import android.view.View; |
import android.view.View; |
22 |
import android.widget.ListView; |
import android.widget.ListView; |
23 |
import android.widget.TextView; |
import android.widget.TextView; |
40 |
ProgressDialog pgDialog; |
ProgressDialog pgDialog; |
41 |
|
|
42 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
43 |
int stationId; |
|
44 |
|
StationBean station; |
|
double latitude,longitude; |
|
45 |
|
|
46 |
@SuppressWarnings("unchecked") |
@SuppressWarnings("unchecked") |
47 |
@Override |
@Override |
53 |
setListAdapter(adapter); |
setListAdapter(adapter); |
54 |
|
|
55 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
56 |
|
|
57 |
|
station = (StationBean) launchedBy.getSerializableExtra("stationbean"); |
58 |
|
|
59 |
latitude = launchedBy.getDoubleExtra("latitude", 0.0); |
((TextView) findViewById(R.id.stationName)).setText( station.getName() ); |
60 |
longitude = launchedBy.getDoubleExtra("longitude", 0.0); |
|
|
|
|
|
String name = launchedBy.getStringExtra("name"); |
|
|
((TextView) findViewById(R.id.stationName)).setText( name ); |
|
61 |
|
|
62 |
String address = launchedBy.getStringExtra("address"); |
((TextView) findViewById(R.id.stationAddr)).setText( station.getAddress() ); |
|
((TextView) findViewById(R.id.stationAddr)).setText( address ); |
|
63 |
|
|
|
stationId = launchedBy.getIntExtra("stationid", -1); |
|
64 |
|
|
65 |
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
66 |
|
|
67 |
NumberFormat format = NumberFormat.getNumberInstance(); |
NumberFormat format = NumberFormat.getNumberInstance(); |
68 |
format.setMaximumFractionDigits(1); |
format.setMaximumFractionDigits(1); |
69 |
format.setMinimumFractionDigits(1); |
format.setMinimumFractionDigits(1); |
|
int distance = launchedBy.getIntExtra("distance", 0); |
|
|
((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); |
|
|
|
|
|
boolean isRegional = launchedBy.getBooleanExtra("isregional", false); |
|
|
boolean isSTrain = launchedBy.getBooleanExtra("isstrain", false); |
|
|
//boolean isMetro = launchedBy.getBooleanExtra("ismetro", false); // not currently used |
|
70 |
|
|
71 |
|
|
72 |
|
int distance = station.getDistance(); |
73 |
|
((TextView) findViewById(R.id.stationDistance)).setText( format.format((double)distance/1000.0) + " km." ); |
74 |
|
station.setRegional(true); |
75 |
|
Log.e("ASD", "" + station.isRegional() + "/" + station.isSTrain() + "/" + station.isMetro()); |
76 |
|
|
77 |
if (isRegional == false && isSTrain == false) { |
if (station.isRegional() == false && station.isSTrain() == false) { |
78 |
getListView().setVisibility( View.GONE ); |
getListView().setVisibility( View.GONE ); |
79 |
findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); |
findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); |
80 |
|
|
134 |
switch (id) { |
switch (id) { |
135 |
case DLG_PROGRESS: |
case DLG_PROGRESS: |
136 |
ProgressDialog dlg = new ProgressDialog(this); |
ProgressDialog dlg = new ProgressDialog(this); |
137 |
dlg.setMessage("Fetch departure data"); |
dlg.setMessage( getString(departurelist_fetchdata) ); |
138 |
dlg.setCancelable(true); |
dlg.setCancelable(true); |
139 |
return dlg; |
return dlg; |
140 |
default: |
default: |
145 |
void startDepartureFetcher() { |
void startDepartureFetcher() { |
146 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
147 |
fetcher = new DepartureFetcher(); |
fetcher = new DepartureFetcher(); |
148 |
fetcher.execute(stationId); |
fetcher.execute(station.getId()); |
149 |
} |
} |
150 |
|
|
151 |
class DialogDismisser implements View.OnClickListener { |
class DialogDismisser implements View.OnClickListener { |
164 |
|
|
165 |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
View.OnClickListener mapLauncher = new View.OnClickListener() { |
166 |
@Override |
@Override |
167 |
public void onClick(View v) { |
public void onClick(View v) { |
168 |
Uri uri = Uri.parse("geo:" + latitude + "," + longitude); |
Uri uri = Uri.parse("geo:" + station.getLatitude() + "," + station.getLongitude()); |
169 |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
170 |
} |
} |
171 |
}; |
}; |
192 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
193 |
builder.setMessage("Error finding departures"); |
builder.setMessage("Error finding departures"); |
194 |
builder.setCancelable(true); |
builder.setCancelable(true); |
195 |
builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
196 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
197 |
dialog.dismiss(); |
dialog.dismiss(); |
198 |
startDepartureFetcher(); |
startDepartureFetcher(); |
199 |
|
|
200 |
} |
} |
201 |
}); |
}); |
202 |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
203 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
204 |
dialog.dismiss(); |
dialog.dismiss(); |
205 |
} |
} |