コード例 #1
0
 /** 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);
   }
 }
コード例 #2
0
 /**
  * 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);
 }
コード例 #3
0
  /**
   * 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());
    }
  }
コード例 #4
0
 private SliderAdapter getRealAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return ((InfinitePagerAdapter) adapter).getRealAdapter();
   }
   return null;
 }
コード例 #5
0
 private InfinitePagerAdapter getWrapperAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return (InfinitePagerAdapter) adapter;
   } else {
     return null;
   }
 }
コード例 #6
0
  /**
   * 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);
  }
コード例 #7
0
  /**
   * 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) {

    }
  }
コード例 #8
0
 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) {
   }
 }
コード例 #9
0
 /**
  * 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();
 }
コード例 #10
0
 /**
  * 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);
 }
コード例 #11
0
 public void addOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   if (onPageChangeListener != null) {
     mViewPager.addOnPageChangeListener(onPageChangeListener);
   }
 }
コード例 #12
0
 @Override
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   mViewPager.nextItem();
 }
コード例 #13
0
 public void slideToPreviousItem() {
   mViewPager.beforeItem();
 }
コード例 #14
0
 public void slideToNextItem() {
   mViewPager.nextItem();
 }
コード例 #15
0
 /**
  * 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);
 }
コード例 #16
0
 /**
  * {@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);
 }
コード例 #17
0
 /** clear self means unregister the dataset observer and cancel all Timer */
 public void destroySelf() {
   mSliderAdapter.unregisterDataSetObserver(sliderDataObserver);
   stopAutoCycle();
   mViewPager.removeAllViews();
 }
コード例 #18
0
 public void removeOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   mViewPager.removeOnPageChangeListener(onPageChangeListener);
 }