public override bool DispatchTouchEvent(MotionEvent e) { base.DispatchTouchEvent(e); mScaleDetector.OnTouchEvent(e); return(mScaleDetector.OnTouchEvent(e)); }
public override bool DispatchTouchEvent(MotionEvent e) { if (isEnable) { MotionEventActions Action = e.ActionMasked; if (e.PointerCount >= 2) { hasMultiTouch = true; } mDetector.OnTouchEvent(e); if (isRotateEnable) { mRotateDetector.onTouchEvent(e); } mScaleDetector.OnTouchEvent(e); if (Action == MotionEventActions.Up || Action == MotionEventActions.Cancel) { onUp(); } return(true); } else { return(base.DispatchTouchEvent(e)); } }
public override bool OnTouchEvent(MotionEvent e) { _pdfScaleDetector.OnTouchEvent(e); _pdfGestureDetector.OnTouchEvent(e); return(base.OnTouchEvent(e)); }
public bool OnTouch(View v, MotionEvent ev) { if (AnimatingZoomEnding || ev.PointerCount > 2) { return(true); } ScaleGestureDetector.OnTouchEvent(ev); GestureDetector.OnTouchEvent(ev); var action = ev.Action & MotionEventActions.Mask; switch (action) { case MotionEventActions.PointerDown: case MotionEventActions.Down: switch (State) { case STATE_IDLE: State = STATE_POINTER_DOWN; break; case STATE_POINTER_DOWN: State = STATE_ZOOMING; ev.MidPointOfEvent(InitialPinchMidPoint); StartZoomingView(Target); break; } break; case MotionEventActions.Move: if (State == STATE_ZOOMING) { ev.MidPointOfEvent(CurrentMovementMidPoint); CurrentMovementMidPoint.X -= InitialPinchMidPoint.X; CurrentMovementMidPoint.Y -= InitialPinchMidPoint.Y; CurrentMovementMidPoint.X += TargetViewCords.X; CurrentMovementMidPoint.Y += TargetViewCords.Y; float x = CurrentMovementMidPoint.X; float y = CurrentMovementMidPoint.Y; ZoomableView.SetX(x); ZoomableView.SetY(y); } break; case MotionEventActions.PointerUp: case MotionEventActions.Up: case MotionEventActions.Cancel: switch (State) { case STATE_ZOOMING: EndZoomingView(); break; case STATE_POINTER_DOWN: State = STATE_IDLE; break; } break; } return(true); }
public DragPinchManager(PdfView pdfView, AnimationManager animationManager) { this.pdfView = pdfView; this.animationManager = animationManager; gestureDetector = new GestureDetector(pdfView.Context, this); scaleGestureDetector = new ScaleGestureDetector(pdfView.Context, this); pdfView.Touch += (s, e) => { if (!enabled) { e.Handled = false; } var retVal = scaleGestureDetector.OnTouchEvent(e.Event); retVal = gestureDetector.OnTouchEvent(e.Event) || retVal; if (e.Event.Action != MotionEventActions.Up) { e.Handled = retVal; } if (!scrolling) { e.Handled = retVal; } scrolling = false; OnScrollEnd(e.Event); e.Handled = retVal; }; }
public override bool OnTouchEvent(MotionEvent e) { gestureDetector.OnTouchEvent(e); scaleGestureDetector.OnTouchEvent(e); rotationGestureDetector.OnTouch(e); return(true); }
public override bool OnTouchEvent(MotionEvent e) { bool handled; handled = scaleGestureDetector.OnTouchEvent(e); // if (handled) // return true; handled = gestureDetector.OnTouchEvent(e); // if (handled) // return true; if (ccContext.CountLayerContext.IsSelectionValid) { if (e.Action == MotionEventActions.Move) { Vector2 pos = new Vector2(e.GetX(), e.GetY()); Vector2 trans = pos - lastDragPos; ccContext.CountLayerContext.OnDrag(pos, trans); lastDragPos = pos; } else { ccContext.CountLayerContext.OnUnselect(); } } return(true); }
void HandleTouch(object sender, TouchEventArgs e) { _scaleDetector.OnTouchEvent(e.Event); if (!_scaleDetector.IsInProgress) { _gestureDetector.OnTouchEvent(e.Event); } }
public override bool OnTouchEvent(MotionEvent ev) { ScaleDetector.OnTouchEvent(ev); MotionEventActions action = ev.Action & MotionEventActions.Mask; int pointerIndex; switch (action) { case MotionEventActions.Down: LastTouchX = ev.GetX(); LastTouchY = ev.GetY(); ActivePointerId = ev.GetPointerId(0); break; case MotionEventActions.Move: pointerIndex = ev.FindPointerIndex(ActivePointerId); float x = ev.GetX(pointerIndex); float y = ev.GetY(pointerIndex); if (!ScaleDetector.IsInProgress) { // Only move the ScaleGestureDetector isn't already processing a gesture. float deltaX = x - LastTouchX; float deltaY = y - LastTouchY; PosX += deltaX; PosY += deltaY; Invalidate(); } LastTouchX = x; LastTouchY = y; break; case MotionEventActions.Up: case MotionEventActions.Cancel: // We no longer need to keep track of the active pointer. ActivePointerId = InvalidPointerId; break; case MotionEventActions.PointerUp: // check to make sure that the pointer that went up is for the gesture we're tracking. pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift; int pointerId = ev.GetPointerId(pointerIndex); if (pointerId == ActivePointerId) { // This was our active pointer going up. Choose a new // action pointer and adjust accordingly int newPointerIndex = pointerIndex == 0 ? 1 : 0; LastTouchX = ev.GetX(newPointerIndex); LastTouchY = ev.GetY(newPointerIndex); ActivePointerId = ev.GetPointerId(newPointerIndex); } break; } return(true); }
/// <summary> /// Raises the touch event. /// </summary> /// <param name="v">V.</param> /// <param name="e">E.</param> public bool OnTouch(global::Android.Views.View v, MotionEvent e) { _scaleGestureDetector.OnTouchEvent(e); if (!_scaled) { _gestureDetector.OnTouchEvent(e); } _scaled = false; return(true); }
/// <summary> /// Raises the touch event. /// </summary> /// <param name="v">V.</param> /// <param name="e">E.</param> public bool OnTouch(global::Android.Views.View v, MotionEvent e) { _tagGestureDetector.OnTouchEvent(e); _scaleGestureDetector.OnTouchEvent(e); _rotateGestureDetector.OnTouchEvent(e); _moveGestureDetector.OnTouchEvent(e); if (_deltaX != 0 || _deltaY != 0 || // was there movement? _deltaScale != 1.0 || // was there scale? _deltaDegrees != 0) { // was there rotation? if (_deltaScale != 1.0) { // calculate the scale. double zoomFactor = this.Map.Projection.ToZoomFactor(this.MapZoom); zoomFactor = zoomFactor * _deltaScale; this.MapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor); } // stop the animation. this.StopCurrentAnimation(); //OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information, // string.Format("OnTouch:[{0},{1}] {2}s {3}d", _deltaX, _deltaY, _deltaScale, _deltaDegrees)); // recreate the view. View2D view = this.CreateView(); // calculate the new center in pixels. double centerXPixels = this.Width / 2.0f - _deltaX; double centerYPixles = this.Height / 2.0f - _deltaY; // calculate the new center from the view. double[] sceneCenter = view.FromViewPort(this.Width, this.Height, centerXPixels, centerYPixles); // convert to the projected center. this.MapCenter = this.Map.Projection.ToGeoCoordinates(sceneCenter[0], sceneCenter[1]); // do the rotation stuff around the new center. if (_deltaDegrees != 0) { View2D rotatedView = view.RotateAroundCenter((Degree)(-_deltaDegrees)); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; } _deltaScale = 1; _deltaDegrees = 0; _deltaX = 0; _deltaY = 0; this.NotifyMovement(); } return(true); }
private void Control_Touch(object sender, TouchEventArgs e) { if (e.Event.PointerCount == 1) { GestureDetector.OnTouchEvent(e.Event); } else { ScaleGestureDetector.OnTouchEvent(e.Event); } }
public override bool OnTouchEvent(MotionEvent e) { PerformClick(); _scaleDetector.OnTouchEvent(e); if (_gestureDetectorCompat.OnTouchEvent(e)) { return(true); } return(base.OnTouchEvent(e)); }
public bool OnTouch(View v, MotionEvent e) { _scaleDetector.OnTouchEvent(e); PointF curr = new PointF(e.GetX(), e.GetY()); switch (e.Action) { case MotionEventActions.Down: _last.Set(curr); _start.Set(_last); _mode = Dragging; break; case MotionEventActions.Move: if (_mode == Dragging) { float deltaX = curr.X - _last.X; float deltaY = curr.Y - _last.Y; float fixTransX = GetFixDragTrans(deltaX, _viewWidth, OrigWidth * _saveScale); float fixTransY = GetFixDragTrans(deltaY, _viewHeight, OrigHeight * _saveScale); Matrix.PostTranslate(fixTransX, fixTransY); FixTrans(); _last.Set(curr.X, curr.Y); } break; case MotionEventActions.Up: _mode = None; var xDiff = (int)Math.Abs(curr.X - _start.X); var yDiff = (int)Math.Abs(curr.Y - _start.Y); if (xDiff < Clicking && yDiff < Clicking) { PerformClick(); } break; case MotionEventActions.PointerUp: _mode = None; break; } ImageMatrix = _matrix; Invalidate(); return(true); // indicate event was handled }
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); }
//dit gebeurd op het moment dat het scherm aangeraakt wordt private void raakAan(object sender, TouchEventArgs e) { det.OnTouchEvent(e.Event); if (e.Event.Action == MotionEventActions.Pointer2Down && e.Event.Action == MotionEventActions.Pointer1Down) { pinching = true; } else if (!pinching) { det2.OnTouchEvent(e.Event); this.Invalidate(); } }
private void TouchImage ( object sender, View.TouchEventArgs arguments ) { bool isHandled = _scrollDetector.OnTouchEvent(arguments.Event); if (isHandled == false) { isHandled = _scaleDetector.OnTouchEvent(arguments.Event); } arguments.Handled = isHandled; }
/// <inheritdoc/> public bool OnTouch(View v, MotionEvent e) { _detector.OnTouchEvent(e); switch (e.Action) { case MotionEventActions.Down: _recognizer.OnTouchesBegan(e.GetX(), e.GetY()); break; case MotionEventActions.Up: _recognizer.OnTouchesEnded(e.GetX(), e.GetY()); break; } return(true); }
/// <summary> /// Raises the touch event. /// </summary> /// <param name="v">V.</param> /// <param name="e">E.</param> public bool OnTouch(global::Android.Views.View v, MotionEvent e) { _scaleGestureDetector.OnTouchEvent(e); if (!_scaled) { _gestureDetector.OnTouchEvent(e); if (e.Action == MotionEventActions.Up) { // calculate event time. long time = e.EventTime - e.DownTime; if (time > 120) { this.NotifyMovement(); OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information, string.Format("OnTouch:{0}ms", time)); this.Change(); } else // raise the map tap event here. { if (this.MapTapEvent != null) { // recreate the view. View2D view = this.CreateView(); // calculate the new center in pixels. double x = e.GetX(); double y = e.GetY(); // calculate the new center from the view. double[] sceneCenter = view.FromViewPort(this.Width, this.Height, x, y); // convert to the projected center. this.MapTapEvent(this.Map.Projection.ToGeoCoordinates(sceneCenter[0], sceneCenter[1])); } } } } _scaled = false; return(true); }
public override bool OnTouchEvent(MotionEvent e) { _scaleDetector.OnTouchEvent(e); switch (e.Action & MotionEventActions.Mask) { case MotionEventActions.Down: readyToDataUpdate = false; initialPanTimeStart = timeStart; initialPinchTimeStart = timeStart; initialPinchTimeEnd = timeEnd; lastTouchX = e.GetX(); relativePos = e.GetX() / Width; currentTouchX = 0; _scaleListener.Scale = 1; break; case MotionEventActions.Move: if (!_scaleDetector.IsInProgress) { currentTouchX = e.GetX(); double relativeX = (currentTouchX - lastTouchX) / Width; double frame = (timeEnd - timeStart).TotalSeconds; timeStart = initialPanTimeStart.AddSeconds(-frame * relativeX); timeEnd = timeStart.AddSeconds(frame); } else { double oldFrame = (initialPinchTimeEnd - initialPinchTimeStart).TotalSeconds; double newFrame = oldFrame / _scaleListener.Scale; timeStart = initialPinchTimeStart.AddSeconds((oldFrame - newFrame) * relativePos); timeEnd = timeStart.AddSeconds(newFrame); } Invalidate(); break; case MotionEventActions.Up: readyToDataUpdate = true; break; } return(true); }
public override bool DispatchTouchEvent(MotionEvent e) { if (e.PointerCount == 2) { return(_scaleDetector.OnTouchEvent(e)); } else if (_isScaleProcess) { //HACK: //Prevent letting any touch events from moving the scroll view until all fingers are up from zooming...This prevents the jumping and skipping around after user zooms. if (e.Action == MotionEventActions.Up) { _isScaleProcess = false; } return(false); } else { return(base.OnTouchEvent(e)); } }
public override bool OnTouchEvent(MotionEvent e) { base.OnTouchEvent(e); mScaleDetector.OnTouchEvent(e); if (mScaleDetector.IsInProgress) { return(true); } if (e.Action == MotionEventActions.Up) { if (Math.Abs(e.DownTime - e.EventTime) < 120) { Toast.MakeText(Context, "You've triggered ball with id = " + GetTappedObjectID((int)(e.GetX()), (int)(e.GetY())), ToastLength.Short).Show(); } } if (e.Action == MotionEventActions.Down) { prevx = e.GetX(); prevy = e.GetY(); } if (e.Action == MotionEventActions.Move) { float e_x = e.GetX(); float e_y = e.GetY(); scene.UpdateSceneOrientation((prevx - e_x), (prevy - e_y)); prevx = e_x; prevy = e_y; } if (e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move) { Render(); } return(true); }
/// <summary> /// Raises the touch event. /// </summary> /// <param name="v">V.</param> /// <param name="e">E.</param> public bool OnTouch(global::Android.Views.View v, MotionEvent e) { _scaleGestureDetector.OnTouchEvent(e); if (!_scaled) { _gestureDetector.OnTouchEvent(e); if (e.Action == MotionEventActions.Up) { // System.Threading.Thread thread = new System.Threading.Thread( // new System.Threading.ThreadStart(NotifyMovement)); // thread.Start(); // _highQuality = true; this.NotifyMovement(); OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapGLView", System.Diagnostics.TraceEventType.Information, "OnTouch"); this.Change(); } } _scaled = false; return(true); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.Inflate(Resource.Layout.fragment_scale, container, false); View rect = rootView.FindViewById(Resource.Id.rect); SpringSystem springSystem = SpringSystem.Create(); Spring spring = springSystem.CreateSpring(); spring.AddListener(new Performer(rect, View.ScaleXs)); spring.AddListener(new Performer(rect, View.ScaleYs)); spring.SetCurrentValue(1.0f); ScaleGestureDetector scaleGestureDetector = new ScaleGestureDetector(this.Activity, new OnScaleGestureListener(spring)); rootView.Touch += (sender, e) => { e.Handled = scaleGestureDetector.OnTouchEvent(e.Event); }; return(rootView); }
public bool OnTouch(View v, MotionEvent e) { try { mDoubleTapDetector.OnTouchEvent(e); mScaleDetector.OnTouchEvent(e); matrix.GetValues(m); float x = m[Matrix.MtransX]; float y = m[Matrix.MtransY]; PointF curr = new PointF(e.GetX(), e.GetY()); switch (e.Action) { //when one finger is touching //set the mode to DRAG case MotionEventActions.Down: RequestDisallowInterceptTouchEvent(true); last.Set(e.GetX(), e.GetY()); start.Set(last); mode = DRAG; break; //when two fingers are touching //set the mode to ZOOM case MotionEventActions.PointerDown: RequestDisallowInterceptTouchEvent(true); last.Set(e.GetX(), e.GetY()); start.Set(last); mode = ZOOM; break; //when a finger moves //If mode is applicable move image case MotionEventActions.Move: //if the mode is ZOOM or //if the mode is DRAG and already zoomed if (mode == ZOOM || (mode == DRAG && saveScale > minScale)) { float deltaX = curr.X - last.X; // x difference float deltaY = curr.Y - last.Y; // y difference float scaleWidth = (float)Math.Round(origWidth * saveScale); // width after applying current scale float scaleHeight = (float)Math.Round(origHeight * saveScale); // height after applying current scale //if scaleWidth is smaller than the views width //in other words if the image width fits in the view //limit left and right movement if (scaleWidth < width) { deltaX = 0; if (y + deltaY > 0) { deltaY = -y; } else if (y + deltaY < -bottom) { deltaY = -(y + bottom); } } //if scaleHeight is smaller than the views height //in other words if the image height fits in the view //limit up and down movement else if (scaleHeight < height) { deltaY = 0; if (x + deltaX > 0) { deltaX = -x; } else if (x + deltaX < -right) { deltaX = -(x + right); } } //if the image doesnt fit in the width or height //limit both up and down and left and right else { if (x + deltaX > 0) { deltaX = -x; } else if (x + deltaX < -right) { deltaX = -(x + right); } if (y + deltaY > 0) { deltaY = -y; } else if (y + deltaY < -bottom) { deltaY = -(y + bottom); } } //move the image with the matrix matrix.PostTranslate(deltaX, deltaY); //set the last touch location to the current last.Set(curr.X, curr.Y); } else { RequestDisallowInterceptTouchEvent(false); } break; //first finger is lifted case MotionEventActions.Up: mode = 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(); } RequestDisallowInterceptTouchEvent(false); break; // second finger is lifted case MotionEventActions.PointerUp: mode = NONE; RequestDisallowInterceptTouchEvent(false); break; } Control.ImageMatrix = (matrix); Control.Invalidate(); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(false); }
public override bool DispatchTouchEvent(MotionEvent e) { base.DispatchTouchEvent(e); MotionEventActions action = e.ActionMasked; switch (action) { case MotionEventActions.Down: int pointerIndex = e.ActionIndex; float x = e.GetX(pointerIndex); float y = e.GetY(pointerIndex); //Remember where we started (for dragging) mLastTouchX = x; mLastTouchY = y; //Save the ID of this pointer (for dragging) mActivePointerId = e.GetPointerId(0); break; case MotionEventActions.Move: //Find the index of the active pointer and fetch its position int activePointerIndex = e.GetPointerId(mActivePointerId); float x2 = e.GetX(activePointerIndex); float y2 = e.GetY(activePointerIndex); //Calculate the distance moved float dx = x2 - mLastTouchX; float dy = y2 - mLastTouchY; mPosX += dx; mPosY += dy; TranslateAnimation translateAnimation = new TranslateAnimation(mPosX, dx, mPosY, dy); translateAnimation.Duration = 0; translateAnimation.FillAfter = true; StartAnimation(translateAnimation); //Remember this touch position for the next move event mLastTouchX = x2; mLastTouchY = y2; break; case MotionEventActions.Up: mActivePointerId = INVALID_POINTER_ID; break; case MotionEventActions.Cancel: mActivePointerId = INVALID_POINTER_ID; break; case MotionEventActions.PointerUp: int pointerIndex2 = e.ActionIndex; int pointerId2 = e.GetPointerId(pointerIndex2); if (pointerId2 == mActivePointerId) { //This was our active pointer going up. Choose a new active pointer and adjust accordingly int newPointerIndex = pointerIndex2 == 0 ? 1 : 0; mLastTouchX = e.GetX(newPointerIndex); mLastTouchY = e.GetY(newPointerIndex); mActivePointerId = e.GetPointerId(newPointerIndex); } break; } return(mScaleDetector.OnTouchEvent(e)); }
/// <summary> /// Raises the touch event. /// </summary> /// <param name="v">V.</param> /// <param name="e">E.</param> public bool OnTouch(global::Android.Views.View v, MotionEvent e) { try { if (!_renderingSuspended && this.Map != null && this.Map.Projection != null && this.MapCenter != null) { _tagGestureDetector.OnTouchEvent(e); _scaleGestureDetector.OnTouchEvent(e); _rotateGestureDetector.OnTouchEvent(e); _moveGestureDetector.OnTouchEvent(e); if (_deltaX != 0 || _deltaY != 0 || // was there movement? _deltaScale != 1.0 || // was there scale? _deltaDegrees != 0) { // was there rotation? bool movement = false; if (this.MapAllowZoom && _deltaScale != 1.0) { // calculate the scale. double zoomFactor = this.Map.Projection.ToZoomFactor(this.MapZoom); zoomFactor = zoomFactor * _deltaScale; this.MapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor); movement = true; } if (this.MapAllowPan) { // stop the animation. this.StopCurrentAnimation(); // recreate the view. View2D view = this.CreateView(); // calculate the new center in pixels. double centerXPixels = this.SurfaceWidth / 2.0f - _deltaX; double centerYPixles = this.SurfaceHeight / 2.0f - _deltaY; // calculate the new center from the view. double[] sceneCenter = view.FromViewPort(this.SurfaceWidth, this.SurfaceHeight, centerXPixels, centerYPixles); // convert to the projected center. this.MapCenter = this.Map.Projection.ToGeoCoordinates(sceneCenter[0], sceneCenter[1]); movement = true; } // do the rotation stuff around the new center. if (this.MapAllowTilt && _deltaDegrees != 0) { // recreate the view. View2D view = this.CreateView(); View2D rotatedView = view.RotateAroundCenter((Degree)(-_deltaDegrees)); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; movement = true; } _deltaScale = 1; _deltaDegrees = 0; _deltaX = 0; _deltaY = 0; // notify touch. if (movement) { _mapView.RaiseMapTouched(); this.NotifyMovement(); } } } } catch (Exception ex) { OsmSharp.Logging.Log.TraceEvent("MapViewSurface.OnTouch", TraceEventType.Critical, string.Format("An unhandled exception occured:{0}", ex.ToString())); } return(true); }
public bool OnTouch(View v, MotionEvent e) { _scaleGestureDetector.OnTouchEvent(e); _gestureDetector.OnTouchEvent(e); return(false); }
private void OnControlTouch(object sender, TouchEventArgs e) { _scaleDetector.OnTouchEvent(e.Event); }
public override bool OnTouchEvent(MotionEvent ev) { try { OnTouchEventWorkingArray[0] = ev.GetX(); //Set the MotionEvent X OnTouchEventWorkingArray[1] = ev.GetY(); //And Y for transformation OnTouchEventWorkingArray = ScaledPointsToScreenPoints(OnTouchEventWorkingArray); //Will Transform the OnTouchEventWrkingArray In place. ev.SetLocation(OnTouchEventWorkingArray[0], OnTouchEventWorkingArray[1]); ScaleDetector.OnTouchEvent(ev); MotionEventActions action = ev.Action; switch (action & ev.ActionMasked) { case MotionEventActions.Down: { float x = ev.GetX(); float y = ev.GetY(); PositionOfLastTouchOnXAxis = x; PositionOfLastTouchOnYAxis = y; // Save the ID of this pointer ActivePointerId = ev.GetPointerId(0); break; } case MotionEventActions.Move: { // Find the index of the active pointer and fetch its position int pointerIndex = ev.FindPointerIndex(ActivePointerId); float x = ev.GetX(pointerIndex); float y = ev.GetY(pointerIndex); float dx = x - PositionOfLastTouchOnXAxis; float dy = y - PositionOfLastTouchOnYAxis; PositionOnXAxis += dx; PositionOnYAxis += dy; TranslateMatrix.PreTranslate(dx, dy); TranslateMatrix.Invert(TranslateMatrixInverse); PositionOfLastTouchOnXAxis = x; PositionOfLastTouchOnYAxis = y; Invalidate(); break; } case MotionEventActions.Up: { ActivePointerId = INVALID_POINTER_ID; break; } case MotionEventActions.Cancel: { ActivePointerId = INVALID_POINTER_ID; break; } case MotionEventActions.PointerUp: { // Extract the index of the pointer that left the touch sensor int pointerIndex = (ev.ActionIndex & PointerIndexMask) >> PointerIndexShift; int pointerId = ev.GetPointerId(pointerIndex); if (pointerId == ActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. int newPointerIndex = pointerIndex == 0 ? 1 : 0; PositionOfLastTouchOnXAxis = ev.GetX(newPointerIndex); PositionOfLastTouchOnYAxis = ev.GetY(newPointerIndex); ActivePointerId = ev.GetPointerId(newPointerIndex); } break; } } return(true); } catch (Exception) { return(true); } }