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; |
|
import android.widget.Toast; |
|
|
import dk.thoerup.traininfo.provider.DepartureFactory; |
|
16 |
import dk.thoerup.traininfo.provider.DepartureProvider; |
import dk.thoerup.traininfo.provider.DepartureProvider; |
17 |
|
import dk.thoerup.traininfo.provider.ProviderFactory; |
18 |
|
import dk.thoerup.traininfo.util.MessageBox; |
19 |
|
|
20 |
public class DepartureList extends ListActivity { |
public class DepartureList extends ListActivity { |
21 |
|
|
33 |
|
|
34 |
DepartureFetcher fetcher; |
DepartureFetcher fetcher; |
35 |
|
|
36 |
|
double latitude,longitude; |
37 |
|
|
38 |
@Override |
@Override |
39 |
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
40 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
44 |
setListAdapter(adapter); |
setListAdapter(adapter); |
45 |
|
|
46 |
Intent launchedBy = getIntent(); |
Intent launchedBy = getIntent(); |
47 |
|
|
48 |
|
latitude = launchedBy.getDoubleExtra("latitude", 0.0); |
49 |
|
longitude = launchedBy.getDoubleExtra("longitude", 0.0); |
50 |
|
|
51 |
String name = launchedBy.getStringExtra("name"); |
String name = launchedBy.getStringExtra("name"); |
52 |
((TextView) findViewById(R.id.stationName)).setText( name ); |
((TextView) findViewById(R.id.stationName)).setText( name ); |
53 |
|
|
54 |
String addr = launchedBy.getStringExtra("address"); |
String addr = launchedBy.getStringExtra("address"); |
55 |
((TextView) findViewById(R.id.stationAddr)).setText( addr ); |
((TextView) findViewById(R.id.stationAddr)).setText( addr ); |
56 |
|
|
57 |
|
findViewById(R.id.header).setOnClickListener( mapLauncher ); |
58 |
|
|
59 |
NumberFormat format = NumberFormat.getNumberInstance(); |
NumberFormat format = NumberFormat.getNumberInstance(); |
60 |
format.setMaximumFractionDigits(1); |
format.setMaximumFractionDigits(1); |
64 |
|
|
65 |
|
|
66 |
showDialog(DLG_PROGRESS); |
showDialog(DLG_PROGRESS); |
67 |
provider = DepartureFactory.getProvider(); |
provider = ProviderFactory.getDepartureProvider(); |
68 |
|
|
69 |
fetcher = new DepartureFetcher(); |
fetcher = new DepartureFetcher(); |
70 |
fetcher.execute(name); |
fetcher.execute(name); |
71 |
} |
} |
72 |
|
|
73 |
|
@Override |
74 |
|
public void onSaveInstanceState(Bundle outState) |
75 |
|
{ |
76 |
|
if (pgDialog.isShowing()) |
77 |
|
pgDialog.dismiss(); |
78 |
|
} |
79 |
|
|
80 |
@Override |
@Override |
81 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
82 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
93 |
switch (id) { |
switch (id) { |
94 |
case DLG_DETAILS: |
case DLG_DETAILS: |
95 |
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime()); |
96 |
|
((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber()); |
97 |
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination()); |
98 |
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin()); |
99 |
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation()); |
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 |