/** remove all the sliders. Notice: It's a not perfect method, a very small bug still exists. */
 public void removeAllSliders() {
   if (getRealAdapter() != null) {
     int count = getRealAdapter().getCount();
     getRealAdapter().removeAllSliders();
     // a small bug, but fixed by this trick.
     // bug: when remove adapter's all the sliders.some caching slider still alive.
     mViewPager.setCurrentItem(mViewPager.getCurrentItem() + count, false);
   }
 }
 /**
  * set the current slider
  *
  * @param position the insert position
  * @param smooth if that is smooth or not
  */
 public void setCurrentPosition(int position, boolean smooth) {
   if (getRealAdapter() == null)
     throw new IllegalStateException("You did not set a slider adapter");
   if (position >= getRealAdapter().getCount()) {
     throw new IllegalStateException("Item position is not exist");
   }
   int p = mViewPager.getCurrentItem() % getRealAdapter().getCount();
   int n = (position - p) + mViewPager.getCurrentItem();
   mViewPager.setCurrentItem(n, smooth);
 }
  /**
   * move to the next slide
   *
   * @param smooth bool
   */
  public void moveNextPosition(boolean smooth) {

    if (getRealAdapter() == null)
      throw new IllegalStateException("You did not set a slider adapter");

    mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, smooth);
    if (mIsShuffle) {
      setPagerTransformer(true, getShuffleTransformer());
    }
  }
 private SliderAdapter getRealAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return ((InfinitePagerAdapter) adapter).getRealAdapter();
   }
   return null;
 }
 private InfinitePagerAdapter getWrapperAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return (InfinitePagerAdapter) adapter;
   } else {
     return null;
   }
 }
  /**
   * get current slider.
   *
   * @return the sliderview
   */
  public BaseSliderView getCurrentSlider() {

    if (getRealAdapter() == null)
      throw new IllegalStateException("You did not set a slider adapter");

    int count = getRealAdapter().getCount();
    int realCount = mViewPager.getCurrentItem() % count;
    return getRealAdapter().getSliderView(realCount);
  }
  /**
   * set the duration between two slider changes.
   *
   * @param period by how many mil second to slide to the next one
   * @param interpolator with what interpolator
   */
  public void setSliderTransformDuration(int period, Interpolator interpolator) {
    try {
      final Field mScroller = ViewPagerEx.class.getDeclaredField("mScroller");
      mScroller.setAccessible(true);
      final FixedSpeedScroller scroller =
          new FixedSpeedScroller(mViewPager.getContext(), interpolator, period);
      mScroller.set(mViewPager, scroller);
    } catch (Exception e) {

    }
  }
 private void pagerSetup() {
   PagerAdapter wrappedAdapter = new InfinitePagerAdapter(mSliderAdapter);
   if (pagerType == 0) {
     mViewPager = (InfiniteViewPager) findViewById(R.id.daimajia_slider_viewpager);
     if (mPagerMargin > -1) {
       mViewPager.setMargin(mPagerMargin);
     }
     mViewPager.setAdapter(wrappedAdapter);
     mViewPager.setOnTouchListener(
         new OnTouchListener() {
           @Override
           public boolean onTouch(View v, MotionEvent event) {
             int action = event.getAction();
             switch (action) {
               case MotionEvent.ACTION_UP:
                 recoverCycle();
                 break;
             }
             return false;
           }
         });
   } else if (pagerType == 1) {
   }
 }
 /**
  * get the current item position
  *
  * @return the int position
  */
 public int getCurrentPosition() {
   if (getRealAdapter() == null)
     throw new IllegalStateException("You did not set a slider adapter");
   return mViewPager.getCurrentItem() % getRealAdapter().getCount();
 }
 /**
  * set ViewPager transformer.
  *
  * @param reverseDrawingOrder the boolean for order
  * @param transformer BaseTransformer
  */
 public void setPagerTransformer(boolean reverseDrawingOrder, BaseTransformer transformer) {
   mViewPagerTransformer = transformer;
   mViewPagerTransformer.setCustomAnimationInterface(mCustomAnimation);
   mViewPager.setPageTransformer(reverseDrawingOrder, mViewPagerTransformer);
 }
 public void addOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   if (onPageChangeListener != null) {
     mViewPager.addOnPageChangeListener(onPageChangeListener);
   }
 }
 @Override
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   mViewPager.nextItem();
 }
 public void slideToPreviousItem() {
   mViewPager.beforeItem();
 }
 public void slideToNextItem() {
   mViewPager.nextItem();
 }
 /**
  * move to prev slide.
  *
  * @param smooth bool
  */
 public void movePrevPosition(boolean smooth) {
   if (getRealAdapter() == null)
     throw new IllegalStateException("You did not set a slider adapter");
   mViewPager.setCurrentItem(mViewPager.getCurrentItem() - 1, smooth);
 }
 /**
  * {@link ViewPagerEx#setOffscreenPageLimit(int)} open ViewPager API.
  *
  * @param limit How many pages will be kept offscreen in an idle state.
  */
 public void setOffscreenPageLimit(int limit) {
   mViewPager.setOffscreenPageLimit(limit);
 }
 /** clear self means unregister the dataset observer and cancel all Timer */
 public void destroySelf() {
   mSliderAdapter.unregisterDataSetObserver(sliderDataObserver);
   stopAutoCycle();
   mViewPager.removeAllViews();
 }
 public void removeOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   mViewPager.removeOnPageChangeListener(onPageChangeListener);
 }