@Override
 public Object instantiateItem(ViewGroup container, int position) {
   WindFragment fragment = (WindFragment) super.instantiateItem(container, position);
   int day = Util.calculateDay(new Date()); // today
   mFragments.put(new Integer(position), fragment);
   return fragment;
 }
 @Override
 public Fragment getItem(int position) {
   WindFragment fragment = mFragments.get(new Integer(position));
   if (fragment == null) {
     int day = Util.calculateDay(new Date()); // today
     fragment = WindFragment.newInstance(mWindSpots.get(position % mWindSpots.size()), day);
     mFragments.put(new Integer(position), fragment);
   }
   return fragment;
 }
Ejemplo n.º 3
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   if (mSpots != null) {
     try {
       outState.putString(KEY_SPOTS, Util.objectToString((Serializable) mSpots));
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   if (mPager != null) {
     outState.putInt(KEY_SAVED_OPEN_TAB, mPager.getCurrentItem());
   }
 }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if ((savedInstanceState != null)
        && savedInstanceState.containsKey(KEY_SPOTS)
        && savedInstanceState.containsKey(KEY_SAVED_OPEN_TAB)) {
      // load from the savedInstanceState
      String spotsString = savedInstanceState.getString(KEY_SPOTS);
      mSavedOpenTab = savedInstanceState.getInt(KEY_SAVED_OPEN_TAB);
      try {
        mSpots = (List<SpotData>) Util.objectFromString(spotsString);
      } catch (IOException e) {
      } catch (ClassNotFoundException e) {
      }
    }
    showSpots();
    loadSpotsInBackground();
    initializeGoogleCloudMessaging();
    startService(this);
  }