/*public void removeTouchDelegate(TouchDelegate touchDelegate) * { * if (touchDelegatesArray != null) * { * touchDelegatesArray.Remove(touchDelegate); * if (touchDelegatesArray.Count() == 0) * touchDelegatesArray = null; * } * }*/ public override bool OnTouchEvent(MotionEvent e) { bool _result = false; float x = e.GetX(); float y = e.GetY(); System.Diagnostics.Debug.Write("X: " + x + " " + "Y: " + y); System.Diagnostics.Debug.Write("TDARRAYCOUNT: " + touchDelegatesArray.Count); foreach (TouchDelegate touchDelegate in touchDelegatesArray) { e.SetLocation(x, y); // See if touch location is within the touchDelegate bounds _result = touchDelegate.OnTouchEvent(e) || _result; int hello = 1; System.Diagnostics.Debug.Write(hello); hello += 1; if (_result == true) { System.Diagnostics.Debug.Write("TRRRUUUEEE"); } else { System.Diagnostics.Debug.Write("FAAALLLSSSEEE"); } } return(_result); }
/// <summary> /// This will translate our touch event into its scaled counterpart for our zoomview, and then /// allow the base handling to occur. /// </summary> /// <param name="ev"> the unscaled touch Event</param> public override bool DispatchTouchEvent(MotionEvent ev) { DispatchTouchEventWorkingArray[0] = ev.GetX(); //Set the MotionEvent X DispatchTouchEventWorkingArray[1] = ev.GetY(); //And Y for transformation DispatchTouchEventWorkingArray = ScreenPointsToScaledPoints(DispatchTouchEventWorkingArray); // Provides the correct scaled version ev.SetLocation(DispatchTouchEventWorkingArray[0], DispatchTouchEventWorkingArray[1]); //Sets the location to be where it is properly scaled to return(base.DispatchTouchEvent(ev)); }
private MotionEvent flipXY(MotionEvent ev) { var width = Width; var height = Height; var x = (ev.GetY() / height) * width; var y = (ev.GetX() / width) * height; ev.SetLocation(x, y); return(ev); }
private MotionEvent SwapTouchEvent(MotionEvent ev) { float width = Width; float height = Height; float swappedX = (ev.GetY() / height) * width; float swappedY = (ev.GetX() / width) * height; ev.SetLocation(swappedX, swappedY); return(ev); }
public override bool DispatchTouchEvent(MotionEvent ev) { if (ev.Action == MotionEventActions.Down) { downY = ev.GetY(); } //if (IsScrollEnabled || ev.Action != MotionEventActions.Move) // return base.OnInterceptTouchEvent(ev); //return true; if (!IsScrollEnabled) { ev.SetLocation(ev.GetX(), downY); } return(base.DispatchTouchEvent(ev)); }
public override bool OnTouchEvent(MotionEvent e) { UpdateSourcePartial(); // The logic below is mostly copied from the parent class, since we // can't update private mBounds variable. // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob; // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98 Rect sourcePartial = mSourcePartial; View target = mTarget; int x = (int)e.GetX(); int y = (int)e.GetY(); bool sendToDelegate = false; bool hit = true; bool handled = false; switch (e.Action) { case MotionEventActions.Down: if (sourcePartial.Contains(x, y)) { mDelegateTargeted = true; sendToDelegate = true; } break; case MotionEventActions.Up: case MotionEventActions.Move: sendToDelegate = mDelegateTargeted; if (sendToDelegate) { if (!sourcePartial.Contains(x, y)) { hit = false; } } break; case MotionEventActions.Cancel: sendToDelegate = mDelegateTargeted; mDelegateTargeted = false; break; } if (sendToDelegate) { if (hit) { e.SetLocation(target.Width / 2, target.Height / 2); } else { e.SetLocation(-1, -1); } handled = target.DispatchTouchEvent(e); } return(handled); }
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); } }
public override bool OnTouchEvent(MotionEvent ev) { if (_mTouchInterceptionListener != null) { switch (ev.ActionMasked) { case MotionEventActions.Down: if (_mIntercepting) { _mTouchInterceptionListener.OnDownMotionEvent(ev); DuplicateTouchEventForChildren(ev); return(true); } break; case MotionEventActions.Move: // ACTION_MOVE will be passed suddenly, so initialize to avoid exception. if (_mInitialPoint == null) { _mInitialPoint = new PointF(ev.GetX(), ev.GetY()); } // diffX and diffY are the origin of the motion, and should be difference // from the position of the ACTION_DOWN event occurred. float diffX = ev.GetX() - _mInitialPoint.X; float diffY = ev.GetY() - _mInitialPoint.Y; _mIntercepting = _mTouchInterceptionListener.ShouldInterceptTouchEvent(ev, true, diffX, diffY); if (_mIntercepting) { // If this layout didn't receive ACTION_DOWN motion event, // we should generate ACTION_DOWN event with current position. if (!_mBeganFromDownMotionEvent) { _mBeganFromDownMotionEvent = true; MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent); event2.SetLocation(ev.GetX(), ev.GetY()); _mTouchInterceptionListener.OnDownMotionEvent(event2); _mInitialPoint = new PointF(ev.GetX(), ev.GetY()); diffX = diffY = 0; } // Children's touches should be canceled if (!_mChildrenEventsCanceled) { _mChildrenEventsCanceled = true; DuplicateTouchEventForChildren(ObtainMotionEvent(ev, MotionEventActions.Cancel)); } _mTouchInterceptionListener.OnMoveMotionEvent(ev, diffX, diffY); // If next mIntercepting become false, // then we should generate fake ACTION_DOWN event. // Therefore we set pending flag to true as if this is a down motion event. _mDownMotionEventPended = true; // Whether or not this event is consumed by the listener, // assume it consumed because we declared to intercept the event. return(true); } if (_mDownMotionEventPended) { _mDownMotionEventPended = false; MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent); event2.SetLocation(ev.GetX(), ev.GetY()); DuplicateTouchEventForChildren(ev, event2); } else { DuplicateTouchEventForChildren(ev); } // If next mIntercepting become true, // then we should generate fake ACTION_DOWN event. // Therefore we set beganFromDownMotionEvent flag to false // as if we haven't received a down motion event. _mBeganFromDownMotionEvent = false; // Reserve children's click cancellation here if they've already canceled _mChildrenEventsCanceled = false; break; case MotionEventActions.Up: case MotionEventActions.Cancel: _mBeganFromDownMotionEvent = false; if (_mIntercepting) { _mTouchInterceptionListener.OnUpOrCancelMotionEvent(ev); } // Children's touches should be canceled regardless of // whether or not this layout intercepted the consecutive motion events. if (!_mChildrenEventsCanceled) { _mChildrenEventsCanceled = true; if (_mDownMotionEventPended) { _mDownMotionEventPended = false; MotionEvent event2 = MotionEvent.ObtainNoHistory(_mPendingDownMotionEvent); event2.SetLocation(ev.GetX(), ev.GetY()); DuplicateTouchEventForChildren(ev, event2); } else { DuplicateTouchEventForChildren(ev); } } return(true); } } return(base.OnTouchEvent(ev)); }