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); }
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; }
public void Run() { float t = Interpolate(); float deltaScale = CalculateDeltaScale(t); view.ScaleImage(deltaScale, bitmapX, bitmapY, stretchImageToSuper); TranslateImageToCenterTouchPosition(t); view.FixScaleTrans(); view.ImageMatrix = view.matrix; if (t < 1f) { // // We haven't finished zooming // view.CompatPostOnAnimation(this); } else { // // Finished zooming // view.SetState(TouchState.NONE); } }
public void CancelFling() { if (scroller != null) { view.SetState(TouchState.NONE); scroller.ForceFinished(true); } }
public DoubleTapZoom(TouchImageView view, float targetZoom, float focusX, float focusY, bool stretchImageToSuper) { this.view = view; view.SetState(TouchState.ANIMATE_ZOOM); startTime = DateTime.Now.Ticks; this.startZoom = view.normalizedScale; this.targetZoom = targetZoom; this.stretchImageToSuper = stretchImageToSuper; PointF bitmapPoint = view.TransformCoordTouchToBitmap(focusX, focusY, false); this.bitmapX = bitmapPoint.X; this.bitmapY = bitmapPoint.Y; // // Used for translating image during scaling // startTouch = view.TransformCoordBitmapToTouch(bitmapX, bitmapY); endTouch = new PointF(view.viewWidth / 2, view.viewHeight / 2); }
public override bool OnScaleBegin(ScaleGestureDetector detector) { view.SetState(TouchState.ZOOM); return(true); }