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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 365 by torben, Wed Sep 30 09:14:27 2009 UTC revision 563 by torben, Thu Jan 28 09:10:44 2010 UTC
# Line 4  package dk.thoerup.traininfo; Line 4  package dk.thoerup.traininfo;
4  import java.util.ArrayList;  import java.util.ArrayList;
5  import java.util.List;  import java.util.List;
6    
7    import android.app.Activity;
8  import android.app.AlertDialog;  import android.app.AlertDialog;
9  import android.app.Dialog;  import android.app.Dialog;
 import android.app.ListActivity;  
10  import android.app.ProgressDialog;  import android.app.ProgressDialog;
11  import android.content.DialogInterface;  import android.content.DialogInterface;
12  import android.content.Intent;  import android.content.Intent;
13  import android.os.AsyncTask;  import android.os.AsyncTask;
14  import android.os.Bundle;  import android.os.Bundle;
15  import android.util.Log;  import android.widget.ListView;
16  import android.widget.TextView;  import android.widget.TextView;
17  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
18  import dk.thoerup.traininfo.provider.TimetableProvider;  import dk.thoerup.traininfo.provider.TimetableProvider;
19  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
20    import static dk.thoerup.traininfo.R.string.*;
21    
22  public class TimetableList extends ListActivity {  public class TimetableList extends Activity {
23                    
24          private static final int DLG_PROGRESS = 8000;          private static final int DLG_PROGRESS = 8000;
25          DepartureBean departure;          DepartureBean departure;
# Line 37  public class TimetableList extends ListA Line 38  public class TimetableList extends ListA
38                  provider = ProviderFactory.getTimetableProvider();                  provider = ProviderFactory.getTimetableProvider();
39                                    
40                  adapter = new TimetableListAdapter(this);                  adapter = new TimetableListAdapter(this);
41                  setListAdapter(adapter);                  
42                    ListView lv = (ListView) findViewById(R.id.List);
43                    lv.setAdapter(adapter);
44    
45                                    
46                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
47                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");
48                                    
49                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
50                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
51                    ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());
52                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());
53                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString());                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this));
54                                                                    
55                                    
56                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
57                          startTimetableFetcher();                          startTimetableFetcher();
# Line 93  public class TimetableList extends ListA Line 98  public class TimetableList extends ListA
98          protected Dialog onCreateDialog(int id) {          protected Dialog onCreateDialog(int id) {
99                  switch (id) {                  switch (id) {
100                  case DLG_PROGRESS:                  case DLG_PROGRESS:
101                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);                  
102                          dlg.setMessage("Fetch timetable data");                          dlg.setMessage( getString(timetablelist_fetchdata) );
103                          dlg.setCancelable(true);                          dlg.setCancelable(true);
104                          return dlg;                                              return dlg;                    
105                  default:                  default:
# Line 121  public class TimetableList extends ListA Line 126  public class TimetableList extends ListA
126                          if (success) {                          if (success) {
127                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
128                                  if (timetables.size() == 0) {                                  if (timetables.size() == 0) {
129                                          MessageBox.showMessage(TimetableList.this, "No timetable found");                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata));
130                                  }                                  }
131                          } else { // communication or parse error                          } else { // communication or parse error
132                                  AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                                                                AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                              
133                                  builder.setMessage("Error finding departures");                                  builder.setMessage(getString(timetablelist_fetcherror));
134                                  builder.setCancelable(true);                                  builder.setCancelable(true);
135                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
136                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
137                                                  dialog.dismiss();                                                  dialog.dismiss();
138                                                  startTimetableFetcher();                                                  startTimetableFetcher();
139                                                                                                    
140                                          }                                          }
141                                  });                                  });
142                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
143                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
144                                                  dialog.dismiss();                                                  dialog.dismiss();
145                                          }                                                                                                }                                                      
# Line 148  public class TimetableList extends ListA Line 153  public class TimetableList extends ListA
153                  protected Void doInBackground(String... arg0) {                  protected Void doInBackground(String... arg0) {
154                          String trainID = arg0[0];                          String trainID = arg0[0];
155                          success = provider.lookupTimetable(trainID);                          success = provider.lookupTimetable(trainID);
156                          timetables = provider.getTimetable();                          timetables = provider.getTimetable(trainID);
157                                                    
158                          return null;                          return null;
159                  }                  }

Legend:
Removed from v.365  
changed lines
  Added in v.563

  ViewVC Help
Powered by ViewVC 1.1.20