/[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 906 by torben, Fri Jun 25 23:59:58 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    
22  import android.util.Log;  import android.util.Log;
23  import android.view.ContextMenu;  import android.view.ContextMenu;
24  import android.view.LayoutInflater;  import android.view.LayoutInflater;
# Line 38  import dk.thoerup.traininfo.stationmap.S Line 38  import dk.thoerup.traininfo.stationmap.S
38  import dk.thoerup.traininfo.util.IntSet;  import dk.thoerup.traininfo.util.IntSet;
39  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
40    
41    import static dk.thoerup.traininfo.R.string.*;
42    
43  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
44          public static final int GOTLOCATION = 1001;          public static final int GOTLOCATION = 1001;
45          public static final int GOTSTATIONLIST = 1002;          public static final int GOTSTATIONLIST = 1002;
# 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 118  public class StationList extends ListAct Line 123  public class StationList extends ListAct
123                                  startLookup();                                  startLookup();
124                                  break;                                  break;
125                          case ListSearch:                          case ListSearch:
126                                  this.showDialog(DLG_STATIONNAME);                                  this.showDialogSafe(DLG_STATIONNAME);
127                                  break;                                  break;
128                          case ListFavorites:                          case ListFavorites:
129                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 135  public class StationList extends ListAct Line 140  public class StationList extends ListAct
140                                    
141          }          }
142          protected void setTitle() {          protected void setTitle() {
143                  String dialogTitle;                  String dialogTitle = getResources().getString(app_name);
144                  switch (listType) {                  switch (listType) {
145                  case ListNearest:                  case ListNearest:
146                          dialogTitle = "TrainInfo DK - Nearby stations";                          dialogTitle += " - " + getString(stationlist_nearbystations);
147                          break;                          break;
148                  case ListSearch:                  case ListSearch:
149                          dialogTitle = "TrainInfo DK - Search";                          dialogTitle += " - " + getString(stationlist_search);
150                          break;                          break;
151                  case ListFavorites:                  case ListFavorites:
152                          dialogTitle = "TrainInfo DK - Favorites";                          dialogTitle += " - " + getString(stationlist_favorites);
153                          break;                          break;
154                  default:                  default:
155                          dialogTitle = "";//not possible                                                          dialogTitle = "";//not possible                                
156                  }                  }
157                    
158                  setTitle(dialogTitle);                  setTitle(dialogTitle);
159                    
160            }
161            
162            
163            /* these 3 dialogs helper functions are very rude and ugly hack
164             * to remove these auto-reported exceptions
165             * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?
166             * - java.lang.IllegalArgumentException: View not attached to window manager
167             */
168            
169            public void showDialogSafe(int id) {
170                    try {
171                            showDialog(id);
172                    } catch (Exception e) {
173                            Log.e("StationList", "showDialog failed", e);
174                    }
175            }
176            
177            public void dismissDialogSafe(int id) {
178                    try {
179                            dismissDialog(id);
180                    } catch (Exception e) {
181                            Log.e("StationList", "dismissDialog failed", e);
182                    }
183            }
184            public void dismissDialogSafe(Dialog dlg) {
185                    try {
186                            dlg.dismiss();
187                    } catch (Exception e) {
188                            Log.e("StationList", "dismissDialog failed", e);
189                    }
190          }          }
191                    
192            public void builderShowSafe(AlertDialog.Builder builder) {
193                    try {
194                            builder.show();
195                    } catch (Exception e) {
196                            Log.e("StationList", "builder.show() failed", e);
197                    }
198                    
199            }
200            /* EOF rude and ugly dialog hack */
201                    
202    
203    
# Line 171  public class StationList extends ListAct Line 216  public class StationList extends ListAct
216          @Override          @Override
217          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
218                  MenuItem item;                  MenuItem item;
219                                                    
220                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");                  item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap));
221                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
222                                    
223                  item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info");                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));
224                  item.setIcon(android.R.drawable.ic_menu_mapmode);                                item.setIcon(android.R.drawable.ic_menu_mapmode);              
225                                    
226                  return true;                  return true;
# Line 190  public class StationList extends ListAct Line 235  public class StationList extends ListAct
235                  case OPTIONS_MAP:                  case OPTIONS_MAP:
236                                                    
237                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
                         intent.putExtra("userlocation", location );  
238                                                    
239                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();
240                          for (StationBean st : stations ) {                          for (StationBean st : stations ) {
# Line 204  public class StationList extends ListAct Line 248  public class StationList extends ListAct
248                  case OPTIONS_GPSINFO:                  case OPTIONS_GPSINFO:
249                          Location loc = locationLookup.getLocation();                          Location loc = locationLookup.getLocation();
250                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
251                          message.append("Location info:\n");                          message.append( getString(stationlist_locationinfo) ).append(":\n");
252                          message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n");                          if (loc != null) {
253                          message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n");                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
254                                    message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
255                          MessageBox.showMessage(this, message.toString());                                  message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");
256                                    message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");
257                            } else {
258                                    message.append( getString(stationlist_nolocation) );
259                            }                      
260                            
261                            MessageBox.showMessage(this, message.toString(), false);
262                          break;                          break;
263                  default:                  default:
264                          retval = super.onOptionsItemSelected(item);                          retval = super.onOptionsItemSelected(item);
# Line 226  public class StationList extends ListAct Line 276  public class StationList extends ListAct
276    
277    
278          }          }
279            
280            public void showMessageAndClose(String message) {
281                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
282                    builder.setMessage(message)
283                    .setCancelable(false)
284                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
285                            public void onClick(DialogInterface dialog, int id) {
286                                    dialog.dismiss();
287                                    StationList.this.finish();
288                            }
289                    })
290                    .show();
291            }
292    
293    
294    
# Line 235  public class StationList extends ListAct Line 298  public class StationList extends ListAct
298                  switch (id) {                  switch (id) {
299                  case DLG_PROGRESS:                  case DLG_PROGRESS:
300                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);
301                          dlg.setMessage("Wait for location fix");                          dlg.setMessage( getString(stationlist_waitforlocation) );
302                          dlg.setCancelable(false);                          dlg.setCancelable(false);
303                          return dlg;                                              return dlg;                    
304                  case DLG_STATIONNAME:                  case DLG_STATIONNAME:
# Line 245  public class StationList extends ListAct Line 308  public class StationList extends ListAct
308                                                    
309                          AlertDialog.Builder builder = new AlertDialog.Builder(this);                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
310                                                    
311                          builder.setTitle("Station search");                          builder.setTitle( getString(stationlist_stationsearch) );
312                          builder.setView(rootView);                          builder.setView(rootView);
313                          builder.setCancelable(true);                          builder.setCancelable(true);
314                          builder.setPositiveButton("Search", new DialogInterface.OnClickListener() {                          builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() {
315                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
316                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
317                                          dialog.dismiss();                                          dialog.dismiss();
318                                          if (et.getText().toString().length() >= 2) {                                          String search = et.getText().toString().trim();
319                                                  startNameSearch(et.getText().toString());                                          if (search.length() >= 2) {
320                                                    startNameSearch(search);
321                                          } else {                                          } else {
322                                                  MessageBox.showMessage(StationList.this, "Two characters minimum" );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
323                                          }                                          }
324                                  }                                  }
325                          });                          });
326                          builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                          builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
327                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
328                                          dialog.dismiss();                                          dialog.dismiss();
329                                            StationList.this.finish(); // Close this Activity
330                                  }                                  }
331                          });                                              });                    
332                          return builder.create();                          return builder.create();
# Line 292  public class StationList extends ListAct Line 357  public class StationList extends ListAct
357                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
358                                                                    
359                  StationBean station = stations.get(position);                  StationBean station = stations.get(position);
   
                 double latitude = station.getLatitude();  
                 double longitude = station.getLongitude();  
   
   
360                                    
361                  Intent intent = new Intent(this, DepartureList.class);                  if (isLaunchedforShortcut == true) {
362                  intent.putExtra("name", station.getName());                          Intent i = new Intent();
363                  intent.putExtra("distance", station.getDistance());                          i.putExtra("station", station);
364                  intent.putExtra("latitude", latitude);                          setResult(Activity.RESULT_OK, i);
365                  intent.putExtra("longitude", longitude);                          finish();
366                  intent.putExtra("stationid", station.getId());                  } else {                
367                  intent.putExtra("address", station.getAddress());                          Intent intent = new Intent(this, DepartureList.class);
368                  startActivity(intent);                          intent.putExtra("stationbean", station);
369                            startActivity(intent);
370                    }
371          }          }
372    
373          /////////////////////////////////////////////////////////////          /////////////////////////////////////////////////////////////
374          //          //
375    
376          public void startLookup() {          public void startLookup() {
377                  isRunning = true;                  isRunning = true;              
378                  dialogMessage = "Wait for location fix";                  dialogMessage = getString( stationlist_waitforlocation );
379                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
380                                    
381                  locationLookup.locateStations();                  locationLookup.locateStations();
382                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);
383          }          }
384                    
385          void startNameSearch(String name) {          void startNameSearch(String name) {
386                  dialogMessage = "Finding stations by name";                  dialogMessage = getString( stationlist_findbyname );
387                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
388    
389                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
390                  findStationsTask.searchByName(name, locationLookup.getLocation());                  findStationsTask.searchByName(name);
391                  findStationsTask.execute();                  findStationsTask.execute();
392                                    
393          }          }
# Line 333  public class StationList extends ListAct Line 395  public class StationList extends ListAct
395          public void startFavoriteLookup() {          public void startFavoriteLookup() {
396                                    
397                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
398                          dialogMessage = "Loading favorites";                          dialogMessage = getString( stationlist_loadfavorites );
399                          showDialog(DLG_PROGRESS);                          showDialogSafe(DLG_PROGRESS);
400    
401                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
402                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());                          findStationsTask.searchByIds( favorites.toString() );
403                          findStationsTask.execute();                          findStationsTask.execute();
404                  } else {                  } else {
405                          MessageBox.showMessage(this, "Favorite list is empty");                          showMessageAndClose( getString( stationlist_nofavorites ) );
406                  }                  }
407          }          }
408    
# Line 348  public class StationList extends ListAct Line 410  public class StationList extends ListAct
410                    
411          void startLocatorTask()          void startLocatorTask()
412          {          {
413                  dialogMessage = "Finding nearby stations";                  dialogMessage = getString( stationlist_findingnearby );
414                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
415                                    
416                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
417                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
418                  findStationsTask.execute();                      findStationsTask.execute();    
419          }          }
           
   
         String lookupAddress(double latitude, double longitude) {  
                   
                 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);  
                 }  
420                                    
                 return sb.toString();  
         }  
           
421                    
422          ////////////////////////////////////////////////////////////////////////////          ////////////////////////////////////////////////////////////////////////////
423          // Inner classes          // Inner classes
# Line 393  public class StationList extends ListAct Line 428  public class StationList extends ListAct
428    
429                          switch (msg.what) {                          switch (msg.what) {
430                          case GOTLOCATION:                          case GOTLOCATION:
431                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
432                                                                    
433                                  startLocatorTask();                                  startLocatorTask();
434                                  location = GeoPair.fromLocation( locationLookup.getLocation() );                                  location = GeoPair.fromLocation( locationLookup.getLocation() );
# Line 401  public class StationList extends ListAct Line 436  public class StationList extends ListAct
436                                  break;                                  break;
437    
438                          case NOPROVIDER:                          case NOPROVIDER:
439                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
440                                  MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps.");                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider), true );
441                                    //StationList.this.finish();
442                                  break;                                  break;
443                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
444                                  if (isRunning) {                                  if (isRunning) {
# Line 410  public class StationList extends ListAct Line 446  public class StationList extends ListAct
446                                          if (locationLookup.hasLocation()) {                                          if (locationLookup.hasLocation()) {
447                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );
448                                          } else {                                                                                          } else {                                                
449                                                  dismissDialog(DLG_PROGRESS);                                                  dismissDialogSafe(DLG_PROGRESS);
450                                                                                                    
451                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
452                                                  builder.setMessage("Location fix timed out");                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
453                                                  builder.setCancelable(true);                                                  builder.setCancelable(true);
454                                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
455                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
456                                                                  dialog.dismiss();                                                                  dialog.dismiss();
457                                                                  startLookup();                                                                  startLookup();
458                                                                                                                                    
459                                                          }                                                          }
460                                                  });                                                  });
461                                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                                  builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
462                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
463                                                                  dialog.dismiss();                                                                  dialog.dismiss();
464                                                          }                                                                                                                }                                                      
465                                                  });                                                                                                                                              });
466                                                  builder.show();                                                  builderShowSafe(builder); // builder.show()
467    
468                                          }                                          }
469                                  }                                  }
# Line 446  public class StationList extends ListAct Line 482  public class StationList extends ListAct
482                  Location loc;                  Location loc;
483                  String ids;                  String ids;
484                                    
485                  public void searchByName(String n, Location l) {                  public void searchByName(String n) {
486                                                    
487                          method = LookupMethod.ByName;                          method = LookupMethod.ByName;
                         loc = l;  
488                          name = n;                          name = n;
489                  }                  }
490                                    
# Line 458  public class StationList extends ListAct Line 493  public class StationList extends ListAct
493                          loc = l;                          loc = l;
494                  }                  }
495                                    
496                  public void searchByIds(String id, Location l) {                  public void searchByIds(String id) {
497                                                    
498                          method = LookupMethod.ByList;                          method = LookupMethod.ByList;
                         loc = l;  
499                          ids = id;                          ids = id;
500                  }                  }
501                                    
# Line 491  public class StationList extends ListAct Line 525  public class StationList extends ListAct
525                          }                          }
526                                                    
527                                                    
                         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);  
                                         }  
                                 }  
   
                         }                                                
                           
528                          return null;                          return null;
529                  }                  }
530    
531                  @Override                  @Override
532                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
533                          super.onPostExecute(result);                          super.onPostExecute(result);
534                          dialog.dismiss();                          dismissDialogSafe(dialog);
535                                                    
536                                                    
537                          if (success) {                                                    if (success) {                          
538                                  if (stationProvider.getStations().size() == 0)                                  if (stationProvider.getStations().size() == 0) {
539                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          showMessageAndClose(getString(stationlist_nostations));
540                                    }
541                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
542                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
543                                                                    
544                          } else { //communication or parse errors                          } else { //communication or parse errors
545                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
546                                  builder.setMessage("Error on finding nearby stations");                                  builder.setMessage(getString(stationlist_fetcherror));                          
547                                  builder.setCancelable(true);                                  builder.setCancelable(true);
548                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
549                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
550                                                  dialog.dismiss();                                                  dialog.dismiss();
551                                                                                                    
552                                                  stationsFetched.post( new Runnable() {                                                  Runnable runner = null;
553                                                          @Override                                                  switch (method) {
554                                                          public void run() {                                                  case ByLocation:
555                                                                  startLocatorTask();                                                                                                                      runner = new Runnable() {
556                                                          }                                                                  @Override
557                                                  });                                                                  public void run() {
558                                                                            startLocatorTask();                                                            
559                                                                    }
560                                                            };
561                                                            break;
562                                                    case ByName:
563                                                            runner = new Runnable() {
564                                                                    @Override
565                                                                    public void run() {
566                                                                            startNameSearch( FindStationsTask.this.name );
567                                                                    }
568                                                            };
569                                                            break;
570                                                    case ByList:
571                                                            runner = new Runnable() {
572                                                                    @Override
573                                                                    public void run() {
574                                                                            startFavoriteLookup();
575                                                                    }
576                                                            };
577                                                            break;
578                                                    }
579                                                    
580                                                    stationsFetched.post( runner );
581                                          }                                          }
582                                  });                                  });
583                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
584                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
585                                                  dialog.dismiss();                                                  dialog.dismiss();
586                                                    StationList.this.finish();
587                                          }                                                                                                }                                                      
588                                  });                                                                                                                              });
589                                  builder.show();                                                          
590                                    builderShowSafe(builder); // builder.show()
591                          }                          }
592                  }                  }
593          }          }
# Line 568  public class StationList extends ListAct Line 608  public class StationList extends ListAct
608                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.get(selectedPosition).getId();
609    
610                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
611                                  menu.add(0, FAVORITES_ADD, 0, "Add to favorites");                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
612                          } else {                          } else {
613                                  menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites");                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) );
614                          }                          }
615                                                    
616                  }                  }
# Line 581  public class StationList extends ListAct Line 621  public class StationList extends ListAct
621                          int stationID = sb.getId();                          int stationID = sb.getId();
622                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
623                                  favorites.add(stationID);                                  favorites.add(stationID);
624                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show();
625                          } else {                          } else {
626                                                                    
627                                  favorites.remove(stationID);                                  favorites.remove(stationID);
628                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show();
629                                                                    
630                                                                    
631                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {

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

  ViewVC Help
Powered by ViewVC 1.1.20