Java Code Examples for android.support.v4.view.ViewPager#getContext()

The following examples show how to use android.support.v4.view.ViewPager#getContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentAdapter.java    From MVVM-JueJin with MIT License 5 votes vote down vote up
@BindingAdapter(value = {"fragments", "curIndex"}, requireAll = false)
public static void bind(ViewPager container, final List<? extends Fragment> fragments, int curIndex) {
    if(!(container.getContext() instanceof FragmentActivity))
        throw new IllegalArgumentException(TAG + "context must instanceof FragmentActivity");
    FragmentManager fm = ((FragmentActivity) container.getContext()).getSupportFragmentManager();

    if (fragments != null && !fragments.isEmpty()) {
        PagerAdapter adapter = container.getAdapter();
        if(adapter == null) {
            // initialize, fragments are only added once !!!
            container.setAdapter(adapter = new FragmentPagerAdapter(fm) {
                @Override
                public Fragment getItem(int position) {
                    return fragments.get(position);
                }

                @Override
                public int getCount() {
                    return fragments.size();
                }
            });
        }

        adapter.notifyDataSetChanged();

        if(curIndex >= 0 && curIndex < fragments.size())
            container.setCurrentItem(curIndex);
    }
}
 
Example 2
Source File: BannerView.java    From bannerview with Apache License 2.0 5 votes vote down vote up
private static void setDuration(ViewPager pager, int duration) {
    try {
        FixedSpeedScroller scroller = new FixedSpeedScroller(pager.getContext(), new AccelerateDecelerateInterpolator(), duration);
        Field field = ViewPager.class.getDeclaredField("mScroller");
        field.setAccessible(true);
        field.set(pager, scroller);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: ViewPageFragmentAdapter.java    From FragmentMixViewPager with Apache License 2.0 5 votes vote down vote up
public ViewPageFragmentAdapter(FragmentManager fm,
		PagerSlidingTabStrip pageStrip, ViewPager pager) {
	super(fm);
	mContext = pager.getContext();
	mPagerStrip = pageStrip;
	mViewPager = pager;
	mViewPager.setAdapter(this);
	mPagerStrip.setViewPager(mViewPager);
}
 
Example 4
Source File: MorePagerAdapter.java    From Android with MIT License 4 votes vote down vote up
public MorePagerAdapter(ViewPager viewPager, List<BaseAction> actions) {
    this.context = viewPager.getContext();
    this.viewPager = viewPager;
    this.actionList = actions;
    this.gridViewCount = (actions.size() + ITEM_COUNT_PER_GRID_VIEW - 1) / ITEM_COUNT_PER_GRID_VIEW;
}
 
Example 5
Source File: ActionsPagerAdapter.java    From NIM_Android_UIKit with MIT License 4 votes vote down vote up
public ActionsPagerAdapter(ViewPager viewPager, List<BaseAction> actions) {
    this.context = viewPager.getContext();
    this.actions = new ArrayList<>(actions);
    this.viewPager = viewPager;
    this.gridViewCount = (actions.size() + ITEM_COUNT_PER_GRID_VIEW - 1) / ITEM_COUNT_PER_GRID_VIEW;
}