/[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 699 by torben, Mon May 3 11:19:18 2010 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
3    
4    import static dk.thoerup.traininfo.R.string.generic_cancel;
5    import static dk.thoerup.traininfo.R.string.generic_retry;
6    import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata;
7    import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror;
8    import static dk.thoerup.traininfo.R.string.timetablelist_nodata;
9    
10  import java.util.ArrayList;  import java.util.ArrayList;
11  import java.util.List;  import java.util.List;
12    
13    import android.app.Activity;
14  import android.app.AlertDialog;  import android.app.AlertDialog;
15  import android.app.Dialog;  import android.app.Dialog;
 import android.app.ListActivity;  
16  import android.app.ProgressDialog;  import android.app.ProgressDialog;
17  import android.content.DialogInterface;  import android.content.DialogInterface;
18  import android.content.Intent;  import android.content.Intent;
19  import android.os.AsyncTask;  import android.os.AsyncTask;
20  import android.os.Bundle;  import android.os.Bundle;
21  import android.util.Log;  import android.util.Log;
22    import android.widget.ListView;
23  import android.widget.TextView;  import android.widget.TextView;
24  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
25  import dk.thoerup.traininfo.provider.TimetableProvider;  import dk.thoerup.traininfo.provider.TimetableProvider;
26  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
27    
28  public class TimetableList extends ListActivity {  public class TimetableList extends Activity {
29                    
30          private static final int DLG_PROGRESS = 8000;          private static final int DLG_PROGRESS = 8000;
31          DepartureBean departure;          DepartureBean departure;
# Line 37  public class TimetableList extends ListA Line 44  public class TimetableList extends ListA
44                  provider = ProviderFactory.getTimetableProvider();                  provider = ProviderFactory.getTimetableProvider();
45                                    
46                  adapter = new TimetableListAdapter(this);                  adapter = new TimetableListAdapter(this);
47                  setListAdapter(adapter);                  
48                    ListView lv = (ListView) findViewById(R.id.List);
49                    lv.setAdapter(adapter);
50    
51                                    
52                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
53                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");
54                                    
55                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
56                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
57                    ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());
58                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());
59                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString());                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this));
60                                                                    
61                                    
62                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
63                          startTimetableFetcher();                          startTimetableFetcher();
# Line 63  public class TimetableList extends ListA Line 74  public class TimetableList extends ListA
74          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);
75      }      }
76    
 /*              case DLG_DETAILS:  
                         DepartureBean currentDeparture = departures.get(selectedItemId);  
                         ((TextView)dialog.findViewById(R.id.Time)).setText(currentDeparture.getTime());  
                         ((TextView)dialog.findViewById(R.id.Train)).setText(currentDeparture.getTrainNumber());  
                         ((TextView)dialog.findViewById(R.id.Destination)).setText( currentDeparture.getDestination());  
                         ((TextView)dialog.findViewById(R.id.Origin)).setText(currentDeparture.getOrigin());  
                         ((TextView)dialog.findViewById(R.id.Location)).setText(currentDeparture.getLocation());  
                         ((TextView)dialog.findViewById(R.id.Updated)).setText(currentDeparture.getLastUpdateString());  
                         ((TextView)dialog.findViewById(R.id.Status)).setText(currentDeparture.getStatus());  
                         ((TextView)dialog.findViewById(R.id.Note)).setText(currentDeparture.getNote());  
                         detailsDialog = dialog;  
                         break;  
   
  */  
77                    
78          @Override          @Override
79          protected void onPrepareDialog(int id, Dialog dialog) {          protected void onPrepareDialog(int id, Dialog dialog) {
# Line 93  public class TimetableList extends ListA Line 90  public class TimetableList extends ListA
90          protected Dialog onCreateDialog(int id) {          protected Dialog onCreateDialog(int id) {
91                  switch (id) {                  switch (id) {
92                  case DLG_PROGRESS:                  case DLG_PROGRESS:
93                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);                  
94                          dlg.setMessage("Fetch timetable data");                          dlg.setMessage( getString(timetablelist_fetchdata) );
95                          dlg.setCancelable(true);                          dlg.setCancelable(true);
96                          return dlg;                                              return dlg;                    
97                  default:                  default:
# Line 105  public class TimetableList extends ListA Line 102  public class TimetableList extends ListA
102          void startTimetableFetcher() {          void startTimetableFetcher() {
103                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
104                  fetcher = new TimetableFetcher();                  fetcher = new TimetableFetcher();
105                  fetcher.execute(departure.getTrainNumber());                  fetcher.execute(departure.getType(), departure.getTrainNumber());
106          }          }
107                    
108          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
# Line 121  public class TimetableList extends ListA Line 118  public class TimetableList extends ListA
118                          if (success) {                          if (success) {
119                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
120                                  if (timetables.size() == 0) {                                  if (timetables.size() == 0) {
121                                          MessageBox.showMessage(TimetableList.this, "No timetable found");                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata));
122                                  }                                  }
123                          } else { // communication or parse error                          } else { // communication or parse error
124                                  AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                                                                AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                              
125                                  builder.setMessage("Error finding departures");                                  builder.setMessage(getString(timetablelist_fetcherror));
126                                  builder.setCancelable(true);                                  builder.setCancelable(true);
127                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
128                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
129                                                  dialog.dismiss();                                                  dialog.dismiss();
130                                                  startTimetableFetcher();                                                  startTimetableFetcher();
131                                                                                                    
132                                          }                                          }
133                                  });                                  });
134                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
135                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
136                                                  dialog.dismiss();                                                  dialog.dismiss();
137                                          }                                                                                                }                                                      
138                                  });                                                                                                                              });
139                                  builder.show();                                                          
140                                    try {
141                                            builder.show();
142                                    } catch (android.view.WindowManager.BadTokenException e) {                                      
143                                            Log.i("TimetableList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
144                                    }
145                                                                    
146                          }                          }
147                                                    
148                  }                  }
149                                    
150                  @Override                  @Override
151                  protected Void doInBackground(String... arg0) {                  protected Void doInBackground(String... arg0) {
152                          String trainID = arg0[0];                          String type = arg0[0];
153                          success = provider.lookupTimetable(trainID);                          String trainID = arg0[1];
154                          timetables = provider.getTimetable();                          success = provider.lookupTimetable(type, trainID);
155                            timetables = provider.getTimetable(type, trainID);
156                                                    
157                          return null;                          return null;
158                  }                  }

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

  ViewVC Help
Powered by ViewVC 1.1.20