/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java
ViewVC logotype

Annotation of /android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 366 - (hide annotations) (download)
Wed Sep 30 10:20:05 2009 UTC (14 years, 8 months ago) by torben
File size: 4758 byte(s)
Minor gui tweaks to timetable list
1 torben 362 package dk.thoerup.traininfo;
2    
3 torben 365
4     import java.util.ArrayList;
5     import java.util.List;
6    
7 torben 366 import android.app.Activity;
8 torben 365 import android.app.AlertDialog;
9     import android.app.Dialog;
10     import android.app.ProgressDialog;
11     import android.content.DialogInterface;
12 torben 364 import android.content.Intent;
13 torben 365 import android.os.AsyncTask;
14 torben 362 import android.os.Bundle;
15 torben 366 import android.widget.ListView;
16 torben 362 import android.widget.TextView;
17 torben 365 import dk.thoerup.traininfo.provider.ProviderFactory;
18     import dk.thoerup.traininfo.provider.TimetableProvider;
19     import dk.thoerup.traininfo.util.MessageBox;
20 torben 362
21 torben 366 public class TimetableList extends Activity {
22 torben 364
23 torben 365 private static final int DLG_PROGRESS = 8000;
24 torben 364 DepartureBean departure;
25 torben 365 TimetableListAdapter adapter;
26     TimetableFetcher fetcher;
27     List<TimetableBean> timetables;
28 torben 364
29 torben 365 TimetableProvider provider;
30    
31     @SuppressWarnings("unchecked")
32 torben 362 @Override
33     protected void onCreate(Bundle savedInstanceState) {
34     super.onCreate(savedInstanceState);
35     setContentView(R.layout.timetablelist);
36 torben 364
37 torben 365 provider = ProviderFactory.getTimetableProvider();
38    
39     adapter = new TimetableListAdapter(this);
40    
41 torben 366 ListView lv = (ListView) findViewById(R.id.List);
42     lv.setAdapter(adapter);
43    
44    
45 torben 364 Intent launchedBy = getIntent();
46     departure = (DepartureBean) launchedBy.getSerializableExtra("departure");
47    
48     ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
49     ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
50     ((TextView)findViewById(R.id.Note)).setText(departure.getNote());
51     ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString());
52 torben 366
53 torben 365
54     if (savedInstanceState == null) {
55     startTimetableFetcher();
56     } else {
57     timetables = (List<TimetableBean>) savedInstanceState.getSerializable("timetables");
58     adapter.setTimetable(timetables);
59     }
60 torben 362 }
61 torben 365
62     @Override
63     public void onSaveInstanceState(Bundle outState)
64     {
65     dismissDialog(DLG_PROGRESS);
66     outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);
67     }
68 torben 364
69     /* case DLG_DETAILS:
70 torben 362 DepartureBean currentDeparture = departures.get(selectedItemId);
71     ((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime());
72     ((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber());
73     ((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination());
74     ((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin());
75     ((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation());
76     ((TextView)dialog.findViewById(R.id.Updated)).setText(currentDeparture.getLastUpdateString());
77     ((TextView)dialog.findViewById(R.id.Status)).setText(currentDeparture.getStatus());
78     ((TextView)dialog.findViewById(R.id.Note)).setText(currentDeparture.getNote());
79     detailsDialog = dialog;
80     break;
81    
82     */
83 torben 365
84     @Override
85     protected void onPrepareDialog(int id, Dialog dialog) {
86     super.onPrepareDialog(id, dialog);
87    
88     switch (id) {
89     case DLG_PROGRESS:
90     //pgDialog = (ProgressDialog) dialog;
91     break;
92     }
93     }
94    
95     @Override
96     protected Dialog onCreateDialog(int id) {
97     switch (id) {
98     case DLG_PROGRESS:
99     ProgressDialog dlg = new ProgressDialog(this);
100     dlg.setMessage("Fetch timetable data");
101     dlg.setCancelable(true);
102     return dlg;
103     default:
104     return super.onCreateDialog(id);
105     }
106     }
107    
108     void startTimetableFetcher() {
109     showDialog(DLG_PROGRESS);
110     fetcher = new TimetableFetcher();
111     fetcher.execute(departure.getTrainNumber());
112     }
113    
114     class TimetableFetcher extends AsyncTask<String,Void,Void> {
115    
116     boolean success;
117    
118     @Override
119     protected void onPostExecute(Void result) {
120     super.onPostExecute(result);
121     dismissDialog(DLG_PROGRESS);
122    
123    
124     if (success) {
125     adapter.setTimetable(timetables);
126     if (timetables.size() == 0) {
127     MessageBox.showMessage(TimetableList.this, "No timetable found");
128     }
129     } else { // communication or parse error
130     AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);
131     builder.setMessage("Error finding departures");
132     builder.setCancelable(true);
133     builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {
134     public void onClick(DialogInterface dialog, int id) {
135     dialog.dismiss();
136     startTimetableFetcher();
137    
138     }
139     });
140     builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
141     public void onClick(DialogInterface dialog, int id) {
142     dialog.dismiss();
143     }
144     });
145     builder.show();
146     }
147    
148     }
149    
150     @Override
151     protected Void doInBackground(String... arg0) {
152     String trainID = arg0[0];
153     success = provider.lookupTimetable(trainID);
154     timetables = provider.getTimetable();
155    
156     return null;
157     }
158    
159     }
160 torben 362 }

  ViewVC Help
Powered by ViewVC 1.1.20