package uk.co.chrisjenx.paralloidexample; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.view.Menu; public class HomeActivity extends FragmentActivity { /** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link android.support.v4.app.FragmentPagerAdapter} derivative, which * will keep every loaded fragment in memory. If this becomes too memory * intensive, it may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ SectionsPagerAdapter mSectionsPagerAdapter; /** * The {@link ViewPager} that will host the section contents. */ ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.home, menu); return true; } /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends FragmentStatePagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { switch (position) { default: case 0: return new ParallaxViewUpFragment(); case 1: return new ShiftBackgroundFragment(); case 2: return new ParallaxBackgroundFragment(); case 3: return new ParallaxBackgroundListFragment(); case 4: return new OverParallaxBackgroundListFragment(); case 5: return new ParallaxViewDownFragment(); case 6: return new ParallaxViewRightFragment(); case 7: return new ParallaxViewCombiFragment(); } } @Override public int getCount() { return 8; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return getString(R.string.title_section1); case 1: return getString(R.string.title_section2); case 2: return getString(R.string.title_section3); case 3: return getString(R.string.title_section4); case 4: return getString(R.string.title_section5); case 5: return getString(R.string.title_invert_transformer); case 6: return getString(R.string.title_transform_right); case 7: return getString(R.string.title_transform_combi); } return null; } } }