public bool onTouch(MotionEvent ev) { if (velocityTracker == null) { velocityTracker = VelocityTracker.Obtain(); } velocityTracker.AddMovement(ev); if (ev.Action == MotionEventActions.Down) { if (!scroller.IsFinished) { scroller.AbortAnimation(); } isSmoothScrolling = false; } else if (ev.Action == MotionEventActions.Move) { velocityTracker.AddMovement(ev); velocityTracker.ComputeCurrentVelocity(500); } else if (ev.Action == MotionEventActions.Up) { handleHorizontalScrolling(); velocityTracker.Recycle(); velocityTracker.Clear(); velocityTracker = null; isScrolling = false; } return(false); }
public override bool OnTouchEvent(MotionEvent e) { if (e.Action == MotionEventActions.Down) { down = new Point(e.RawX, e.RawY); } else if (e.Action == MotionEventActions.Up) { up = new Point(e.RawX, e.RawY); } if (node.TouchEvents) { if (e.Action == MotionEventActions.Move || e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Up) { if (e.Action == MotionEventActions.Down || velocity == null) { velocity = VelocityTracker.Obtain(); } var result = node.Touch(new NodeTouchEvent(e, velocity)); if (e.Action == MotionEventActions.Up) { velocity = null; } return(result); } } return(base.OnTouchEvent(e)); }
void Awake() { instance = this; m_GestureLib = new GestureLibrary(Application.dataPath + "/BHZ.GLIB"); m_VTLeft = m_TCLeft.GetComponent <VelocityTracker>(); m_VTRight = m_TCRight.GetComponent <VelocityTracker>(); }
bool OnCancel(MotionEvent motionEvent) { if (_velocityTracker == null) { return(false); } if (_downView != null && isSwiping) { AnimateDismissCancel(_downView); } _velocityTracker.Recycle(); _velocityTracker = null; mDownX = 0; mDownY = 0; _downView = null; _downPosition = AdapterView.InvalidPosition; isSwiping = false; return(false); }
private void InitVelocityTrackerIfNotExists() { if (this.velocityTracker == null) { this.velocityTracker = VelocityTracker.Obtain(); } }
private void Awake() { //devices = new List<InputDevice>(); //InputDevices.GetDevices(devices); //foreach (var device in devices) //{ // Debug.Log($"{device.name} {device.subsystem} {device.characteristics}"); //} if (Headset && !HeadsetVelocityTracker) { HeadsetVelocityTracker = Headset.AddComponent <VelocityTracker>(); } if (LeftController && !LeftControllerVelocityTracker) { LeftControllerVelocityTracker = LeftController.AddComponent <VelocityTracker>(); } if (RightController && !RightControllerVelocityTracker) { RightControllerVelocityTracker = RightController.AddComponent <VelocityTracker>(); } }
private void Up(MotionEvent motionEvent) { if (_velocityTracker == null) { return; } _pauseTimer(false); var deltaX = motionEvent.RawX - _downX; _velocityTracker.AddMovement(motionEvent); _velocityTracker.ComputeCurrentVelocity(1000); var velocityX = _velocityTracker.XVelocity; var absVelocityX = Math.Abs(velocityX); var absVelocityY = Math.Abs(_velocityTracker.YVelocity); var dismiss = false; var dismissRight = false; if (Math.Abs(deltaX) > _viewWidth / 2 && _swiping) { dismiss = true; dismissRight = deltaX > 0; } else if (_minFlingVelocity <= absVelocityX && absVelocityX <= _maxFlingVelocity && absVelocityY < absVelocityX && absVelocityY < absVelocityX && _swiping) { // dismiss only if flinging in the same direction as dragging dismiss = (velocityX < 0) == (deltaX < 0); dismissRight = _velocityTracker.XVelocity > 0; } if (dismiss) { // dismiss _view.Animate() .TranslationX(dismissRight ? _viewWidth : -_viewWidth) .Alpha(0) .SetDuration(_animationTime) .SetListener(this); } else if (_swiping) { // cancel _view.Animate() .TranslationX(0) .Alpha(1) .SetDuration(_animationTime) .SetListener(null); } if (_velocityTracker != null) { _velocityTracker.Recycle(); _velocityTracker = null; } _translationX = 0; _downX = 0; _downY = 0; _swiping = false; }
protected override void Dispose(bool disposing) { if (disposing) { if (null != _gestureDetector) { _gestureDetector.Dispose(); _gestureDetector = null; } if (null != Scroller) { Scroller.Dispose(); Scroller = null; } if (null != _dataSetObserver) { _dataSetObserver.Dispose(); _dataSetObserver = null; } if (null != _velocityTracker) { _velocityTracker.Recycle(); _velocityTracker = null; } } base.Dispose(disposing); }
void Start() { // get max value for spread cursor roundsToMaxSpread = spreadCurve.keys[spreadCurve.length - 1].time; speedToMaxSpread = movementSpreadCurve.keys[movementSpreadCurve.length - 1].time; tracker = transform.root.GetComponent <VelocityTracker>(); }
private void RecycleVelocityTracker() { if (this.velocityTracker != null) { this.velocityTracker.Recycle(); this.velocityTracker = null; } }
/// <summary> /// Sets the <see cref="InteractorFacade.VelocityTracker"/> to the value of <see cref="TargetVelocityTracker"/>. /// </summary> /// <param name="cacheCurrentVelocityTracker">Caches the current <see cref="InteractorFacade.VelocityTracker"/> value to be restored later.</param> public virtual void SetTargetVelocityTracker(bool cacheCurrentVelocityTracker) { if (cacheCurrentVelocityTracker) { cachedVelocityTracker = TargetFacade.VelocityTracker; } TargetFacade.VelocityTracker = TargetVelocityTracker; }
void Start() { mainCamera = Camera.main; targetPostion = cameraPoint.position; positionDirection = transform.InverseTransformDirection(cameraPoint.position - transform.position); lookDirection = transform.InverseTransformDirection(cameraPoint.forward); range = positionDirection.magnitude; velocityTracker = transform.root.GetComponent <VelocityTracker>(); }
private void reset() { mActivePointerId = ViewDragHelper.InvalidPointer; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } }
bool OnUp(MotionEvent motionEvent) { if (_velocityTracker == null) { return(false); } float deltaX = motionEvent.RawX - mDownX; _velocityTracker.AddMovement(motionEvent); _velocityTracker.ComputeCurrentVelocity(1000); float velocityX = _velocityTracker.XVelocity; float absVelocityX = Math.Abs(velocityX); float absVelocityY = Math.Abs(_velocityTracker.YVelocity); bool dismiss = false; bool dismissRight = false; if (Math.Abs(deltaX) > _viewWidth / 2 && isSwiping) { dismiss = true; dismissRight = deltaX > 0; } else if (FlingingSameDirectionAsDragging(absVelocityX, absVelocityY)) { dismiss = (velocityX < 0) == (deltaX < 0); dismissRight = _velocityTracker.XVelocity > 0; } if (dismiss && _downPosition != AdapterView.InvalidPosition) { View downView = _downView; int downPosition = _downPosition; ++mDismissAnimationRefCount; AnimateDismissStart(_downView, dismissRight, new SwipeAnimatorListenerAdapter(_ => AnimateDismissEnd(downView, downPosition))); } else { AnimateDismissCancel(_downView); } _velocityTracker.Recycle(); _velocityTracker = null; mDownX = 0; mDownY = 0; _downView = null; InvalidateDownPosition(); isSwiping = false; 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); }
public override bool OnTouchEvent(MotionEvent ev) { switch (ev.Action) { case MotionEventActions.Cancel: #region Cancel if (null != mVelocityTracker) { mVelocityTracker.Recycle(); mVelocityTracker = null; } #endregion break; case MotionEventActions.Down: #region Down mVelocityTracker = VelocityTracker.Obtain(); mVelocityTracker.AddMovement(ev); mLastTouchX = GetActiveX(ev); mLastTouchY = GetActiveY(ev); mIsDragging = false; #endregion break; case MotionEventActions.Move: #region 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 = Math.Sqrt((dx * dx) + (dy * dy)) >= mTouchSlop; } if (mIsDragging) { mListener.OnDrag(dx, dy); mLastTouchX = x; mLastTouchY = y; if (null != mVelocityTracker) { mVelocityTracker.AddMovement(ev); } } #endregion break; } return(true); }
private void EndDrag() { _quickReturn = false; _isBeingDragged = false; _isUnableToDrag = false; ActivePointerId = InvalidPointer; if (VelocityTracker == null) return; VelocityTracker.Recycle(); VelocityTracker = null; }
public override bool OnInterceptTouchEvent(MotionEvent ev) { if (!_enabled) return false; var action = (int) ev.Action & MotionEventCompat.ActionMask; #if DEBUG if (action == (int) MotionEventActions.Down) Log.Verbose(Tag, "Recieved ACTION_DOWN"); #endif if (action == (int) MotionEventActions.Cancel || action == (int) MotionEventActions.Up || (action != (int) MotionEventActions.Down && _isUnableToDrag)) { EndDrag(); return false; } switch (action) { case (int) MotionEventActions.Move: DetermineDrag(ev); break; case (int) MotionEventActions.Down: var index = MotionEventCompat.GetActionIndex(ev); ActivePointerId = MotionEventCompat.GetPointerId(ev, index); if (ActivePointerId == InvalidPointer) break; _lastMotionX = _initialMotionX = MotionEventCompat.GetX(ev, index); _lastMotionY = MotionEventCompat.GetY(ev, index); if (ThisTouchAllowed(ev)) { _isBeingDragged = false; _isUnableToDrag = false; if (IsMenuOpen && _viewBehind.MenuTouchInQuickReturn(_content, _curItem, ev.GetX() + _scrollX)) _quickReturn = true; } else _isUnableToDrag = true; break; case (int) MotionEventActions.PointerUp: OnSecondaryPointerUp(ev); break; } if (!_isBeingDragged) { if (VelocityTracker == null) VelocityTracker = VelocityTracker.Obtain(); VelocityTracker.AddMovement(ev); } return _isBeingDragged || _quickReturn; }
private void InitOrResetVelocityTracker() { if (this.velocityTracker == null) { this.velocityTracker = VelocityTracker.Obtain(); } else { this.velocityTracker.Clear(); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); FindViewById(Android.Resource.Id.Content).SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutStable | SystemUiFlags.LayoutFullscreen | SystemUiFlags.HideNavigation); stiffness = FindViewById <SeekBar>(Resource.Id.stiffness); damping = FindViewById <SeekBar>(Resource.Id.damping); velocityTracker = VelocityTracker.Obtain(); View box = FindViewById(Resource.Id.box); box.Touch += (sender, args) => { switch (args.Event.Action) { case MotionEventActions.Down: downX = args.Event.GetX(); downY = args.Event.GetY(); velocityTracker.AddMovement(args.Event); break; case MotionEventActions.Move: box.TranslationX = args.Event.GetX() - downX; box.TranslationY = args.Event.GetY() - downY; velocityTracker.AddMovement(args.Event); break; case MotionEventActions.Up: case MotionEventActions.Cancel: velocityTracker.ComputeCurrentVelocity(1000); if (box.TranslationX != 0) { SpringAnimation animX = new SpringAnimation(box, DynamicAnimation.TranslationX, 0); animX.Spring.SetStiffness(Stiffness); animX.Spring.SetDampingRatio(Damping); animX.SetStartVelocity(velocityTracker.XVelocity); animX.Start(); } if (box.TranslationY != 0) { SpringAnimation animY = new SpringAnimation(box, DynamicAnimation.TranslationY, 0); animY.Spring.SetStiffness(Stiffness); animY.Spring.SetDampingRatio(Damping); animY.SetStartVelocity(velocityTracker.YVelocity); animY.Start(); } velocityTracker.Clear(); break; } }; }
protected override void Dispose(bool disposing) { if (disposing) { if (_velocityTracker != null) { _velocityTracker.Recycle(); _velocityTracker = null; } } base.Dispose(disposing); }
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 Down(MotionEvent motionEvent) { // TODO: ensure this is a finger, and set a flag _downX = motionEvent.RawX; _downY = motionEvent.RawY; if (_canDismiss(_token)) { _pauseTimer(true); _velocityTracker = VelocityTracker.Obtain(); _velocityTracker.AddMovement(motionEvent); } return(false); }
private void EndDrag() { mQuickReturn = false; mIsBeingDragged = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } }
private void Cancel() { _view.Animate() .TranslationX(0) .Alpha(1) .SetDuration(_animationTime) .SetListener(null); _velocityTracker.Recycle(); _velocityTracker = null; _translationX = 0; _downX = 0; _downY = 0; _swiping = false; }
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); }
private void stopTracking() { mHandle.Pressed = false; mTracking = false; if (mOnDrawerScrollListener != null) { mOnDrawerScrollListener.onScrollEnded(); } if (mVelocityTracker != null) { mVelocityTracker.Recycle(); mVelocityTracker = null; } }
/** * Resets the fields to the initial values, ready to start over. */ private void reset() { if (mVelocityTracker != null) { mVelocityTracker.Recycle(); } mVelocityTracker = null; mDownX = 0; mDownY = 0; mCurrentView = null; mSwipingView = null; mCurrentPosition = AdapterView.InvalidPosition; mSwiping = false; mCanDismissCurrent = false; }
public CompactCalendarController(Paint dayPaint, OverScroller scroller, Rect rect, IAttributeSet attrs, Context context, int currentDayBackgroundColor, int calenderTextColor, int currentSelectedDayBackgroundColor, VelocityTracker velocityTracker) { this.dayPaint = dayPaint; this.scroller = scroller; this.rect = rect; this.currentDayBackgroundColor = currentDayBackgroundColor; this.calenderTextColor = calenderTextColor; this.currentSelectedDayBackgroundColor = currentSelectedDayBackgroundColor; this.velocityTracker = velocityTracker; this.currentCalender = Calendar.GetInstance(locale); this.todayCalender = Calendar.GetInstance(locale); this.calendarWithFirstDayOfMonth = Calendar.GetInstance(locale); this.eventsCalendar = Calendar.GetInstance(locale); loadAttributes(attrs, context); init(context); }
public override bool OnTouchEvent(CoordinatorLayout parent, Java.Lang.Object childObject, MotionEvent @event) { View child = Android.Runtime.Extensions.JavaCast <View>(childObject); if (!child.IsShown) { return(false); } int action = MotionEventCompat.GetActionMasked(@event); if (mState == STATE_DRAGGING && action == (int)MotionEventActions.Down) { return(true); } mViewDragHelper.ProcessTouchEvent(@event); // Record the velocity if (action == (int)MotionEventActions.Down) { reset(); } if (mVelocityTracker == null || mVelocityTracker.Handle == IntPtr.Zero) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(@event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == (int)MotionEventActions.Move && !mIgnoreEvents) { if (Math.Abs(mInitialY - @event.GetY()) > mViewDragHelper.TouchSlop) { mViewDragHelper.CaptureChildView(child, @event.GetPointerId(@event.ActionIndex)); } } return(!mIgnoreEvents); }