private void OnTimerEvent(object sender, System.Timers.ElapsedEventArgs e) { var x = motion?.GetX(); var y = motion?.GetY(); if (IsViewInBounds((int)x, (int)y)) { timer.Stop(); Xamarin.Forms.Device.BeginInvokeOnMainThread(LongClickHandler); } }
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { bool result = false; float diffY = e2?.GetY() - e1?.GetY() ?? 0; float diffX = e2?.GetX() - e1?.GetX() ?? 0; if (Math.Abs(diffX) > Math.Abs(diffY)) { if (Math.Abs(diffX) > SwipeThreshold && Math.Abs(velocityX) > SwipeVelocityThreshold) { if (diffX > 0) { //Swiped Right OnSwipe?.Swipe(MainView, SwipeType.Right); } else { //Swiped Left OnSwipe?.Swipe(MainView, SwipeType.Left); } result = true; } } else if (Math.Abs(diffY) > SwipeThreshold && Math.Abs(velocityY) > SwipeVelocityThreshold) { if (diffY > 0) { //Swiped Down OnSwipe?.Swipe(MainView, SwipeType.Bottom); } else { //Swiped Up OnSwipe?.Swipe(MainView, SwipeType.Top); } result = true; } return(result); } catch (Exception e) { Methods.DisplayReportResultTrack(e); return(base.OnFling(e1, e2, velocityX, velocityY)); } }
/// <summary> /// /// </summary> /// <param name="e1"></param> /// <param name="e2"></param> /// <param name="velocityX"></param> /// <param name="velocityY"></param> /// <returns></returns> public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { var diffX = (e2?.GetX() ?? 0) - (e1?.GetX() ?? 0); var diffY = (e2?.GetY() ?? 0) - (e1?.GetY() ?? 0); var absDiffX = Math.Abs(diffX); var absDiffY = Math.Abs(diffY); if (absDiffX > absDiffY && absDiffX > SwipeThreshold && Math.Abs(velocityX) > SwipeVelocityThreshold) { _onSwiped?.Invoke(new SwipeArgs(diffX > 0 ? SwipeDirection.Right : SwipeDirection.Left, Math.Abs(velocityX / 1750))); return(true); } return(false); }
void SetStartingPosition(MotionEvent e1) { _lastX = e1.GetX(); _lastY = e1.GetY(); }
private float GetTotalY(MotionEvent ev) => (ev.GetY() - _startY.GetValueOrDefault()) / Context.Resources.DisplayMetrics.Density;
public override bool OnTouchEvent(MotionEvent e) { switch (e.ActionMasked) { case MotionEventActions.Down: { int id = e.GetPointerId(0); var start = new MotionEvent.PointerCoords(); e.GetPointerCoords(id, start); coords.Add(id, start); return(true); } case MotionEventActions.PointerDown: { int id = e.GetPointerId(e.ActionIndex); var start = new MotionEvent.PointerCoords(); e.GetPointerCoords(id, start); coords.Add(id, start); return(true); } case MotionEventActions.Move: { for (int index = 0; index < e.PointerCount; index++) { var id = e.GetPointerId(index); float x = e.GetX(index); float y = e.GetY(index); drawCanvas.DrawLine(coords[id].X, coords[id].Y, x, y, paint); coords[id].X = x; coords[id].Y = y; if (LineDrawn != null) { LineDrawn(this, EventArgs.Empty); } } Invalidate(); return(true); } case MotionEventActions.PointerUp: { int id = e.GetPointerId(e.ActionIndex); coords.Remove(id); return(true); } case MotionEventActions.Up: { int id = e.GetPointerId(0); coords.Remove(id); return(true); } default: return(false); } }
bool ProcessSwipingInteractions(MotionEvent e) { bool?handled = true; var point = new APointF(e.GetX() / _density, e.GetY() / _density); switch (e.Action) { case MotionEventActions.Down: _downX = e.RawX; _downY = e.RawY; handled = HandleTouchInteractions(GestureStatus.Started, point); if (handled == true) { Parent.RequestDisallowInterceptTouchEvent(true); } break; case MotionEventActions.Up: handled = HandleTouchInteractions(GestureStatus.Completed, point); if (Parent == null) { break; } Parent.RequestDisallowInterceptTouchEvent(false); break; case MotionEventActions.Move: handled = HandleTouchInteractions(GestureStatus.Running, point); if (handled == true || Parent == null) { break; } Parent.RequestDisallowInterceptTouchEvent(true); break; case MotionEventActions.Cancel: handled = HandleTouchInteractions(GestureStatus.Canceled, point); if (Parent == null) { break; } Parent.RequestDisallowInterceptTouchEvent(false); break; } if (handled.HasValue) { return(!handled.Value); } return(false); }
public bool dispatchTouchEvent(MotionEvent ev) { float x = ev.GetX(); float y = ev.GetY(); switch (ev.Action) { case MotionEventActions.Down: mLastX = x; mLastY = y; mDownTime = Java.Lang.JavaSystem.CurrentTimeMillis(); mTmpAngle = 0; if (isFling) { //RemoveCallbacks(mFlingRunnable); isFling = false; return true; } break; case MotionEventActions.Move: float start = getAngle(mLastX, mLastY); float end = getAngle(x, y); // Console.WriteLine("TAG", "start = " + start + " , end =" + end); if (getQuadrant(x, y) == 1 || getQuadrant(x, y) == 4) { mStartAngle += end - start; mTmpAngle += end - start; } else { mStartAngle += start - end; mTmpAngle += start - end; } RequestLayout(); mLastX = x; mLastY = y; break; case MotionEventActions.Up: float anglePerSecond2 = mTmpAngle * 1000 / (Java.Lang.JavaSystem.CurrentTimeMillis() - mDownTime); // Console.WriteLine("TAG anglePrMillionSecond + "+ mTmpAngle +" = +"+ // mTmpAngle); if (Math.Abs(anglePerSecond2) > mFlingableValue && !isFling) { AutoFlingEvent AutoFlingPost = new AutoFlingEvent(); AutoFlingPost.AutoFlingFinished += OnAutoFlingFinished; // new CircleMenuEventArgs() { velocity = anglePerSecond2 }; // AutoFlingHandler.Post(mFlingRunnable = (new AutoFlingEvent.AutoFlingDelegate(anglePerSecond2))); return true; } if (Math.Abs(mTmpAngle) > NOCLICK_VALUE) { return true; } break; } return true; // return base.DispatchTouchEvent(ev); }
//@SuppressLint("ClickableViewAccessibility") public bool OnTouch(View v, MotionEvent ev) { bool retVal; //if (!mMotionListenerEnabled || mMotions.Count // < 0 ) //{ // if (mOnTouchListener != null) // { // retVal = mOnTouchListener.OnTouch(v, ev); // } // else { // retVal = false; // } // return retVal; //} foreach (Actor.Motion motion in mMotions) { foreach (EventImitator imitator in motion.imitators) { imitator.Imitate(v, ev); } } if (mOnTouchListener != null) { retVal = mOnTouchListener.OnTouch(v, ev); } else { retVal = true; } if (mRequestDisallowTouchEvent) { // prevents parent from scrolling or otherwise stealing touch events v.Parent.RequestDisallowInterceptTouchEvent(true); } if (v.Clickable) { if (ev.EventTime - ev.DownTime > ViewConfiguration.LongPressTimeout) { v.Pressed = false; return(true); } if (ev.HistorySize > 0) { float deltaX = ev.GetHistoricalSize(ev.HistorySize - 1) - ev.GetX(); float deltaY = ev.GetHistoricalSize(ev.HistorySize - 1) - ev.GetY(); // if user has moved too far, it is no longer a click bool removeClickState = Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2) > Math.Pow(MAX_CLICK_DISTANCE, 2); v.Pressed = !removeClickState; return(removeClickState); } else { return(false); } } return(retVal); }
/// <summary> /// Do noting /// </summary> /// <param name="e"></param> /// <returns>Return false to indicate the the event has not been handled</returns> public bool OnDown(MotionEvent e) { Element.ProcessGesture( new GestureResult { ViewStack = null, GestureType = GestureType.Down, Direction = Directionality.None, Origin = new Point(ConvertPixelsToDp(e.GetX(0)), ConvertPixelsToDp(e.GetY(0))), }); return(true); }
public override bool OnTouch( View v, MotionEvent e ) { // check to see if we should monitor navBar reveal if ( e.Action == MotionEventActions.Down ) { NavBarRevealTracker.BeginTracking( ScrollView.ScrollY ); } if ( base.OnTouch( v, e ) == true ) { return true; } else { switch ( e.Action ) { case MotionEventActions.Move: { // if at any point during a move the task is no longer allowed to receive input, // STOP SCROLLING. It means the user began panning out the view if ( ParentTask.NavbarFragment.ShouldTaskAllowInput( ) == false ) { ScrollView.ScrollEnabled = false; } if ( Note != null ) { Note.TouchesMoved( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) ); } break; } case MotionEventActions.Up: { if ( Note != null ) { AnimateTutorialScreen( false ); string activeUrl = Note.TouchesEnded( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) ); // again, only process this if we didn't create a note. We don't want to treat a double tap // like a request to view a note if ( DidGestureCreateNote == false ) { if ( string.IsNullOrEmpty( activeUrl ) == false ) { ParentTask.OnClick( this, 0, activeUrl ); } } } ScrollView.ScrollEnabled = true; MovingUserNote = false; DidGestureCreateNote = false; break; } } } return false; }
public override bool OnDownGesture( MotionEvent e ) { // only processes TouchesBegan if we didn't create a note with this gesture. if ( DidGestureCreateNote == false ) { if ( Note != null ) { if ( Note.TouchesBegan( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) ) ) { ScrollView.ScrollEnabled = false; MovingUserNote = true; } } } return false; }
public override bool OnDoubleTap(MotionEvent e) { // a double tap CAN create a user note. If it did, // we want to know that so we suppress further input until we receive // TouchUp try { DidGestureCreateNote = Note.DidDoubleTap( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) ); } catch( Exception ex ) { Springboard.DisplayError( "Notes", ex.Message ); DidGestureCreateNote = false; } return true; }
public override bool OnTouchEvent(MotionEvent e) { this.SetValue(e.GetX(), e.GetY()); this.Invalidate(); return(true); }
/// <summary> /// Gets the screen position in pixels relative to the MapControl. /// </summary> /// <param name="motionEvent"></param> /// <param name="view"></param> /// <returns></returns> private static Point GetScreenPositionInPixels(MotionEvent motionEvent, View view) { return(new PointF( motionEvent.GetX(0) - view.Left, motionEvent.GetY(0) - view.Top).ToMapsui()); }
public override bool OnInterceptTouchEvent( CoordinatorLayout parent, Java.Lang.Object childObject, MotionEvent @event) { View child = Android.Runtime.Extensions.JavaCast <View>(childObject); if (!child.IsShown) { Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return false"); return(false); } int action = MotionEventCompat.GetActionMasked(@event); // Record the velocity if (action == (int)MotionEventActions.Down) { reset(); } if (mVelocityTracker == null || mVelocityTracker.Handle == IntPtr.Zero) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(@event); switch (action) { case (int)MotionEventActions.Up: case (int)MotionEventActions.Cancel: mTouchingScrollingChild = false; mActivePointerId = MotionEvent.InvalidPointerId; // Reset the ignore flag if (mIgnoreEvents) { mIgnoreEvents = false; return(false); } break; case (int)MotionEventActions.Down: int initialX = (int)@event.GetX(); mInitialY = (int)@event.GetY(); View nestedScroll; if (mNestedScrollingChildRef.TryGetTarget(out nestedScroll) && parent.IsPointInChildBounds(nestedScroll, initialX, mInitialY)) { mActivePointerId = @event.GetPointerId(@event.ActionIndex); //mTouchingScrollingChild = true; } mIgnoreEvents = mActivePointerId == MotionEvent.InvalidPointerId && !parent.IsPointInChildBounds(child, initialX, mInitialY); break; } if (!mIgnoreEvents && mViewDragHelper.ShouldInterceptTouchEvent(@event)) { Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return true"); return(true); } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. View scroll; var result = action == (int)MotionEventActions.Move && mNestedScrollingChildRef.TryGetTarget(out scroll) && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.IsPointInChildBounds(scroll, (int)@event.GetX(), (int)@event.GetY()) && Math.Abs(mInitialY - @event.GetY()) > mViewDragHelper.TouchSlop; Debug.WriteLineIf(DebugTrace, $"OnInterceptTouchEvent: return {result}"); return(result); }
public override bool OnFling ( MotionEvent startFlingMotion, MotionEvent stopFlingMotion, float motionHorizontalVelocity, float motionVerticalVelocity ) { float motionHorizontalDistance; int motionHorizontalDirection; GetDimentionDistanceAndDirection(startFlingMotion.GetX(), stopFlingMotion.GetX(), motionHorizontalVelocity, _minHorizontalDistance, _minHorizontalVelocity, out motionHorizontalDistance, out motionHorizontalDirection); float motionVerticalDistance; int motionVerticalDirection; GetDimentionDistanceAndDirection(startFlingMotion.GetY(), stopFlingMotion.GetY(), motionVerticalVelocity, _minVerticalDistance, _minVerticalVelocity, out motionVerticalDistance, out motionVerticalDirection); bool isMotionHandled = (motionHorizontalDistance + motionVerticalDistance > 0); if (isMotionHandled) { Size unscaledViewSize = _getViewSize(); float viewScaleFactor = _getScaleFactor(); PointF viewScrollPoint = _getScrollPoint(); float horizontalScrollDistance = (motionHorizontalDirection == 0) ? 0 : GetFeasibleDimentionDistance ( motionHorizontalDistance, motionHorizontalDirection, viewScaleFactor, viewScrollPoint.X, unscaledViewSize.Width ); float verticalScrollDistance = (motionVerticalDirection == 0) ? 0 : GetFeasibleDimentionDistance ( motionVerticalDistance, motionVerticalDirection, viewScaleFactor, viewScrollPoint.Y, unscaledViewSize.Height ); if (horizontalScrollDistance + verticalScrollDistance > 0) { _moveScrolledView ( -motionHorizontalDirection * horizontalScrollDistance, -motionVerticalDirection * verticalScrollDistance ); } } return(isMotionHandled); }
/// <summary> /// Pass the longpress to the <see cref="GesturesContentView"/> /// </summary> /// <param name="e"></param> public void OnLongPress(MotionEvent e) { Element.ProcessGesture(new GestureResult { ViewStack = null, GestureType = GestureType.LongPress, Direction = Directionality.None, Origin = new Point(ConvertPixelsToDp(e.GetX()), ConvertPixelsToDp(e.GetY())) }); }
public override bool OnTouchEvent(MotionEvent e) { if (!(e.Action != MotionEventActions.Down && mTouchView == null)) { switch (e.Action) { case MotionEventActions.Down: { int oldPos = mTouchPosition; mDownX = e.RawX; mDownY = e.RawY; mTouchState = TOUCH_STATE_NONE; mTouchPosition = PointToPosition((int)e.GetX(), (int)e.GetY()); if (mTouchPosition == oldPos && mTouchView != null && mTouchView.IsOpen()) { mTouchState = TOUCH_STATE_X; mTouchView.OnSwipe(e); return(true); } View view = GetChildAt(mTouchPosition - FirstVisiblePosition); if (mTouchView != null && mTouchView.IsOpen()) { mTouchView.SmoothCloseMenu(); mTouchView = null; MotionEvent cancelEvent = MotionEvent.Obtain(e); cancelEvent.Action = MotionEventActions.Cancel; OnTouchEvent(cancelEvent); return(true); } if (view is SwipeMenuLayout) { mTouchView = (SwipeMenuLayout)view; } if (mTouchView != null) { mTouchView.OnSwipe(e); } } break; case MotionEventActions.Move: { float dy = Math.Abs(e.RawY - mDownY); float dx = Math.Abs(e.RawX - mDownX); if (mTouchState == TOUCH_STATE_X) { if (mTouchView != null) { mTouchView.OnSwipe(e); } Selector.SetState(new int[] { 0 }); e.Action = MotionEventActions.Cancel; base.OnTouchEvent(e); return(true); } else if (mTouchState == TOUCH_STATE_NONE) { if (Math.Abs(dy) > MAX_Y) { mTouchState = TOUCH_STATE_Y; } else if (dx > MAX_X) { mTouchState = TOUCH_STATE_X; if (mOnSwipeListener != null) { mOnSwipeListener.OnSwipeStart(mTouchPosition); } } } } break; case MotionEventActions.Up: { if (mTouchState == TOUCH_STATE_X) { mTouchView.OnSwipe(e); if (!mTouchView.IsOpen()) { mTouchPosition = -1; mTouchView = null; } if (mOnSwipeListener != null) { mOnSwipeListener.OnSwipeEnd(mTouchPosition); } e.Action = MotionEventActions.Cancel; base.OnTouchEvent(e); return(true); } } break; } } //if (mTouchState != TOUCH_STATE_X) //{ // return (Parent as ViewWrapper).OnTouchEvent(e) || IgnoreTouchEvents || base.OnTouchEvent(e); //} //else //{ return(base.OnTouchEvent(e)); //} }
/// <summary> /// Ignored /// </summary> /// <param name="e1"></param> /// <param name="e2"></param> /// <param name="distanceX"></param> /// <param name="distanceY"></param> /// <returns></returns> public bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // we need to check if e2 has 2 finger touch and if yes, do callback. Then in the app we can disable scrolling and process these events.... if (e2.Action == MotionEventActions.Move) { if (e2.PointerCount == 2) { return(!Element.ProcessGesture( new GestureResult { ViewStack = null, GestureType = GestureType.Pinch, Direction = Directionality.None, Origin = new Point(ConvertPixelsToDp(e2.GetX(0)), ConvertPixelsToDp(e2.GetY(0))), Origin2 = new Point(ConvertPixelsToDp(e2.GetX(1)), ConvertPixelsToDp(e2.GetY(1))), })); } else if (e2.PointerCount == 1) { return(!Element.ProcessGesture( new GestureResult { ViewStack = null, GestureType = GestureType.Move, Direction = Directionality.None, Origin = new Point(ConvertPixelsToDp(e2.GetX(0)), ConvertPixelsToDp(e2.GetY(0))), })); } } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { var cropImage = (CropImage)_context; if (cropImage.Saving) { return(false); } switch (ev.Action) { case MotionEventActions.Down: foreach (var hv in _hightlightViews) { var edge = hv.GetHit(ev.GetX(), ev.GetY()); if (edge != HighlightView.HitPosition.None) { _motionEdge = edge; _mMotionHighlightView = hv; _mLastX = ev.GetX(); _mLastY = ev.GetY(); _mMotionHighlightView.Mode = (edge == HighlightView.HitPosition.Move) ? HighlightView.ModifyMode.Move : HighlightView.ModifyMode.Grow; break; } } break; case MotionEventActions.Up: if (_mMotionHighlightView != null) { CenterBasedOnHighlightView(_mMotionHighlightView); _mMotionHighlightView.Mode = HighlightView.ModifyMode.None; } _mMotionHighlightView = null; break; case MotionEventActions.Move: if (_mMotionHighlightView != null) { _mMotionHighlightView.HandleMotion(_motionEdge, ev.GetX() - _mLastX, ev.GetY() - _mLastY); _mLastX = ev.GetX(); _mLastY = ev.GetY(); if (true) { // This section of code is optional. It has some user // benefit in that moving the crop rectangle against // the edge of the screen causes scrolling but it means // that the crop rectangle is no longer fixed under // the user's finger. EnsureVisible(_mMotionHighlightView); } } break; } switch (ev.Action) { case MotionEventActions.Up: Center(true, true); break; case MotionEventActions.Move: // if we're not zoomed then there's no point in even allowing // the user to move the image around. This call to center puts // it back to the normalized location (with false meaning don't // animate). if (Math.Abs(GetScale() - 1F) < double.Epsilon) { Center(true, true); } break; } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { if (_mCallbacks != null) { switch (ev.ActionMasked) { case MotionEventActions.Down: break; case MotionEventActions.Up: case MotionEventActions.Cancel: _mIntercepted = false; _mDragging = false; _mCallbacks.OnUpOrCancelMotionEvent(_mScrollState); break; case MotionEventActions.Move: if (_mPrevMoveEvent == null) { _mPrevMoveEvent = ev; } float diffY = ev.GetY() - _mPrevMoveEvent.GetY(); _mPrevMoveEvent = MotionEvent.ObtainNoHistory(ev); if (GetCurrentScrollY() - diffY <= 0) { // Can't scroll anymore. if (_mIntercepted) { // Already dispatched ACTION_DOWN event to parents, so stop here. return(false); } // Apps can set the interception target other than the direct parent. ViewGroup parent; if (_mTouchInterceptionViewGroup == null) { parent = (ViewGroup)Parent; } else { parent = _mTouchInterceptionViewGroup; } // Get offset to parents. If the parent is not the direct parent, // we should aggregate offsets from all of the parents. float offsetX = 0; float offsetY = 0; for (View v = this; v != null && v != parent; v = (View)v.Parent) { offsetX += v.Left - v.ScrollX; offsetY += v.Top - v.ScrollY; } MotionEvent eventNoHistory = MotionEvent.ObtainNoHistory(ev); eventNoHistory.OffsetLocation(offsetX, offsetY); if (parent.OnInterceptTouchEvent(eventNoHistory)) { _mIntercepted = true; // If the parent wants to intercept ACTION_MOVE events, // we pass ACTION_DOWN event to the parent // as if these touch events just have began now. eventNoHistory.Action = MotionEventActions.Down; // Return this onTouchEvent() first and set ACTION_DOWN event for parent // to the queue, to keep events sequence. Post(() => parent.DispatchTouchEvent(eventNoHistory)); return(false); } // Even when this can't be scrolled anymore, // simply returning false here may cause subView's click, // so delegate it to base. return(base.OnTouchEvent(ev)); } break; } } return(base.OnTouchEvent(ev)); }
public override bool OnDoubleTap(MotionEvent e) { bool consumed = false; if (view.doubleTapListener != null) { consumed = view.doubleTapListener.OnDoubleTap(e); } if (view.state == TouchState.NONE) { float targetZoom = (view.normalizedScale == view.minScale) ? view.maxScale : view.minScale; DoubleTapZoom doubleTap = new DoubleTapZoom(view, targetZoom, e.GetX(), e.GetY(), false); view.CompatPostOnAnimation(doubleTap); consumed = true; } return(consumed); }
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { Log.Info(TAG, "OnFling: " + String.Format("Fling velocity: x {0}, y {1}, e1 {2},{3}, e2 {4},{5}", velocityX, velocityY, e1.GetX(), e1.GetY(), e2.GetX(), e2.GetY())); this.imageView.HandleFling(e1, e2, velocityX, velocityY); return(true); }
void OnTouch(object sender, Android.Views.View.TouchEventArgs args) { // Two object common to all the events Android.Views.View senderView = sender as Android.Views.View; MotionEvent motionEvent = args.Event; // Get the pointer index int pointerIndex = motionEvent.ActionIndex; // Get the id that identifies a finger over the course of its progress int id = motionEvent.GetPointerId(pointerIndex); senderView.GetLocationOnScreen(twoIntArray); Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); // Use ActionMasked here rather than Action to reduce the number of possibilities switch (args.Event.ActionMasked) { case MotionEventActions.Down: case MotionEventActions.PointerDown: FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true); idToEffectDictionary.Add(id, this); capture = pclTouchEffect.Capture; break; case MotionEventActions.Move: // Multiple Move events are bundled, so handle them in a loop for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++) { id = motionEvent.GetPointerId(pointerIndex); if (capture) { senderView.GetLocationOnScreen(twoIntArray); screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex), twoIntArray[1] + motionEvent.GetY(pointerIndex)); FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true); } } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: if (capture) { FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false); } else { CheckForBoundaryHop(id, screenPointerCoords); if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; case MotionEventActions.Cancel: if (capture) { FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false); } else { if (idToEffectDictionary[id] != null) { FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false); } } idToEffectDictionary.Remove(id); break; } }
public override bool OnTouchEvent(MotionEvent e) { if (gestureDetector.OnTouchEvent(e)) { previousMoveX = (int)e.GetX(); previousMoveY = (int)e.GetY(); return(true); } var touchCount = e.PointerCount; switch (e.Action) { case MotionEventActions.Down: case MotionEventActions.Pointer1Down: case MotionEventActions.Pointer2Down: { if (touchCount >= 2) { var distance = Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1)); previousDistance = distance; isScaling = true; } } break; case MotionEventActions.Move: { if (touchCount >= 2 && isScaling) { var distance = Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1)); var tmpScale = (distance - previousDistance) / DispDistance(); previousDistance = distance; tmpScale += 1; tmpScale = tmpScale * tmpScale; ZoomTo(tmpScale, width / 2, height / 2); Cutting(); } else if (!isScaling) { var distanceX = previousMoveX - (int)e.GetX(); var distanceY = previousMoveY - (int)e.GetY(); previousMoveX = (int)e.GetX(); previousMoveY = (int)e.GetY(); matrix.PostTranslate(-distanceX, -distanceY); Cutting(); } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: case MotionEventActions.Pointer2Up: { if (touchCount <= 1) { isScaling = false; } } break; } return(true); }
/** * 在触摸事件中, 处理上拉和下拉的逻辑 */ public override bool DispatchTouchEvent(MotionEvent ev) { if (contentView == null) { return(base.DispatchTouchEvent(ev)); } MotionEventActions action = ev.Action; switch (action) { case MotionEventActions.Down: // 判断是否可以上拉和下拉 canPullDown = isCanPullDown(); canPullUp = isCanPullUp(); // 记录按下时的Y值 startY = ev.GetY(); break; case MotionEventActions.Up: if (!isMoved) { break; // 如果没有移动布局, 则跳过执行 } // 开启动画 TranslateAnimation anim = new TranslateAnimation(0, 0, contentView.Top, originalRect.Top); anim.Duration = (ANIM_TIME); contentView.StartAnimation(anim); // 设置回到正常的布局位置 contentView.Layout(originalRect.Left, originalRect.Top, originalRect.Right, originalRect.Bottom); // 将标志位设回false canPullDown = false; canPullUp = false; isMoved = false; break; case MotionEventActions.Move: // 在移动的过程中, 既没有滚动到可以上拉的程度, 也没有滚动到可以下拉的程度 if (!canPullDown && !canPullUp) { startY = ev.GetY(); canPullDown = isCanPullDown(); canPullUp = isCanPullUp(); break; } // 计算手指移动的距离 float nowY = ev.GetY(); int deltaY = (int)(nowY - startY); // 是否应该移动布局 bool shouldMove = (canPullDown && deltaY > 0) || // 可以下拉, 并且手指向下移动 (canPullUp && deltaY < 0) || // 可以上拉, 并且手指向上移动 (canPullUp && canPullDown); // 既可以上拉也可以下拉(这种情况出现在ScrollView包裹的控件比ScrollView还小) if (shouldMove) { // 计算偏移量 int offset = (int)(deltaY * MOVE_FACTOR); // 随着手指的移动而移动布局 contentView.Layout(originalRect.Left, originalRect.Top + offset, originalRect.Right, originalRect.Bottom + offset); isMoved = true; // 记录移动了布局 } break; default: break; } return(base.DispatchTouchEvent(ev)); }
public bool dispatchTouchEvent(MotionEvent ev) { float x = ev.GetX(); float y = ev.GetY(); switch (ev.Action) { case MotionEventActions.Down: mLastX = x; mLastY = y; mDownTime = Java.Lang.JavaSystem.CurrentTimeMillis(); mTmpAngle = 0; if (isFling) { RemoveCallbacks(mFlingRunnable); isFling = false; return(true); } break; case MotionEventActions.Move: float start = getAngle(mLastX, mLastY); float end = getAngle(x, y); // Log.e("TAG", "start = " + start + " , end =" + end); if (getQuadrant(x, y) == 1 || getQuadrant(x, y) == 4) { mStartAngle += end - start; mTmpAngle += end - start; } else { mStartAngle += start - end; mTmpAngle += start - end; } RequestLayout(); mLastX = x; mLastY = y; break; case MotionEventActions.Up: float anglePerSecond = mTmpAngle * 1000 / (Java.Lang.JavaSystem.CurrentTimeMillis() - mDownTime); // Log.e("TAG", anglePrMillionSecond + " , mTmpAngel = " + // mTmpAngle); if (Math.Abs(anglePerSecond) > mFlingableValue && !isFling) { Post(mFlingRunnable = (AutoFlingRunnable(anglePerSecond))); return(true); } if (Math.Abs(mTmpAngle) > NOCLICK_VALUE) { return(true); } break; } return(base.DispatchTouchEvent(ev)); }
public override bool OnTouchEvent(MotionEvent e) { float x1, y1, x2, y2, x, y; switch (e.Action) { case MotionEventActions.Down: this.touchX = this.startTouchX = e.GetX(); this.touchY = this.startTouchY = e.GetY(); this.touchTime = DateTime.Now; return(true); case MotionEventActions.Move: switch (e.PointerCount) { case 1: x = e.GetX(); y = e.GetY(); this.rgView.ScrollCurrentWorksheet((this.touchX - x) / this.rgView.currentWorksheet.renderScaleFactor, (this.touchY - y) / this.rgView.currentWorksheet.renderScaleFactor); this.touchX = x; this.touchY = y; this.Invalidate(); break; case 2: x1 = e.GetX(0); x2 = e.GetX(1); y1 = e.GetY(0); y2 = e.GetY(0); x = x2 - x1; y = y2 - y1; float distance = (float)Math.Sqrt(x * x + y * y); float scaleChange = (distance - lastDistance) / (100 * this.rgView.baseScale); if (scaleChange != 0) { this.rgView.currentWorksheet.ScaleFactor += scaleChange; lastDistance = distance; } break; } return(true); case MotionEventActions.Up: float ms = ((float)(DateTime.Now - this.touchTime).TotalMilliseconds + 0.3f); this.remainX = (this.startTouchX - e.GetX()) / ms; this.remainY = (this.startTouchY - e.GetY()) / ms; if (this.remainX > 1 || this.remainY > 1 || this.remainX < -1 || this.remainY < -1) { this.remainX *= 15.0f * this.rgView.baseScale; this.remainY *= 15.0f * this.rgView.baseScale; timer.Change(20, 10); } return(true); case MotionEventActions.Pointer2Down: x1 = e.GetX(0); x2 = e.GetX(1); y1 = e.GetY(0); y2 = e.GetY(0); x = x2 - x1; y = y2 - y1; lastDistance = (float)Math.Sqrt(x * x + y * y); return(true); case MotionEventActions.Pointer2Up: return(true); case MotionEventActions.Scroll: break; } //this.scaleDetector.OnTouchEvent(e); return(base.OnTouchEvent(e)); }
public override bool OnInterceptTouchEvent(CoordinatorLayout parent, Java.Lang.Object cChild, MotionEvent ev) { var child = cChild.JavaCast <View>(); if (!child.IsShown) { _ignoreEvents = true; return(false); } var action = ev.ActionMasked; if (action == MotionEventActions.Down) { Reset(); } switch (action) { case MotionEventActions.Up: case MotionEventActions.Cancel: _touchingScrollingChild = false; _activePointerId = MotionEvent.InvalidPointerId; // Reset the ignore flag if (_ignoreEvents) { _ignoreEvents = false; return(false); } break; case MotionEventActions.Down: _scrollVelocityTracker.Clear(); int initialX = (int)ev.GetX(); _initialY = (int)ev.GetY(); if (_state == StateAnchorPoint) { _activePointerId = ev.GetPointerId(ev.ActionIndex); _touchingScrollingChild = true; } else { _nestedScrollingChildRef.TryGetTarget(out View scroll); if (scroll != null && parent.IsPointInChildBounds(scroll, initialX, _initialY)) { _activePointerId = ev.GetPointerId(ev.ActionIndex); _touchingScrollingChild = true; } } _ignoreEvents = _activePointerId == MotionEvent.InvalidPointerId && !parent.IsPointInChildBounds(child, initialX, _initialY); break; case MotionEventActions.Move: break; } if (!_ignoreEvents && _viewDragHelper.ShouldInterceptTouchEvent(ev)) { return(true); } // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because // it is not the top most view of its parent. This is not necessary when the touch event is // happening over the scrolling content as nested scrolling logic handles that case. _nestedScrollingChildRef.TryGetTarget(out View scroll1); return(action == MotionEventActions.Move && scroll1 != null && !_ignoreEvents && _state != StateDragging && !parent.IsPointInChildBounds(scroll1, (int)ev.GetX(), (int)ev.GetY()) && System.Math.Abs(_initialY - ev.GetY()) > _viewDragHelper.TouchSlop); }
public override bool OnTouchEvent(MotionEvent e) { if (m_GestureDetector.OnTouchEvent(e)) { m_PreviousMoveX = (int)e.GetX(); m_PreviousMoveY = (int)e.GetY(); return(true); } var touchCount = e.PointerCount; switch (e.Action) { case MotionEventActions.Down: case MotionEventActions.Pointer1Down: case MotionEventActions.Pointer2Down: { if (touchCount >= 2) { var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1)); m_PreviousDistance = distance; m_IsScaling = true; } } break; case MotionEventActions.Move: { if (touchCount >= 2 && m_IsScaling) { var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1)); var scale = (distance - m_PreviousDistance) / this.DispDistance(); m_PreviousDistance = distance; scale += 1; scale = scale * scale; this.ZoomTo(scale, m_Width / 2, m_Height / 2); this.Cutting(); } else if (!m_IsScaling) { var distanceX = m_PreviousMoveX - (int)e.GetX(); var distanceY = m_PreviousMoveY - (int)e.GetY(); m_PreviousMoveX = (int)e.GetX(); m_PreviousMoveY = (int)e.GetY(); m_Matrix.PostTranslate(-distanceX, -distanceY); this.Cutting(); } } break; case MotionEventActions.Up: case MotionEventActions.Pointer1Up: case MotionEventActions.Pointer2Up: { if (touchCount <= 1) { m_IsScaling = false; } } break; } return(true); }
public override bool OnDoubleTap(MotionEvent e) { m_ScaleImageView.MaxZoomTo((int)e.GetX(), (int)e.GetY()); m_ScaleImageView.Cutting(); return(true); }
public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { bool result = false; try { float diffY = e2.GetY() - e1.GetY(); float diffX = e2.GetX() - e1.GetX(); if (Math.Abs(diffX) > Math.Abs(diffY)) { if (Math.Abs(diffX) > SWIPE_THRESHOLD && Math.Abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { if (diffX > 0) { result = listener.OnSwipeRight(); } else { result = listener.OnSwipeLeft(); } } } else { if (Math.Abs(diffY) > SWIPE_THRESHOLD && Math.Abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) { if (diffY > 0) { result = listener.OnSwipeBottom(); } else { result = listener.OnSwipeTop(); } } } } catch (Exception exception) { // exception.PrintStackTrace(); } return result; }
public override bool OnTouchEvent(MotionEvent e) { //Android.Util.Log.Debug("OnTouchEvent", "OnTouchEvent " + e.ToString()); switch (e.Action & MotionEventActions.Mask) { case MotionEventActions.Down: { // Remember where the motion event started mLastMotionY = e.GetY(); mLastMotionX = e.GetX(); tab.GetContentOffset(out _began_x, out _began_y); break; } case MotionEventActions.Move: float y = e.GetY(); float x = e.GetX(); float deltaY = mLastMotionY - y; float deltaX = mLastMotionX - x; if (!mIsBeingDragged && (Math.Abs(deltaY) > mTouchSlop || Math.Abs(deltaX) > mTouchSlop)) { mIsBeingDragged = true; } if (mIsBeingDragged) { //Actually perform the scroll double tr_x = Xamarin.Forms.Platform.Android.ContextExtensions.FromPixels(this.Context, x - mFirstMotionX); double tr_y = Xamarin.Forms.Platform.Android.ContextExtensions.FromPixels(this.Context, y - mFirstMotionY); double newx = _began_x - tr_x; double newy = _began_y - tr_y; //Android.Util.Log.Debug("ActualScroll", "deltaX " + deltaX + " deltaY " + deltaY + " newx " + newx + " newy " + newy); //Android.Util.Log.Debug("ActualScroll", "began_x " + _began_x + " tr_x " + tr_x +" began_y " + _began_y + " tr_y " + tr_y); //Android.Util.Log.Debug("ActualScroll", "mLastMotionX " + mLastMotionX + " x " + x + " mLastMotionY " + mLastMotionY + " y " + y); mLastMotionY = y; mLastMotionX = x; tab.SetContentOffset(newx, newy); } break; case MotionEventActions.Up: if (mIsBeingDragged) { mIsBeingDragged = false; mLastMotionY = 0; mLastMotionX = 0; } else { //If they are releasing the touch, they didn't drag, and none of our children caught it, call it a tap event. double touch_x = Xamarin.Forms.Platform.Android.ContextExtensions.FromPixels(this.Context, e.GetX()); double touch_y = Xamarin.Forms.Platform.Android.ContextExtensions.FromPixels(this.Context, e.GetY()); tab.SingleTap(touch_x, touch_y); // TODO shouldn't we use the return value of this call? } break; case MotionEventActions.Cancel: if (mIsBeingDragged) { mIsBeingDragged = false; mLastMotionY = 0; mLastMotionX = 0; } break; } return(true); }