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; |
14 |
import android.widget.ListView; |
import android.widget.ListView; |
15 |
import android.widget.TextView; |
import android.widget.TextView; |
16 |
import android.widget.Toast; |
import android.widget.Toast; |
17 |
import dk.thoerup.traininfo.provider.DepartureFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
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); |
65 |
|
|
66 |
|
|
67 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
68 |
provider = DepartureFactory.getProvider(); |
provider = ProviderFactory.getDepartureProvider(); |
69 |
|
|
70 |
fetcher = new DepartureFetcher(); |
fetcher = new DepartureFetcher(); |
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); |
94 |
switch (id) { |
switch (id) { |
95 |
case DLG_DETAILS: |
case DLG_DETAILS: |
96 |
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
97 |
|
((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber()); |
98 |
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
99 |
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
100 |
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
146 |
} |
} |
147 |
} |
} |
148 |
|
|
149 |
|
View.OnClickListener mapLauncher = new View.OnClickListener() { |
150 |
|
@Override |
151 |
|
public void onClick(View v) { |
152 |
|
Uri uri = Uri.parse("geo:" + latitude + "," + longitude); |
153 |
|
startActivity( new Intent(Intent.ACTION_VIEW, uri)); |
154 |
|
} |
155 |
|
}; |
156 |
|
|
157 |
|
|
158 |
class DepartureFetcher extends AsyncTask<String, Void, Void> { |
class DepartureFetcher extends AsyncTask<String, Void, Void> { |
159 |
|
|
165 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
166 |
|
|
167 |
if (departures.size() == 0) |
if (departures.size() == 0) |
168 |
Toast.makeText(DepartureList.this, "No departures found", Toast.LENGTH_LONG); |
MessageBox.showMessage(DepartureList.this, "No departures found"); |
169 |
} |
} |
170 |
|
|
171 |
@Override |
@Override |