7 |
import android.app.ListActivity; |
import android.app.ListActivity; |
8 |
import android.app.ProgressDialog; |
import android.app.ProgressDialog; |
9 |
import android.content.Intent; |
import android.content.Intent; |
10 |
|
import android.net.Uri; |
11 |
import android.os.AsyncTask; |
import android.os.AsyncTask; |
12 |
import android.os.Bundle; |
import android.os.Bundle; |
13 |
import android.view.View; |
import android.view.View; |
16 |
import android.widget.Toast; |
import android.widget.Toast; |
17 |
import dk.thoerup.traininfo.provider.DepartureFactory; |
import dk.thoerup.traininfo.provider.DepartureFactory; |
18 |
import dk.thoerup.traininfo.provider.DepartureProvider; |
import dk.thoerup.traininfo.provider.DepartureProvider; |
19 |
|
import dk.thoerup.traininfo.util.MessageBox; |
20 |
|
|
21 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
22 |
|
|
34 |
|
|
35 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
36 |
|
|
37 |
|
double latitude,longitude; |
38 |
|
|
39 |
@Override |
@Override |
40 |
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
41 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
45 |
setListAdapter(adapter); |
setListAdapter(adapter); |
46 |
|
|
47 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
48 |
|
|
49 |
|
latitude = launchedBy.getDoubleExtra("latitude", 0.0); |
50 |
|
longitude = launchedBy.getDoubleExtra("longitude", 0.0); |
51 |
|
|
52 |
String name = launchedBy.getStringExtra("name"); |
String name = launchedBy.getStringExtra("name"); |
53 |
((TextView) findViewById(R.id.stationName)).setText( name ); |
((TextView) findViewById(R.id.stationName)).setText( name ); |
54 |
|
|
55 |
String addr = launchedBy.getStringExtra("address"); |
String addr = launchedBy.getStringExtra("address"); |
56 |
((TextView) findViewById(R.id.stationAddr)).setText( addr ); |
((TextView) findViewById(R.id.stationAddr)).setText( addr ); |
57 |
|
|
58 |
|
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
59 |
|
|
60 |
NumberFormat format = NumberFormat.getNumberInstance(); |
NumberFormat format = NumberFormat.getNumberInstance(); |
61 |
format.setMaximumFractionDigits(1); |
format.setMaximumFractionDigits(1); |
71 |
fetcher.execute(name); |
fetcher.execute(name); |
72 |
} |
} |
73 |
|
|
74 |
|
@Override |
75 |
|
public void onSaveInstanceState(Bundle outState) |
76 |
|
{ |
77 |
|
if (pgDialog.isShowing()) |
78 |
|
pgDialog.dismiss(); |
79 |
|
} |
80 |
|
|
81 |
@Override |
@Override |
82 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
83 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
145 |
} |
} |
146 |
} |
} |
147 |
|
|
148 |
|
View.OnClickListener mapLauncher = new View.OnClickListener() { |
149 |
|
@Override |
150 |
|
public void onClick(View v) { |
151 |
|
Uri uri = Uri.parse("geo:" + latitude + "," + longitude); |
152 |
|
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
153 |
|
} |
154 |
|
}; |
155 |
|
|
156 |
|
|
157 |
class DepartureFetcher extends AsyncTask<String, Void, Void> { |
class DepartureFetcher extends AsyncTask<String, Void, Void> { |
158 |
|
|
164 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
165 |
|
|
166 |
if (departures.size() == 0) |
if (departures.size() == 0) |
167 |
Toast.makeText(DepartureList.this, "No departures found", Toast.LENGTH_LONG); |
MessageBox.showMessage(DepartureList.this, "No departures found"); |
168 |
} |
} |
169 |
|
|
170 |
@Override |
@Override |