Search in sources :

Example 1 with ColorPointHintView

use of com.daotangbill.exlib.ui.rollviewpager.hintview.ColorPointHintView in project MLib by DaoBillTang.

the class RollPagerView method initView.

/**
 * 读取提示形式  和   提示位置   和    播放延迟
 *
 * @param attrs
 */
private void initView(AttributeSet attrs) {
    if (mViewPager != null) {
        removeView(mViewPager);
    }
    TypedArray type = getContext().obtainStyledAttributes(attrs, R.styleable.RollPagerView);
    gravity = type.getInteger(R.styleable.RollPagerView_rollviewpager_hint_gravity, 1);
    delay = type.getInt(R.styleable.RollPagerView_rollviewpager_play_delay, 0);
    color = type.getColor(R.styleable.RollPagerView_rollviewpager_hint_color, Color.BLACK);
    alpha = type.getInt(R.styleable.RollPagerView_rollviewpager_hint_alpha, 0);
    isHint = type.getBoolean(R.styleable.RollPagerView_rollviewpager_ishint, true);
    paddingLeft = (int) type.getDimension(R.styleable.RollPagerView_rollviewpager_hint_paddingLeft, 0);
    paddingRight = (int) type.getDimension(R.styleable.RollPagerView_rollviewpager_hint_paddingRight, 0);
    paddingTop = (int) type.getDimension(R.styleable.RollPagerView_rollviewpager_hint_paddingTop, 0);
    paddingBottom = (int) type.getDimension(R.styleable.RollPagerView_rollviewpager_hint_paddingBottom, DensityUtilsKt.dip2px(4));
    mViewPager = new ViewPager(getContext());
    mViewPager.setId(R.id.viewpager_inner);
    mViewPager.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(mViewPager);
    type.recycle();
    // 颜色
    initHint(new ColorPointHintView(getContext(), Color.parseColor("#CFAF78"), Color.parseColor("#88ffffff")));
    // 手势处理
    mGestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (mOnItemClickListener != null) {
                // 原谅我写了这么丑的代码
                if (mAdapter instanceof LoopPagerAdapter) {
                    mOnItemClickListener.onItemClick(mViewPager.getCurrentItem() % ((LoopPagerAdapter) mAdapter).getRealCount());
                } else {
                    mOnItemClickListener.onItemClick(mViewPager.getCurrentItem());
                }
            }
            return super.onSingleTapUp(e);
        }
    });
}
Also used : LoopPagerAdapter(com.daotangbill.exlib.ui.rollviewpager.adapter.LoopPagerAdapter) TypedArray(android.content.res.TypedArray) ColorPointHintView(com.daotangbill.exlib.ui.rollviewpager.hintview.ColorPointHintView) GestureDetector(android.view.GestureDetector) ViewPager(android.support.v4.view.ViewPager) MotionEvent(android.view.MotionEvent)

Aggregations

TypedArray (android.content.res.TypedArray)1 ViewPager (android.support.v4.view.ViewPager)1 GestureDetector (android.view.GestureDetector)1 MotionEvent (android.view.MotionEvent)1 LoopPagerAdapter (com.daotangbill.exlib.ui.rollviewpager.adapter.LoopPagerAdapter)1 ColorPointHintView (com.daotangbill.exlib.ui.rollviewpager.hintview.ColorPointHintView)1