예제 #1
0
  /** 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);
  }
예제 #2
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);
   }
 }
예제 #3
0
 /**
  * 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);
 }
예제 #4
0
  public SliderLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContext = context;
    LayoutInflater.from(context).inflate(R.layout.slider_layout, this, true);

    final TypedArray attributes =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.SliderLayout, defStyle, 0);

    mTransformerSpan = attributes.getInteger(R.styleable.SliderLayout_pager_animation_span, 1100);
    mTransformerId =
        attributes.getInt(R.styleable.SliderLayout_pager_animation, Transformer.Default.ordinal());
    mAutoCycle = attributes.getBoolean(R.styleable.SliderLayout_auto_cycle, true);
    int visibility = attributes.getInt(R.styleable.SliderLayout_indicator_visibility, 0);
    for (PagerIndicator.IndicatorVisibility v : PagerIndicator.IndicatorVisibility.values()) {
      if (v.ordinal() == visibility) {
        mIndicatorVisibility = v;
        break;
      }
    }
    mSliderAdapter = new SliderAdapter(mContext);
    PagerAdapter wrappedAdapter = new InfinitePagerAdapter(mSliderAdapter);

    mViewPager = (InfiniteViewPager) findViewById(R.id.daimajia_slider_viewpager);
    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;
          }
        });

    attributes.recycle();
    setPresetIndicator(PresetIndicators.Center_Bottom);
    setPresetTransformer(mTransformerId);
    setSliderTransformDuration(mTransformerSpan, null);
    setIndicatorVisibility(mIndicatorVisibility);
    if (mAutoCycle) {
      startAutoCycle();
    }
  }
예제 #5
0
  /**
   * 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();
  }
예제 #6
0
 private SliderAdapter getRealAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return ((InfinitePagerAdapter) adapter).getRealAdapter();
   }
   return null;
 }
예제 #7
0
 private InfinitePagerAdapter getWrapperAdapter() {
   PagerAdapter adapter = mViewPager.getAdapter();
   if (adapter != null) {
     return (InfinitePagerAdapter) adapter;
   } else {
     return null;
   }
 }
예제 #8
0
  /**
   * 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);
  }
예제 #9
0
  /**
   * set the duration between two slider changes.
   *
   * @param period
   * @param interpolator
   */
  public void setSliderTransformDuration(int period, Interpolator interpolator) {
    try {
      Field mScroller = ViewPagerEx.class.getDeclaredField("mScroller");
      mScroller.setAccessible(true);
      FixedSpeedScroller scroller =
          new FixedSpeedScroller(mViewPager.getContext(), interpolator, period);
      mScroller.set(mViewPager, scroller);
    } catch (Exception e) {

    }
  }
예제 #10
0
 /**
  * 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);
   }
 }
예제 #11
0
 /**
  * set ViewPager transformer.
  *
  * @param reverseDrawingOrder
  * @param transformer
  */
 public void setPagerTransformer(boolean reverseDrawingOrder, BaseTransformer transformer) {
   mViewPagerTransformer = transformer;
   mViewPagerTransformer.setCustomAnimationInterface(mCustomAnimation);
   mViewPager.setPageTransformer(reverseDrawingOrder, mViewPagerTransformer);
 }
예제 #12
0
 public void removeOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   mViewPager.removeOnPageChangeListener(onPageChangeListener);
 }
예제 #13
0
 public void addOnPageChangeListener(ViewPagerEx.OnPageChangeListener onPageChangeListener) {
   if (onPageChangeListener != null) {
     mViewPager.addOnPageChangeListener(onPageChangeListener);
   }
 }