示例#1
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            switch (e.Action)
            {
            case MotionEventActions.Down:
                et          = JavaSystem.CurrentTimeMillis();
                dx          = (int)e.GetX();
                dy          = (int)e.GetY();
                mTouch.X    = dx;
                mTouch.Y    = dy;
                actiondownX = dx;
                actiondownY = dy;
                touch_down  = 0;
                pagefactory.onDraw(mCurrentPageCanvas);
                if (actiondownX >= mScreenWidth / 3 && actiondownX <= mScreenWidth * 2 / 3 &&
                    actiondownY >= mScreenHeight / 3 && actiondownY <= mScreenHeight * 2 / 3)
                {
                    center = true;
                }
                else
                {
                    center = false;
                    calcCornerXY(actiondownX, actiondownY);
                    if (actiondownX < mScreenWidth / 2)  // 从左翻
                    {
                        BookStatus status = pagefactory.prePage();
                        if (status == BookStatus.NO_PRE_PAGE)
                        {
                            ToastUtils.showSingleToast("没有上一页啦");
                            return(false);
                        }
                        else if (status == BookStatus.LOAD_SUCCESS)
                        {
                            abortAnimation();
                            pagefactory.onDraw(mNextPageCanvas);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else if (actiondownX >= mScreenWidth / 2)    // 从右翻
                    {
                        BookStatus status = pagefactory.nextPage();
                        if (status == BookStatus.NO_NEXT_PAGE)
                        {
                            ToastUtils.showSingleToast("没有下一页啦");
                            return(false);
                        }
                        else if (status == BookStatus.LOAD_SUCCESS)
                        {
                            abortAnimation();
                            pagefactory.onDraw(mNextPageCanvas);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    listener.onFlip();
                    setBitmaps(mCurPageBitmap, mNextPageBitmap);
                }
                break;

            case MotionEventActions.Move:
                if (center)
                {
                    break;
                }
                int mx = (int)e.GetX();
                int my = (int)e.GetY();
                cancel     = (actiondownX < mScreenWidth / 2 && mx < mTouch.X) || (actiondownX > mScreenWidth / 2 && mx > mTouch.X);
                mTouch.X   = mx;
                mTouch.Y   = my;
                touch_down = mTouch.X - actiondownX;
                this.PostInvalidate();
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:

                long t  = JavaSystem.CurrentTimeMillis();
                int  ux = (int)e.GetX();
                int  uy = (int)e.GetY();

                if (center)   // ACTION_DOWN的位置在中间,则不响应滑动事件
                {
                    resetTouchPoint();
                    if (System.Math.Abs(ux - actiondownX) < 5 && System.Math.Abs(uy - actiondownY) < 5)
                    {
                        listener.onCenterClick();
                        return(false);
                    }
                    break;
                }

                if ((System.Math.Abs(ux - dx) < 10) && (System.Math.Abs(uy - dy) < 10))
                {
                    if ((t - et < 1000))   // 单击
                    {
                        startAnimation();
                    }
                    else     // 长按
                    {
                        pagefactory.cancelPage();
                        restoreAnimation();
                    }
                    PostInvalidate();
                    return(true);
                }
                if (cancel)
                {
                    pagefactory.cancelPage();
                    restoreAnimation();
                    PostInvalidate();
                }
                else
                {
                    startAnimation();
                    PostInvalidate();
                }
                cancel = false;
                center = false;
                break;

            default:
                break;
            }
            return(true);
        }