Example #1
0
            bool OnScale(ScaleGestureDetector detector)
            {
                float mScaleFactor = detector.ScaleFactor;
                float origScale    = imgView.saveScale;

                imgView.saveScale *= mScaleFactor;
                if (imgView.saveScale > imgView.maxScale)
                {
                    imgView.saveScale = imgView.maxScale;
                    mScaleFactor      = imgView.maxScale / origScale;
                }
                else if (imgView.saveScale < imgView.minScale)
                {
                    imgView.saveScale = imgView.minScale;
                    mScaleFactor      = imgView.minScale / origScale;
                }

                if (imgView.origWidth * imgView.saveScale <= imgView.viewWidth || imgView.origHeight * imgView.saveScale <= imgView.viewHeight)
                {
                    imgView.matrix.PostScale(mScaleFactor, mScaleFactor, imgView.viewWidth / 2, imgView.viewHeight / 2);
                }
                else
                {
                    imgView.matrix.PostScale(mScaleFactor, mScaleFactor, detector.FocusX, detector.FocusY);
                }

                imgView.fixTrans();
                return(true);
            }
Example #2
0
            public bool OnTouch(View v, MotionEvent evnt)
            {
                imgView = (ScalableImageView)v;
                flingGestureDetector.OnTouchEvent(evnt);
                mScaleDetector.OnTouchEvent(evnt);
                PointF curr = new PointF(evnt.GetX(), evnt.GetY());

                switch (evnt.Action)
                {
                case MotionEventActions.Down:
                    last.Set(curr);
                    start.Set(last);
                    currentState = State.DRAG;
                    //mode = TouchImageView.DRAG;
                    break;

                case MotionEventActions.Move:
                    //if (mode == DRAG)
                    if (currentState == State.DRAG)
                    {
                        float deltaX    = curr.X - last.X;
                        float deltaY    = curr.Y - last.Y;
                        float fixTransX = imgView.getFixDragTrans(deltaX, imgView.viewWidth, imgView.origWidth * imgView.saveScale);
                        float fixTransY = imgView.getFixDragTrans(deltaY, imgView.viewHeight, imgView.origHeight * imgView.saveScale);
                        imgView.matrix.PostTranslate(fixTransX, fixTransY);
                        imgView.fixTrans();
                        last.Set(curr.X, curr.Y);
                    }
                    break;

                case MotionEventActions.Up:
                    //mode = NONE;
                    currentState = State.NONE;
                    int xDiff = (int)Math.Abs(curr.X - start.X);
                    int yDiff = (int)Math.Abs(curr.Y - start.Y);
                    if (xDiff < CLICK && yDiff < CLICK)
                    {
                        PerformClick();
                    }
                    break;

                case MotionEventActions.PointerUp:
                    //mode = NONE;
                    currentState = State.NONE;
                    break;
                }

                imgView.ImageMatrix = imgView.matrix;
                Invalidate();
                //return true; // indicate event was handled
                return(false);
            }