Ejemplo n.º 1
0
        private void OnTimerEvent(object sender, System.Timers.ElapsedEventArgs e)
        {
            var x = motion?.GetX();
            var y = motion?.GetY();

            if (IsViewInBounds((int)x, (int)y))
            {
                timer.Stop();
                Xamarin.Forms.Device.BeginInvokeOnMainThread(LongClickHandler);
            }
        }
 public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
 {
     try
     {
         bool  result = false;
         float diffY  = e2?.GetY() - e1?.GetY() ?? 0;
         float diffX  = e2?.GetX() - e1?.GetX() ?? 0;
         if (Math.Abs(diffX) > Math.Abs(diffY))
         {
             if (Math.Abs(diffX) > SwipeThreshold && Math.Abs(velocityX) > SwipeVelocityThreshold)
             {
                 if (diffX > 0)
                 {
                     //Swiped Right
                     OnSwipe?.Swipe(MainView, SwipeType.Right);
                 }
                 else
                 {
                     //Swiped Left
                     OnSwipe?.Swipe(MainView, SwipeType.Left);
                 }
                 result = true;
             }
         }
         else if (Math.Abs(diffY) > SwipeThreshold && Math.Abs(velocityY) > SwipeVelocityThreshold)
         {
             if (diffY > 0)
             {
                 //Swiped Down
                 OnSwipe?.Swipe(MainView, SwipeType.Bottom);
             }
             else
             {
                 //Swiped Up
                 OnSwipe?.Swipe(MainView, SwipeType.Top);
             }
             result = true;
         }
         return(result);
     }
     catch (Exception e)
     {
         Methods.DisplayReportResultTrack(e);
         return(base.OnFling(e1, e2, velocityX, velocityY));
     }
 }
Ejemplo n.º 3
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="e1"></param>
            /// <param name="e2"></param>
            /// <param name="velocityX"></param>
            /// <param name="velocityY"></param>
            /// <returns></returns>
            public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
            {
                var diffX = (e2?.GetX() ?? 0) - (e1?.GetX() ?? 0);
                var diffY = (e2?.GetY() ?? 0) - (e1?.GetY() ?? 0);

                var absDiffX = Math.Abs(diffX);
                var absDiffY = Math.Abs(diffY);

                if (absDiffX > absDiffY &&
                    absDiffX > SwipeThreshold &&
                    Math.Abs(velocityX) > SwipeVelocityThreshold)
                {
                    _onSwiped?.Invoke(new SwipeArgs(diffX > 0 ? SwipeDirection.Right : SwipeDirection.Left, Math.Abs(velocityX / 1750)));
                    return(true);
                }

                return(false);
            }
Ejemplo n.º 4
0
                public override bool OnDownGesture( MotionEvent e )
                {
                    // only processes TouchesBegan if we didn't create a note with this gesture.
                    if ( DidGestureCreateNote == false )
                    {
                        if ( Note != null )
                        {
                            if ( Note.TouchesBegan( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) ) )
                            {
                                ScrollView.ScrollEnabled = false;

                                MovingUserNote = true;
                            }
                        }
                    }
                    return false;
                }
Ejemplo n.º 5
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            _rippleX = e.GetX();
            _rippleY = e.GetY();

            if (e.Action == MotionEventActions.Up)
            {
                // Parent.RequestDisallowInterceptTouchEvent(false);
                //_touchAction = MotionEventActions.Up;

                OnClick?.Invoke(this, EventArgs.Empty);

                //_radius = 1;
                //_endRadius = Math.Max(Math.Max(Math.Max(_width - _rippleX, _rippleX), _rippleY), _height - _rippleY);
                //_speed = _endRadius / _duration * 10;
                //Action animAction = null;
                //animAction = () =>
                //{
                //    if (_radius < _endRadius)
                //    {
                //        _radius += _speed;
                //        _paint.Alpha = 90 - (int)(_radius / _endRadius * 90);
                //        _handler.PostDelayed(animAction, 1);
                //    }
                //};
                //_handler.PostDelayed(animAction, 10);
                // Invalidate();
                return(false);
            }
            else if (e.Action == MotionEventActions.Cancel)
            {
                // Parent.RequestDisallowInterceptTouchEvent(false);
                _touchAction = MotionEventActions.Cancel;
                //  _radius = 0;
                //  Invalidate();
                return(false);
            }
            else if (e.Action == MotionEventActions.Down)
            {
                //Parent.RequestDisallowInterceptTouchEvent(true);
                //_touchAction = MotionEventActions.Up;
                //_endRadius = Math.Max(Math.Max(Math.Max(_width - _rippleX, _rippleX), _rippleY), _height - _rippleY);
                //_paint.Alpha = 90;
                //_radius = _endRadius / 4;
                //Invalidate();
                return(true);
            }
            else if (e.Action == MotionEventActions.Move)
            {
                if (_rippleX < 0 || _rippleX > _width || _rippleY < 0 || _rippleY > _height)
                {
                    //Parent.RequestDisallowInterceptTouchEvent(false);
                    //_touchAction = MotionEventActions.Cancel;
                    //_radius = 0;
                    //Invalidate();
                    return(false);
                }
                else
                {
                    //_touchAction = MotionEventActions.Move;
                    //Invalidate();
                    return(true);
                }
            }

            return(false);
        }
        public bool dispatchTouchEvent(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();

            switch (ev.Action)
            {
            case MotionEventActions.Down:

                mLastX    = x;
                mLastY    = y;
                mDownTime = Java.Lang.JavaSystem.CurrentTimeMillis();
                mTmpAngle = 0;

                if (isFling)
                {
                    RemoveCallbacks(mFlingRunnable);
                    isFling = false;
                    return(true);
                }

                break;

            case MotionEventActions.Move:


                float start = getAngle(mLastX, mLastY);

                float end = getAngle(x, y);

                // Log.e("TAG", "start = " + start + " , end =" + end);
                if (getQuadrant(x, y) == 1 || getQuadrant(x, y) == 4)
                {
                    mStartAngle += end - start;
                    mTmpAngle   += end - start;
                }
                else
                {
                    mStartAngle += start - end;
                    mTmpAngle   += start - end;
                }

                RequestLayout();

                mLastX = x;
                mLastY = y;

                break;

            case MotionEventActions.Up:

                float anglePerSecond = mTmpAngle * 1000
                                       / (Java.Lang.JavaSystem.CurrentTimeMillis() - mDownTime);

                // Log.e("TAG", anglePrMillionSecond + " , mTmpAngel = " +
                // mTmpAngle);

                if (Math.Abs(anglePerSecond) > mFlingableValue && !isFling)
                {
                    Post(mFlingRunnable = (AutoFlingRunnable(anglePerSecond)));

                    return(true);
                }

                if (Math.Abs(mTmpAngle) > NOCLICK_VALUE)
                {
                    return(true);
                }

                break;
            }
            return(base.DispatchTouchEvent(ev));
        }
Ejemplo n.º 7
0
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            /*
             * This method JUST determines whether we want to intercept the motion.
             * If we return true, onMotionEvent will be called and we do the actual
             * scrolling there.
             *
             * Shortcut the most recurring case: the user is in the dragging
             * state and he is moving his finger.  We want to intercept this
             * motion.
             */
            MotionEventActions action = ev.Action;

            if ((action == MotionEventActions.Move) && (mIsBeingDragged))
            {
                return(true);
            }
            if (!canScroll())
            {
                mIsBeingDragged = false;
                return(false);
            }
            float y = ev.GetY();
            float x = ev.GetX();

            switch (action)
            {
            case MotionEventActions.Move:
                /*
                 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
                 * whether the user has moved far enough from his original down touch.
                 */
                /*
                 * Locally do absolute value. mLastMotionY is set to the y value
                 * of the down event.
                 */
                int yDiff = (int)Math.Abs(y - mLastMotionY);
                int xDiff = (int)Math.Abs(x - mLastMotionX);
                if (yDiff > mTouchSlop || xDiff > mTouchSlop)
                {
                    mIsBeingDragged = true;
                }
                break;

            case MotionEventActions.Down:
                /* Remember location of down touch */
                mLastMotionY = y;
                mLastMotionX = x;

                /*
                 * If being flinged and user touches the screen, initiate drag;
                 * otherwise don't.  mScroller.isFinished should be false when
                 * being flinged.
                 */
                mIsBeingDragged = !mScroller.IsFinished;
                break;

            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                /* Release the drag */
                mIsBeingDragged = false;
                break;
            }

            /*
             * The only time we want to intercept motion events is if we are in the
             * drag mode.
             */
            return(mIsBeingDragged);
        }
Ejemplo n.º 8
0
        private void DecideAction(MotionEvent e1)
        {
            var screenWidth = _info.DeviceWidth;

            _action = e1.GetX() > screenWidth - (screenWidth / 100 * 10) ? TouchEnum.Scroll : TouchEnum.Single;
        }
Ejemplo n.º 9
0
 private float GetTotalX(MotionEvent ev) => (ev.GetX() - _startX.GetValueOrDefault()) / Context.Resources.DisplayMetrics.Density;
Ejemplo n.º 10
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            isLastTouch = true;
            if (Enabled)
            {
                if (e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Move)
                {
                    if (numberIndicator != null && numberIndicator.IsShowing == false)
                    {
                        numberIndicator.Show();
                    }
                    if ((e.GetX() <= Width && e.GetX() >= 0))
                    {
                        press = true;
                        // calculate value
                        int   newValue = 0;
                        float division = (ball.xFin - ball.xIni) / (max - min);
                        if (e.GetX() > ball.xFin)
                        {
                            newValue = max;
                        }
                        else if (e.GetX() < ball.xIni)
                        {
                            newValue = min;
                        }
                        else
                        {
                            newValue = min + (int)((e.GetX() - ball.xIni) / division);
                        }
                        if (val != newValue)
                        {
                            val = newValue;
                            if (onValueChangedListener != null)
                            {
                                onValueChangedListener.OnValueChanged(newValue);
                            }
                        }
                        // move ball indicator
                        float x = e.GetX();
                        x = (x < ball.xIni) ? ball.xIni : x;
                        x = (x > ball.xFin) ? ball.xFin : x;
                        ViewHelper.SetX(ball, x);
                        ball.ChangeBackground();

                        // If slider has number indicator
                        if (numberIndicator != null)
                        {
                            // move number indicator
                            numberIndicator.indicator.x          = x;
                            numberIndicator.indicator.finalY     = Utils.GetRelativeTop(this) - Height / 2;
                            numberIndicator.indicator.finalSize  = Height / 2;
                            numberIndicator.numberIndicator.Text = "";
                        }
                    }
                    else
                    {
                        press       = false;
                        isLastTouch = false;
                        if (numberIndicator != null)
                        {
                            numberIndicator.Dismiss();
                        }
                    }
                }
                else if (e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Cancel)
                {
                    if (numberIndicator != null)
                    {
                        numberIndicator.Dismiss();
                    }
                    isLastTouch = false;
                    press       = false;
                }
            }
            return(true);
        }
Ejemplo n.º 11
0
 public static PointF ToPointF(this MotionEvent motionEvent)
 => new PointF(motionEvent.GetX(), motionEvent.GetY());
Ejemplo n.º 12
0
        /// <summary>
        ///     Handles thumb selection and movement. Notifies listener callback on certain evs.
        /// </summary>
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (!Enabled)
            {
                return(false);
            }

            int pointerIndex;

            var action = ev.Action;

            switch (action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
                // Remember where the motion ev started
                _activePointerId = ev.GetPointerId(ev.PointerCount - 1);
                pointerIndex     = ev.FindPointerIndex(_activePointerId);
                _downMotionX     = ev.GetX(pointerIndex);

                _pressedThumb = EvalPressedThumb(_downMotionX);

                // Only handle thumb presses.
                if (_pressedThumb == null)
                {
                    return(base.OnTouchEvent(ev));
                }

                Pressed = true;
                Invalidate();
                OnStartTrackingTouch();
                TrackTouchEvent(ev, StepValueContinuously);
                AttemptClaimDrag();

                break;

            case MotionEventActions.Move:
                if (_pressedThumb != null)
                {
                    if (_isDragging)
                    {
                        TrackTouchEvent(ev, StepValueContinuously);
                    }
                    else
                    {
                        // Scroll to follow the motion ev
                        pointerIndex = ev.FindPointerIndex(_activePointerId);
                        var x = ev.GetX(pointerIndex);

                        if (Math.Abs(x - _downMotionX) > _scaledTouchSlop)
                        {
                            Pressed = true;
                            Invalidate();
                            OnStartTrackingTouch();
                            TrackTouchEvent(ev, StepValueContinuously);
                            AttemptClaimDrag();
                        }
                    }

                    if (NotifyWhileDragging)
                    {
                        if (_pressedThumb == Thumb.Lower)
                        {
                            OnLowerValueChanged();
                        }
                        if (_pressedThumb == Thumb.Upper)
                        {
                            OnUpperValueChanged();
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
                if (_isDragging)
                {
                    TrackTouchEvent(ev, true);
                    OnStopTrackingTouch();
                    Pressed = false;
                }
                else
                {
                    // Touch up when we never crossed the touch slop threshold
                    // should be interpreted as a tap-seek to that location.
                    OnStartTrackingTouch();
                    TrackTouchEvent(ev, true);
                    OnStopTrackingTouch();
                }
                if (_pressedThumb == Thumb.Lower)
                {
                    OnLowerValueChanged();
                }
                if (_pressedThumb == Thumb.Upper)
                {
                    OnUpperValueChanged();
                }
                _pressedThumb = null;
                Invalidate();
                break;

            case MotionEventActions.PointerDown:
                var index = ev.PointerCount - 1;
                // readonly int index = ev.getActionIndex();
                _downMotionX     = ev.GetX(index);
                _activePointerId = ev.GetPointerId(index);
                Invalidate();
                break;

            case MotionEventActions.PointerUp:
                OnSecondaryPointerUp(ev);
                Invalidate();
                break;

            case MotionEventActions.Cancel:
                if (_isDragging)
                {
                    OnStopTrackingTouch();
                    Pressed = false;
                }
                Invalidate();     // see above explanation
                break;
            }
            return(true);
        }
Ejemplo n.º 13
0
        public bool OnTouch(View v, MotionEvent e)
        {
            if (mGestureDetector.OnTouchEvent(e))
            {
                return(true);
            }
            mScaleGestureDetector.OnTouchEvent(e);

            float x = 0, y = 0;
            // 拿到触摸点的个数
            int pointerCount = e.PointerCount;

            // 得到多个触摸点的x与y均值
            for (int i = 0; i < pointerCount; i++)
            {
                x += e.GetX(i);
                y += e.GetY(i);
            }
            x = x / pointerCount;
            y = y / pointerCount;

            /**
             * 每当触摸点发生变化时,重置mLasX , mLastY
             */
            if (pointerCount != lastPointerCount)
            {
                isCanDrag = false;
                mLastX    = x;
                mLastY    = y;
            }

            lastPointerCount = pointerCount;

            RectF rectF = getMatrixRectF();

            var width = Width - 2 * mHorizontalPadding;

            switch (e.Action)
            {
            //case MotionEventActions.Down:
            //    if (rectF.Width() > Width || rectF.Height() > Height)
            //    {
            //        Parent.RequestDisallowInterceptTouchEvent(true);
            //    }
            //    break;
            case MotionEventActions.Move:
                //if (rectF.Width() > Width || rectF.Height() > Height)
                //{
                //    Parent.RequestDisallowInterceptTouchEvent(true);
                //}
                //Log.e(TAG, "ACTION_MOVE");
                float dx = x - mLastX;
                float dy = y - mLastY;

                if (!isCanDrag)
                {
                    isCanDrag = IsCanDrag(dx, dy);
                }
                if (isCanDrag)
                {
                    if (Drawable != null)
                    {
                        // if (getMatrixRectF().left == 0 && dx > 0)
                        // {
                        // getParent().requestDisallowInterceptTouchEvent(false);
                        // }
                        //
                        // if (getMatrixRectF().right == Width && dx < 0)
                        // {
                        // getParent().requestDisallowInterceptTouchEvent(false);
                        // }
                        //isCheckLeftAndRight = isCheckTopAndBottom = true;
                        //// 如果宽度小于屏幕宽度,则禁止左右移动
                        //if (rectF.Width() < width)
                        //{
                        //    dx = 0;
                        //}
                        //// 如果高度小雨屏幕高度,则禁止上下移动
                        //if (rectF.Height() < width)
                        //{
                        //    dy = 0;
                        //    isCheckTopAndBottom = false;
                        //}


                        mScaleMatrix.PostTranslate(dx, dy);
                        checkMatrixBounds();
                        ImageMatrix = (mScaleMatrix);
                    }
                }
                mLastX = x;
                mLastY = y;
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                //Log.e(TAG, "ACTION_UP");
                lastPointerCount = 0;
                break;
            }
            return(true);
        }
Ejemplo n.º 14
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (m_GestureDetector.OnTouchEvent(e))
            {
                m_PreviousMoveX = (int)e.GetX();
                m_PreviousMoveY = (int)e.GetY();
                return(true);
            }

            var touchCount = e.PointerCount;

            switch (e.Action)
            {
            case MotionEventActions.Down:
            case MotionEventActions.Pointer1Down:
            case MotionEventActions.Pointer2Down:
            {
                if (touchCount >= 2)
                {
                    var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1));
                    m_PreviousDistance = distance;
                    m_IsScaling        = true;
                }
            }
            break;

            case MotionEventActions.Move:
            {
                if (touchCount >= 2 && m_IsScaling)
                {
                    var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1));
                    var scale    = (distance - m_PreviousDistance) / this.DispDistance();
                    m_PreviousDistance = distance;
                    scale += 1;
                    scale  = scale * scale;
                    this.ZoomTo(scale, m_Width / 2, m_Height / 2);
                    this.Cutting();
                }
                else if (!m_IsScaling)
                {
                    var distanceX = m_PreviousMoveX - (int)e.GetX();
                    var distanceY = m_PreviousMoveY - (int)e.GetY();
                    m_PreviousMoveX = (int)e.GetX();
                    m_PreviousMoveY = (int)e.GetY();

                    m_Matrix.PostTranslate(-distanceX, -distanceY);
                    this.Cutting();
                }
            }
            break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
            case MotionEventActions.Pointer2Up:
            {
                if (touchCount <= 1)
                {
                    m_IsScaling = false;
                }
            }
            break;
            }
            return(true);
        }
Ejemplo n.º 15
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (Settings.ScanMode.Equals("FULL"))
            {
                return(true);
            }


            //return base.OnTouchEvent(e);
            MotionEventActions action = e.Action;
            bool  intercept           = true;
            int   pointerIndex;
            float x;
            float y;

            float dx;
            float dy;

            switch (action)
            {
            case MotionEventActions.Down:
                x = e.GetX();
                y = e.GetY();

                // in CameraPreview we have Rect rec. This is passed here to return
                // a false when the camera button is pressed so that this view ignores
                // the touch event.

                //if ((x >= buttonRec.Left) && (x <= buttonRec.Right) && (y >= buttonRec.Top) && (y <= buttonRec.Bottom))
                //{
                //    intercept = false;
                //    break;
                //}

                // is explained below, when we get to this method.
                manhattanDistance(x, y);

                // Remember where we started
                mLastTouchX      = x;
                mLastTouchY      = y;
                mActivePointerId = e.GetPointerId(0);
                break;

            case MotionEventActions.Move:
                pointerIndex = e.FindPointerIndex(mActivePointerId);
                x            = e.GetX();
                y            = e.GetY();
                //Log.i(TAG,"x: "+x);
                //Log.i(TAG,"y: "+y);

                // Only move if the ScaleGestureDetector isn't processing a gesture.
                // but we ignore here because we are not using ScaleGestureDetector.
                if (!mScaleDetector.IsInProgress)
                {
                    dx = x - mLastTouchX;
                    dy = y - mLastTouchY;

                    mPosX += dx;
                    mPosY += dy;

                    Invalidate();
                }

                // Calculate the distance moved
                dx = x - mLastTouchX;
                dy = y - mLastTouchY;

                // Move the object
                if (mPosX >= 0 && mPosX <= _width)
                {
                    mPosX += dx;
                }

                if (mPosY >= 0 && mPosY <= _height)
                {
                    mPosY += dy;
                }

                // while its being pressed n it does not overlap the bottom line or right line
                if (mLeftTopBool && ((y + mCenter * 2) < mLeftBottomPosY) && ((x + mCenter * 2) < mRightTopPosX))
                {
                    if (dy != 0)
                    {
                        mRightTopPosY = y;
                    }
                    if (dx != 0)
                    {
                        mLeftBottomPosX = x;
                    }

                    mLeftTopPosX = x;    //mPosX;
                    mLeftTopPosY = y;    //mPosY;
                }

                if (mRightTopBool && ((y + mCenter * 2) < mRightBottomPosY) && (x > (mLeftTopPosX + mCenter * 2)))
                {
                    if (dy != 0)
                    {
                        mLeftTopPosY = y;
                    }
                    if (dx != 0)
                    {
                        mRightBottomPosX = x;
                    }
                    mRightTopPosX = x;    //mPosX;
                    mRightTopPosY = y;    //mPosY;
                }

                if (mLeftBottomBool && (y > (mLeftTopPosY + mCenter * 2)) && ((x + mCenter * 2) < mRightBottomPosX))
                {
                    if (dx != 0)
                    {
                        mLeftTopPosX = x;
                    }
                    if (dy != 0)
                    {
                        mRightBottomPosY = y;
                    }
                    mLeftBottomPosX = x;
                    mLeftBottomPosY = y;
                }

                if (mRightBottomBool && (y > (mLeftTopPosY + mCenter * 2)) && (x > (mLeftBottomPosX + mCenter * 2)))
                {
                    if (dx != 0)
                    {
                        mRightTopPosX = x;
                    }
                    if (dy != 0)
                    {
                        mLeftBottomPosY = y;
                    }
                    mRightBottomPosX = x;
                    mRightBottomPosY = y;
                }

                // Remember this touch position for the next move event
                mLastTouchX = x;
                mLastTouchY = y;

                // Invalidate to request a redraw
                Invalidate();
                break;

            case MotionEventActions.Up:
                // when one of these is true, that means it can move when onDraw is called
                mLeftTopBool     = false;
                mRightTopBool    = false;
                mLeftBottomBool  = false;
                mRightBottomBool = false;
                //mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.Cancel:
                mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.PointerUp:
                // Extract the index of the pointer that left the touch sensor
                //int pointerIndex = MotionEventActions.PointerIndexMask >> MotionEventActions.PointerIndexShift;

                /*
                 * pointerIndex = (int)MotionEventActions.PointerIndexMask;
                 *
                 * int pointerId = e.GetPointerId(pointerIndex);
                 * if (pointerId == mActivePointerId)
                 * {
                 *  // This was our active pointer going up. Choose a new
                 *  // active pointer and adjust accordingly.
                 *  int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                 *  mLastTouchX = e.GetX(newPointerIndex);
                 *  mLastTouchY = e.GetY(newPointerIndex);
                 *  mActivePointerId = e.GetPointerId(newPointerIndex);
                 * }
                 */
                break;
            }

            return(intercept);
        }
Ejemplo n.º 16
0
 public virtual Point GetPerspexPointFromEvent(MotionEvent e) => new Point(e.GetX(), e.GetY());
Ejemplo n.º 17
0
        public bool OnTouch(View v, MotionEvent e)
        {
            switch (e.Action)
            {
            case MotionEventActions.Up:
                //return stick view to original position.
                v.Layout((int)_originalX, (int)_originalY, (int)_originalX + v.Width, (int)_originalY + v.Height);
                UpdateXandY((int)v.GetX(), (int)v.GetY());
                break;

            case MotionEventActions.Down:
                //Set initial X and Y position for the stick location.
                _originalX = v.GetX();
                _originalY = v.GetY();
                //Set initial X and Y position for the user finger on the stick
                ////since this event only triggers on the stick view, the finger position will always be inside the stick view.
                _xInView = e.GetX();
                _yInView = e.GetY();
                break;

            case MotionEventActions.Move:
                //get the "SquareLinearLayout" Left and Top position on screen
                var   parent            = v.Parent as View;
                int[] parentCoordinates = new[] { 0, 0 };
                parent.GetLocationOnScreen(parentCoordinates);

                //Calculate the future position of the stick, as left,right,top,bottom
                var newLeft   = (int)(e.RawX - (_xInView)) - parentCoordinates[0];
                var newRight  = (int)(newLeft + v.Width);
                var newTop    = (int)(e.RawY - (_yInView)) - parentCoordinates[1];
                var newBottom = (int)(newTop + v.Height);

                //_originalX is the distance between left of "SquareLinearLayout" and left of "stick view", so it is might as well be the maximum distance the stick can move
                int maxDistance = (int)_originalX;

                //Calculate future position from left and top to X and Y.
                int    newViewX            = newLeft - (int)_originalX;
                int    newViewY            = (newTop - (int)_originalY) * -1;
                double newDistanceFromZero = Math.Sqrt(Math.Pow(newViewX, 2) + Math.Pow(newViewY, 2));

                //System.Diagnostics.Debug.WriteLine($"x:{newViewX}, y:{newViewY}, d:{newDistanceFromZero}, MAXd:{maxDistance}");

                //check if calculated future position exceeds maximum distance
                if (newDistanceFromZero > maxDistance)
                {
                    //if exceeds then get set the position to the maximum distance with respect to "future angle".
                    //"future angle" is the angle of the imaginary line drawn from (x=0, y=0) to calculated future stick position on the x-axis

                    //get radians then get angle.
                    double radians = Math.Atan2(newViewX, newViewY);
                    double angle   = radians * (180 / Math.PI);

                    //calculate the X and Y from maximum distance and "future angle".
                    newViewX = (int)(Math.Sin(angle * (Math.PI / 180)) * maxDistance);
                    //multiply Yposition by -1 to change sign to make y-axis positive on above x-axis and negative under x-axis
                    newViewY = (int)(Math.Cos(angle * (Math.PI / 180)) * maxDistance) * -1;

                    //ReCalculate the future position of the stick, as left,right,top,bottom
                    newLeft   = (int)(newViewX + (int)_originalX);
                    newRight  = (int)(newLeft + v.Width);
                    newTop    = (int)(newViewY + (int)_originalX);
                    newBottom = (int)(newTop + v.Height);
                }

                //change position of "stick view"
                v.Layout(newLeft, newTop, newRight, newBottom);

                //update X and Y from the actual position of "stick view" relative to "SquareLinearLayout".
                UpdateXandY((int)v.GetX(), (int)v.GetY());
                break;
            }
            return(true);
        }
Ejemplo n.º 18
0
 void SetStartingPosition(MotionEvent e1)
 {
     _lastX = e1.GetX();
     _lastY = e1.GetY();
 }
Ejemplo n.º 19
0
        void OnTouch(object sender, Android.Views.View.TouchEventArgs args)
        {
            // Two object common to all the events
            Android.Views.View senderView  = sender as Android.Views.View;
            MotionEvent        motionEvent = args.Event;

            // Get the pointer index
            int pointerIndex = motionEvent.ActionIndex;

            // Get the id that identifies a finger over the course of its progress
            int id = motionEvent.GetPointerId(pointerIndex);


            senderView.GetLocationOnScreen(twoIntArray);
            Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                  twoIntArray[1] + motionEvent.GetY(pointerIndex));


            // Use ActionMasked here rather than Action to reduce the number of possibilities
            switch (args.Event.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                FireEvent(this, id, TouchActionType.Pressed, screenPointerCoords, true);

                idToEffectDictionary.Add(id, this);

                _capture = _pclTouchEffect.Capture;
                break;

            case MotionEventActions.Move:
                // Multiple Move events are bundled, so handle them in a loop
                for (pointerIndex = 0; pointerIndex < motionEvent.PointerCount; pointerIndex++)
                {
                    id = motionEvent.GetPointerId(pointerIndex);

                    if (_capture)
                    {
                        senderView.GetLocationOnScreen(twoIntArray);

                        screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(pointerIndex),
                                                        twoIntArray[1] + motionEvent.GetY(pointerIndex));

                        FireEvent(this, id, TouchActionType.Moved, screenPointerCoords, true);
                    }
                    else
                    {
                        CheckForBoundaryHop(id, screenPointerCoords);

                        if (idToEffectDictionary[id] != null)
                        {
                            FireEvent(idToEffectDictionary[id], id, TouchActionType.Moved, screenPointerCoords, true);
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
                }
                else
                {
                    CheckForBoundaryHop(id, screenPointerCoords);

                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Released, screenPointerCoords, false);
                    }
                }
                idToEffectDictionary.Remove(id);
                break;

            case MotionEventActions.Cancel:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                }
                else
                {
                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
                    }
                }
                idToEffectDictionary.Remove(id);
                break;
            }
        }
Ejemplo n.º 20
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            // only handle the touch if either scroll or zoom is enabled
            if (!ZoomImage.ZoomEnabled && !ZoomImage.ScrollEnabled)
            {
                return(false);
            }

            if (m_GestureDetector.OnTouchEvent(e))
            {
                m_PreviousMoveX = (int)e.GetX();
                m_PreviousMoveY = (int)e.GetY();
                return(true);
            }

            var touchCount = e.PointerCount;
            var handled    = false;

            switch (e.Action)
            {
            case MotionEventActions.Down:
            case MotionEventActions.Pointer1Down:
            case MotionEventActions.Pointer2Down:
                if (touchCount >= 2)
                {
                    if (ZoomImage.ZoomEnabled)
                    {
                        var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1));
                        m_PreviousDistance = distance;
                        m_IsScaling        = true;
                        handled            = true;
                    }
                }
                break;

            case MotionEventActions.Move:
                if (touchCount >= 2 && m_IsScaling)
                {
                    if (ZoomImage.ZoomEnabled)
                    {
                        var distance = this.Distance(e.GetX(0), e.GetX(1), e.GetY(0), e.GetY(1));
                        var scale    = (distance - m_PreviousDistance) / this.DispDistance();
                        m_PreviousDistance = distance;
                        scale += 1;
                        scale  = scale * scale;
                        this.ZoomTo(scale, m_Width / 2, m_Height / 2);
                        this.Cutting();

                        handled = true;
                    }
                }
                else if (!m_IsScaling)
                {
                    if (ZoomImage.ScrollEnabled)
                    {
                        var distanceX = m_PreviousMoveX - (int)e.GetX();
                        var distanceY = m_PreviousMoveY - (int)e.GetY();
                        m_PreviousMoveX = (int)e.GetX();
                        m_PreviousMoveY = (int)e.GetY();

                        m_Matrix.PostTranslate(-distanceX, -distanceY);
                        this.Cutting();

                        handled = true;
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
            case MotionEventActions.Pointer2Up:
                if (touchCount <= 1)
                {
                    m_IsScaling = false;
                    handled     = true;
                }
                break;
            }
            return(handled);
        }
Ejemplo n.º 21
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            TouchLocationState state = TouchLocationState.Invalid;

            if (e.Action == MotionEventActions.Cancel)
            {
                state = TouchLocationState.Invalid;
            }
            if (e.Action == MotionEventActions.Up)
            {
                state                  = TouchLocationState.Released;
                Mouse.State.X          = (int)e.GetX();
                Mouse.State.Y          = (int)e.GetY();
                Mouse.State.LeftButton = ButtonState.Released;
            }
            if (e.Action == MotionEventActions.Move)
            {
                state         = TouchLocationState.Moved;
                Mouse.State.X = (int)e.GetX();
                Mouse.State.Y = (int)e.GetY();
            }
            if (e.Action == MotionEventActions.Down)
            {
                state                  = TouchLocationState.Pressed;
                Mouse.State.X          = (int)e.GetX();
                Mouse.State.Y          = (int)e.GetY();
                Mouse.State.LeftButton = ButtonState.Pressed;
            }

            TouchLocation tprevious;
            TouchLocation tlocation;
            Vector2       position           = new Vector2(e.GetX(), e.GetY());
            Vector2       translatedPosition = position;

            switch (CurrentOrientation)
            {
            case DisplayOrientation.Portrait:
            case DisplayOrientation.LandscapeLeft:
                break;

            case DisplayOrientation.LandscapeRight:
                translatedPosition = new Vector2(ClientBounds.Width - position.X, ClientBounds.Height - position.Y);
                break;
                //case DisplayOrientation.PortraitUpsideDown:
                //   translatedPosition = new Vector2(ClientBounds.Width - position.X, ClientBounds.Height - position.Y);
                break;
            }


            if (state != TouchLocationState.Pressed && _previousTouches.TryGetValue(e.Handle, out tprevious))
            {
                tlocation = new TouchLocation(e.Handle.ToInt32(), state, translatedPosition, e.Pressure, tprevious.State, tprevious.Position, tprevious.Pressure);
            }
            else
            {
                tlocation = new TouchLocation(e.Handle.ToInt32(), state, translatedPosition, e.Pressure);
            }

            TouchPanel.Collection.Clear();
            TouchPanel.Collection.Add(tlocation);
            if (gesture != null)
            {
                gesture.OnTouchEvent(e);
            }

            if (state != TouchLocationState.Released)
            {
                _previousTouches[e.Handle] = tlocation;
            }
            else
            {
                _previousTouches.Remove(e.Handle);
            }

            GamePad.Instance.Update(e);

            return(true);
        }
Ejemplo n.º 22
0
 public override bool OnDoubleTap(MotionEvent e)
 {
     m_ScaleImageView.TapZoomTo((int)e.GetX(), (int)e.GetY());
     m_ScaleImageView.Cutting();
     return(true);
 }
Ejemplo n.º 23
0
        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);


            float y = ev.GetY();
            float x = ev.GetX();

            switch (ev.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 = 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 = 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 ((Math.Abs(initialXVelocity) + Math.Abs(initialYVelocity) > mMinimumVelocity) && ChildCount > 0)
                {
                    fling(-initialXVelocity, -initialYVelocity);
                }
                if (mVelocityTracker != null)
                {
                    mVelocityTracker.Recycle();
                    mVelocityTracker = null;
                }
                break;
            }
            return(true);
        }
 float GetAngle(MotionEvent e)
 {
     return(GetAngle(e.GetX(0), e.GetY(0), e.GetX(1), e.GetY(1)));
 }
Ejemplo n.º 25
0
            public void OnTouchEvent(MotionEvent e)
            {
                switch (e.Action)
                {
                case MotionEventActions.Down:
                case MotionEventActions.Pointer1Down:
                case MotionEventActions.Pointer2Down:
                case MotionEventActions.Pointer3Down:
                {
                    for (Int32 i = 0; i < _Touches.Count; ++i)
                    {
                        if (_Touches[i].Activated)
                        {
                            continue;
                        }

                        var X = e.GetX(e.ActionIndex);
                        var Y = e.GetY(e.ActionIndex);

                        if (
                            X < _Touches[i].Rect.Left ||
                            X > _Touches[i].Rect.Right ||
                            Y <_Touches[i].Rect.Bottom ||
                               Y> _Touches[i].Rect.Top)
                        {
                            continue;
                        }

                        _Touches[i].Activated = true;
                        DownCallback?.Invoke(i, new CPointF(X, Y));
                        break;
                    }
                }
                break;

                case MotionEventActions.Up:
                case MotionEventActions.Pointer1Up:
                case MotionEventActions.Pointer2Up:
                case MotionEventActions.Pointer3Up:
                case MotionEventActions.Cancel:
                case MotionEventActions.Outside:
                {
                    var Index = e.GetPointerId(e.ActionIndex);
                    if (!_Touches[Index].Activated)
                    {
                        break;
                    }

                    UpCallback?.Invoke(Index, new CPointF(e.GetX(e.ActionIndex), e.GetY(e.ActionIndex)));
                    _Touches[Index].Activated = false;
                }
                break;

                case MotionEventActions.Move:
                {
                    var Index = e.GetPointerId(e.ActionIndex);
                    if (!_Touches[Index].Activated)
                    {
                        break;
                    }

                    MoveCallback?.Invoke(Index, new CPointF(e.GetX(e.ActionIndex), e.GetY(e.ActionIndex)));
                }
                break;
                }
            }
 private void ActionDown(MotionEvent e)
 {
     Curvature       = _maxCurvature;
     _fingerX        = e.GetX();
     _isUserTouching = true;
 }
Ejemplo n.º 27
0
                public override bool OnDoubleTap(MotionEvent e)
                {
                    // a double tap CAN create a user note. If it did,
                    // we want to know that so we suppress further input until we receive
                    // TouchUp
                    try
                    {
                        DidGestureCreateNote = Note.DidDoubleTap( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) );
                    }
                    catch( Exception ex )
                    {
                        Springboard.DisplayError( "Notes", ex.Message );
                        DidGestureCreateNote = false;
                    }

                    return true;
                }
Ejemplo n.º 28
0
        public override bool OnTouchEvent(MotionEvent event_)
        {
            mScaleDetector.OnTouchEvent(event_);

            matrix.GetValues(m);
            float  x    = m[Matrix.MtransX];
            float  y    = m[Matrix.MtransY];
            PointF curr = new PointF(event_.GetX(), event_.GetY());

            Log.Debug("TOUCH", event_.Action.ToString(), " mode=" + mode);
            switch (event_.Action)
            {
            //when one finger is touching
            //set the mode to DRAG
            case MotionEventActions.Down:
                last.Set(event_.GetX(), event_.GetY());
                start.Set(last);
                mode = DRAG;
                break;

            //when two fingers are touching
            //set the mode to ZOOM
            case MotionEventActions.Pointer2Down:
            case MotionEventActions.PointerDown:
                last.Set(event_.GetX(), event_.GetY());
                start.Set(last);
                mode = ZOOM;
                break;

            //when a finger moves
            //If mode is applicable move image
            case MotionEventActions.Move:
                //if the mode is ZOOM or
                //if the mode is DRAG and already zoomed
                if (mode == ZOOM || (mode == DRAG && saveScale > minScale))
                {
                    float deltaX      = curr.X - last.X;                                            // x difference
                    float deltaY      = curr.Y - last.Y;                                            // y difference
                    float scaleWidth  = (float)System.Math.Round(originalBitmapWidth * saveScale);  // width after applying current scale
                    float scaleHeight = (float)System.Math.Round(originalBitmapHeight * saveScale); // height after applying current scale

                    bool limitX = false;
                    bool limitY = false;

                    //if scaleWidth is smaller than the views width
                    //in other words if the image width fits in the view
                    //limit left and right movement
                    if (scaleWidth < Width && scaleHeight < Height)
                    {
                        // don't do anything
                    }
                    else if (scaleWidth < Width)
                    {
                        deltaX = 0;
                        limitY = true;
                    }
                    //if scaleHeight is smaller than the views height
                    //in other words if the image height fits in the view
                    //limit up and down movement
                    else if (scaleHeight < Height)
                    {
                        deltaY = 0;
                        limitX = true;
                    }
                    //if the image doesnt fit in the width or height
                    //limit both up and down and left and right
                    else
                    {
                        limitX = true;
                        limitY = true;
                    }

                    if (limitY)
                    {
                        if (y + deltaY > 0)
                        {
                            deltaY = -y;
                        }
                        else if (y + deltaY < -bottom)
                        {
                            deltaY = -(y + bottom);
                        }
                    }

                    if (limitX)
                    {
                        if (x + deltaX > 0)
                        {
                            deltaX = -x;
                        }
                        else if (x + deltaX < -right)
                        {
                            deltaX = -(x + right);
                        }
                    }
                    //move the image with the matrix
                    matrix.PostTranslate(deltaX, deltaY);
                    //set the last touch location to the current
                    last.Set(curr.X, curr.Y);
                }
                break;

            //first finger is lifted
            case MotionEventActions.Up:
                mode = NONE;
                int xDiff = (int)System.Math.Abs(curr.X - start.X);
                int yDiff = (int)System.Math.Abs(curr.Y - start.Y);
                if (xDiff < CLICK && yDiff < CLICK)
                {
                    PerformClick();
                }
                break;

            // second finger is lifted
            case MotionEventActions.Pointer2Up:
            case MotionEventActions.PointerUp:
                mode = NONE;
                break;
            }
            ImageMatrix = matrix;
            Invalidate();
            return(true);
        }
Ejemplo n.º 29
0
                public override bool OnTouch( View v, MotionEvent e )
                {
                    // check to see if we should monitor navBar reveal
                    if ( e.Action == MotionEventActions.Down )
                    {
                        NavBarRevealTracker.BeginTracking( ScrollView.ScrollY );
                    }

                    if ( base.OnTouch( v, e ) == true )
                    {
                        return true;
                    }
                    else
                    {
                        switch ( e.Action )
                        {
                            case MotionEventActions.Move:
                            {
                                // if at any point during a move the task is no longer allowed to receive input,
                                // STOP SCROLLING. It means the user began panning out the view
                                if ( ParentTask.NavbarFragment.ShouldTaskAllowInput( ) == false )
                                {
                                    ScrollView.ScrollEnabled = false;
                                }

                                if ( Note != null )
                                {
                                    Note.TouchesMoved( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) );
                                }

                                break;
                            }

                            case MotionEventActions.Up:
                            {
                                if ( Note != null )
                                {
                                    AnimateTutorialScreen( false );

                                    string activeUrl = Note.TouchesEnded( new System.Drawing.PointF( e.GetX( ), e.GetY( ) ) );

                                    // again, only process this if we didn't create a note. We don't want to treat a double tap
                                    // like a request to view a note
                                    if ( DidGestureCreateNote == false )
                                    {
                                        if ( string.IsNullOrEmpty( activeUrl ) == false )
                                        {
                                            ParentTask.OnClick( this, 0, activeUrl );
                                        }
                                    }
                                }

                                ScrollView.ScrollEnabled = true;
                                MovingUserNote = false;

                                DidGestureCreateNote = false;

                                break;
                            }
                        }
                    }
                    return false;
                }
Ejemplo n.º 30
0
            public override bool OnTouchEvent(MotionEvent e)
            {
                float x1, y1, x2, y2, x, y;

                switch (e.Action)
                {
                case MotionEventActions.Down:
                    this.touchX    = this.startTouchX = e.GetX();
                    this.touchY    = this.startTouchY = e.GetY();
                    this.touchTime = DateTime.Now;
                    return(true);

                case MotionEventActions.Move:
                    switch (e.PointerCount)
                    {
                    case 1:
                        x = e.GetX();
                        y = e.GetY();
                        this.rgView.ScrollCurrentWorksheet((this.touchX - x) / this.rgView.currentWorksheet.renderScaleFactor,
                                                           (this.touchY - y) / this.rgView.currentWorksheet.renderScaleFactor);
                        this.touchX = x;
                        this.touchY = y;
                        this.Invalidate();
                        break;

                    case 2:
                        x1 = e.GetX(0); x2 = e.GetX(1);
                        y1 = e.GetY(0); y2 = e.GetY(0);
                        x  = x2 - x1;
                        y  = y2 - y1;
                        float distance    = (float)Math.Sqrt(x * x + y * y);
                        float scaleChange = (distance - lastDistance) / (100 * this.rgView.baseScale);
                        if (scaleChange != 0)
                        {
                            this.rgView.currentWorksheet.ScaleFactor += scaleChange;
                            lastDistance = distance;
                        }
                        break;
                    }
                    return(true);

                case MotionEventActions.Up:
                    float ms = ((float)(DateTime.Now - this.touchTime).TotalMilliseconds + 0.3f);
                    this.remainX = (this.startTouchX - e.GetX()) / ms;
                    this.remainY = (this.startTouchY - e.GetY()) / ms;

                    if (this.remainX > 1 || this.remainY > 1 ||
                        this.remainX < -1 || this.remainY < -1)
                    {
                        this.remainX *= 15.0f * this.rgView.baseScale;
                        this.remainY *= 15.0f * this.rgView.baseScale;

                        timer.Change(20, 10);
                    }
                    return(true);

                case MotionEventActions.Pointer2Down:
                    x1           = e.GetX(0); x2 = e.GetX(1);
                    y1           = e.GetY(0); y2 = e.GetY(0);
                    x            = x2 - x1;
                    y            = y2 - y1;
                    lastDistance = (float)Math.Sqrt(x * x + y * y);
                    return(true);

                case MotionEventActions.Pointer2Up:
                    return(true);

                case MotionEventActions.Scroll:
                    break;
                }

                //this.scaleDetector.OnTouchEvent(e);
                return(base.OnTouchEvent(e));
            }
Ejemplo n.º 31
0
        public bool dispatchTouchEvent(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();


            switch (ev.Action)
            {
            case MotionEventActions.Down:

                mLastX    = x;
                mLastY    = y;
                mDownTime = Java.Lang.JavaSystem.CurrentTimeMillis();
                mTmpAngle = 0;

                if (isFling)
                {
                    //RemoveCallbacks(mFlingRunnable);
                    isFling = false;
                    return(true);
                }

                break;

            case MotionEventActions.Move:


                float start = getAngle(mLastX, mLastY);

                float end = getAngle(x, y);

                // Console.WriteLine("TAG", "start = " + start + " , end =" + end);
                if (getQuadrant(x, y) == 1 || getQuadrant(x, y) == 4)
                {
                    mStartAngle += end - start;
                    mTmpAngle   += end - start;
                }
                else
                {
                    mStartAngle += start - end;
                    mTmpAngle   += start - end;
                }

                RequestLayout();

                mLastX = x;
                mLastY = y;

                break;

            case MotionEventActions.Up:

                float anglePerSecond2 = mTmpAngle * 1000
                                        / (Java.Lang.JavaSystem.CurrentTimeMillis() - mDownTime);

                // Console.WriteLine("TAG anglePrMillionSecond + "+  mTmpAngle +" =  +"+
                //  mTmpAngle);

                if (Math.Abs(anglePerSecond2) > mFlingableValue && !isFling)
                {
                    AutoFlingEvent AutoFlingPost = new AutoFlingEvent();
                    AutoFlingPost.AutoFlingFinished += OnAutoFlingFinished;
                    // new CircleMenuEventArgs() { velocity = anglePerSecond2 };
                    // AutoFlingHandler.Post(mFlingRunnable = (new AutoFlingEvent.AutoFlingDelegate(anglePerSecond2)));

                    return(true);
                }

                if (Math.Abs(mTmpAngle) > NOCLICK_VALUE)
                {
                    return(true);
                }

                break;
            }
            return(true);
            // return base.DispatchTouchEvent(ev);
        }
Ejemplo n.º 32
0
 public virtual Point GetAvaloniaPointFromEvent(MotionEvent e) => new Point(e.GetX(), e.GetY());
 public override bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
 {
     bool result = false;
     try {
         float diffY = e2.GetY() - e1.GetY();
         float diffX = e2.GetX() - e1.GetX();
         if (Math.Abs(diffX) > Math.Abs(diffY)) {
             if (Math.Abs(diffX) > SWIPE_THRESHOLD && Math.Abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
                 if (diffX > 0) {
                     result = listener.OnSwipeRight();
                 } else {
                     result = listener.OnSwipeLeft();
                 }
             }
         } else {
             if (Math.Abs(diffY) > SWIPE_THRESHOLD && Math.Abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
                 if (diffY > 0) {
                     result = listener.OnSwipeBottom();
                 } else {
                     result = listener.OnSwipeTop();
                 }
             }
         }
     } catch (Exception exception) {
         // exception.PrintStackTrace();
     }
     return result;
 }
        public bool OnTouchEvent(View view, MotionEvent Event)
        {
            try
            {
                var action = Event.ActionMasked;
                if (action == MotionEventActions.Down)
                {
                    Reset(); // Start fresh
                }

                bool handled = true;
                if (MInvalidGesture)
                {
                    handled = false;
                }
                else if (!MGestureInProgress)
                {
                    switch (action)
                    {
                    case MotionEventActions.Down:
                    {
                        MActiveId0         = Event.GetPointerId(0);
                        MActive0MostRecent = true;
                    }
                    break;

                    case MotionEventActions.Up:
                        Reset();
                        break;

                    case MotionEventActions.PointerDown:
                    {
                        // We have a new multi-finger gesture
                        if (MPrevEvent != null)
                        {
                            MPrevEvent.Recycle();
                        }
                        MPrevEvent = MotionEvent.Obtain(Event);
                        MTimeDelta = 0;

                        int index1 = Event.ActionIndex;
                        int index0 = Event.FindPointerIndex(MActiveId0);
                        MActiveId1 = Event.GetPointerId(index1);
                        if (index0 < 0 || index0 == index1)
                        {
                            // Probably someone sending us a broken Event stream.
                            index0     = FindNewActiveIndex(Event, MActiveId1, -1);
                            MActiveId0 = Event.GetPointerId(index0);
                        }

                        MActive0MostRecent = false;

                        SetContext(view, Event);

                        MGestureInProgress = MListener.OnScaleBegin(view, this);
                        break;
                    }
                    }
                }
                else
                {
                    // Transform gesture in progress - attempt to handle it
                    switch (action)
                    {
                    case MotionEventActions.PointerDown:
                    {
                        // End the old gesture and begin a new one with the most recent two fingers.
                        MListener.OnScaleEnd(view, this);
                        int oldActive0 = MActiveId0;
                        int oldActive1 = MActiveId1;
                        Reset();

                        MPrevEvent         = MotionEvent.Obtain(Event);
                        MActiveId0         = MActive0MostRecent ? oldActive0 : oldActive1;
                        MActiveId1         = Event.GetPointerId(Event.ActionIndex);
                        MActive0MostRecent = false;

                        int index0 = Event.FindPointerIndex(MActiveId0);
                        if (index0 < 0 || MActiveId0 == MActiveId1)
                        {
                            // Probably someone sending us a broken Event stream.
                            index0     = FindNewActiveIndex(Event, MActiveId1, -1);
                            MActiveId0 = Event.GetPointerId(index0);
                        }

                        SetContext(view, Event);

                        MGestureInProgress = MListener.OnScaleBegin(view, this);
                    }
                    break;

                    case MotionEventActions.PointerUp:
                    {
                        int pointerCount = Event.PointerCount;
                        int actionIndex  = Event.ActionIndex;
                        int actionId     = Event.GetPointerId(actionIndex);

                        bool gestureEnded = false;
                        if (pointerCount > 2)
                        {
                            if (actionId == MActiveId0)
                            {
                                int newIndex = FindNewActiveIndex(Event, MActiveId1, actionIndex);
                                if (newIndex >= 0)
                                {
                                    MListener.OnScaleEnd(view, this);
                                    MActiveId0         = Event.GetPointerId(newIndex);
                                    MActive0MostRecent = true;
                                    MPrevEvent         = MotionEvent.Obtain(Event);
                                    SetContext(view, Event);
                                    MGestureInProgress = MListener.OnScaleBegin(view, this);
                                }
                                else
                                {
                                    gestureEnded = true;
                                }
                            }
                            else if (actionId == MActiveId1)
                            {
                                int newIndex = FindNewActiveIndex(Event, MActiveId0, actionIndex);
                                if (newIndex >= 0)
                                {
                                    MListener.OnScaleEnd(view, this);
                                    MActiveId1         = Event.GetPointerId(newIndex);
                                    MActive0MostRecent = false;
                                    MPrevEvent         = MotionEvent.Obtain(Event);
                                    SetContext(view, Event);
                                    MGestureInProgress = MListener.OnScaleBegin(view, this);
                                }
                                else
                                {
                                    gestureEnded = true;
                                }
                            }

                            MPrevEvent.Recycle();
                            MPrevEvent = MotionEvent.Obtain(Event);
                            SetContext(view, Event);
                        }
                        else
                        {
                            gestureEnded = true;
                        }

                        if (gestureEnded)
                        {
                            // Gesture ended
                            SetContext(view, Event);

                            // Set focus point to the remaining finger
                            int activeId = actionId == MActiveId0 ? MActiveId1 : MActiveId0;
                            int index    = Event.FindPointerIndex(activeId);
                            MFocusX = Event.GetX(index);
                            MFocusY = Event.GetY(index);

                            MListener.OnScaleEnd(view, this);
                            Reset();
                            MActiveId0         = activeId;
                            MActive0MostRecent = true;
                        }
                    }
                    break;

                    case MotionEventActions.Cancel:
                        MListener.OnScaleEnd(view, this);
                        Reset();
                        break;

                    case MotionEventActions.Up:
                        Reset();
                        break;

                    case MotionEventActions.Move:
                    {
                        SetContext(view, Event);

                        // Only accept the Event if our relative pressure is within
                        // a certain limit - this can help filter shaky data as a
                        // finger is lifted.
                        if (MCurrPressure / MPrevPressure > PressureThreshold)
                        {
                            bool updatePrevious = MListener.OnScale(view, this);

                            if (updatePrevious)
                            {
                                MPrevEvent.Recycle();
                                MPrevEvent = MotionEvent.Obtain(Event);
                            }
                        }
                    }
                    break;
                    }
                }

                return(handled);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(false);
            }
        }