private void CompleteScroll() { bool needPopulate = mScrolling; if (needPopulate) { // Done with scroll, no longer want to cache view drawing. ScrollingCacheEnabled = false; mScroller.AbortAnimation(); int oldX = ScrollX; int oldY = ScrollY; int x = mScroller.CurrX; int y = mScroller.CurrY; if (oldX != x || oldY != y) { ScrollTo(x, y); } if (IsMenuOpen) { if (mOpenedListener != null) { mOpenedListener.OnOpened(); } } else { if (mClosedListener != null) { mClosedListener.OnClosed(); } } } mScrolling = false; }
private void InterruptSnapback() { // reset our current scroll position scroller.ComputeScrollOffset(); current_scroll_y = scroller.CurrY; scroller.AbortAnimation(); }
private void CompleteScroll() { var needPopulate = _scrolling; if (needPopulate) { ScrollingCacheEnabled = false; _scroller.AbortAnimation(); var oldX = ScrollX; var oldY = ScrollY; var x = _scroller.CurrX; var y = _scroller.CurrY; if (oldX != x || oldY != y) ScrollTo(x, y); if (IsMenuOpen) { if (null != Opened) Opened(this, EventArgs.Empty); } else { if (null != Closed) Closed(this, EventArgs.Empty); } } _scrolling = false; }
private void HandleTouchEvent(MotionEvent @event) { velocityTracker.AddMovement(@event); gestureHelper.OnTouchEvent(@event); if (@event.Action == MotionEventActions.Down) { touching = true; ResetTouchStart(@event.GetX(), @event.GetY()); if (!layerScroller.IsFinished) { layerScroller.AbortAnimation(); } } else if (@event.Action == MotionEventActions.Up || @event.Action == MotionEventActions.Cancel) { touching = false; } }
public override bool OnTouchEvent(MotionEvent e) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(e); MotionEventActions action = e.Action; float x = e.GetX(); switch (action) { case MotionEventActions.Down: if (!mScroller.IsFinished) { mScroller.AbortAnimation(); } mLastMotionX = x; if (mScroller.IsFinished) { mTouchState = TOUCH_STATE_REST; } else { mTouchState = TOUCH_STATE_HORIZONTAL_SCROLLING; } break; case MotionEventActions.Move: int xDiff = (int)Math.Abs(x - mLastMotionX); bool xMoved = xDiff > mTouchSlop; if (xMoved) { mTouchState = TOUCH_STATE_HORIZONTAL_SCROLLING; } if (mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) { int deltaX = (int)(mLastMotionX - x); mLastMotionX = x; int scrollX = this.ScrollX; if (deltaX < 0) { if (scrollX > 0) { ScrollBy(Math.Max(-scrollX, deltaX), 0); } } else if (deltaX > 0) { if (this.ChildCount >= 1) { int avalableToScroll = this.GetChildAt(this.ChildCount - 1).Right - scrollX - Width; if (avalableToScroll > 0) { ScrollBy(Math.Min(avalableToScroll, deltaX), 0); } } } } break; case MotionEventActions.Up: if (mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) { VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.ComputeCurrentVelocity(VELOCITY_UNIT_PIXELS_PER_SECOND, mMaximumVelocity); int velocityX = (int)velocityTracker.XVelocity; if (velocityX > mDensityAdjustedSnapVelocity && mCurrentScreen > 0) { SnapToScreen(mCurrentScreen - 1); } else if (velocityX < -mDensityAdjustedSnapVelocity && mCurrentScreen < this.ChildCount - 1) { SnapToScreen(mCurrentScreen + 1); } else { SnapToDestination(); } if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } mTouchState = TOUCH_STATE_REST; } break; case MotionEventActions.Cancel: mTouchState = TOUCH_STATE_REST; break; default: break; } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { if (mIsVerbose) { Log.Verbose(TAG, "onTouchEvent: " + ((int)ev.Action & MotionEventCompat.ActionMask)); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(ev); var action = ev.Action; switch ((int)action & MotionEventCompat.ActionMask) { case (int)MotionEventActions.Down: // If being flinged and user touches, stop the fling. isFinished // will be false if being flinged. if (!mScroller.IsFinished) { mScroller.AbortAnimation(); } // Remember where the motion event started mDownMotionX = ev.GetX(); mDownMotionY = ev.GetY(); mDownScrollX = ScrollX; mActivePointerId = MotionEventCompat.GetPointerId(ev, 0); break; case (int)MotionEventActions.Move: if (mIsVerbose) { Log.Verbose(TAG, "mTouchState=" + mTouchState); } if (mTouchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event int pointerIndex = MotionEventCompat.FindPointerIndex(ev, mActivePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); View lastChild = GetChildAt(ChildCount - 1); int maxScrollX = lastChild.Right - Width; ScrollTo(Math.Max(0, Math.Min(maxScrollX, (int)(mDownScrollX + mDownMotionX - x ))), 0); if (mOnScrollListener != null) { mOnScrollListener.OnScroll(GetCurrentScreenFraction()); } } else if (mTouchState == TOUCH_STATE_REST) { if (mLocked) { // we're locked on the current screen, don't allow moving break; } /* * Locally do absolute value. mLastMotionX is set to the y value * of the down event. */ int pointerIndex = MotionEventCompat.FindPointerIndex(ev, mActivePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); float y = MotionEventCompat.GetY(ev, pointerIndex); int xDiff = (int)Math.Abs(x - mDownMotionX); int yDiff = (int)Math.Abs(y - mDownMotionY); bool xPaged = xDiff > mPagingTouchSlop; bool xMoved = xDiff > mTouchSlop; bool yMoved = yDiff > mTouchSlop; if (xMoved || yMoved) { if (xPaged) { // Scroll if the user moved far enough along the X axis mTouchState = TOUCH_STATE_SCROLLING; } // Either way, cancel any pending longpress if (mAllowLongPress) { mAllowLongPress = false; // Try canceling the long press. It could also have been scheduled // by a distant descendant, so use the mAllowLongPress flag to block // everything View currentScreen = GetScreenAt(mCurrentScreen); if (currentScreen != null) { currentScreen.CancelLongPress(); } } } } break; case (int)MotionEventActions.Up: if (mTouchState == TOUCH_STATE_SCROLLING) { int activePointerId = mActivePointerId; int pointerIndex = MotionEventCompat.FindPointerIndex(ev, activePointerId); float x = MotionEventCompat.GetX(ev, pointerIndex); VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.ComputeCurrentVelocity(1000, mMaximumVelocity); //TODO(minsdk8): int velocityX = (int) MotionEventUtils.getXVelocity(velocityTracker, activePointerId); int velocityX = (int)velocityTracker.XVelocity; bool isFling = Math.Abs(mDownMotionX - x) > MIN_LENGTH_FOR_FLING; float scrolledPos = GetCurrentScreenFraction(); int whichScreen = Math.Round(scrolledPos); if (isFling && mIsVerbose) { Log.Verbose(TAG, "isFling, whichScreen=" + whichScreen + " scrolledPos=" + scrolledPos + " mCurrentScreen=" + mCurrentScreen + " velocityX=" + velocityX); } if (isFling && velocityX > SNAP_VELOCITY && mCurrentScreen > 0) { // Fling hard enough to move left // Don't fling across more than one screen at a time. int bound = scrolledPos <= whichScreen ? mCurrentScreen - 1 : mCurrentScreen; SnapToScreen(Math.Min(whichScreen, bound)); } else if (isFling && velocityX < -SNAP_VELOCITY && mCurrentScreen < ChildCount - 1) { // Fling hard enough to move right // Don't fling across more than one screen at a time. int bound = scrolledPos >= whichScreen ? mCurrentScreen + 1 : mCurrentScreen; SnapToScreen(Math.Max(whichScreen, bound)); } else { SnapToDestination(); } } else { PerformClick(); } mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; // Can't do this -> // Intentially fall through to cancel mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; case (int)MotionEventActions.Cancel: mTouchState = TOUCH_STATE_REST; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; case (int)MotionEventCompat.ActionPointerUp: OnSecondaryPointerUp(ev); break; } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { if (_velocityTracker == null) { _velocityTracker = VelocityTracker.Obtain(); } _velocityTracker.AddMovement(ev); var action = ev.Action; var x = ev.GetX(); switch (action) { case MotionEventActions.Down: /* * If being flinged and user touches, stop the fling. isFinished will be false if being flinged. */ if (!_scroller.IsFinished) { _scroller.AbortAnimation(); } // Remember where the motion event started _lastMotionX = x; _touchState = _scroller.IsFinished ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING; break; case MotionEventActions.Move: var xDiff = (int)Math.Abs(x - _lastMotionX); var xMoved = xDiff > _touchSlop; if (xMoved) { // Scroll if the user moved far enough along the X axis _touchState = TOUCH_STATE_SCROLLING; } if (_touchState == TOUCH_STATE_SCROLLING) { // Scroll to follow the motion event var deltaX = (int)(_lastMotionX - x); _lastMotionX = x; var scrollX = ScrollX; if (deltaX < 0) { if (scrollX > 0) { ScrollBy(Math.Max(-scrollX, deltaX), 0); } } else if (deltaX > 0) { var availableToScroll = GetChildAt(ChildCount - 1).Right - scrollX - Width; if (availableToScroll > 0) { ScrollBy(Math.Min(availableToScroll, deltaX), 0); } } } break; case MotionEventActions.Up: if (_touchState == TOUCH_STATE_SCROLLING) { var velocityTracker = _velocityTracker; velocityTracker.ComputeCurrentVelocity(1000, _maximumVelocity); var velocityX = (int)velocityTracker.XVelocity; if (velocityX > SNAP_VELOCITY && _currentScreen > 0) { // Fling hard enough to move left SnapToScreen(_currentScreen - 1); } else if (velocityX < -SNAP_VELOCITY && _currentScreen < ChildCount - 1) { // Fling hard enough to move right SnapToScreen(_currentScreen + 1); } else { SnapToDestination(); } if (_velocityTracker != null) { _velocityTracker.Recycle(); _velocityTracker = null; } } _touchState = TOUCH_STATE_REST; break; case MotionEventActions.Cancel: _touchState = TOUCH_STATE_REST; break; } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { if (_mVelocityTracker == null) { _mVelocityTracker = VelocityTracker.Obtain(); } _mVelocityTracker.AddMovement(ev); MotionEventActions action = ev.Action; float x = ev.GetX(); switch (action) { case MotionEventActions.Down: /* * If being flinged and user touches, stop the fling. isFinished will be false if * being flinged. */ if (!_mScroller.IsFinished) { _mScroller.AbortAnimation(); } // Remember where the motion event started _mLastMotionX = x; _mTouchState = _mScroller.IsFinished ? TOUCH_STATE_REST : TOUCH_STATE_HORIZONTAL_SCROLLING; break; case MotionEventActions.Move: var xDiff = (int)Math.Abs(x - _mLastMotionX); bool xMoved = xDiff > _mTouchSlop; if (xMoved) { // Scroll if the user moved far enough along the X axis _mTouchState = TOUCH_STATE_HORIZONTAL_SCROLLING; } if (_mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) { // Scroll to follow the motion event var deltaX = (int)(_mLastMotionX - x); _mLastMotionX = x; int scrollX = ScrollX; if (deltaX < 0) { if (scrollX > 0) { ScrollBy(Math.Max(-scrollX, deltaX), 0); } } else if (deltaX > 0) { int availableToScroll = GetChildAt(ChildCount - 1).Right - scrollX - Width; if (availableToScroll > 0) { ScrollBy(Math.Min(availableToScroll, deltaX), 0); } } } break; case MotionEventActions.Up: if (_mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) { VelocityTracker velocityTracker = _mVelocityTracker; velocityTracker.ComputeCurrentVelocity(VELOCITY_UNIT_PIXELS_PER_SECOND, _mMaximumVelocity); var velocityX = (int)velocityTracker.XVelocity; if (velocityX > mDensityAdjustedSnapVelocity && _mCurrentScreen > 0) { // Fling hard enough to move left SnapToScreen(_mCurrentScreen - 1); } else if (velocityX < -mDensityAdjustedSnapVelocity && _mCurrentScreen < ChildCount - 1) { // Fling hard enough to move right SnapToScreen(_mCurrentScreen + 1); } else { SnapToDestination(); } if (_mVelocityTracker != null) { _mVelocityTracker.Recycle(); _mVelocityTracker = null; } } _mTouchState = TOUCH_STATE_REST; break; case MotionEventActions.Cancel: _mTouchState = TOUCH_STATE_REST; break; } return(true); }
public override bool OnTouchEvent(MotionEvent ev) { if (ev.Action == MotionEventActions.Down && ev.EdgeFlags != 0) { // Don't handle edge touches immediately -- they may actually belong to one of our // descendants. return(false); } if (!CanScroll) { return(false); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(ev); MotionEventActions action = ev.Action; float y = ev.GetY(); float x = ev.GetX(); switch (action) { case MotionEventActions.Down: /* * If being flinged and user touches, stop the fling. isFinished * will be false if being flinged. */ if (!mScroller.IsFinished) { mScroller.AbortAnimation(); } // Remember where the motion event started mLastMotionY = y; mLastMotionX = x; break; case MotionEventActions.Move: // Scroll to follow the motion event int deltaX = (int)(mLastMotionX - x); int deltaY = (int)(mLastMotionY - y); mLastMotionX = x; mLastMotionY = y; if (deltaX < 0) { if (ScrollX < 0) { deltaX = 0; } } else if (deltaX > 0) { int rightEdge = Width - PaddingRight; int availableToScroll = GetChildAt(0).Right - ScrollX - rightEdge; if (availableToScroll > 0) { deltaX = System.Math.Min(availableToScroll, deltaX); } else { deltaX = 0; } } if (deltaY < 0) { if (ScrollY < 0) { deltaY = 0; } } else if (deltaY > 0) { int bottomEdge = Height - PaddingBottom; int availableToScroll = GetChildAt(0).Bottom - ScrollY - bottomEdge; if (availableToScroll > 0) { deltaY = System.Math.Min(availableToScroll, deltaY); } else { deltaY = 0; } } if (deltaY != 0 || deltaX != 0) { ScrollBy(deltaX, deltaY); } break; case MotionEventActions.Up: VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.ComputeCurrentVelocity(1000, mMaximumVelocity); int initialXVelocity = (int)velocityTracker.XVelocity; int initialYVelocity = (int)velocityTracker.YVelocity; if ((System.Math.Abs(initialXVelocity) + System.Math.Abs(initialYVelocity) > mMinimumVelocity) && ChildCount > 0) { Fling(-initialXVelocity, -initialYVelocity); } if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } break; } return(true); }