コード例 #1
0
 @Override
 public void onChanged() {
   PagerAdapter adapter = mPager.getAdapter();
   int count = 0;
   if (adapter instanceof InfinitePagerAdapter) {
     count = ((InfinitePagerAdapter) adapter).getRealCount();
   } else {
     count = adapter.getCount();
   }
   if (count > mItemCount) {
     for (int i = 0; i < count - mItemCount; i++) {
       ImageView indicator = new ImageView(mContext);
       indicator.setImageDrawable(mUnselectedDrawable);
       indicator.setPadding(
           (int) mUnSelectedPadding_Left,
           (int) mUnSelectedPadding_Top,
           (int) mUnSelectedPadding_Right,
           (int) mUnSelectedPadding_Bottom);
       addView(indicator);
       mIndicators.add(indicator);
     }
   } else if (count < mItemCount) {
     for (int i = 0; i < mItemCount - count; i++) {
       removeView(mIndicators.get(0));
       mIndicators.remove(0);
     }
   }
   mItemCount = count;
   mPager.setCurrentItem(mItemCount * 20 + mPager.getCurrentItem());
 }
コード例 #2
0
 /**
  * since we used a adapter wrapper, so we can't getCount directly from wrapper.
  *
  * @return
  */
 private int getShouldDrawCount() {
   if (mPager.getAdapter() instanceof InfinitePagerAdapter) {
     return ((InfinitePagerAdapter) mPager.getAdapter()).getRealCount();
   } else {
     return mPager.getAdapter().getCount();
   }
 }
コード例 #3
0
 /**
  * bind indicator with viewpagerEx.
  *
  * @param pager
  */
 public void setViewPager(ViewPagerEx pager) {
   if (pager.getAdapter() == null) {
     throw new IllegalStateException("Viewpager does not have adapter instance");
   }
   mPager = pager;
   mPager.setOnPageChangeListener(this);
   ((InfinitePagerAdapter) mPager.getAdapter())
       .getRealAdapter()
       .registerDataSetObserver(dataChangeObserver);
 }
コード例 #4
0
 /**
  * clear self means unregister the dataset observer and remove all the child views(indicators).
  */
 public void destroySelf() {
   if (mPager == null || mPager.getAdapter() == null) {
     return;
   }
   InfinitePagerAdapter wrapper = (InfinitePagerAdapter) mPager.getAdapter();
   PagerAdapter adapter = wrapper.getRealAdapter();
   if (adapter != null) {
     adapter.unregisterDataSetObserver(dataChangeObserver);
   }
   removeAllViews();
 }