Ejemplo n.º 1
0
 public override bool dispatchTouchEvent(android.view.MotionEvent ev)
 {
     if (mDefaultTouchRecepient == null)
     {
         return(base.dispatchTouchEvent(ev));
     }
     if (base.dispatchTouchEvent(ev))
     {
         return(true);
     }
     mTempRect.set(0, 0, 0, 0);
     offsetRectIntoDescendantCoords(mDefaultTouchRecepient, mTempRect);
     ev.setLocation(ev.getX() + mTempRect.left, ev.getY() + mTempRect.top);
     return(mDefaultTouchRecepient.dispatchTouchEvent(ev));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Will forward touch events to the delegate view if the event is within the bounds
        /// specified in the constructor.
        /// </summary>
        /// <remarks>
        /// Will forward touch events to the delegate view if the event is within the bounds
        /// specified in the constructor.
        /// </remarks>
        /// <param name="event">The touch event to forward</param>
        /// <returns>True if the event was forwarded to the delegate, false otherwise.</returns>
        public virtual bool onTouchEvent(android.view.MotionEvent @event)
        {
            int  x = (int)@event.getX();
            int  y = (int)@event.getY();
            bool sendToDelegate = false;
            bool hit            = true;
            bool handled        = false;

            switch (@event.getAction())
            {
            case android.view.MotionEvent.ACTION_DOWN:
            {
                android.graphics.Rect bounds = mBounds;
                if (bounds.contains(x, y))
                {
                    mDelegateTargeted = true;
                    sendToDelegate    = true;
                }
                break;
            }

            case android.view.MotionEvent.ACTION_UP:
            case android.view.MotionEvent.ACTION_MOVE:
            {
                sendToDelegate = mDelegateTargeted;
                if (sendToDelegate)
                {
                    android.graphics.Rect slopBounds = mSlopBounds;
                    if (!slopBounds.contains(x, y))
                    {
                        hit = false;
                    }
                }
                break;
            }

            case android.view.MotionEvent.ACTION_CANCEL:
            {
                sendToDelegate    = mDelegateTargeted;
                mDelegateTargeted = false;
                break;
            }
            }
            if (sendToDelegate)
            {
                android.view.View delegateView = mDelegateView;
                if (hit)
                {
                    // Offset event coordinates to be inside the target view
                    @event.setLocation(delegateView.getWidth() / 2, delegateView.getHeight() / 2);
                }
                else
                {
                    // Offset event coordinates to be outside the target view (in case it does
                    // something like tracking pressed state)
                    int slop = mSlop;
                    @event.setLocation(-(slop * 2), -(slop * 2));
                }
                handled = delegateView.dispatchTouchEvent(@event);
            }
            return(handled);
        }