/** * set current slider * * @param position */ 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 next slide. */ public void moveNextPosition(boolean smooth) { if (getRealAdapter() == null) throw new IllegalStateException("You did not set a slider adapter"); mViewPager.setCurrentItem(mViewPager.getCurrentItem() + 1, smooth); }
/** * get the current item position * * @return */ public int getCurrentPosition() { if (getRealAdapter() == null) throw new IllegalStateException("You did not set a slider adapter"); return mViewPager.getCurrentItem() % getRealAdapter().getCount(); }
/** 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); } }
/** * get current slider. * * @return */ 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); }
/** * remove the slider at the position. Notice: It's a not perfect method, a very small bug still * exists. */ public void removeSliderAt(int position) { if (getRealAdapter() != null) { getRealAdapter().removeSliderAt(position); mViewPager.setCurrentItem(mViewPager.getCurrentItem(), false); } }