/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/WelcomeScreen.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1547 by torben, Thu Jul 7 19:07:55 2011 UTC revision 1551 by torben, Thu Jul 7 20:45:17 2011 UTC
# Line 1  Line 1 
1  package dk.thoerup.traininfo;  package dk.thoerup.traininfo;
2    
3    
4    
5  import android.app.Activity;  import android.app.Activity;
6  import android.app.ProgressDialog;  import android.app.ProgressDialog;
7  import android.content.Intent;  import android.content.Intent;
# Line 10  import android.os.AsyncTask; Line 12  import android.os.AsyncTask;
12  import android.os.Bundle;  import android.os.Bundle;
13  import android.os.Handler;  import android.os.Handler;
14  import android.util.Log;  import android.util.Log;
15    import android.view.Menu;
16    import android.view.MenuItem;
17  import android.view.View;  import android.view.View;
18  import android.view.View.OnClickListener;  import android.view.View.OnClickListener;
19  import android.view.Window;  import android.view.Window;
# Line 23  import dk.thoerup.traininfo.provider.Off Line 27  import dk.thoerup.traininfo.provider.Off
27  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
28  import dk.thoerup.traininfo.provider.StationProvider;  import dk.thoerup.traininfo.provider.StationProvider;
29    
30    
31  public class WelcomeScreen extends Activity{  public class WelcomeScreen extends Activity{
32                    
33          final static String stationsreload = "stationsreload";          final static String stationsreload = "stationsreload";
34            final static int MENU_SETTINGS = 1;
35            final static int MENU_RELOAD = 2;
36            
37                    
38          public enum ListType {          public enum ListType {
39                  ListNearest,                  ListNearest,
# Line 56  public class WelcomeScreen extends Activ Line 64  public class WelcomeScreen extends Activ
64                  Button favoritesButton = (Button) findViewById(R.id.favorites);                  Button favoritesButton = (Button) findViewById(R.id.favorites);
65                  favoritesButton.setOnClickListener( new StationListListener(ListType.ListFavorites));                  favoritesButton.setOnClickListener( new StationListListener(ListType.ListFavorites));
66                                    
                 Button settingsButton = (Button) findViewById(R.id.settings);  
                 settingsButton.setOnClickListener( new SettingsListener() );  
                   
67                  Button aboutButton = (Button) findViewById(R.id.about);                  Button aboutButton = (Button) findViewById(R.id.about);
68                  aboutButton.setOnClickListener( new AboutListener() );                  aboutButton.setOnClickListener( new AboutListener() );
69                                    
# Line 86  public class WelcomeScreen extends Activ Line 91  public class WelcomeScreen extends Activ
91                                  long last = prefs.getLong(stationsreload, 0);                                  long last = prefs.getLong(stationsreload, 0);
92                                  long now = System.currentTimeMillis();                                  long now = System.currentTimeMillis();
93                                                                    
94                                    Log.i("TrainInfo", "Last Load: " + last);
95                                    
96                                  if ( (now-last) > (14*24*60*60*1000) ) {                                  if ( (now-last) > (14*24*60*60*1000) ) {
97                                          new StationLoader(osp).execute( (Void)null);                                          new StationLoader(osp).execute( (Void)null);
98                                  } else {                                  } else {
# Line 112  public class WelcomeScreen extends Activ Line 119  public class WelcomeScreen extends Activ
119          }          }
120    
121    
122            @Override
123            public boolean onCreateOptionsMenu(Menu menu) {
124                    MenuItem item;
125                    
126                    item = menu.add(0, MENU_SETTINGS, 0, getString(R.string.welcome_settings) );
127                    item.setIcon(android.R.drawable.ic_menu_preferences);
128                    
129                    item = menu.add(0, MENU_RELOAD, 0, getString(R.string.welcome_reloadstations));
130                    item.setIcon(android.R.drawable.ic_menu_rotate);
131                    
132                    return true;
133            }
134            
135            @Override
136            public boolean onOptionsItemSelected(MenuItem item) {
137                    boolean retval = true;
138                    
139                    switch (item.getItemId()) {
140                    case MENU_SETTINGS:
141                            Intent intent = new Intent(WelcomeScreen.this, SettingsScreen.class);
142                            WelcomeScreen.this.startActivity(intent);
143                            break;
144                            
145                    case MENU_RELOAD:
146                            OfflineStationProvider osp = (OfflineStationProvider) ProviderFactory.getStationProvider();
147                            new StationLoader(osp).execute( (Void)null);                    
148                            break;
149                            
150                    default:
151                            retval = super.onOptionsItemSelected(item);
152                    }
153                    
154                    return retval;
155            }
156            
157    
158          class AboutListener implements OnClickListener {          class AboutListener implements OnClickListener {
159    
# Line 133  public class WelcomeScreen extends Activ Line 175  public class WelcomeScreen extends Activ
175    
176          }          }
177                    
         class SettingsListener implements OnClickListener{  
           
                 @Override  
                 public void onClick(View v) {  
                         Intent intent = new Intent(WelcomeScreen.this, SettingsScreen.class);  
                         WelcomeScreen.this.startActivity(intent);  
                 }                
         }  
178    
179          class StationListListener implements OnClickListener{          class StationListListener implements OnClickListener{
180                  ListType launchType;                  ListType launchType;
# Line 163  public class WelcomeScreen extends Activ Line 197  public class WelcomeScreen extends Activ
197                  boolean succeeded;                  boolean succeeded;
198                  ProgressDialog dlg;                  ProgressDialog dlg;
199                  OfflineStationProvider osp;                  OfflineStationProvider osp;
200                    String exMsg;
201                                    
202                  public StationLoader(OfflineStationProvider osp) {                  public StationLoader(OfflineStationProvider osp) {
203                          this.osp = osp;                          this.osp = osp;
# Line 175  public class WelcomeScreen extends Activ Line 210  public class WelcomeScreen extends Activ
210                                  succeeded = true;                                  succeeded = true;
211                          } catch (Exception e) {                          } catch (Exception e) {
212                                  succeeded = false;                                  succeeded = false;
213                                  Toast.makeText(WelcomeScreen.this, "Error " + e.getMessage(), Toast.LENGTH_LONG).show();                                  exMsg = e.getMessage();                        
214                          }                          }
215                          return null;                          return null;
216                  }                  }
# Line 201  public class WelcomeScreen extends Activ Line 236  public class WelcomeScreen extends Activ
236                                  Editor edit = prefs.edit();                                  Editor edit = prefs.edit();
237                                  edit.putLong(stationsreload, System.currentTimeMillis() );                                  edit.putLong(stationsreload, System.currentTimeMillis() );
238                                  edit.commit();                                  edit.commit();
239                            } else {
240                                    Toast.makeText(WelcomeScreen.this, "Error " + exMsg, Toast.LENGTH_LONG).show();
241                          }                          }
242                  }                        }      
243          }          }

Legend:
Removed from v.1547  
changed lines
  Added in v.1551

  ViewVC Help
Powered by ViewVC 1.1.20