public override bool DispatchTouchEvent(MotionEvent me)
        {
            bool wasInTitle = false;

            switch (me.ActionMasked)
            {
            case MotionEventActions.Down:
                touchInHeader = (me.YPrecision <= VisibleHeaderHeight);
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                wasInTitle    = touchInHeader;
                touchInHeader = false;
                break;
            }
            if (touchInHeader || wasInTitle)
            {
                View title = GetChildAt(0);
                if (title != null)
                {
                    me.OffsetLocation(0, ScrollY);
                    return(title.DispatchTouchEvent(me));
                }
            }
            me.OffsetLocation(0, -headerHeight);
            return(base.DispatchTouchEvent(me));
        }
        public static bool TouchUpViewHeirarchy(this Android.Views.View view, MotionEvent e)
        {
            if (view == null)
            {
                return(true);
            }
            if (!(view.Parent is Android.Views.View parent))
            {
                return(true);
            }

            // If the number of pointers is the same and we don't need to perform any fancy
            // irreversible transformations, then we can reuse the motion event for this
            // dispatch as long as we are careful to revert any changes we make.
            // Otherwise we need to make a copy.
            //MotionEvent newEvent = MotionEvent.Obtain(e);
            float offsetX = parent.ScrollX - view.Left;
            float offsetY = parent.ScrollY - view.Top;

            e.OffsetLocation(-offsetX, -offsetY);

            var handled = parent.OnTouchEvent(MotionEvent.Obtain(e));

            //var handled = parent.DispatchTouchEvent(e);
            //System.Diagnostics.Debug.WriteLine("TouchUpViewHeirarchy: x=["+e.GetX()+"] y=["+e.GetY()+"] type=["+parent.GetType()+"] action=["+e.Action+"] handled=["+handled+"] ");
            if (!handled)
            {
                handled = parent.TouchUpViewHeirarchy(e);
            }
            e.OffsetLocation(offsetX, offsetY);
            return(handled);
        }
Exemple #3
0
        public override bool DispatchTouchEvent(MotionEvent e)
        {
            bool ret = false;

            // vérifi que le InfoWindows est affiché
            if (_marker != null && _marker.IsInfoWindowShown && _map != null && _infoWindow != null)
            {
                // obtient la position du marker à l'écran
                Point point = _map.Projection.ToScreenLocation(_marker.Position);

                // ajustement du clique pour un pin Seekios
                MotionEvent seekiosRefresh = MotionEvent.ObtainNoHistory(e);
                seekiosRefresh.OffsetLocation(
                    -point.X + (_infoWindow.Width / 2),
                    -point.Y + _infoWindow.Height + _heightSeekios);   // 130 = la hauteur du pin seekios

                // ajustement du clique pour un pin Marker
                MotionEvent copyEvMarker = MotionEvent.ObtainNoHistory(e);
                copyEvMarker.OffsetLocation(
                    -point.X + (_infoWindow.Width / 2),
                    -point.Y + _infoWindow.Height + _heightMarker);    // 35 = la hauteur du pin marker

                // dispatch le MotionEvent ajusté vers le InfoWindow
                ret = _infoWindow.DispatchTouchEvent(seekiosRefresh);
                ret = _infoWindow.DispatchTouchEvent(copyEvMarker);
            }

            return(ret || base.DispatchTouchEvent(e));
        }
Exemple #4
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (_redirectTouchesToStickyView)
            {
                ev.OffsetLocation(0, ((ScrollY + _stickyViewTopOffset) - GetTopForViewRelativeOnlyChild(_currentlyStickingView)));
            }

            if (ev.Action == MotionEventActions.Down)
            {
                _hasNotDoneActionDown = false;
            }

            if (_hasNotDoneActionDown)
            {
                MotionEvent down = MotionEvent.Obtain(ev);
                down.Action = MotionEventActions.Down;
                base.OnTouchEvent(down);
                _hasNotDoneActionDown = false;
            }

            if (ev.Action == MotionEventActions.Up || ev.Action == MotionEventActions.Cancel)
            {
                _hasNotDoneActionDown = true;
            }

            return(base.OnTouchEvent(ev));
        }
Exemple #5
0
        public override bool DispatchTouchEvent(MotionEvent ev)
        {
            if (ev.Action == MotionEventActions.Down)
            {
                _redirectTouchesToStickyView = true;
            }

            if (_redirectTouchesToStickyView)
            {
                _redirectTouchesToStickyView = _currentlyStickingView != null;
                if (_redirectTouchesToStickyView)
                {
                    _redirectTouchesToStickyView =
                        ev.GetY() <= (_currentlyStickingView.Height + _stickyViewTopOffset) &&
                        ev.GetX() >= GetLeftForViewRelativeOnlyChild(_currentlyStickingView) &&
                        ev.GetX() <= GetRightForViewRelativeOnlyChild(_currentlyStickingView);
                }
            }
            else if (_currentlyStickingView == null)
            {
                _redirectTouchesToStickyView = false;
            }
            if (_redirectTouchesToStickyView)
            {
                ev.OffsetLocation(0, -1 * ((ScrollY + _stickyViewTopOffset) - GetTopForViewRelativeOnlyChild(_currentlyStickingView)));
            }
            return(base.DispatchTouchEvent(ev));
        }
        public bool OnTouch(View view, MotionEvent motionEvent)
        {
            // offset because the view is translated during swipe
            motionEvent.OffsetLocation(_translationX, 0);

            if (_viewWidth < 2)
            {
                _viewWidth = _view.Width;
            }

            switch (motionEvent.ActionMasked)
            {
            case MotionEventActions.Down:
                return(Down(motionEvent));

            case MotionEventActions.Up:
                Up(motionEvent);
                break;

            case MotionEventActions.Cancel:
                if (_velocityTracker == null)
                {
                    break;
                }

                Cancel();
                break;

            case MotionEventActions.Move:
                if (_velocityTracker == null)
                {
                    break;
                }

                if (Move(motionEvent))
                {
                    return(true);
                }
                break;
            }

            return(false);
        }
Exemple #7
0
 /**
  * Duplicate touch events to child views.
  * We want to dispatch a down motion event and the move events to
  * child views, but calling dispatchTouchEvent() causes StackOverflowError.
  * Therefore we do it manually.
  *
  * @param ev            motion event to be passed to children
  * @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children before ev
  */
 private void DuplicateTouchEventForChildren(MotionEvent ev, params MotionEvent[] pendingEvents)
 {
     if (ev == null)
     {
         return;
     }
     for (int i = ChildCount - 1; 0 <= i; i--)
     {
         View childView = GetChildAt(i);
         if (childView != null)
         {
             Rect childRect = new Rect();
             childView.GetHitRect(childRect);
             MotionEvent event2 = MotionEvent.ObtainNoHistory(ev);
             if (!childRect.Contains((int)event2.GetX(), (int)event2.GetY()))
             {
                 continue;
             }
             float offsetX  = -childView.Left;
             float offsetY  = -childView.Top;
             bool  consumed = false;
             if (pendingEvents != null)
             {
                 foreach (MotionEvent pe in pendingEvents)
                 {
                     if (pe != null)
                     {
                         MotionEvent peAdjusted = MotionEvent.ObtainNoHistory(pe);
                         peAdjusted.OffsetLocation(offsetX, offsetY);
                         consumed |= childView.DispatchTouchEvent(peAdjusted);
                     }
                 }
             }
             event2.OffsetLocation(offsetX, offsetY);
             consumed |= childView.DispatchTouchEvent(event2);
             if (consumed)
             {
                 break;
             }
         }
     }
 }
Exemple #8
0
        //		public override bool OnDown (MotionEvent e)
        //		{
        //			return base.OnDown (e);
        //		}


        #region handling gestures at a group level

        /**
         * We have an issue with Android that makes it pretty much impossible to compose gestures.
         * For now, this is all parked on android till I come up with a solution that works.
         */
        /**
         * Because we are composing, we have to do a bit of hackery to get touches from the main activity
         */
        #endregion
        public bool ConsumesActivityTouch(MotionEvent ev)
        {
            //TODO work out if it's our view in here, then update the coordinates
            var offset = GetOffsetInNativeView(ev.GetX(), ev.GetY());

            Console.WriteLine("location " + ev.GetX() + ", " + ev.GetY() + " offset " + offset);
            ev.OffsetLocation(-offset.X, -offset.Y);
            Console.WriteLine("ofseeted " + ev.GetX() + ", " + ev.GetY());
            if (ev.GetX() < 0 || ev.GetY() < 0 || ev.GetX() > NativeView.Width || ev.GetY() > NativeView.Height)
            {
                return(false);
            }
            else
            {
                //next check children
//				var isConsumedByChild = IsTouchConsumedByChildren (NativeView as ViewGroup, ev);
                //we need to check all views to see if they ate the touch
                OnTouch(this.NativeView, ev);
            }
            return(false);
        }
Exemple #9
0
 public MotionEvent GetCachedEvent()
 {
     MotionEvent.Action = _cachedAction;
     MotionEvent.OffsetLocation(_cachedX - MotionEvent.GetX(), _cachedY - MotionEvent.GetY());
     return(MotionEvent);
 }
Exemple #10
0
        /*public override bool OnInterceptTouchEvent (MotionEvent ev)
         * {
         *      // Only accept single touch
         *      if (ev.PointerCount != 1)
         *              return false;
         *      ev.OffsetLocation (0, TranslationY);
         *      return CaptureMovementCheck (ev);
         * }*/

        public override bool OnTouchEvent(MotionEvent e)
        {
            if (paneGestureDetector == null)
            {
                var l = new DoubleTapListener(() => SetState(Opened && FullyOpened ? State.Opened : State.FullyOpened));
                paneGestureDetector = new GestureDetector(Context, l);
            }
            paneGestureDetector.OnTouchEvent(e);

            e.OffsetLocation(0, TranslationY);
            if (e.Action == MotionEventActions.Down)
            {
                CaptureMovementCheck(e);
                return(true);
            }
            if (!isTracking && !CaptureMovementCheck(e))
            {
                return(true);
            }

            if (e.Action != MotionEventActions.Move || MoveDirectionTest(e))
            {
                velocityTracker.AddMovement(e);
            }

            if (e.Action == MotionEventActions.Move)
            {
                var y = e.GetY();
                // We don't want to go beyond startY
                if (state == State.Opened && y > startY ||
                    state == State.FullyOpened && y < startY)
                {
                    return(true);
                }
                // We reset the velocity tracker in case a movement goes back to its origin
                if (state == State.Opened && y > oldY ||
                    state == State.FullyOpened && y < oldY)
                {
                    velocityTracker.Clear();
                }

                var traveledDistance = (int)Math.Round(Math.Abs(y - startY));
                if (state == State.Opened)
                {
                    traveledDistance = OffsetForState(State.Opened) - traveledDistance;
                }
                SetNewOffset(traveledDistance);
                oldY = y;
            }
            else if (e.Action == MotionEventActions.Up)
            {
                velocityTracker.ComputeCurrentVelocity(1000, maxFlingVelocity);
                if (Math.Abs(velocityTracker.YVelocity) > minFlingVelocity &&
                    Math.Abs(velocityTracker.YVelocity) < maxFlingVelocity)
                {
                    SetState(state == State.FullyOpened ? State.Opened : State.FullyOpened);
                }
                else if (state == State.FullyOpened && contentOffsetY > Height / 2)
                {
                    SetState(State.Opened);
                }
                else if (state == State.Opened && contentOffsetY < Height / 2)
                {
                    SetState(State.FullyOpened);
                }
                else
                {
                    SetState(state);
                }

                preTracking = isTracking = false;
                velocityTracker.Clear();
                velocityTracker.Recycle();
            }

            return(true);
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (_mCallbacks != null)
            {
                switch (ev.ActionMasked)
                {
                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 eventHistoryLess = MotionEvent.ObtainNoHistory(ev);
                        eventHistoryLess.OffsetLocation(offsetX, offsetY);

                        if (parent.OnInterceptTouchEvent(eventHistoryLess))
                        {
                            _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.
                            eventHistoryLess.Action = MotionEventActions.Down;

                            // Return this onTouchEvent() first and set ACTION_DOWN event for parent
                            // to the queue, to keep events sequence.
                            Post(() => parent.DispatchTouchEvent(eventHistoryLess));
                            return(false);
                        }
                        // Even when this can't be scrolled anymore,
                        // simply returning false here may cause subView's click,
                        // so delegate it to super.
                        return(base.OnTouchEvent(ev));
                    }
                    break;
                }
            }
            return(base.OnTouchEvent(ev));
        }