/[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 560 by torben, Wed Jan 27 10:04:28 2010 UTC revision 561 by torben, Thu Jan 28 08:55:19 2010 UTC
# Line 36  import dk.thoerup.traininfo.stationmap.S Line 36  import dk.thoerup.traininfo.stationmap.S
36  import dk.thoerup.traininfo.util.IntSet;  import dk.thoerup.traininfo.util.IntSet;
37  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
38    
39    import static dk.thoerup.traininfo.R.string.*;
40    
41  public class StationList extends ListActivity  {  public class StationList extends ListActivity  {
42          public static final int GOTLOCATION = 1001;          public static final int GOTLOCATION = 1001;
43          public static final int GOTSTATIONLIST = 1002;          public static final int GOTSTATIONLIST = 1002;
# Line 133  public class StationList extends ListAct Line 135  public class StationList extends ListAct
135                                    
136          }          }
137          protected void setTitle() {          protected void setTitle() {
138                  String dialogTitle = getResources().getString(R.string.app_name);                  String dialogTitle = getResources().getString(app_name);
139                  switch (listType) {                  switch (listType) {
140                  case ListNearest:                  case ListNearest:
141                          dialogTitle += " - Nearby stations";                          dialogTitle += " - " + getString(stationlist_nearbystations);
142                          break;                          break;
143                  case ListSearch:                  case ListSearch:
144                          dialogTitle += " - Search";                          dialogTitle += " - " + getString(stationlist_search);
145                          break;                          break;
146                  case ListFavorites:                  case ListFavorites:
147                          dialogTitle += " - Favorites";                          dialogTitle += " - " + getString(stationlist_favorites);
148                          break;                          break;
149                  default:                  default:
150                          dialogTitle = "";//not possible                                                          dialogTitle = "";//not possible                                
# Line 169  public class StationList extends ListAct Line 171  public class StationList extends ListAct
171          @Override          @Override
172          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
173                  MenuItem item;                  MenuItem item;
174                                                    
175                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");                  item = menu.add(0, OPTIONS_MAP, 0, getString(stationlist_stationmap));
176                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
177                                    
178                  item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info");                  item = menu.add(0, OPTIONS_GPSINFO, 0, getString(stationlist_gpsinfo));
179                  item.setIcon(android.R.drawable.ic_menu_mapmode);                                item.setIcon(android.R.drawable.ic_menu_mapmode);              
180                                    
181                  return true;                  return true;
# Line 201  public class StationList extends ListAct Line 203  public class StationList extends ListAct
203                  case OPTIONS_GPSINFO:                  case OPTIONS_GPSINFO:
204                          Location loc = locationLookup.getLocation();                          Location loc = locationLookup.getLocation();
205                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
206                          message.append("Location info:\n");                          message.append( getString(stationlist_locationinfo) ).append(":\n");
207                          if (loc != null) {                          if (loc != null) {
208                                  message.append("-Obtained by: ").append( loc.getProvider() ).append("\n");                                  message.append( getString(stationlist_obtainedby) ).append( loc.getProvider() ).append("\n");
209                                  message.append("-Accuracy: ").append( (int)loc.getAccuracy()).append("m\n");                                  message.append( getString(stationlist_accuracy) ).append( (int)loc.getAccuracy()).append("m\n");
210                                  message.append("-Latitude: ").append( loc.getLatitude()).append("\n");                                  message.append( getString(stationlist_latitude) ).append( loc.getLatitude()).append("\n");
211                                  message.append("-Longitude: ").append( loc.getLongitude() ).append("\n");                                  message.append( getString(stationlist_longitude) ).append( loc.getLongitude() ).append("\n");
212                          } else {                          } else {
213                                  message.append(" - No location data!");                                  message.append( getString(stationlist_nolocation) );
214                          }                                                }                      
215                                                    
216                          MessageBox.showMessage(this, message.toString());                          MessageBox.showMessage(this, message.toString());
# Line 251  public class StationList extends ListAct Line 253  public class StationList extends ListAct
253                  switch (id) {                  switch (id) {
254                  case DLG_PROGRESS:                  case DLG_PROGRESS:
255                          ProgressDialog dlg = new ProgressDialog(this);                          ProgressDialog dlg = new ProgressDialog(this);
256                          dlg.setMessage("Wait for location fix");                          dlg.setMessage( getString(stationlist_waitforlocation) );
257                          dlg.setCancelable(false);                          dlg.setCancelable(false);
258                          return dlg;                                              return dlg;                    
259                  case DLG_STATIONNAME:                  case DLG_STATIONNAME:
# Line 261  public class StationList extends ListAct Line 263  public class StationList extends ListAct
263                                                    
264                          AlertDialog.Builder builder = new AlertDialog.Builder(this);                          AlertDialog.Builder builder = new AlertDialog.Builder(this);
265                                                    
266                          builder.setTitle("Station search");                          builder.setTitle( getString(stationlist_stationsearch) );
267                          builder.setView(rootView);                          builder.setView(rootView);
268                          builder.setCancelable(true);                          builder.setCancelable(true);
269                          builder.setPositiveButton("Search", new DialogInterface.OnClickListener() {                          builder.setPositiveButton( getString(generic_search), new DialogInterface.OnClickListener() {
270                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
271                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);                                          EditText et = (EditText) rootView.findViewById(R.id.EditText);
272                                          dialog.dismiss();                                          dialog.dismiss();
273                                          if (et.getText().toString().length() >= 2) {                                          if (et.getText().toString().length() >= 2) {
274                                                  startNameSearch(et.getText().toString());                                                  startNameSearch(et.getText().toString());
275                                          } else {                                          } else {
276                                                  showMessageAndClose("Two characters minimum");                                                  showMessageAndClose( getString(stationlist_twocharmin) );
277                                          }                                          }
278                                  }                                  }
279                          });                          });
280                          builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                          builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
281                                  public void onClick(DialogInterface dialog, int which) {                                  public void onClick(DialogInterface dialog, int which) {
282                                          dialog.dismiss();                                          dialog.dismiss();
283                                          StationList.this.finish(); // Close this Activity                                          StationList.this.finish(); // Close this Activity
# Line 319  public class StationList extends ListAct Line 321  public class StationList extends ListAct
321          //          //
322    
323          public void startLookup() {          public void startLookup() {
324                  isRunning = true;                  isRunning = true;              
325                  dialogMessage = "Wait for location fix";                  dialogMessage = getString( stationlist_waitforlocation );
326                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
327                                    
328                  locationLookup.locateStations();                  locationLookup.locateStations();
# Line 328  public class StationList extends ListAct Line 330  public class StationList extends ListAct
330          }          }
331                    
332          void startNameSearch(String name) {          void startNameSearch(String name) {
333                  dialogMessage = "Finding stations by name";                  dialogMessage = getString( stationlist_findbyname );
334                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
335    
336                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
# Line 340  public class StationList extends ListAct Line 342  public class StationList extends ListAct
342          public void startFavoriteLookup() {          public void startFavoriteLookup() {
343                                    
344                  if (favorites.size() > 0) {                  if (favorites.size() > 0) {
345                          dialogMessage = "Loading favorites";                          dialogMessage = getString( stationlist_loadfavorites );
346                          showDialog(DLG_PROGRESS);                          showDialog(DLG_PROGRESS);
347    
348                          findStationsTask = new FindStationsTask();                          findStationsTask = new FindStationsTask();
349                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());                          findStationsTask.searchByIds(favorites.toString(), locationLookup.getLocation());
350                          findStationsTask.execute();                          findStationsTask.execute();
351                  } else {                  } else {
352                          showMessageAndClose( "Favorite list is empty");                          showMessageAndClose( getString( stationlist_nofavorites ) );
353                  }                  }
354          }          }
355    
# Line 355  public class StationList extends ListAct Line 357  public class StationList extends ListAct
357                    
358          void startLocatorTask()          void startLocatorTask()
359          {          {
360                  dialogMessage = "Finding nearby stations";                  dialogMessage = getString( stationlist_findingnearby );
361                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
362                                    
363                  findStationsTask = new FindStationsTask();                  findStationsTask = new FindStationsTask();
# Line 410  public class StationList extends ListAct Line 412  public class StationList extends ListAct
412    
413                          case NOPROVIDER:                          case NOPROVIDER:
414                                  dismissDialog(DLG_PROGRESS);                                  dismissDialog(DLG_PROGRESS);
415                                  MessageBox.showMessage(StationList.this,"No location provider enabled. Plase enable gps.");                                  MessageBox.showMessage(StationList.this, getString(stationlist_nolocationprovider) );
416                                  break;                                  break;
417                          case LOCATIONFIXTIMEOUT:                                                          case LOCATIONFIXTIMEOUT:                                
418                                  if (isRunning) {                                  if (isRunning) {
# Line 421  public class StationList extends ListAct Line 423  public class StationList extends ListAct
423                                                  dismissDialog(DLG_PROGRESS);                                                  dismissDialog(DLG_PROGRESS);
424                                                                                                    
425                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
426                                                  builder.setMessage("Location fix timed out");                                                  builder.setMessage(  getString( stationlist_gpstimeout) );
427                                                  builder.setCancelable(true);                                                  builder.setCancelable(true);
428                                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
429                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
430                                                                  dialog.dismiss();                                                                  dialog.dismiss();
431                                                                  startLookup();                                                                  startLookup();
432                                                                                                                                    
433                                                          }                                                          }
434                                                  });                                                  });
435                                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                                  builder.setNegativeButton( getString(generic_cancel), new DialogInterface.OnClickListener() {
436                                                          public void onClick(DialogInterface dialog, int id) {                                                          public void onClick(DialogInterface dialog, int id) {
437                                                                  dialog.dismiss();                                                                  dialog.dismiss();
438                                                          }                                                                                                                }                                                      
# Line 527  public class StationList extends ListAct Line 529  public class StationList extends ListAct
529                                                    
530                          if (success) {                                                    if (success) {                          
531                                  if (stationProvider.getStations().size() == 0)                                  if (stationProvider.getStations().size() == 0)
532                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          MessageBox.showMessage(StationList.this, getString(stationlist_nostations) ); // this should not be possible !?!
533                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
534                                  adapter.setStations( stations );                                                                  adapter.setStations( stations );                                
535                                                                    
536                          } else { //communication or parse errors                          } else { //communication or parse errors
537                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
538                                  builder.setMessage("Error on finding nearby stations");                                  builder.setMessage(getString(stationlist_nearbyerror));                        
539                                  builder.setCancelable(true);                                  builder.setCancelable(true);
540                                  builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() {                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
541                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
542                                                  dialog.dismiss();                                                  dialog.dismiss();
543                                                                                                    
# Line 547  public class StationList extends ListAct Line 549  public class StationList extends ListAct
549                                                  });                                                  });
550                                          }                                          }
551                                  });                                  });
552                                  builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
553                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
554                                                  dialog.dismiss();                                                  dialog.dismiss();
555                                          }                                                                                                }                                                      
# Line 573  public class StationList extends ListAct Line 575  public class StationList extends ListAct
575                          int stationID = stations.get(selectedPosition).getId();                          int stationID = stations.get(selectedPosition).getId();
576    
577                          if (!favorites.contains(stationID)) {                          if (!favorites.contains(stationID)) {
578                                  menu.add(0, FAVORITES_ADD, 0, "Add to favorites");                                  menu.add(0, FAVORITES_ADD, 0, getString(stationlist_addfavorite) );
579                          } else {                          } else {
580                                  menu.add(0, FAVORITES_REMOVE, 0, "Remove from favorites");                                  menu.add(0, FAVORITES_REMOVE, 0, getString(stationlist_addfavorite) );
581                          }                          }
582                                                    
583                  }                  }
# Line 586  public class StationList extends ListAct Line 588  public class StationList extends ListAct
588                          int stationID = sb.getId();                          int stationID = sb.getId();
589                          if (item.getItemId() == FAVORITES_ADD) {                          if (item.getItemId() == FAVORITES_ADD) {
590                                  favorites.add(stationID);                                  favorites.add(stationID);
591                                  Toast.makeText(StationList.this, "Station added", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationadded), Toast.LENGTH_SHORT).show();
592                          } else {                          } else {
593                                                                    
594                                  favorites.remove(stationID);                                  favorites.remove(stationID);
595                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, getString(stationlist_stationremoved), Toast.LENGTH_SHORT).show();
596                                                                    
597                                                                    
598                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {                                  if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {

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

  ViewVC Help
Powered by ViewVC 1.1.20