Search in sources :

Example 1 with CarouselTransformer

use of com.instructure.parentapp.util.CarouselTransformer in project instructure-android by instructure.

the class StudentViewActivity method configureUserCarousel.

private void configureUserCarousel() {
    mCarouselViewPager = (ViewPager) findViewById(R.id.carouselPager);
    mCarouselAdapter = new CarouselPagerAdapter(this);
    mCarouselViewPager.addOnPageChangeListener(this);
    mCarouselViewPager.setPageTransformer(true, new CarouselTransformer());
    if (getIntent().getExtras().getParcelableArrayList(Const.USER) != null) {
        ArrayList<Student> students = getIntent().getExtras().getParcelableArrayList(Const.USER);
        if (students != null && students.size() > 0) {
            mCarouselAdapter.clear();
            mCarouselViewPager.setOffscreenPageLimit(students.size());
            mCarouselAdapter.addAll(students);
        }
    }
    mCarouselViewPager.post(new Runnable() {

        @Override
        public void run() {
            mCarouselViewPager.setAdapter(mCarouselAdapter);
            // Use this to set the offset for the viewpager
            int childWidth = (int) getResources().getDimension(R.dimen.carousel_avatar_size);
            double factor = 1.30;
            if (getResources().getBoolean(R.bool.isTablet)) {
                // adjust for tablets so the student's icons are closer together
                factor = 1.15;
            }
            double width = (mCarouselViewPager.getWidth() / factor) + (childWidth / 2);
            int truncWidth = (int) width;
            mCarouselViewPager.setPageMargin(-truncWidth);
            if (mCarouselAdapter.getCount() > 1) {
                Prefs prefs = new Prefs(StudentViewActivity.this, com.instructure.parentapp.util.Const.CANVAS_PARENT_SP);
                int pos = prefs.load(Const.POSITION, mCarouselAdapter.getCount() / 2);
                mCarouselViewPager.setCurrentItem(pos);
                onPageSelected(pos);
            } else if (mCarouselAdapter.getCount() == 1) {
                // need to call onPageSelected so that it shows the user's name
                onPageSelected(0);
            }
        }
    });
}
Also used : CarouselTransformer(com.instructure.parentapp.util.CarouselTransformer) CarouselPagerAdapter(com.instructure.parentapp.adapter.CarouselPagerAdapter) Student(com.instructure.canvasapi2.models.Student) ApiPrefs(com.instructure.canvasapi2.utils.ApiPrefs) Prefs(com.instructure.pandautils.utils.Prefs)

Aggregations

Student (com.instructure.canvasapi2.models.Student)1 ApiPrefs (com.instructure.canvasapi2.utils.ApiPrefs)1 Prefs (com.instructure.pandautils.utils.Prefs)1 CarouselPagerAdapter (com.instructure.parentapp.adapter.CarouselPagerAdapter)1 CarouselTransformer (com.instructure.parentapp.util.CarouselTransformer)1