Search in sources :

Example 1 with ExpandingFragment

use of com.qslll.library.fragments.ExpandingFragment in project ExpandingPager by qs-lll.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    setupWindowAnimations();
    TravelViewPagerAdapter adapter = new TravelViewPagerAdapter(getSupportFragmentManager());
    adapter.addAll(generateTravelList());
    viewPager.setAdapter(adapter);
    ExpandingPagerFactory.setupViewPager(viewPager);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            ExpandingFragment expandingFragment = ExpandingPagerFactory.getCurrentFragment(viewPager);
            if (expandingFragment != null && expandingFragment.isOpenend()) {
                expandingFragment.close();
            }
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
}
Also used : TravelViewPagerAdapter(com.qslll.expandingpager.adapter.TravelViewPagerAdapter) ExpandingFragment(com.qslll.library.fragments.ExpandingFragment) ViewPager(android.support.v4.view.ViewPager)

Example 2 with ExpandingFragment

use of com.qslll.library.fragments.ExpandingFragment in project ExpandingPager by qs-lll.

the class ExpandingPagerFactory method getCurrentFragment.

public static ExpandingFragment getCurrentFragment(ViewPager viewPager) {
    if (viewPager.getAdapter() instanceof ExpandingViewPagerAdapter) {
        ExpandingViewPagerAdapter adapter = (ExpandingViewPagerAdapter) viewPager.getAdapter();
        Fragment fragment = adapter.getCurrentFragment();
        if (fragment instanceof ExpandingFragment) {
            return (ExpandingFragment) fragment;
        }
    }
    return null;
}
Also used : ExpandingFragment(com.qslll.library.fragments.ExpandingFragment) Fragment(android.support.v4.app.Fragment) ExpandingFragment(com.qslll.library.fragments.ExpandingFragment)

Aggregations

ExpandingFragment (com.qslll.library.fragments.ExpandingFragment)2 Fragment (android.support.v4.app.Fragment)1 ViewPager (android.support.v4.view.ViewPager)1 TravelViewPagerAdapter (com.qslll.expandingpager.adapter.TravelViewPagerAdapter)1