示例#1
0
            public Fling(TouchImageView view, int velocityX, int velocityY)
            {
                this.view = view;
                view.SetState(TouchState.FLING);
                scroller = new Scroller(view.context);
                view.matrix.GetValues(view.m);

                int startX = (int)view.m[Matrix.MtransX];
                int startY = (int)view.m[Matrix.MtransY];
                int minX, maxX, minY, maxY;

                if (view.GetImageWidth() > view.viewWidth)
                {
                    minX = view.viewWidth - (int)view.GetImageWidth();
                    maxX = 0;
                }
                else
                {
                    minX = maxX = startX;
                }

                if (view.GetImageHeight() > view.viewHeight)
                {
                    minY = view.viewHeight - (int)view.GetImageHeight();
                    maxY = 0;
                }
                else
                {
                    minY = maxY = startY;
                }

                scroller.Fling(startX, startY, (int)velocityX, (int)velocityY, minX, maxX, minY, maxY);
                currX = startX;
                currY = startY;
            }
示例#2
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);
            }