public NodeTouchEvent(MotionEvent motion, VelocityTracker velocity) { this.velocity = velocity; velocity.AddMovement (motion); point = new Point (motion.GetX (), motion.GetY ()); if (motion.Action == MotionEventActions.Move) { type = TouchType.Move; } else if (motion.Action == MotionEventActions.Down) { type = TouchType.Down; } else if (motion.Action == MotionEventActions.Up) { type = TouchType.Up; } }
bool OnDown (MotionEvent motionEvent) { if (_paused) { return false; } var rect = new Rect (); int childCount = _listView.ChildCount; var listViewCoords = new int[2]; _listView.GetLocationOnScreen (listViewCoords); int x = (int)motionEvent.RawX - listViewCoords [0]; int y = (int)motionEvent.RawY - listViewCoords [1]; View child; for (int i = 0; i < childCount; i++) { child = _listView.GetChildAt (i); child.GetHitRect (rect); if (rect.Contains (x, y)) { _downView = child; break; } } if (_downView != null) { mDownX = motionEvent.RawX; mDownY = motionEvent.RawY; _downPosition = _listView.GetPositionForView (_downView); if (_dismissCommand.CanExecute (_downPosition)) { _velocityTracker = VelocityTracker.Obtain (); _velocityTracker.AddMovement (motionEvent); } else { _downView = null; } } return false; }
bool CaptureMovementCheck(MotionEvent ev) { if (ev.Action == MotionEventActions.Down) { startX = (int)ev.GetX (); startY = (int)ev.GetY (); // Only work if the initial touch was in the start strip when the menu is closed // When the menu is opened, anywhere will do if (!opened && (startX > Context.ToPixels (30))) return false; velocityTracker = VelocityTracker.Obtain (); velocityTracker.AddMovement (ev); preTracking = true; stateBeforeTracking = opened; return false; } if (ev.Action == MotionEventActions.Up) preTracking = isTracking = false; if (!preTracking) return false; velocityTracker.AddMovement (ev); if (ev.Action == MotionEventActions.Move) { // Check we are going in the right direction, if not cancel the current gesture if (!MoveDirectionTest (ev)) { preTracking = false; return false; } // If the current gesture has not gone long enough don't intercept it just yet var distance = Math.Sqrt (Math.Pow (ev.GetX () - startX, 2) + Math.Pow (ev.GetY () - startY, 2)); if (distance < pagingTouchSlop) return false; } startX = (int)ev.GetX (); startY = (int)ev.GetY (); isTracking = true; return true; }
bool CaptureMovementCheck(MotionEvent ev) { if (ev.Action == MotionEventActions.Down) { oldY = startY = (int)ev.GetY (); if (!Opened) return false; velocityTracker = VelocityTracker.Obtain (); velocityTracker.AddMovement (ev); preTracking = true; stateBeforeTracking = state; return false; } if (ev.Action == MotionEventActions.Up) preTracking = isTracking = false; if (!preTracking) return false; velocityTracker.AddMovement (ev); if (ev.Action == MotionEventActions.Move) { // Check we are going in the right direction, if not cancel the current gesture if (!MoveDirectionTest (ev)) { preTracking = false; return false; } // If the current gesture has not gone long enough don't intercept it just yet var distance = Math.Abs (ev.GetY () - startY); if (distance < pagingTouchSlop) return false; } oldY = startY = (int)ev.GetY (); isTracking = true; return true; }
private bool handleDownEvent(View view, MotionEvent motionEvent) { if (!mSwipeEnabled) { return false; } View downView = findDownView(motionEvent); if (downView == null) { return false; } int downPosition = AdapterViewUtil.getPositionForView(mListViewWrapper, downView); mCanDismissCurrent = isDismissable(downPosition); /* Check if we are processing the item at this position */ if (mCurrentPosition == downPosition || downPosition >= mVirtualListCount) { return false; } if (view != null) { view.OnTouchEvent(motionEvent); } disableHorizontalScrollContainerIfNecessary(motionEvent, downView); mDownX = motionEvent.GetX(); mDownY = motionEvent.GetY(); mCurrentView = downView; mSwipingView = getSwipeView(downView); mCurrentPosition = downPosition; mVelocityTracker = VelocityTracker.Obtain(); mVelocityTracker.AddMovement(motionEvent); return true; }
public virtual bool OnTouchEvent(Android.Views.MotionEvent ev) { switch (ev.Action) { case MotionEventActions.Down: { mVelocityTracker = VelocityTracker.Obtain(); if (null != mVelocityTracker) { mVelocityTracker.AddMovement(ev); } else { Log.Info(LOG_TAG, "Velocity tracker is null"); } mLastTouchX = GetActiveX(ev); mLastTouchY = GetActiveY(ev); mIsDragging = false; break; } case MotionEventActions.Move: { float x = GetActiveX(ev); float y = GetActiveY(ev); float dx = x - mLastTouchX, dy = y - mLastTouchY; if (!mIsDragging) { // Use Pythagoras to see if drag length is larger than // touch slop mIsDragging = FloatMath.Sqrt((dx * dx) + (dy * dy)) >= mTouchSlop; } if (mIsDragging) { mListener.OnDrag(dx, dy); mLastTouchX = x; mLastTouchY = y; if (null != mVelocityTracker) { mVelocityTracker.AddMovement(ev); } } break; } case MotionEventActions.Cancel: { // Recycle Velocity Tracker if (null != mVelocityTracker) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; } case MotionEventActions.Up: { if (mIsDragging) { if (null != mVelocityTracker) { mLastTouchX = GetActiveX(ev); mLastTouchY = GetActiveY(ev); // Compute velocity within the last 1000ms mVelocityTracker.AddMovement(ev); mVelocityTracker.ComputeCurrentVelocity(1000); float vX = mVelocityTracker.GetXVelocity(0), vY = mVelocityTracker .GetYVelocity(0); // If the velocity is greater than minVelocity, call // listener if (Math.Max(Math.Abs(vX), Math.Abs(vY)) >= mMinimumVelocity) { mListener.OnFling(mLastTouchX, mLastTouchY, -vX, -vY); } } } // Recycle Velocity Tracker if (null != mVelocityTracker) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; } } return true; }