Android Open Source - llibre2014 Sections Pager Adapter






From Project

Back to project page llibre2014.

License

The source code is released under:

GNU General Public License

If you think the Android project llibre2014 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package es.rpallas.llibre2014.adapter;
/*  www  . j  a  v a 2s .  c  o m*/
import java.util.Locale;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import es.rpallas.llibre2014.AboutFragment;
import es.rpallas.llibre2014.LlibreFragment;
import es.rpallas.llibre2014.R;
import es.rpallas.llibre2014.ScheduleFragment;

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

  /**
   * First day of the agenda
   */
  private static final int BASE_DAY = 12 - 1; 
  
  /**
   * Number of pages in the ViewPager
   */
  private static final int NUMBER_OF_PAGES = 6;
  
  /**
   * Activity context
   */
  private Context context;
  
  
  public SectionsPagerAdapter(FragmentManager fm, Context context) {
    super(fm);
    this.context = context;
  }

  @Override
  public Fragment getItem(int position) {
    // getItem is called to instantiate the fragment for the given page.
    switch (position) {
    case 0:
      return new LlibreFragment();
    case 5:
      return new AboutFragment();
    default:
      return ScheduleFragment.newInstance(position + BASE_DAY);

    }
  }

  @Override
  public int getCount() {
    return NUMBER_OF_PAGES;
  }

  @Override
  public CharSequence getPageTitle(int position) {
    Locale l = Locale.getDefault();
    switch (position) {

    case 0:
      return context.getString(R.string.title_portada).toUpperCase(l);
    case 1:
      return context.getString(R.string.title_dia12).toUpperCase(l);
    case 2:
      return context.getString(R.string.title_dia13).toUpperCase(l);
    case 3:
      return context.getString(R.string.title_dia14).toUpperCase(l);
    case 4:
      return context.getString(R.string.title_dia15).toUpperCase(l);
    case 5:
      return context.getString(R.string.title_about).toUpperCase(l);
    }
    return null;
  }


}




Java Source Code List

es.rpallas.llibre2014.AboutFragment.java
es.rpallas.llibre2014.LlibreActivity.java
es.rpallas.llibre2014.LlibreFragment.java
es.rpallas.llibre2014.ScheduleFragment.java
es.rpallas.llibre2014.adapter.ScheduleListViewAdapter.java
es.rpallas.llibre2014.adapter.SectionsPagerAdapter.java
es.rpallas.llibre2014.data.MockData.java
es.rpallas.llibre2014.models.Event.java