Search in sources :

Example 1 with DisableableViewPager

use of org.edx.mobile.view.custom.DisableableViewPager in project edx-app-android by edx.

the class CourseUnitNavigationActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    RelativeLayout insertPoint = (RelativeLayout) findViewById(R.id.fragment_container);
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.view_course_unit_pager, null);
    insertPoint.addView(v, 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    pager = (DisableableViewPager) findViewById(R.id.pager);
    pagerAdapter = new CourseUnitPagerAdapter(getSupportFragmentManager(), environment.getConfig(), unitList, courseData, this);
    pager.setAdapter(pagerAdapter);
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            if (state == ViewPager.SCROLL_STATE_DRAGGING) {
                int curIndex = pager.getCurrentItem();
                PageViewStateCallback curView = (PageViewStateCallback) pagerAdapter.instantiateItem(pager, curIndex);
                if (curView != null)
                    curView.onPageDisappear();
            }
            if (state == ViewPager.SCROLL_STATE_IDLE) {
                int curIndex = pager.getCurrentItem();
                PageViewStateCallback curView = (PageViewStateCallback) pagerAdapter.instantiateItem(pager, curIndex);
                if (curView != null)
                    curView.onPageShow();
                tryToUpdateForEndOfSequential();
            }
        }
    });
    findViewById(R.id.course_unit_nav_bar).setVisibility(View.VISIBLE);
    mPreviousBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            navigatePreviousComponent();
        }
    });
    mNextBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            navigateNextComponent();
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PageViewStateCallback(org.edx.mobile.view.common.PageViewStateCallback) View(android.view.View) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) DisableableViewPager(org.edx.mobile.view.custom.DisableableViewPager) ViewPager(android.support.v4.view.ViewPager) CourseUnitPagerAdapter(org.edx.mobile.view.adapters.CourseUnitPagerAdapter) LayoutInflater(android.view.LayoutInflater) RelativeLayout(android.widget.RelativeLayout)

Aggregations

ViewPager (android.support.v4.view.ViewPager)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 CourseUnitPagerAdapter (org.edx.mobile.view.adapters.CourseUnitPagerAdapter)1 PageViewStateCallback (org.edx.mobile.view.common.PageViewStateCallback)1 DisableableViewPager (org.edx.mobile.view.custom.DisableableViewPager)1 InjectView (roboguice.inject.InjectView)1