/** * Add {@link Decor} into this layout. Decor will be added to the layout based on its start page * and end page. Calling this method will also enables children drawing order, which follows the * order of the parameters, e.g the first Decor will be drawn first. * * @param decor Decor object to be added to this layout. * @throws IllegalStateException when ViewPager is not set in this layout. */ @SuppressWarnings("unused") public void addDecor(Decor decor) { if (mViewPager == null) { throw new IllegalStateException( "ViewPager is not found in SparkleViewPagerLayout, please provide a ViewPager first"); } if (decor == null) { return; } // Make sure there is no duplicate. if (mDecors.contains(decor)) { return; } mDecors.add(decor); // Add slide in and slide out animations to the presenter. SparkleAnimationPresenter presenter = SparkleMotionCompat.getAnimationPresenter(mViewPager); if (presenter == null) { throw new IllegalStateException("Failed initializing animation"); } presenter.addAnimation(decor, decor.slideInAnimation, decor.slideOutAnimation); if (decor.layoutBehindViewPage) { addView(decor.contentView, mViewPagerIndex); mViewPagerIndex++; } else { addView(decor.contentView); } layoutDecors(mViewPager.getCurrentItem(), 0); }
private void init() { if (SparkleMotionCompat.hasPresenter(mViewPager)) { mPresenter = SparkleMotionCompat.getAnimationPresenter(mViewPager); } else { mPresenter = new SparkleAnimationPresenter(); } mAnimations = new ArrayList<Animation>(); }