/[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 480 by torben, Wed Oct 28 12:52:52 2009 UTC revision 481 by torben, Thu Oct 29 08:56:17 2009 UTC
# Line 44  public class StationList extends ListAct Line 44  public class StationList extends ListAct
44          public static final int NOPROVIDER = 1003;          public static final int NOPROVIDER = 1003;
45          public static final int LOCATIONFIXTIMEOUT = 1004;          public static final int LOCATIONFIXTIMEOUT = 1004;
46                    
         public static final int OPTIONS_RESCAN = 2001;  
         public static final int OPTIONS_NAMESEARCH = 2002;  
47          public static final int OPTIONS_MAP = 2003;          public static final int OPTIONS_MAP = 2003;
48          public static final int OPTIONS_ABOUT = 2004;          public static final int OPTIONS_GPSINFO = 2004;
49          public static final int OPTIONS_FAVORITES = 2005;  
50                    
51    
52                    
# Line 80  public class StationList extends ListAct Line 78  public class StationList extends ListAct
78                    
79          FavoritesMenu contextMenu = new FavoritesMenu();          FavoritesMenu contextMenu = new FavoritesMenu();
80          IntSet favorites = new IntSet();          IntSet favorites = new IntSet();
81            
82          boolean showingFavorites = false;          WelcomeScreen.ListType listType;
83          String dialogTitle;          String dialogTitle;
84          SharedPreferences prefs;          SharedPreferences prefs;
85                    
# Line 92  public class StationList extends ListAct Line 90  public class StationList extends ListAct
90          @Override          @Override
91          public void onCreate(Bundle savedInstanceState) {          public void onCreate(Bundle savedInstanceState) {
92                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
93                  setContentView(R.layout.main);                  setContentView(R.layout.stationlist);
94                                    
95                                    
96                  adapter = new StationListAdapter(this);                  adapter = new StationListAdapter(this);
# Line 111  public class StationList extends ListAct Line 109  public class StationList extends ListAct
109                  }                  }
110                                    
111                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
112                          startLookup();                          listType = (WelcomeScreen.ListType) getIntent().getSerializableExtra("type");
113                            switch (listType) {
114                            case ListNearest:
115                                    startLookup();
116                                    break;
117                            case ListSearch:
118                                    this.showDialog(DLG_STATIONNAME);
119                                    break;
120                            case ListFavorites:
121                                    startFavoriteLookup();
122                                    break;
123                            default:
124                                    // Not possible !?!
125                            }
126                            
127                  } else {                  } else {
128                          stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations");                          stations = (ArrayList<StationBean>) savedInstanceState.getSerializable("stations");
129                          adapter.setStations(stations);                          adapter.setStations(stations);
# Line 137  public class StationList extends ListAct Line 149  public class StationList extends ListAct
149          @Override          @Override
150          public boolean onCreateOptionsMenu(Menu menu) {          public boolean onCreateOptionsMenu(Menu menu) {
151                  MenuItem item;                  MenuItem item;
152                                                    
                 item = menu.add(0, OPTIONS_RESCAN, 0, "Nearest stations");  
                 item.setIcon(android.R.drawable.ic_menu_mylocation);  
                   
                 item = menu.add(0, OPTIONS_NAMESEARCH, 0, "Search for station");  
                 item.setIcon(android.R.drawable.ic_menu_search);  
                   
                 item = menu.add(0, OPTIONS_FAVORITES, 0, "Favorites");  
                 item.setIcon(android.R.drawable.ic_menu_agenda);  
                   
153                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");                  item = menu.add(0, OPTIONS_MAP, 0, "Station map");
154                  item.setIcon(android.R.drawable.ic_menu_mapmode);                  item.setIcon(android.R.drawable.ic_menu_mapmode);
155                                    
156                  item = menu.add(0, OPTIONS_ABOUT, 0, "About");                  item = menu.add(0, OPTIONS_GPSINFO, 0, "GPS Info");
157                  item.setIcon(android.R.drawable.ic_menu_info_details);                  item.setIcon(android.R.drawable.ic_menu_mapmode);              
158                    
159                  return true;                  return true;
160          }          }
161    
# Line 159  public class StationList extends ListAct Line 163  public class StationList extends ListAct
163          public boolean onOptionsItemSelected(MenuItem item) {          public boolean onOptionsItemSelected(MenuItem item) {
164                  boolean retval = true;                  boolean retval = true;
165    
166                                    //TODO: Cleanup
167                  switch (item.getItemId()) {                  switch (item.getItemId()) {
                 case OPTIONS_RESCAN:  
                         startLookup();  
                         break;  
                 case OPTIONS_NAMESEARCH:  
                         showDialog(DLG_STATIONNAME);  
                         break;  
                 case OPTIONS_FAVORITES:  
                         startFavoriteLookup();  
                         break;  
168                  case OPTIONS_MAP:                  case OPTIONS_MAP:
169                                                    
170                          Intent intent = new Intent(this,StationMapView.class);                          Intent intent = new Intent(this,StationMapView.class);
# Line 184  public class StationList extends ListAct Line 179  public class StationList extends ListAct
179                                                    
180                          startActivity(intent);                          startActivity(intent);
181                          break;                          break;
182                  case OPTIONS_ABOUT:                  case OPTIONS_GPSINFO:
                         String ver = this.getResources().getString(R.string.app_version);  
                           
183                          Location loc = locator.getLocation();                          Location loc = locator.getLocation();
184                          StringBuffer message = new StringBuffer();                          StringBuffer message = new StringBuffer();
                         message.append("TrainInfo DK v").append(ver).append("\n");  
                         message.append("By Torben Nielsen\n");  
                         message.append("\n");  
185                          message.append("Location info:\n");                          message.append("Location info:\n");
186                          message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n");                          message.append("-Obtained by: ").append(loc != null ? loc.getProvider() : "-").append("\n");
187                          message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n");                          message.append("-Accuracy: ").append(loc != null ? (int)loc.getAccuracy() : "-").append("m\n");
# Line 529  public class StationList extends ListAct Line 519  public class StationList extends ListAct
519                                  if (stationProvider.getStations().size() == 0)                                  if (stationProvider.getStations().size() == 0)
520                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!                                          MessageBox.showMessage(StationList.this, "No stations found!"); // this should not be possible !?!
521                                  stations = stationProvider.getStations();                                  stations = stationProvider.getStations();
522                                  adapter.setStations( stations );                                  adapter.setStations( stations );                                
                                   
                                 showingFavorites = method.equals(LookupMethod.ByList);                            
523                                                                    
524                          } else { //communication or parse errors                          } else { //communication or parse errors
525                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                                                  AlertDialog.Builder builder = new AlertDialog.Builder(StationList.this);                                                
# Line 594  public class StationList extends ListAct Line 582  public class StationList extends ListAct
582                                  favorites.remove(stationID);                                  favorites.remove(stationID);
583                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();                                  Toast.makeText(StationList.this, "Station removed", Toast.LENGTH_SHORT).show();
584                                                                    
585                                  if (showingFavorites) {                                  
586                                    if (listType.equals( WelcomeScreen.ListType.ListFavorites) ) {
587                                          stations.remove(selectedPosition);                                          stations.remove(selectedPosition);
588                                          adapter.notifyDataSetChanged();                                          adapter.notifyDataSetChanged();
589                                  }                                  }

Legend:
Removed from v.480  
changed lines
  Added in v.481

  ViewVC Help
Powered by ViewVC 1.1.20