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

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

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

revision 561 by torben, Thu Jan 28 08:55:19 2010 UTC revision 1219 by torben, Sun Jan 30 21:08:32 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
3  import java.util.ArrayList;  import static dk.thoerup.traininfo.R.string.app_name;
4  import java.util.List;  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.generic_search;
7    import static dk.thoerup.traininfo.R.string.stationlist_accuracy;
8    import static dk.thoerup.traininfo.R.string.stationlist_addfavorite;
9    import static dk.thoerup.traininfo.R.string.stationlist_favorites;
10    import static dk.thoerup.traininfo.R.string.stationlist_fetcherror;
11    import static dk.thoerup.traininfo.R.string.stationlist_findbyname;
12    import static dk.thoerup.traininfo.R.string.stationlist_findingnearby;
13    import static dk.thoerup.traininfo.R.string.stationlist_gpsinfo;
14    import static dk.thoerup.traininfo.R.string.stationlist_gpstimeout;
15    import static dk.thoerup.traininfo.R.string.stationlist_latitude;
16    import static dk.thoerup.traininfo.R.string.stationlist_loadfavorites;
17    import static dk.thoerup.traininfo.R.string.stationlist_locationinfo;
18    import static dk.thoerup.traininfo.R.string.stationlist_longitude;
19    import static dk.thoerup.traininfo.R.string.stationlist_nearbystations;
20    import static dk.thoerup.traininfo.R.string.stationlist_nofavorites;
21    import static dk.thoerup.traininfo.R.string.stationlist_nolocation;
22    import static dk.thoerup.traininfo.R.string.stationlist_nolocationprovider;
23    import static dk.thoerup.traininfo.R.string.stationlist_nostations;
24    import static dk.thoerup.traininfo.R.string.stationlist_obtainedby;
25    import static dk.thoerup.traininfo.R.string.stationlist_removefavorite;
26    import static dk.thoerup.traininfo.R.string.stationlist_satellitecount;
27    import static dk.thoerup.traininfo.R.string.stationlist_search;
28    import static dk.thoerup.traininfo.R.string.stationlist_stationadded;
29    import static dk.thoerup.traininfo.R.string.stationlist_stationmap;
30    import static dk.thoerup.traininfo.R.string.stationlist_stationremoved;
31    import static dk.thoerup.traininfo.R.string.stationlist_stationsearch;
32    import static dk.thoerup.traininfo.R.string.stationlist_twocharmin;
33    import static dk.thoerup.traininfo.R.string.stationlist_waitforlocation;
34    
35    import java.util.ArrayList;
36    
37    import android.app.Activity;
38  import android.app.AlertDialog;  import android.app.AlertDialog;
39  import android.app.Dialog;  import android.app.Dialog;
40  import android.app.ListActivity;  import android.app.ListActivity;
# Line 17  import android.os.AsyncTask; Line 48  import android.os.AsyncTask;
48  import android.os.Bundle;  import android.os.Bundle;
49  import android.os.Handler;  import android.os.Handler;
50  import android.os.Message;  import android.os.Message;
51    import android.util.Log;
52  import android.view.ContextMenu;  import android.view.ContextMenu;
53  import android.view.LayoutInflater;  import android.view.LayoutInflater;
54  import android.view.Menu;  import android.view.Menu;
# Line 29  import android.widget.AdapterView; Line 60  import android.widget.AdapterView;
60  import android.widget.EditText;  import android.widget.EditText;
61  import android.widget.ListView;  import android.widget.ListView;
62  import android.widget.Toast;  import android.widget.Toast;
63    import dk.thoerup.android.traininfo.common.StationBean;
64    import dk.thoerup.android.traininfo.common.StationBean.StationEntry;
65  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
66  import dk.thoerup.traininfo.provider.StationProvider;  import dk.thoerup.traininfo.provider.StationProvider;
67  import dk.thoerup.traininfo.stationmap.GeoPair;  import dk.thoerup.traininfo.stationmap.GeoPair;
# Line 36  import dk.thoerup.traininfo.stationmap.S Line 69  import dk.thoerup.traininfo.stationmap.S
69  import dk.thoerup.traininfo.util.IntSet;  import dk.thoerup.traininfo.util.IntSet;
70  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
71    
 import static dk.thoerup.traininfo.R.string.*;  
   
72  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
73          public static final int GOTLOCATION = 1001;  
74          public static final int GOTSTATIONLIST = 1002;          
         public static final int NOPROVIDER = 1003;  
         public static final int LOCATIONFIXTIMEOUT = 1004;  
75                    
76          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
77          public static final int OPTIONS_GPSINFO = 2004;          public static final int OPTIONS_GPSINFO = 2004;
   
           
   
78                    
79          public static final int DLG_PROGRESS = 3001;          public static final int DLG_PROGRESS = 3001;
80          public static final int DLG_STATIONNAME = 3002;          public static final int DLG_STATIONNAME = 3002;
81                    
82            
83            public static final int GPS_TIMEOUT_MS = 15000; //how long are we willing to wait for gps fix -in milliseconds
84            
85            
86          static enum LookupMethod {          static enum LookupMethod {
87                  ByLocation,                  ByLocation,
88                  ByName,                  ByName,
# Line 67  public class StationList extends ListAct Line 97  public class StationList extends ListAct
97          FindStationsTask findStationsTask;          FindStationsTask findStationsTask;
98          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();
99                    
100          GeoPair location = new GeoPair();          //GeoPair location = new GeoPair();
101            
102          boolean isRunning = false;          boolean isLaunchedforShortcut;
103          List<StationBean> stations = new ArrayList<StationBean>();  
104            StationBean stations = new StationBean();
105                    
106          StationProvider stationProvider = ProviderFactory.getStationProvider();          StationProvider stationProvider = ProviderFactory.getStationProvider();
107                                    
# Line 81  public class StationList extends ListAct Line 112  public class StationList extends ListAct
112    
113          WelcomeScreen.ListType listType;          WelcomeScreen.ListType listType;
114          SharedPreferences prefs;          SharedPreferences prefs;
115                                    
116          ///////////////////////////////////////////////////////////////////////////////////////////          ///////////////////////////////////////////////////////////////////////////////////////////
117          //Activity call backs          //Activity call backs
118                    
119          @SuppressWarnings("unchecked")  
120          @Override          @Override
121          public void onCreate(Bundle savedInstanceState) {          public void onCreate(Bundle savedInstanceState) {
122                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
# Line 98  public class StationList extends ListAct Line 129  public class StationList extends ListAct
129                  ListView lv = getListView();                  ListView lv = getListView();
130                  lv.setOnCreateContextMenuListener(contextMenu);                  lv.setOnCreateContextMenuListener(contextMenu);
131                                    
132                  locationLookup = new LocationLookup(this, stationsFetched);                  locationLookup = new LocationLookup(this);
133                                    
134    
135                  prefs = getSharedPreferences("TrainStation", 0);                  prefs = getSharedPreferences("TrainStation", 0);
# Line 110  public class StationList extends ListAct Line 141  public class StationList extends ListAct
141                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");
142                  setTitle();                  setTitle();
143                                    
144                    isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false);
145                    
146                    ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
147                    
148                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
149    
150                                                    
151                          switch (listType) {                          switch (listType) {
152                          case ListNearest:                          case ListNearest:
153                                  startLookup();                                  startNearestLookup();
154                                  break;                                  break;
155                          case ListSearch:                          case ListSearch:                                
156                                  this.showDialog(DLG_STATIONNAME);                                  showDialog(DLG_STATIONNAME);
157                                  break;                                  break;
158                          case ListFavorites:                          case ListFavorites:
159                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 128  public class StationList extends ListAct Line 163  public class StationList extends ListAct
163                          }                          }
164                                                    
165                  } else {                  } else {
166                          stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations");                          stations = (StationBean) savedInstanceState.getSerializable("stations");
167                          adapter.setStations(stations);                          adapter.setStations(stations);
                         location = (GeoPair) savedInstanceState.getSerializable("location");  
168                  }                  }
169                                    
170          }          }
171            
172            
173    
174    
175    
176    
177            @Override
178            protected void onDestroy() {
179                    super.onDestroy();
180                    
181                    
182                    if (locationLookup != null) {
183                            locationLookup.stopSearch();
184                    }
185                    if (findStationsTask != null) {
186                            findStationsTask.cancel(true);
187                    }              
188            }
189    
190            
191          protected void setTitle() {          protected void setTitle() {
192                  String dialogTitle = getResources().getString(app_name);                  String dialogTitle = getResources().getString(app_name);
193                  switch (listType) {                  switch (listType) {
# Line 151  public class StationList extends ListAct Line 205  public class StationList extends ListAct
205                  }                  }
206                    
207                  setTitle(dialogTitle);                  setTitle(dialogTitle);
208                    
209          }          }
210                    
211                            
   
212    
213      @Override      @Override
214      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
215      {      {
216          if (dialog != null && dialog.isShowing())          if (dialog != null && dialog.isShowing())
217                  dialog.dismiss();                  dialog.dismiss();
218          outState.putSerializable("stations", (ArrayList<StationBean>) stations);          outState.putSerializable("stations", (StationBean) stations);
         outState.putSerializable("location", location);  
219                    
220      }      }
221                    
# Line 192  public class StationList extends ListAct Line 245  public class StationList extends ListAct
245                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
246                                                    
247                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();
248                          for (StationBean st : stations ) {                          for (StationEntry st : stations.entries ) {
249                                  stationPoints.add( new GeoPair(st.getLatitude(), st.getLongitude(), st.getName()) );                                  stationPoints.add( new GeoPair(st.getLatitude(), st.getLongitude(), st.getName()) );
250                          }                          }
251                                                    
# Line 207  public class StationList extends ListAct Line 260  public class StationList extends ListAct
260                          if (loc != null) {                          if (loc != null) {
261                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
262                                  message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");                                  message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
263                                  message.append( getString(stationlist_latitude) ).append( loc.getLatitude()).append("\n");                                  message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");
264                                  message.append( getString(stationlist_longitude) ).append( loc.getLongitude() ).append("\n");                                  message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");
265                          } else {                          } else {
266                                  message.append( getString(stationlist_nolocation) );                                  message.append( getString(stationlist_nolocation) );
267                          }                                                }                      
268                                                    
269                          MessageBox.showMessage(this, message.toString());                          MessageBox.showMessage(this, message.toString(), false);
270                          break;                          break;
271                  default:                  default:
272                          retval = super.onOptionsItemSelected(item);                          retval = super.onOptionsItemSelected(item);
# Line 270  public class StationList extends ListAct Line 323  public class StationList extends ListAct
323                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
324                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
325                                          dialog.dismiss();                                          dialog.dismiss();
326                                          if (et.getText().toString().length() >= 2) {                                          String search = et.getText().toString().trim();
327                                                  startNameSearch(et.getText().toString());                                          if (search.length() >= 2) {
328                                                    startNameLookup(search);
329                                          } else {                                          } else {
330                                                  showMessageAndClose( getString(stationlist_twocharmin) );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
331                                          }                                          }
# Line 310  public class StationList extends ListAct Line 364  public class StationList extends ListAct
364          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
365                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
366                                                                    
367                  StationBean station = stations.get(position);                  StationEntry station = stations.entries.get(position);
368                                    
369                  Intent intent = new Intent(this, DepartureList.class);                  if (isLaunchedforShortcut == true) {
370                  intent.putExtra("stationbean", station);                          Intent i = new Intent();
371                  startActivity(intent);                          i.putExtra("station", station);
372                            setResult(Activity.RESULT_OK, i);
373                            finish();
374                    } else {                
375                            Intent intent = new Intent(this, DepartureList.class);
376                            intent.putExtra("stationbean", station);
377                            startActivity(intent);
378                    }
379          }          }
380    
381          /////////////////////////////////////////////////////////////          /////////////////////////////////////////////////////////////
382          //          //
383    
384          public void startLookup() {          public void startNearestLookup() {
                 isRunning = true;                
385                  dialogMessage = getString( stationlist_waitforlocation );                  dialogMessage = getString( stationlist_waitforlocation );
386                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
387                                    
388                  locationLookup.locateStations();                  locationLookup.locateStations();
389                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(0, 500);
390          }          }
391                    
392          void startNameSearch(String name) {          void startNameLookup(String name) {
393                  dialogMessage = getString( stationlist_findbyname );                  dialogMessage = getString( stationlist_findbyname );
394                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
395    
396                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
397                  findStationsTask.searchByName(name, locationLookup.getLocation());                  findStationsTask.searchByName(name);
398                  findStationsTask.execute();                  findStationsTask.execute();
399                                    
400          }          }
# Line 346  public class StationList extends ListAct Line 406  public class StationList extends ListAct
406                          showDialog(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);
407    
408                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
409                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());                          findStationsTask.searchByIds( favorites.toString() );
410                          findStationsTask.execute();                          findStationsTask.execute();
411                  } else {                  } else {
412                          showMessageAndClose( getString( stationlist_nofavorites ) );                          showMessageAndClose( getString( stationlist_nofavorites ) );
# Line 358  public class StationList extends ListAct Line 418  public class StationList extends ListAct
418          void startLocatorTask()          void startLocatorTask()
419          {          {
420                  dialogMessage = getString( stationlist_findingnearby );                  dialogMessage = getString( stationlist_findingnearby );
421                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);              
422                                    
423                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
424                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
425                  findStationsTask.execute();                      findStationsTask.execute();    
426          }          }
           
   
         /* TODO: Remove this no longer needed function  
         String lookupAddress(double latitude, double longitude) {  
427                                    
                 Geocoder coder = new Geocoder(this, new Locale("da"));  
                 StringBuilder sb = new StringBuilder();  
                 Log.i("lookupaddr", "" + latitude + "/" + longitude);  
                 try {  
                         List<Address> addressList = coder.getFromLocation(latitude, longitude, 1);  
                         Address addr = addressList.get(0);  
                           
                           
                         int max = addr.getMaxAddressLineIndex();  
                         for (int i=0; i<max; i++) {  
                                 if (i>0)  
                                         sb.append(", ");  
                                   
                                 sb.append(addr.getAddressLine(i));  
                         }  
                           
                           
                 } catch (Exception e) {  
                         Log.e("DepartureList", "geocoder failed", e);  
                 }  
                   
                 return sb.toString();  
         }*/  
           
428                    
429          ////////////////////////////////////////////////////////////////////////////          ////////////////////////////////////////////////////////////////////////////
430          // Inner classes          // Inner classes
# Line 401  public class StationList extends ListAct Line 433  public class StationList extends ListAct
433                  @Override                  @Override
434                  public void handleMessage(Message msg) {                  public void handleMessage(Message msg) {
435    
436                          switch (msg.what) {                          LocationLookup.LookupStates state = locationLookup.getState();
437    
438    
439                            switch (state) {
440                          case GOTLOCATION:                          case GOTLOCATION:
441                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
442                                    
443                                  startLocatorTask();                                  startLocatorTask();
444                                  location = GeoPair.fromLocation( locationLookup.getLocation() );  
445                                                                    return;
                                 break;  
446    
447                          case NOPROVIDER:                          case NOPROVIDER:
448                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
449                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
450                                  break;                                  //StationList.this.finish();
451                          case LOCATIONFIXTIMEOUT:                                                                  return;
452                                  if (isRunning) {                          }
                                         locationLookup.stopSearch();  
                                         if (locationLookup.hasLocation()) {  
                                                 stationsFetched.sendEmptyMessage( GOTLOCATION );  
                                         } else {                                                  
                                                 dismissDialog(DLG_PROGRESS);  
                                                   
                                                 AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                  
                                                 builder.setMessage(  getString( stationlist_gpstimeout) );  
                                                 builder.setCancelable(true);  
                                                 builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {  
                                                         public void onClick(DialogInterface dialog, int id) {  
                                                                 dialog.dismiss();  
                                                                 startLookup();  
                                                                   
                                                         }  
                                                 });  
                                                 builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {  
                                                         public void onClick(DialogInterface dialog, int id) {  
                                                                 dialog.dismiss();  
                                                         }                                                        
                                                 });                                                                                              
                                                 builder.show();  
453    
454                                          }  
455    
456                            if (locationLookup.elapsedTime() >=  GPS_TIMEOUT_MS) {
457                                    try {
458                                            dismissDialog(DLG_PROGRESS);
459                                    } catch (IllegalArgumentException ex) {
460                                            // I get  stacktraces that reports an exception is thrown here -
461                                            // but i can not recreate the situation that causes said exception
462                                            Log.e("TrainInfo", "Why the f*** is this exception thrown here ?? " + ex.getMessage() );
463                                  }                                  }
464                                  break;  
465                                    locationLookup.stopSearch();
466    
467                                    if (locationLookup.hasLocation()) {
468                                            startLocatorTask();
469                                    } else {                                                
470                                            AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
471                                            builder.setMessage(  getString( stationlist_gpstimeout) );
472                                            builder.setCancelable(true);
473                                            builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
474                                                    public void onClick(DialogInterface dialog, int id) {
475                                                            dialog.dismiss();
476                                                            startNearestLookup();
477    
478                                                    }
479                                            });
480                                            builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
481                                                    public void onClick(DialogInterface dialog, int id) {
482                                                            dialog.dismiss();
483                                                            StationList.this.finish(); // Close this Activity
484                                                    }                                                      
485                                            });
486                                            builder.show();
487    
488                                    }
489                            } else {
490                                    if (locationLookup.hasGps()) {
491                                            int count = locationLookup.getSatCount();
492                                            String dialogMessage = getString( stationlist_waitforlocation ) + "\n" + getString( stationlist_satellitecount ) + ": " + count;
493                                            dialog.setMessage( dialogMessage );
494                                    }
495                                    this.sendEmptyMessageDelayed(0, 500);
496                          }                          }
497                          isRunning = false;                          
498                  }                  }
499          };          }
500    
501    
502    
503                    
504          class FindStationsTask extends AsyncTask<Void,Void,Void> {          class FindStationsTask extends AsyncTask<Void,Void,Void> {
505                                    
506                  LookupMethod method = LookupMethod.MethodNone;                  LookupMethod method = LookupMethod.MethodNone;
                 boolean success;  
507                  String name;                  String name;
508                  Location loc;                  Location loc;
509                  String ids;                  String ids;
510                                    
511                  public void searchByName(String n, Location l) {                  public void searchByName(String n) {
512                                                    
513                          method = LookupMethod.ByName;                          method = LookupMethod.ByName;
                         loc = l;  
514                          name = n;                          name = n;
515                  }                  }
516                                    
# Line 468  public class StationList extends ListAct Line 519  public class StationList extends ListAct
519                          loc = l;                          loc = l;
520                  }                  }
521                                    
522                  public void searchByIds(String id, Location l) {                  public void searchByIds(String id) {
523                                                    
524                          method = LookupMethod.ByList;                          method = LookupMethod.ByList;
                         loc = l;  
525                          ids = id;                          ids = id;
526                  }                  }
527                                    
# Line 488  public class StationList extends ListAct Line 538  public class StationList extends ListAct
538    
539                          switch (method) {                          switch (method) {
540                          case ByLocation:                          case ByLocation:
541                                  success = stationProvider.lookupStations(loc);                                  stations = stationProvider.lookupStationsByLocation(loc);
542                                  break;                                  break;
543                          case ByName:                          case ByName:
544                                  success = stationProvider.lookupStationsByName(name);                                  stations = stationProvider.lookupStationsByName(name);
545                                  break;                                  break;
546                          case ByList:                          case ByList:
547                                  success = stationProvider.lookupStationsByIds(ids);                                  stations = stationProvider.lookupStationsByIds(ids);
548                                  break;                                  break;
549                          default:                          default:
550                                  success = false; // not possible                                          stations = null; // not possible        
551                          }                          }
552                                                    
553                                                    
                         Location dummy = new Location("gps");  
                         List<StationBean> stations = stationProvider.getStations();  
                           
                         for (StationBean station : stations) {  
                                                                   
                                 if (method.equals(LookupMethod.ByName) || method.equals(LookupMethod.ByList)) {  
                                         if (loc != null) { //only do the distance calc if we have a location  
                                                 dummy.setLatitude(station.getLatitude());  
                                                 dummy.setLongitude(station.getLongitude());  
                                                 station.setDistance( (int)loc.distanceTo(dummy) );  
                                         } else {  
                                                 station.setDistance(0);  
                                         }  
                                 }  
   
                         }                                                
                           
554                          return null;                          return null;
555                  }                  }
556    
# Line 527  public class StationList extends ListAct Line 560  public class StationList extends ListAct
560                          dialog.dismiss();                          dialog.dismiss();
561                                                    
562                                                    
563                          if (success) {                                                    if (stations != null) {                        
564                                  if (stationProvider.getStations().size() == 0)                                  if (stations.entries.size() == 0) {
565                                          MessageBox.showMessage(StationList.this, getString(stationlist_nostations) ); // this should not be possible !?!                                          showMessageAndClose(getString(stationlist_nostations));
566                                  stations = stationProvider.getStations();                                  }
567    
568                                    StationList.this.getListView().invalidateViews();
569                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
570                                                                    
571                                    
572                          } else { //communication or parse errors                          } else { //communication or parse errors
573                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
574                                  builder.setMessage(getString(stationlist_nearbyerror));                                                          builder.setMessage(getString(stationlist_fetcherror));                          
575                                  builder.setCancelable(true);                                  builder.setCancelable(true);
576                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
577                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
578                                                  dialog.dismiss();                                                  dialog.dismiss();
579                                                                                                    
580                                                  stationsFetched.post( new Runnable() {                                                  Runnable runner = null;
581                                                          @Override                                                  switch (method) {
582                                                          public void run() {                                                  case ByLocation:
583                                                                  startLocatorTask();                                                                                                                      runner = new Runnable() {
584                                                          }                                                                  @Override
585                                                  });                                                                  public void run() {
586                                                                            startLocatorTask();                                                            
587                                                                    }
588                                                            };
589                                                            break;
590                                                    case ByName:
591                                                            runner = new Runnable() {
592                                                                    @Override
593                                                                    public void run() {
594                                                                            startNameLookup( FindStationsTask.this.name );
595                                                                    }
596                                                            };
597                                                            break;
598                                                    case ByList:
599                                                            runner = new Runnable() {
600                                                                    @Override
601                                                                    public void run() {
602                                                                            startFavoriteLookup();
603                                                                    }
604                                                            };
605                                                            break;
606                                                    }
607                                                    
608                                                    stationsFetched.post( runner );
609                                          }                                          }
610                                  });                                  });
611                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
612                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
613                                                  dialog.dismiss();                                                  dialog.dismiss();
614                                                    StationList.this.finish();
615                                          }                                                                                                }                                                      
616                                  });                                                                                                                              });
617                                  builder.show();                                                          
618                                    builder.show();
619                          }                          }
620                  }                  }
621          }          }
# Line 572  public class StationList extends ListAct Line 633  public class StationList extends ListAct
633                                                                                                    
634                          AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;                          AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
635                          selectedPosition = info.position;                          selectedPosition = info.position;
636                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.entries.get(selectedPosition).getId();
637    
638                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
639                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
640                          } else {                          } else {
641                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_addfavorite) );                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) );
642                          }                          }
643                                                    
644                  }                  }
645                                    
646                  public void onContextItemSelected(MenuItem item) {                  public void onContextItemSelected(MenuItem item) {
647                          StationBean sb = stations.get(selectedPosition);                          StationEntry sb = stations.entries.get(selectedPosition);
648                                                    
649                          int stationID = sb.getId();                          int stationID = sb.getId();
650                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
# Line 596  public class StationList extends ListAct Line 657  public class StationList extends ListAct
657                                                                    
658                                                                    
659                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {
660                                          stations.remove(selectedPosition);                                          stations.entries.remove(selectedPosition);
661                                          adapter.notifyDataSetChanged();                                          adapter.notifyDataSetChanged();
662                                  }                                  }
663                          }                          }

Legend:
Removed from v.561  
changed lines
  Added in v.1219

  ViewVC Help
Powered by ViewVC 1.1.20