示例#1
0
            public bool OnTouch(View v, MotionEvent evt)
            {
                if (view.touchListener != null)
                {
                    view.touchListener.OnTouch(v, evt);                            // User-defined handler, maybe
                }
                view.mScaleDetector.OnTouchEvent(evt);
                view.mGestureDetector.OnTouchEvent(evt);
                PointF curr = new PointF(evt.GetX(), evt.GetY());

                if (view.state == TouchState.NONE || view.state == TouchState.DRAG || view.state == TouchState.FLING)
                {
                    switch (evt.Action)
                    {
                    case MotionEventActions.Down:
                        last.Set(curr);
                        if (view.fling != null)
                        {
                            view.fling.CancelFling();
                        }
                        view.SetState(TouchState.DRAG);
                        break;

                    case MotionEventActions.Move:
                        if (view.state == TouchState.DRAG)
                        {
                            float deltaX    = curr.X - last.X;
                            float deltaY    = curr.Y - last.Y;
                            float fixTransX = view.GetFixDragTrans(deltaX, view.viewWidth, view.GetImageWidth());
                            float fixTransY = view.GetFixDragTrans(deltaY, view.viewHeight, view.GetImageHeight());
                            view.matrix.PostTranslate(fixTransX, fixTransY);
                            view.FixTrans();
                            last.Set(curr.X, curr.Y);
                        }
                        break;

                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                        view.SetState(TouchState.NONE);
                        break;
                    }
                }

                view.ImageMatrix = view.matrix;
                //
                // indicate event was handled
                //
                return(true);
            }
示例#2
0
            public void Run()
            {
                if (scroller.IsFinished)
                {
                    scroller = null;
                    return;
                }

                if (scroller.ComputeScrollOffset())
                {
                    int newX   = scroller.CurrX;
                    int newY   = scroller.CurrY;
                    int transX = newX - currX;
                    int transY = newY - currY;
                    currX = newX;
                    currY = newY;
                    view.matrix.PostTranslate(transX, transY);
                    view.FixTrans();
                    view.ImageMatrix = view.matrix;
                    view.CompatPostOnAnimation(this);
                }
            }