/[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 483 by torben, Thu Oct 29 10:49:14 2009 UTC revision 1027 by torben, Wed Sep 8 06:03:45 2010 UTC
# Line 2  package dk.thoerup.traininfo; Line 2  package dk.thoerup.traininfo;
2    
3  import java.util.ArrayList;  import java.util.ArrayList;
4  import java.util.List;  import java.util.List;
 import java.util.Locale;  
5    
6    
7    import android.app.Activity;
8  import android.app.AlertDialog;  import android.app.AlertDialog;
9  import android.app.Dialog;  import android.app.Dialog;
10  import android.app.ListActivity;  import android.app.ListActivity;
# Line 12  import android.content.DialogInterface; Line 13  import android.content.DialogInterface;
13  import android.content.Intent;  import android.content.Intent;
14  import android.content.SharedPreferences;  import android.content.SharedPreferences;
15  import android.content.SharedPreferences.Editor;  import android.content.SharedPreferences.Editor;
 import android.location.Address;  
 import android.location.Geocoder;  
16  import android.location.Location;  import android.location.Location;
17  import android.os.AsyncTask;  import android.os.AsyncTask;
18  import android.os.Bundle;  import android.os.Bundle;
19  import android.os.Handler;  import android.os.Handler;
20  import android.os.Message;  import android.os.Message;
21  import android.util.Log;  
22  import android.view.ContextMenu;  import android.view.ContextMenu;
23  import android.view.LayoutInflater;  import android.view.LayoutInflater;
24  import android.view.Menu;  import android.view.Menu;
# Line 38  import dk.thoerup.traininfo.stationmap.S Line 37  import dk.thoerup.traininfo.stationmap.S
37  import dk.thoerup.traininfo.util.IntSet;  import dk.thoerup.traininfo.util.IntSet;
38  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
39    
40    import static dk.thoerup.traininfo.R.string.*;
41    
42  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
43          public static final int GOTLOCATION = 1001;          public static final int GOTLOCATION = 1001;
44          public static final int GOTSTATIONLIST = 1002;          public static final int GOTSTATIONLIST = 1002;
# Line 46  public class StationList extends ListAct Line 47  public class StationList extends ListAct
47                    
48          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
49          public static final int OPTIONS_GPSINFO = 2004;          public static final int OPTIONS_GPSINFO = 2004;
   
           
   
50                    
51          public static final int DLG_PROGRESS = 3001;          public static final int DLG_PROGRESS = 3001;
52          public static final int DLG_STATIONNAME = 3002;          public static final int DLG_STATIONNAME = 3002;
53                    
54            
55            public static final int GPS_TIMEOUT_MS = 15000; //how long are we willing to wait for gps fix -in milliseconds
56            
57            
58          static enum LookupMethod {          static enum LookupMethod {
59                  ByLocation,                  ByLocation,
60                  ByName,                  ByName,
# Line 68  public class StationList extends ListAct Line 70  public class StationList extends ListAct
70          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();          StationsFetchedHandler stationsFetched = new StationsFetchedHandler();
71                    
72          GeoPair location = new GeoPair();          GeoPair location = new GeoPair();
73            
74            boolean isLaunchedforShortcut;
75          boolean isRunning = false;          boolean isRunning = false;
76          List<StationBean> stations = new ArrayList<StationBean>();          List<StationBean> stations = new ArrayList<StationBean>();
77                    
# Line 110  public class StationList extends ListAct Line 113  public class StationList extends ListAct
113                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");                  listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");
114                  setTitle();                  setTitle();
115                                    
116                    isLaunchedforShortcut = getIntent().getBooleanExtra("shortcut", false);
117                    
118                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
119    
120                                                    
# Line 117  public class StationList extends ListAct Line 122  public class StationList extends ListAct
122                          case ListNearest:                          case ListNearest:
123                                  startLookup();                                  startLookup();
124                                  break;                                  break;
125                          case ListSearch:                          case ListSearch:                                
126                                  this.showDialog(DLG_STATIONNAME);                                  showDialog(DLG_STATIONNAME);
127                                  break;                                  break;
128                          case ListFavorites:                          case ListFavorites:
129                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 134  public class StationList extends ListAct Line 139  public class StationList extends ListAct
139                  }                  }
140                                    
141          }          }
142            
143            
144            
145    
146            @Override
147            protected void onStart() {
148                    super.onStart();
149                    ProviderFactory.purgeOldEntries();
150            }
151    
152    
153    
154    
155            @Override
156            protected void onDestroy() {
157                    super.onDestroy();
158                    
159                    isRunning = false;
160                    
161                    if (locationLookup != null) {
162                            locationLookup.stopSearch();
163                    }
164                    if (findStationsTask != null) {
165                            findStationsTask.cancel(true);
166                    }              
167            }
168    
169            
170          protected void setTitle() {          protected void setTitle() {
171                  String dialogTitle;                  String dialogTitle = getResources().getString(app_name);
172                  switch (listType) {                  switch (listType) {
173                  case ListNearest:                  case ListNearest:
174                          dialogTitle = "TrainInfo DK - Nearby stations";                          dialogTitle += " - " + getString(stationlist_nearbystations);
175                          break;                          break;
176                  case ListSearch:                  case ListSearch:
177                          dialogTitle = "TrainInfo DK - Search";                          dialogTitle += " - " + getString(stationlist_search);
178                          break;                          break;
179                  case ListFavorites:                  case ListFavorites:
180                          dialogTitle = "TrainInfo DK - Favorites";                          dialogTitle += " - " + getString(stationlist_favorites);
181                          break;                          break;
182                  default:                  default:
183                          dialogTitle = "";//not possible                                                          dialogTitle = "";//not possible                                
184                  }                  }
185                    
186                  setTitle(dialogTitle);                  setTitle(dialogTitle);
187                    
188          }          }
189                    
190                            
   
191    
192      @Override      @Override
193      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
# Line 171  public class StationList extends ListAct Line 204  public class StationList extends ListAct
204          @Override          @Override
205          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
206                  MenuItem item;                  MenuItem item;
207                                                    
208                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");                  item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap));
209                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
210                                    
211                  item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info");                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));
212                  item.setIcon(android.R.drawable.ic_menu_mapmode);                                item.setIcon(android.R.drawable.ic_menu_mapmode);              
213                                    
214                  return true;                  return true;
# Line 190  public class StationList extends ListAct Line 223  public class StationList extends ListAct
223                  case OPTIONS_MAP:                  case OPTIONS_MAP:
224                                                    
225                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
                         intent.putExtra("userlocation", location );  
226                                                    
227                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();
228                          for (StationBean st : stations ) {                          for (StationBean st : stations ) {
# Line 204  public class StationList extends ListAct Line 236  public class StationList extends ListAct
236                  case OPTIONS_GPSINFO:                  case OPTIONS_GPSINFO:
237                          Location loc = locationLookup.getLocation();                          Location loc = locationLookup.getLocation();
238                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
239                          message.append("Location info:\n");                          message.append( getString(stationlist_locationinfo) ).append(":\n");
240                          message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n");                          if (loc != null) {
241                          message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n");                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
242                                    message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
243                          MessageBox.showMessage(this, message.toString());                                  message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");
244                                    message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");
245                            } else {
246                                    message.append( getString(stationlist_nolocation) );
247                            }                      
248                            
249                            MessageBox.showMessage(this, message.toString(), false);
250                          break;                          break;
251                  default:                  default:
252                          retval = super.onOptionsItemSelected(item);                          retval = super.onOptionsItemSelected(item);
# Line 226  public class StationList extends ListAct Line 264  public class StationList extends ListAct
264    
265    
266          }          }
267            
268            public void showMessageAndClose(String message) {
269                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
270                    builder.setMessage(message)
271                    .setCancelable(false)
272                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
273                            public void onClick(DialogInterface dialog, int id) {
274                                    dialog.dismiss();
275                                    StationList.this.finish();
276                            }
277                    })
278                    .show();
279            }
280    
281    
282    
# Line 235  public class StationList extends ListAct Line 286  public class StationList extends ListAct
286                  switch (id) {                  switch (id) {
287                  case DLG_PROGRESS:                  case DLG_PROGRESS:
288                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);
289                          dlg.setMessage("Wait for location fix");                          dlg.setMessage( getString(stationlist_waitforlocation) );
290                          dlg.setCancelable(false);                          dlg.setCancelable(false);
291                          return dlg;                                              return dlg;                    
292                  case DLG_STATIONNAME:                  case DLG_STATIONNAME:
# Line 245  public class StationList extends ListAct Line 296  public class StationList extends ListAct
296                                                    
297                          AlertDialog.Builder builder = new AlertDialog.Builder(this);                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
298                                                    
299                          builder.setTitle("Station search");                          builder.setTitle( getString(stationlist_stationsearch) );
300                          builder.setView(rootView);                          builder.setView(rootView);
301                          builder.setCancelable(true);                          builder.setCancelable(true);
302                          builder.setPositiveButton("Search", new DialogInterface.OnClickListener() {                          builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() {
303                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
304                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
305                                          dialog.dismiss();                                          dialog.dismiss();
306                                          if (et.getText().toString().length() >= 2) {                                          String search = et.getText().toString().trim();
307                                                  startNameSearch(et.getText().toString());                                          if (search.length() >= 2) {
308                                                    startNameSearch(search);
309                                          } else {                                          } else {
310                                                  MessageBox.showMessage(StationList.this, "Two characters minimum" );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
311                                          }                                          }
312                                  }                                  }
313                          });                          });
314                          builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                          builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
315                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
316                                          dialog.dismiss();                                          dialog.dismiss();
317                                            StationList.this.finish(); // Close this Activity
318                                  }                                  }
319                          });                                              });                    
320                          return builder.create();                          return builder.create();
# Line 292  public class StationList extends ListAct Line 345  public class StationList extends ListAct
345                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
346                                                                    
347                  StationBean station = stations.get(position);                  StationBean station = stations.get(position);
   
                 double latitude = station.getLatitude();  
                 double longitude = station.getLongitude();  
   
   
348                                    
349                  Intent intent = new Intent(this, DepartureList.class);                  if (isLaunchedforShortcut == true) {
350                  intent.putExtra("name", station.getName());                          Intent i = new Intent();
351                  intent.putExtra("distance", station.getDistance());                          i.putExtra("station", station);
352                  intent.putExtra("latitude", latitude);                          setResult(Activity.RESULT_OK, i);
353                  intent.putExtra("longitude", longitude);                          finish();
354                  intent.putExtra("stationid", station.getId());                  } else {                
355                  intent.putExtra("address", station.getAddress());                          Intent intent = new Intent(this, DepartureList.class);
356                  startActivity(intent);                          intent.putExtra("stationbean", station);
357                            startActivity(intent);
358                    }
359          }          }
360    
361          /////////////////////////////////////////////////////////////          /////////////////////////////////////////////////////////////
362          //          //
363    
364          public void startLookup() {          public void startLookup() {
365                  isRunning = true;                  isRunning = true;              
366                  dialogMessage = "Wait for location fix";                  dialogMessage = getString( stationlist_waitforlocation );
367                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
368                                    
369                  locationLookup.locateStations();                  locationLookup.locateStations();
370                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, GPS_TIMEOUT_MS);
371          }          }
372                    
373          void startNameSearch(String name) {          void startNameSearch(String name) {
374                  dialogMessage = "Finding stations by name";                  dialogMessage = getString( stationlist_findbyname );
375                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
376    
377                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
378                  findStationsTask.searchByName(name, locationLookup.getLocation());                  findStationsTask.searchByName(name);
379                  findStationsTask.execute();                  findStationsTask.execute();
380                                    
381          }          }
# Line 333  public class StationList extends ListAct Line 383  public class StationList extends ListAct
383          public void startFavoriteLookup() {          public void startFavoriteLookup() {
384                                    
385                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
386                          dialogMessage = "Loading favorites";                          dialogMessage = getString( stationlist_loadfavorites );
387                          showDialog(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);
388    
389                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
390                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());                          findStationsTask.searchByIds( favorites.toString() );
391                          findStationsTask.execute();                          findStationsTask.execute();
392                  } else {                  } else {
393                          MessageBox.showMessage(this, "Favorite list is empty");                          showMessageAndClose( getString( stationlist_nofavorites ) );
394                  }                  }
395          }          }
396    
# Line 348  public class StationList extends ListAct Line 398  public class StationList extends ListAct
398                    
399          void startLocatorTask()          void startLocatorTask()
400          {          {
401                  dialogMessage = "Finding nearby stations";                  dialogMessage = getString( stationlist_findingnearby );
402                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
403                                    
404                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
405                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
406                  findStationsTask.execute();                      findStationsTask.execute();    
407          }          }
           
   
         String lookupAddress(double latitude, double longitude) {  
408                                    
                 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();  
         }  
           
409                    
410          ////////////////////////////////////////////////////////////////////////////          ////////////////////////////////////////////////////////////////////////////
411          // Inner classes          // Inner classes
# Line 402  public class StationList extends ListAct Line 425  public class StationList extends ListAct
425    
426                          case NOPROVIDER:                          case NOPROVIDER:
427                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
428                                  MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps.");                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
429                                    //StationList.this.finish();
430                                  break;                                  break;
431                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
432                                  if (isRunning) {                                  if (isRunning) {
# Line 413  public class StationList extends ListAct Line 437  public class StationList extends ListAct
437                                                  dismissDialog(DLG_PROGRESS);                                                  dismissDialog(DLG_PROGRESS);
438                                                                                                    
439                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
440                                                  builder.setMessage("Location fix timed out");                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
441                                                  builder.setCancelable(true);                                                  builder.setCancelable(true);
442                                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
443                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
444                                                                  dialog.dismiss();                                                                  dialog.dismiss();
445                                                                  startLookup();                                                                  startLookup();
446                                                                                                                                    
447                                                          }                                                          }
448                                                  });                                                  });
449                                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                                  builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
450                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
451                                                                  dialog.dismiss();                                                                  dialog.dismiss();
452                                                          }                                                                                                                }                                                      
453                                                  });                                                                                                                                              });
454                                                  builder.show();                                                  builder.show();
455    
456                                          }                                          }
457                                  }                                  }
# Line 441  public class StationList extends ListAct Line 465  public class StationList extends ListAct
465          class FindStationsTask extends AsyncTask<Void,Void,Void> {          class FindStationsTask extends AsyncTask<Void,Void,Void> {
466                                    
467                  LookupMethod method = LookupMethod.MethodNone;                  LookupMethod method = LookupMethod.MethodNone;
                 boolean success;  
468                  String name;                  String name;
469                  Location loc;                  Location loc;
470                  String ids;                  String ids;
471                                    
472                  public void searchByName(String n, Location l) {                  public void searchByName(String n) {
473                                                    
474                          method = LookupMethod.ByName;                          method = LookupMethod.ByName;
                         loc = l;  
475                          name = n;                          name = n;
476                  }                  }
477                                    
# Line 458  public class StationList extends ListAct Line 480  public class StationList extends ListAct
480                          loc = l;                          loc = l;
481                  }                  }
482                                    
483                  public void searchByIds(String id, Location l) {                  public void searchByIds(String id) {
484                                                    
485                          method = LookupMethod.ByList;                          method = LookupMethod.ByList;
                         loc = l;  
486                          ids = id;                          ids = id;
487                  }                  }
488                                    
# Line 478  public class StationList extends ListAct Line 499  public class StationList extends ListAct
499    
500                          switch (method) {                          switch (method) {
501                          case ByLocation:                          case ByLocation:
502                                  success = stationProvider.lookupStations(loc);                                  stations = stationProvider.lookupStations(loc);
503                                  break;                                  break;
504                          case ByName:                          case ByName:
505                                  success = stationProvider.lookupStationsByName(name);                                  stations = stationProvider.lookupStationsByName(name);
506                                  break;                                  break;
507                          case ByList:                          case ByList:
508                                  success = stationProvider.lookupStationsByIds(ids);                                  stations = stationProvider.lookupStationsByIds(ids);
509                                  break;                                  break;
510                          default:                          default:
511                                  success = false; // not possible                                          stations = null; // not possible        
512                          }                          }
513                                                    
514                                                    
                         Location dummy = new Location("gps");  
                         List<StationBean> stations = stationProvider.getStations();  
                           
                         for (StationBean station : stations) {  
                                 String addr = lookupAddress(station.getLatitude(), station.getLongitude());  
                                 station.setAddress(addr);  
                                   
                                   
                                 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);  
                                         }  
                                 }  
   
                         }                                                
                           
515                          return null;                          return null;
516                  }                  }
517    
# Line 520  public class StationList extends ListAct Line 521  public class StationList extends ListAct
521                          dialog.dismiss();                          dialog.dismiss();
522                                                    
523                                                    
524                          if (success) {                                                    if (stations != null) {                        
525                                  if (stationProvider.getStations().size() == 0)                                  if (stations.size() == 0) {
526                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          showMessageAndClose(getString(stationlist_nostations));
527                                  stations = stationProvider.getStations();                                  }
528    
529                                    StationList.this.getListView().invalidateViews();
530                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
531                                                                    
532                                    
533                          } else { //communication or parse errors                          } else { //communication or parse errors
534                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
535                                  builder.setMessage("Error on finding nearby stations");                                  builder.setMessage(getString(stationlist_fetcherror));                          
536                                  builder.setCancelable(true);                                  builder.setCancelable(true);
537                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
538                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
539                                                  dialog.dismiss();                                                  dialog.dismiss();
540                                                                                                    
541                                                  stationsFetched.post( new Runnable() {                                                  Runnable runner = null;
542                                                          @Override                                                  switch (method) {
543                                                          public void run() {                                                  case ByLocation:
544                                                                  startLocatorTask();                                                                                                                      runner = new Runnable() {
545                                                          }                                                                  @Override
546                                                  });                                                                  public void run() {
547                                                                            startLocatorTask();                                                            
548                                                                    }
549                                                            };
550                                                            break;
551                                                    case ByName:
552                                                            runner = new Runnable() {
553                                                                    @Override
554                                                                    public void run() {
555                                                                            startNameSearch( FindStationsTask.this.name );
556                                                                    }
557                                                            };
558                                                            break;
559                                                    case ByList:
560                                                            runner = new Runnable() {
561                                                                    @Override
562                                                                    public void run() {
563                                                                            startFavoriteLookup();
564                                                                    }
565                                                            };
566                                                            break;
567                                                    }
568                                                    
569                                                    stationsFetched.post( runner );
570                                          }                                          }
571                                  });                                  });
572                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
573                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
574                                                  dialog.dismiss();                                                  dialog.dismiss();
575                                                    StationList.this.finish();
576                                          }                                                                                                }                                                      
577                                  });                                                                                                                              });
578                                  builder.show();                                                          
579                                    builder.show();
580                          }                          }
581                  }                  }
582          }          }
# Line 568  public class StationList extends ListAct Line 597  public class StationList extends ListAct
597                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.get(selectedPosition).getId();
598    
599                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
600                                  menu.add(0, FAVORITES_ADD, 0, "Add to favorites");                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
601                          } else {                          } else {
602                                  menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites");                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) );
603                          }                          }
604                                                    
605                  }                  }
# Line 581  public class StationList extends ListAct Line 610  public class StationList extends ListAct
610                          int stationID = sb.getId();                          int stationID = sb.getId();
611                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
612                                  favorites.add(stationID);                                  favorites.add(stationID);
613                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show();
614                          } else {                          } else {
615                                                                    
616                                  favorites.remove(stationID);                                  favorites.remove(stationID);
617                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show();
618                                                                    
619                                                                    
620                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {

Legend:
Removed from v.483  
changed lines
  Added in v.1027

  ViewVC Help
Powered by ViewVC 1.1.20