/[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 366 by torben, Wed Sep 30 10:20:05 2009 UTC revision 839 by torben, Fri Jun 11 17:39:11 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    
 import android.app.Activity;  
13  import android.app.AlertDialog;  import android.app.AlertDialog;
14  import android.app.Dialog;  import android.app.Dialog;
15    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.widget.ListView;  import android.util.Log;
22  import android.widget.TextView;  import android.widget.TextView;
23  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
24  import dk.thoerup.traininfo.provider.TimetableProvider;  import dk.thoerup.traininfo.provider.TimetableProvider;
25  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
26    
27  public class TimetableList extends Activity {  public class TimetableList extends ListActivity {
28                    
29          private static final int DLG_PROGRESS = 8000;          private static final int DLG_PROGRESS = 8000;
30          DepartureBean departure;          DepartureBean departure;
# Line 36  public class TimetableList extends Activ Line 42  public class TimetableList extends Activ
42                                    
43                  provider = ProviderFactory.getTimetableProvider();                  provider = ProviderFactory.getTimetableProvider();
44                                    
45                  adapter = new TimetableListAdapter(this);                  adapter = new TimetableListAdapter(this);              
46                                    setListAdapter(adapter);
47                  ListView lv = (ListView) findViewById(R.id.List);  
                 lv.setAdapter(adapter);  
48    
49                                    
50                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
# Line 47  public class TimetableList extends Activ Line 52  public class TimetableList extends Activ
52                                    
53                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
54                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
55                    ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());
56                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());
57                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString());                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this));
58                                                                                                    
59                                    
60                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
# Line 59  public class TimetableList extends Activ Line 65  public class TimetableList extends Activ
65                  }                  }
66          }          }
67                    
68            
69      @Override      @Override
70      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
71      {                {          
# Line 66  public class TimetableList extends Activ Line 73  public class TimetableList extends Activ
73          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);
74      }      }
75    
 /*              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;  
   
  */  
76                    
77          @Override          @Override
78          protected void onPrepareDialog(int id, Dialog dialog) {          protected void onPrepareDialog(int id, Dialog dialog) {
# Line 96  public class TimetableList extends Activ Line 89  public class TimetableList extends Activ
89          protected Dialog onCreateDialog(int id) {          protected Dialog onCreateDialog(int id) {
90                  switch (id) {                  switch (id) {
91                  case DLG_PROGRESS:                  case DLG_PROGRESS:
92                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);                  
93                          dlg.setMessage("Fetch timetable data");                          dlg.setMessage( getString(timetablelist_fetchdata) );
94                          dlg.setCancelable(true);                          dlg.setCancelable(true);
95                          return dlg;                                              return dlg;                    
96                  default:                  default:
# Line 108  public class TimetableList extends Activ Line 101  public class TimetableList extends Activ
101          void startTimetableFetcher() {          void startTimetableFetcher() {
102                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
103                  fetcher = new TimetableFetcher();                  fetcher = new TimetableFetcher();
104                  fetcher.execute(departure.getTrainNumber());                  fetcher.execute(departure.getType(), departure.getTrainNumber());
105          }          }
106                    
107          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
# Line 124  public class TimetableList extends Activ Line 117  public class TimetableList extends Activ
117                          if (success) {                          if (success) {
118                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
119                                  if (timetables.size() == 0) {                                  if (timetables.size() == 0) {
120                                          MessageBox.showMessage(TimetableList.this, "No timetable found");                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata));
121                                  }                                  }
122                          } else { // communication or parse error                          } else { // communication or parse error
123                                  AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                                                                AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                              
124                                  builder.setMessage("Error finding departures");                                  builder.setMessage(getString(timetablelist_fetcherror));
125                                  builder.setCancelable(true);                                  builder.setCancelable(true);
126                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
127                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
128                                                  dialog.dismiss();                                                  dialog.dismiss();
129                                                  startTimetableFetcher();                                                  startTimetableFetcher();
130                                                                                                    
131                                          }                                          }
132                                  });                                  });
133                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
134                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
135                                                  dialog.dismiss();                                                  dialog.dismiss();
136                                          }                                                                                                }                                                      
137                                  });                                                                                                                              });
138                                  builder.show();                                                          
139                                    try {
140                                            builder.show();
141                                    } catch (android.view.WindowManager.BadTokenException e) {                                      
142                                            Log.i("TimetableList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running
143                                    }
144                                                                    
145                          }                          }
146                                                    
147                  }                  }
148                                    
149                  @Override                  @Override
150                  protected Void doInBackground(String... arg0) {                  protected Void doInBackground(String... arg0) {
151                          String trainID = arg0[0];                          String type = arg0[0];
152                          success = provider.lookupTimetable(trainID);                          String trainID = arg0[1];
153                          timetables = provider.getTimetable();                          success = provider.lookupTimetable(type, trainID);
154                            timetables = provider.getTimetable(type, trainID);
155                                                    
156                          return null;                          return null;
157                  }                  }

Legend:
Removed from v.366  
changed lines
  Added in v.839

  ViewVC Help
Powered by ViewVC 1.1.20