Beispiel #1
0
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            var action = ev.Action;

            if (action == MotionEventActions.Cancel || action == MotionEventActions.Up)
            {
                mDragHelper.Cancel();
                return(false);
            }
            return(mDragHelper.ShouldInterceptTouchEvent(ev));
        }
Beispiel #2
0
 /// <summary>
 /// Intercepts only touch events over the draggable view.
 /// </summary>
 /// <param name="ev"></param>
 /// <returns></returns>
 public override bool OnInterceptTouchEvent(MotionEvent ev)
 {
     try
     {
         bool handled = false;
         if (Enabled)
         {
             handled = DragHelper.ShouldInterceptTouchEvent(ev) &&
                       DragHelper.IsViewUnder(DraggableView, (int)ev.GetX(), (int)ev.GetY());
         }
         else
         {
             DragHelper.Cancel();
         }
         return(handled || base.OnInterceptTouchEvent(ev));
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
         return(base.OnInterceptTouchEvent(ev));
     }
 }
Beispiel #3
0
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            var action = MotionEventCompat.GetActionMasked(ev);

            if (!_canSlide || !SlidingEnabled || (_isUnableToDrag && action != (int)MotionEventActions.Down))
            {
                _dragHelper.Cancel();
                return(base.OnInterceptTouchEvent(ev));
            }

            if (action == (int)MotionEventActions.Cancel || action == (int)MotionEventActions.Up)
            {
                _dragHelper.Cancel();
                return(false);
            }

            var x            = ev.GetX();
            var y            = ev.GetY();
            var interceptTap = false;

            switch (action)
            {
            case (int)MotionEventActions.Down:
                _isUnableToDrag = false;
                _initialMotionX = x;
                _initialMotionY = y;
                if (IsDragViewUnder((int)x, (int)y) && !IsUsingDragViewTouchEvents)
                {
                    interceptTap = true;
                }
                break;

            case (int)MotionEventActions.Move:
                var adx      = Math.Abs(x - _initialMotionX);
                var ady      = Math.Abs(y - _initialMotionY);
                var dragSlop = _dragHelper.TouchSlop;

                if (IsUsingDragViewTouchEvents)
                {
                    if (adx > _scrollTouchSlop && ady < _scrollTouchSlop)
                    {
                        return(base.OnInterceptTouchEvent(ev));
                    }
                    if (ady > _scrollTouchSlop)
                    {
                        interceptTap = IsDragViewUnder((int)x, (int)y);
                    }
                }

                if ((ady > dragSlop && adx > ady) || !IsDragViewUnder((int)x, (int)y))
                {
                    _dragHelper.Cancel();
                    _isUnableToDrag = true;
                    return(false);
                }
                break;
            }

            var interceptForDrag = _dragHelper.ShouldInterceptTouchEvent(ev);

            return(interceptForDrag || interceptTap);
        }
        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);
        }