/[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 482 by torben, Thu Oct 29 09:38:13 2009 UTC revision 725 by torben, Tue May 11 05:38:18 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;
5  import java.util.Locale;  
6    
7  import android.app.AlertDialog;  import android.app.AlertDialog;
8  import android.app.Dialog;  import android.app.Dialog;
# Line 12  import android.content.DialogInterface; Line 12  import android.content.DialogInterface;
12  import android.content.Intent;  import android.content.Intent;
13  import android.content.SharedPreferences;  import android.content.SharedPreferences;
14  import android.content.SharedPreferences.Editor;  import android.content.SharedPreferences.Editor;
 import android.location.Address;  
 import android.location.Geocoder;  
15  import android.location.Location;  import android.location.Location;
16  import android.os.AsyncTask;  import android.os.AsyncTask;
17  import android.os.Bundle;  import android.os.Bundle;
18  import android.os.Handler;  import android.os.Handler;
19  import android.os.Message;  import android.os.Message;
20    
21  import android.util.Log;  import android.util.Log;
22  import android.view.ContextMenu;  import android.view.ContextMenu;
23  import android.view.LayoutInflater;  import android.view.LayoutInflater;
# 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 118  public class StationList extends ListAct Line 119  public class StationList extends ListAct
119                                  startLookup();                                  startLookup();
120                                  break;                                  break;
121                          case ListSearch:                          case ListSearch:
122                                  this.showDialog(DLG_STATIONNAME);                                  this.showDialogSafe(DLG_STATIONNAME);
123                                  break;                                  break;
124                          case ListFavorites:                          case ListFavorites:
125                                  startFavoriteLookup();                                  startFavoriteLookup();
# Line 135  public class StationList extends ListAct Line 136  public class StationList extends ListAct
136                                    
137          }          }
138          protected void setTitle() {          protected void setTitle() {
139                  String dialogTitle;                  String dialogTitle = getResources().getString(app_name);
140                  switch (listType) {                  switch (listType) {
141                  case ListNearest:                  case ListNearest:
142                          dialogTitle = "Traininfo DK - Nearby stations";                          dialogTitle += " - " + getString(stationlist_nearbystations);
143                          break;                          break;
144                  case ListSearch:                  case ListSearch:
145                          dialogTitle = "Traininfo DK - Search";                          dialogTitle += " - " + getString(stationlist_search);
146                          break;                          break;
147                  case ListFavorites:                  case ListFavorites:
148                          dialogTitle = "Traininfo DK - Favorites";                          dialogTitle += " - " + getString(stationlist_favorites);
149                          break;                          break;
150                  default:                  default:
151                          dialogTitle = "";//not possible                                                          dialogTitle = "";//not possible                                
152                  }                  }
153                    
154                  setTitle(dialogTitle);                  setTitle(dialogTitle);
155                    
156            }
157            
158            
159            /* these 3 dialogs helper functions are very rude and ugly hack
160             * to remove these auto-reported exceptions
161             * - android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@436aaef8 is not valid; is your activity running?
162             * - java.lang.IllegalArgumentException: View not attached to window manager
163             */
164            
165            public void showDialogSafe(int id) {
166                    try {
167                            showDialog(id);
168                    } catch (Exception e) {
169                            Log.e("StationList", "showDialog failed", e);
170                    }
171            }
172            
173            public void dismissDialogSafe(int id) {
174                    try {
175                            dismissDialog(id);
176                    } catch (Exception e) {
177                            Log.e("StationList", "dismissDialog failed", e);
178                    }
179            }
180            public void dismissDialogSafe(Dialog dlg) {
181                    try {
182                            dlg.dismiss();
183                    } catch (Exception e) {
184                            Log.e("StationList", "dismissDialog failed", e);
185                    }
186          }          }
187                    
188            public void builderShowSafe(AlertDialog.Builder builder) {
189                    try {
190                            builder.show();
191                    } catch (Exception e) {
192                            Log.e("StationList", "builder.show() failed", e);
193                    }
194                    
195            }
196            /* EOF rude and ugly dialog hack */
197                    
198    
199    
# Line 171  public class StationList extends ListAct Line 212  public class StationList extends ListAct
212          @Override          @Override
213          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
214                  MenuItem item;                  MenuItem item;
215                                                    
216                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");                  item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap));
217                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
218                                    
219                  item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info");                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));
220                  item.setIcon(android.R.drawable.ic_menu_mapmode);                                item.setIcon(android.R.drawable.ic_menu_mapmode);              
221                                    
222                  return true;                  return true;
# Line 190  public class StationList extends ListAct Line 231  public class StationList extends ListAct
231                  case OPTIONS_MAP:                  case OPTIONS_MAP:
232                                                    
233                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
                         intent.putExtra("userlocation", location );  
234                                                    
235                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();                          ArrayList<GeoPair> stationPoints = new ArrayList<GeoPair>();
236                          for (StationBean st : stations ) {                          for (StationBean st : stations ) {
# Line 204  public class StationList extends ListAct Line 244  public class StationList extends ListAct
244                  case OPTIONS_GPSINFO:                  case OPTIONS_GPSINFO:
245                          Location loc = locationLookup.getLocation();                          Location loc = locationLookup.getLocation();
246                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
247                          message.append("Location info:\n");                          message.append( getString(stationlist_locationinfo) ).append(":\n");
248                          message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n");                          if (loc != null) {
249                          message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n");                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
250                                    message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
251                                    message.append( getString(stationlist_latitude) ).append( (float)loc.getLatitude()).append("\n");
252                                    message.append( getString(stationlist_longitude) ).append( (float)loc.getLongitude() ).append("\n");
253                            } else {
254                                    message.append( getString(stationlist_nolocation) );
255                            }                      
256                            
257                          MessageBox.showMessage(this, message.toString());                          MessageBox.showMessage(this, message.toString());
258                          break;                          break;
259                  default:                  default:
# Line 226  public class StationList extends ListAct Line 272  public class StationList extends ListAct
272    
273    
274          }          }
275            
276            public void showMessageAndClose(String message) {
277                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
278                    builder.setMessage(message)
279                    .setCancelable(false)
280                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
281                            public void onClick(DialogInterface dialog, int id) {
282                                    dialog.dismiss();
283                                    StationList.this.finish();
284                            }
285                    })
286                    .show();
287            }
288    
289    
290    
# Line 235  public class StationList extends ListAct Line 294  public class StationList extends ListAct
294                  switch (id) {                  switch (id) {
295                  case DLG_PROGRESS:                  case DLG_PROGRESS:
296                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);
297                          dlg.setMessage("Wait for location fix");                          dlg.setMessage( getString(stationlist_waitforlocation) );
298                          dlg.setCancelable(false);                          dlg.setCancelable(false);
299                          return dlg;                                              return dlg;                    
300                  case DLG_STATIONNAME:                  case DLG_STATIONNAME:
# Line 245  public class StationList extends ListAct Line 304  public class StationList extends ListAct
304                                                    
305                          AlertDialog.Builder builder = new AlertDialog.Builder(this);                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
306                                                    
307                          builder.setTitle("Station search");                          builder.setTitle( getString(stationlist_stationsearch) );
308                          builder.setView(rootView);                          builder.setView(rootView);
309                          builder.setCancelable(true);                          builder.setCancelable(true);
310                          builder.setPositiveButton("Search", new DialogInterface.OnClickListener() {                          builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() {
311                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
312                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
313                                          dialog.dismiss();                                          dialog.dismiss();
314                                          if (et.getText().toString().length() >= 2) {                                          String search = et.getText().toString().trim();
315                                                  startNameSearch(et.getText().toString());                                          if (search.length() >= 2) {
316                                                    startNameSearch(search);
317                                          } else {                                          } else {
318                                                  MessageBox.showMessage(StationList.this, "Two characters minimum" );                                                  showMessageAndClose( getString(stationlist_twocharmin) );
319                                          }                                          }
320                                  }                                  }
321                          });                          });
322                          builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                          builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
323                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
324                                          dialog.dismiss();                                          dialog.dismiss();
325                                            StationList.this.finish(); // Close this Activity
326                                  }                                  }
327                          });                                              });                    
328                          return builder.create();                          return builder.create();
# Line 292  public class StationList extends ListAct Line 353  public class StationList extends ListAct
353                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
354                                                                    
355                  StationBean station = stations.get(position);                  StationBean station = stations.get(position);
   
                 double latitude = station.getLatitude();  
                 double longitude = station.getLongitude();  
   
   
356                                    
357                  Intent intent = new Intent(this, DepartureList.class);                  Intent intent = new Intent(this, DepartureList.class);
358                  intent.putExtra("name", station.getName());                  intent.putExtra("stationbean", station);
                 intent.putExtra("distance", station.getDistance());  
                 intent.putExtra("latitude", latitude);  
                 intent.putExtra("longitude", longitude);  
                 intent.putExtra("stationid", station.getId());  
                 intent.putExtra("address", station.getAddress());  
359                  startActivity(intent);                  startActivity(intent);
360          }          }
361    
# Line 312  public class StationList extends ListAct Line 363  public class StationList extends ListAct
363          //          //
364    
365          public void startLookup() {          public void startLookup() {
366                  isRunning = true;                  isRunning = true;              
367                  dialogMessage = "Wait for location fix";                  dialogMessage = getString( stationlist_waitforlocation );
368                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
369                                    
370                  locationLookup.locateStations();                  locationLookup.locateStations();
371                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);                  stationsFetched.sendEmptyMessageDelayed(LOCATIONFIXTIMEOUT, 20000);
372          }          }
373                    
374          void startNameSearch(String name) {          void startNameSearch(String name) {
375                  dialogMessage = "Finding stations by name";                  dialogMessage = getString( stationlist_findbyname );
376                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
377    
378                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
379                  findStationsTask.searchByName(name, locationLookup.getLocation());                  findStationsTask.searchByName(name);
380                  findStationsTask.execute();                  findStationsTask.execute();
381                                    
382          }          }
# Line 333  public class StationList extends ListAct Line 384  public class StationList extends ListAct
384          public void startFavoriteLookup() {          public void startFavoriteLookup() {
385                                    
386                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
387                          dialogMessage = "Loading favorites";                          dialogMessage = getString( stationlist_loadfavorites );
388                          showDialog(DLG_PROGRESS);                          showDialogSafe(DLG_PROGRESS);
389    
390                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
391                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());                          findStationsTask.searchByIds( favorites.toString() );
392                          findStationsTask.execute();                          findStationsTask.execute();
393                  } else {                  } else {
394                          MessageBox.showMessage(this, "Favorite list is empty");                          showMessageAndClose( getString( stationlist_nofavorites ) );
395                  }                  }
396          }          }
397    
# Line 348  public class StationList extends ListAct Line 399  public class StationList extends ListAct
399                    
400          void startLocatorTask()          void startLocatorTask()
401          {          {
402                  dialogMessage = "Finding nearby stations";                  dialogMessage = getString( stationlist_findingnearby );
403                  showDialog(DLG_PROGRESS);                  showDialogSafe(DLG_PROGRESS);
404                                    
405                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
406                  findStationsTask.searchByLocation( locationLookup.getLocation() );                  findStationsTask.searchByLocation( locationLookup.getLocation() );
407                  findStationsTask.execute();                      findStationsTask.execute();    
408          }          }
           
   
         String lookupAddress(double latitude, double longitude) {  
409                                    
                 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();  
         }  
           
410                    
411          ////////////////////////////////////////////////////////////////////////////          ////////////////////////////////////////////////////////////////////////////
412          // Inner classes          // Inner classes
# Line 393  public class StationList extends ListAct Line 417  public class StationList extends ListAct
417    
418                          switch (msg.what) {                          switch (msg.what) {
419                          case GOTLOCATION:                          case GOTLOCATION:
420                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
421                                                                    
422                                  startLocatorTask();                                  startLocatorTask();
423                                  location = GeoPair.fromLocation( locationLookup.getLocation() );                                  location = GeoPair.fromLocation( locationLookup.getLocation() );
# Line 401  public class StationList extends ListAct Line 425  public class StationList extends ListAct
425                                  break;                                  break;
426    
427                          case NOPROVIDER:                          case NOPROVIDER:
428                                  dismissDialog(DLG_PROGRESS);                                  dismissDialogSafe(DLG_PROGRESS);
429                                  MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps.");                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );
430                                  break;                                  break;
431                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
432                                  if (isRunning) {                                  if (isRunning) {
# Line 410  public class StationList extends ListAct Line 434  public class StationList extends ListAct
434                                          if (locationLookup.hasLocation()) {                                          if (locationLookup.hasLocation()) {
435                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );                                                  stationsFetched.sendEmptyMessage( GOTLOCATION );
436                                          } else {                                                                                          } else {                                                
437                                                  dismissDialog(DLG_PROGRESS);                                                  dismissDialogSafe(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();                                                  builderShowSafe(builder); // builder.show()
455    
456                                          }                                          }
457                                  }                                  }
# Line 446  public class StationList extends ListAct Line 470  public class StationList extends ListAct
470                  Location loc;                  Location loc;
471                  String ids;                  String ids;
472                                    
473                  public void searchByName(String n, Location l) {                  public void searchByName(String n) {
474                                                    
475                          method = LookupMethod.ByName;                          method = LookupMethod.ByName;
                         loc = l;  
476                          name = n;                          name = n;
477                  }                  }
478                                    
# Line 458  public class StationList extends ListAct Line 481  public class StationList extends ListAct
481                          loc = l;                          loc = l;
482                  }                  }
483                                    
484                  public void searchByIds(String id, Location l) {                  public void searchByIds(String id) {
485                                                    
486                          method = LookupMethod.ByList;                          method = LookupMethod.ByList;
                         loc = l;  
487                          ids = id;                          ids = id;
488                  }                  }
489                                    
# Line 491  public class StationList extends ListAct Line 513  public class StationList extends ListAct
513                          }                          }
514                                                    
515                                                    
                         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);  
                                         }  
                                 }  
   
                         }                                                
                           
516                          return null;                          return null;
517                  }                  }
518    
519                  @Override                  @Override
520                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
521                          super.onPostExecute(result);                          super.onPostExecute(result);
522                          dialog.dismiss();                          dismissDialogSafe(dialog);
523                                                    
524                                                    
525                          if (success) {                                                    if (success) {                          
526                                  if (stationProvider.getStations().size() == 0)                                  if (stationProvider.getStations().size() == 0) {
527                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          showMessageAndClose(getString(stationlist_nostations));
528                                    }
529                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
530                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
531                                                                    
532                          } else { //communication or parse errors                          } else { //communication or parse errors
533                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
534                                  builder.setMessage("Error on finding nearby stations");                                  builder.setMessage(getString(stationlist_nearbyerror));                        
535                                  builder.setCancelable(true);                                  builder.setCancelable(true);
536                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
537                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
538                                                  dialog.dismiss();                                                  dialog.dismiss();
539                                                                                                    
540                                                  stationsFetched.post( new Runnable() {                                                  Runnable runner = null;
541                                                          @Override                                                  switch (method) {
542                                                          public void run() {                                                  case ByLocation:
543                                                                  startLocatorTask();                                                                                                                      runner = new Runnable() {
544                                                          }                                                                  @Override
545                                                  });                                                                  public void run() {
546                                                                            startLocatorTask();                                                            
547                                                                    }
548                                                            };
549                                                            break;
550                                                    case ByName:
551                                                            runner = new Runnable() {
552                                                                    @Override
553                                                                    public void run() {
554                                                                            startNameSearch( FindStationsTask.this.name );
555                                                                    }
556                                                            };
557                                                            break;
558                                                    case ByList:
559                                                            runner = new Runnable() {
560                                                                    @Override
561                                                                    public void run() {
562                                                                            startFavoriteLookup();
563                                                                    }
564                                                            };
565                                                            break;
566                                                    }
567                                                    
568                                                    stationsFetched.post( runner );
569                                          }                                          }
570                                  });                                  });
571                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
572                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
573                                                  dialog.dismiss();                                                  dialog.dismiss();
574                                          }                                                                                                }                                                      
575                                  });                                                                                                                              });
576                                  builder.show();                                                          
577                                    builderShowSafe(builder); // builder.show()
578                          }                          }
579                  }                  }
580          }          }
# Line 568  public class StationList extends ListAct Line 595  public class StationList extends ListAct
595                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.get(selectedPosition).getId();
596    
597                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
598                                  menu.add(0, FAVORITES_ADD, 0, "Add to favorites");                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
599                          } else {                          } else {
600                                  menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites");                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_removefavorite) );
601                          }                          }
602                                                    
603                  }                  }
# Line 581  public class StationList extends ListAct Line 608  public class StationList extends ListAct
608                          int stationID = sb.getId();                          int stationID = sb.getId();
609                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
610                                  favorites.add(stationID);                                  favorites.add(stationID);
611                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show();
612                          } else {                          } else {
613                                                                    
614                                  favorites.remove(stationID);                                  favorites.remove(stationID);
615                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show();
616                                                                    
617                                                                    
618                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {

Legend:
Removed from v.482  
changed lines
  Added in v.725

  ViewVC Help
Powered by ViewVC 1.1.20