public override bool OnTouchEvent(MotionEvent e)
        {
            //System.Diagnostics.Debug.WriteLine("=============================================================");
            //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent e.Action=[" + e.Action + "]");
            bool handled = base.OnTouchEvent(e);

            //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent handled=" + handled);

            if (e.PointerCount > 1 && _listener != null)
            {
                // multi point gesture ?
                bool[] valid = new bool[6];
                MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[6];
                for (int i = 0; i < Math.Min(e.PointerCount, 6); i++)
                {
                    coords[i] = new MotionEvent.PointerCoords();
                    var index = e.FindPointerIndex(i);
                    if (index > -1 && index < 6)
                    {
                        valid[index] = true;
                        e.GetPointerCoords(index, coords[i]);
                        if (_lastCoords != null && _lastCoords[i] != null)
                        {
                            _avgCoords[i].X = (float)((coords[i].X + _lastCoords[i].X) / 2.0);
                            _avgCoords[i].Y = (float)((coords[i].Y + _lastCoords[i].Y) / 2.0);
                        }
                        _lastCoords = coords;
                    }
                }

                if (e.Action == MotionEventActions.Down || e.Action == MotionEventActions.Pointer1Down || e.Action == MotionEventActions.Pointer2Down)
                {
                    handled = handled || _listener.OnMultiDown(e, _lastCoords);
                }
                else if (e.Action == MotionEventActions.Move)
                {
                    handled = handled || _listener.OnMultiMove(e, _avgCoords);
                }
                else if (e.Action == MotionEventActions.Cancel || e.Action == MotionEventActions.Up || e.Action == MotionEventActions.Pointer1Up || e.Action == MotionEventActions.Pointer2Up)
                {
                    handled     = handled || _listener.OnMultiUp(e, _avgCoords);
                    _lastCoords = null;
                }
            }
            // the following line was once needed but now it seems to cause double "UPS" to be called when used with Bc3.Forms.KeypadButton;
            //else if (e.ActionMasked == MotionEventActions.Up || e.ActionMasked == MotionEventActions.Pointer1Up || (e.Action == MotionEventActions.Down && _lastMotionEvent != null && _lastMotionEvent.Action == MotionEventActions.Down))
            else if (e.ActionMasked == MotionEventActions.Up || e.ActionMasked == MotionEventActions.Pointer1Up)
            {
                _listener?.OnUp(e);
            }
            else if (e.Action == MotionEventActions.Cancel)
            {
                _listener?.Cancel(e);
            }
            else if (e.Action == MotionEventActions.Move)
            {
                handled = handled || _listener.HandlesMove;
            }


            _lastMotionEvent = e;
            //System.Diagnostics.Debug.WriteLine("NativeGestureDetector.OnTouchEvent handled=" + handled);
            return(handled);
        }
示例#2
0
        public override bool OnTouchEvent(MotionEvent motionEvent)
        {
            lock (this) {
                if (_baseMapView == null)
                {
                    return(false);
                }

                bool clickable = Clickable || LongClickable;
                if (!Enabled || !clickable)
                {
                    return(clickable);
                }

                try {
                    int pointer1Index;
                    int pointer2Index;
                    switch (motionEvent.ActionMasked)
                    {
                    case MotionEventActions.Down:
                        pointer1Index = motionEvent.ActionIndex;
                        _pointer1Id   = motionEvent.GetPointerId(pointer1Index);
                        _baseMapView.OnInputEvent(NativeActionPointer1Down,
                                                  motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                  NativeNoCoordinate, NativeNoCoordinate);
                        break;

                    case MotionEventActions.PointerDown:
                        if (motionEvent.PointerCount == 2)
                        {
                            // Check which pointer to use
                            if (_pointer1Id != InvalidPointerId)
                            {
                                pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                                pointer2Index = motionEvent.ActionIndex;
                                _pointer2Id   = motionEvent.GetPointerId(motionEvent.ActionIndex);
                            }
                            else if (_pointer2Id != InvalidPointerId)
                            {
                                pointer2Index = motionEvent.FindPointerIndex(_pointer2Id);
                                pointer1Index = motionEvent.ActionIndex;
                                _pointer1Id   = motionEvent.GetPointerId(motionEvent.ActionIndex);
                            }
                            else
                            {
                                break;
                            }
                            _baseMapView.OnInputEvent(NativeActionPointer2Down,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      motionEvent.GetX(pointer2Index), motionEvent.GetY(pointer2Index));
                        }
                        break;

                    case MotionEventActions.Move:
                        if (_pointer1Id != InvalidPointerId && _pointer2Id == InvalidPointerId)
                        {
                            pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                            _baseMapView.OnInputEvent(NativeActionMove,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      NativeNoCoordinate, NativeNoCoordinate);
                        }
                        else if (_pointer1Id != InvalidPointerId && _pointer2Id != InvalidPointerId)
                        {
                            pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                            pointer2Index = motionEvent.FindPointerIndex(_pointer2Id);
                            _baseMapView.OnInputEvent(NativeActionMove,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      motionEvent.GetX(pointer2Index), motionEvent.GetY(pointer2Index));
                        }
                        break;

                    case MotionEventActions.Cancel:
                        _baseMapView.OnInputEvent(NativeActionCancel,
                                                  NativeNoCoordinate, NativeNoCoordinate,
                                                  NativeNoCoordinate, NativeNoCoordinate);
                        _pointer1Id = InvalidPointerId;
                        _pointer2Id = InvalidPointerId;
                        break;

                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                        int pointerIndex = motionEvent.ActionIndex;
                        int pointerId    = motionEvent.GetPointerId(pointerIndex);
                        // Single pointer
                        if (_pointer1Id == pointerId && _pointer2Id == InvalidPointerId)
                        {
                            pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                            _baseMapView.OnInputEvent(NativeActionPointer1Up,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      NativeNoCoordinate, NativeNoCoordinate);
                            _pointer1Id = InvalidPointerId;
                            // Dual pointer, first pointer up
                        }
                        else if (_pointer1Id == pointerId)
                        {
                            pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                            pointer2Index = motionEvent.FindPointerIndex(_pointer2Id);
                            _baseMapView.OnInputEvent(NativeActionPointer1Up,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      motionEvent.GetX(pointer2Index), motionEvent.GetY(pointer2Index));
                            _pointer1Id = _pointer2Id;
                            _pointer2Id = InvalidPointerId;
                            // Dual pointer, second finger up
                        }
                        else if (_pointer2Id == pointerId)
                        {
                            pointer1Index = motionEvent.FindPointerIndex(_pointer1Id);
                            pointer2Index = motionEvent.FindPointerIndex(_pointer2Id);
                            _baseMapView.OnInputEvent(NativeActionPointer2Up,
                                                      motionEvent.GetX(pointer1Index), motionEvent.GetY(pointer1Index),
                                                      motionEvent.GetX(pointer2Index), motionEvent.GetY(pointer2Index));
                            _pointer2Id = InvalidPointerId;
                        }
                        break;
                    }
                } catch (Java.Lang.Exception e) {
                    Carto.Utils.Log.Error("MapView.OnTouchEvent: Java exception: " + e);
                } catch (System.Exception e) {
                    Carto.Utils.Log.Error("MapView.OnTouchEvent: Exception: " + e);
                }
                return(true);
            }
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            _scaleDetector.OnTouchEvent(ev);

            MotionEventActions action = ev.Action & MotionEventActions.Mask;
            int pointerIndex;

            switch (action)
            {
            case MotionEventActions.Down:
                _lastTouchX      = ev.GetX();
                _lastTouchY      = ev.GetY();
                _activePointerId = ev.GetPointerId(0);
                break;

            case MotionEventActions.Move:
                pointerIndex = ev.FindPointerIndex(_activePointerId);
                float x = ev.GetX(pointerIndex);
                float y = ev.GetY(pointerIndex);
                if (!_scaleDetector.IsInProgress)
                {
                    // Only move the ScaleGestureDetector isn't already processing a gesture.
                    float deltaX = x - _lastTouchX;
                    float deltaY = y - _lastTouchY;
                    _posX += deltaX;
                    _posY += deltaY;

                    //ADDITION
                    StickerXLocation = _posX;
                    StickerYLocation = _posY;

                    Invalidate();
                }

                _lastTouchX = x;
                _lastTouchY = y;

                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                // This events occur when something cancels the gesture (for example the
                // activity going in the background) or when the pointer has been lifted up.
                // We no longer need to keep track of the active pointer.
                _activePointerId = InvalidPointerId;
                break;

            case MotionEventActions.PointerUp:

                // We only want to update the last touch position if the the appropriate pointer
                // has been lifted off the screen.
                pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId = ev.GetPointerId(pointerIndex);
                if (pointerId == _activePointerId)
                {
                    // This was our active pointer going up. Choose a new
                    // action pointer and adjust accordingly
                    int newPointerIndex = pointerIndex == 0 ? 1 : 0;

                    _lastTouchX      = ev.GetX(newPointerIndex);
                    _lastTouchY      = ev.GetY(newPointerIndex);
                    _activePointerId = ev.GetPointerId(newPointerIndex);
                }
                break;
            }
            return(true);
        }
        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);
        }
示例#5
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            try
            {
                OnTouchEventWorkingArray[0] = ev.GetX();                                         //Set the  MotionEvent X
                OnTouchEventWorkingArray[1] = ev.GetY();                                         //And Y for transformation

                OnTouchEventWorkingArray = ScaledPointsToScreenPoints(OnTouchEventWorkingArray); //Will Transform the OnTouchEventWrkingArray In place.

                ev.SetLocation(OnTouchEventWorkingArray[0], OnTouchEventWorkingArray[1]);
                ScaleDetector.OnTouchEvent(ev);

                MotionEventActions action = ev.Action;
                switch (action & ev.ActionMasked)
                {
                case MotionEventActions.Down:
                {
                    float x = ev.GetX();
                    float y = ev.GetY();

                    PositionOfLastTouchOnXAxis = x;
                    PositionOfLastTouchOnYAxis = y;

                    // Save the ID of this pointer
                    ActivePointerId = ev.GetPointerId(0);
                    break;
                }

                case MotionEventActions.Move:
                {
                    // Find the index of the active pointer and fetch its position
                    int   pointerIndex = ev.FindPointerIndex(ActivePointerId);
                    float x            = ev.GetX(pointerIndex);
                    float y            = ev.GetY(pointerIndex);

                    float dx = x - PositionOfLastTouchOnXAxis;
                    float dy = y - PositionOfLastTouchOnYAxis;

                    PositionOnXAxis += dx;
                    PositionOnYAxis += dy;
                    TranslateMatrix.PreTranslate(dx, dy);
                    TranslateMatrix.Invert(TranslateMatrixInverse);

                    PositionOfLastTouchOnXAxis = x;
                    PositionOfLastTouchOnYAxis = y;

                    Invalidate();
                    break;
                }

                case MotionEventActions.Up:
                {
                    ActivePointerId = INVALID_POINTER_ID;
                    break;
                }

                case MotionEventActions.Cancel:
                {
                    ActivePointerId = INVALID_POINTER_ID;
                    break;
                }

                case MotionEventActions.PointerUp:
                {
                    // Extract the index of the pointer that left the touch sensor
                    int pointerIndex = (ev.ActionIndex & PointerIndexMask) >> PointerIndexShift;
                    int pointerId    = ev.GetPointerId(pointerIndex);
                    if (pointerId == ActivePointerId)
                    {
                        // This was our active pointer going up. Choose a new
                        // active pointer and adjust accordingly.
                        int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                        PositionOfLastTouchOnXAxis = ev.GetX(newPointerIndex);
                        PositionOfLastTouchOnYAxis = ev.GetY(newPointerIndex);
                        ActivePointerId            = ev.GetPointerId(newPointerIndex);
                    }
                    break;
                }
                }
                return(true);
            }
            catch (Exception)
            {
                return(true);
            }
        }
        /// <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.Min)
                        {
                            OnLowerValueChanged();
                        }
                        if (_pressedThumb == Thumb.Max)
                        {
                            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();
                }

                _pressedThumb = null;
                Invalidate();
                if (_pressedThumb == Thumb.Min)
                {
                    OnLowerValueChanged();
                }
                if (_pressedThumb == Thumb.Max)
                {
                    OnUpperValueChanged();
                }
                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);
        }
        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);
            }
        }
示例#8
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            mScaleDetector.OnTouchEvent(e);
            mgestureDetector.OnTouchEvent(e);

            //int action = e.Action;
            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
                //if(!mScaleDetector.IsInProgress)
            {
                float x = e.GetX();
                float y = e.GetY();

                mLastTouchX      = x;
                mLastTouchY      = y;
                mActivePointerId = e.GetPointerId(0);

                //Console.WriteLine("DOWN: x=" + x + "y=" + y);
            }
                //Parent.RequestDisallowInterceptTouchEvent(true);
                break;

            case MotionEventActions.PointerDown:
                //if(mScaleDetector.IsInProgress)
            {
                float gx = mScaleDetector.FocusX;
                float gy = mScaleDetector.FocusY;

                mLastGestureX = gx;
                mLastGestureY = gy;
            }
            break;

            case MotionEventActions.Move:
                if (!mScaleDetector.IsInProgress)
                {
                    int   pointerIdx = e.FindPointerIndex(mActivePointerId);
                    float x          = e.GetX(pointerIdx);
                    float y          = e.GetY(pointerIdx);

                    float dx = x - mLastTouchX;
                    float dy = y - mLastTouchY;

                    mPosX += dx;
                    mPosY += dy;

                    //translateX = dx;
                    //translateY = dx;

                    Invalidate();

                    mLastTouchX = x;
                    mLastTouchY = y;

                    //Console.WriteLine("MOVE: x=" + x + "y=" + y + "dx=" + dx + "dy=" + dy);
                }
                else
                {
                    float gx = mScaleDetector.FocusX;
                    float gy = mScaleDetector.FocusY;

                    float gdx = gx - mLastGestureX;
                    float gdy = gy - mLastGestureY;

                    mPosX += gdx;
                    mPosY += gdy;

                    Invalidate();

                    mLastGestureX = gx;
                    mLastGestureY = gy;
                }
                break;

            case MotionEventActions.Up:
                mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.Cancel:
                mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.PointerUp:

                int pointerIdx2 = (int)(e.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId   = e.GetPointerId(pointerIdx2);

                if (pointerId == mActivePointerId)
                {
                    int NewPointerIndex = pointerIdx2 == 0 ? 1 : 0;
                    mLastTouchX      = e.GetX(NewPointerIndex);
                    mLastTouchY      = e.GetY(NewPointerIndex);
                    mActivePointerId = e.GetPointerId(NewPointerIndex);
                }
                else
                {
                    int TempPointerIdx = e.FindPointerIndex(mActivePointerId);
                    mLastTouchX = e.GetX(TempPointerIdx);
                    mLastTouchY = e.GetY(TempPointerIdx);
                }

                break;
            }
            return(true);
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            Log.Debug("PullToZoomScrollView", "onTouchEvent --> action = " + (0xFF & (int)ev.Action));
            if (_isHeaderTop && _isEnableZoom)
            {
                switch ((MotionEventActions)0xFF & ev.Action)
                {
                case MotionEventActions.Down:
                case MotionEventActions.Outside:
                    if (!_scalingRunnable.IsFinished())
                    {
                        _scalingRunnable.AbortAnimation();
                    }
                    _lastMotionY     = ev.GetY();
                    _activePointerId = ev.GetPointerId(0);
                    _maxScale        = (_screenHeight / _zoomHeight);
                    _lastScale       = (_zoomContainer.Bottom / _zoomHeight);
                    if (_onScrollViewZoomListener != null)
                    {
                        _onScrollViewZoomListener.onStart();
                    }
                    break;

                case MotionEventActions.Move:
                    Log.Debug("PullToZoomScrollView", "_activePointerId = " + _activePointerId);
                    int j = ev.FindPointerIndex(_activePointerId);
                    if (j == -1)
                    {
                        Log.Error("PullToZoomScrollView", "Invalid pointerId = " + _activePointerId + " in onTouchEvent");
                    }
                    else
                    {
                        if (_lastMotionY == -1.0F)
                        {
                            _lastMotionY = ev.GetY(j);
                        }
                        if (_zoomContainer.Bottom >= _zoomHeight)
                        {
                            FrameLayout.LayoutParams localLayoutParams = (FrameLayout.LayoutParams)_zoomContainer.LayoutParameters;
                            ViewGroup.LayoutParams   headLayoutParams  = _headerContainer.LayoutParameters;
                            float f = ((ev.GetY(j) - _lastMotionY + _zoomContainer.Bottom) / _zoomHeight - _lastScale) / 2.0F + _lastScale;
                            if ((_lastScale <= 1.0D) && (f < _lastScale))
                            {
                                localLayoutParams.Height          = _zoomHeight;
                                localLayoutParams.Width           = _zoomWidth;
                                localLayoutParams.Gravity         = GravityFlags.Center;
                                headLayoutParams.Height           = _zoomHeight;
                                _zoomContainer.LayoutParameters   = localLayoutParams;
                                _headerContainer.LayoutParameters = headLayoutParams;
                                return(base.OnTouchEvent(ev));
                            }
                            _lastScale = Math.Min(Math.Max(f, 1.0F), _maxScale);
                            localLayoutParams.Height  = ((int)(_zoomHeight * _lastScale));
                            localLayoutParams.Width   = ((int)(_zoomWidth * _lastScale));
                            localLayoutParams.Gravity = GravityFlags.Center;
                            headLayoutParams.Height   = ((int)(_zoomHeight * _lastScale));
                            if (localLayoutParams.Height < _screenHeight)
                            {
                                _zoomContainer.LayoutParameters   = localLayoutParams;
                                _headerContainer.LayoutParameters = headLayoutParams;
                            }
                            _lastMotionY = ev.GetY(j);
                            return(true);
                        }
                        _lastMotionY = ev.GetY(j);
                    }
                    break;

                case MotionEventActions.Up:
                    Reset();
                    EndScaling();
                    if (_onScrollViewZoomListener != null)
                    {
                        _onScrollViewZoomListener.onFinish();
                    }
                    break;

                case MotionEventActions.Cancel:
                    int i = ev.ActionIndex;
                    _lastMotionY     = ev.GetY(i);
                    _activePointerId = ev.GetPointerId(i);
                    break;

                case MotionEventActions.PointerDown:
                    OnSecondaryPointerUp(ev);
                    _lastMotionY = ev.GetY(ev.FindPointerIndex(_activePointerId));
                    break;
                }
            }
            return(base.OnTouchEvent(ev));
        }
        public override bool OnTouchEvent(MotionEvent ev)
        {
            int action = ev.ActionIndex;

            switch (ev.Action)
            {
            case MotionEventActions.Down:
            {
                float x = ev.GetX();
                float y = ev.GetY();

                mLastTouchX = x;
                mLastTouchY = y;

                // Save the ID of this pointer
                mActivePointerId = ev.GetPointerId(0);
                break;
            }

            case MotionEventActions.Move:
            {
                // Find the index of the active pointer and fetch its position
                int   pointerIndex = ev.FindPointerIndex(mActivePointerId);
                float x            = ev.GetX(pointerIndex);
                float y            = ev.GetY(pointerIndex);

                if (m_isScaling && ev.PointerCount == 1)
                {
                    // Don't move during a QuickScale.
                    mLastTouchX = x;
                    mLastTouchY = y;

                    break;
                }

                float dx = x - mLastTouchX;
                float dy = y - mLastTouchY;

                float[] topLeft     = { 0f, 0f };
                float[] bottomRight = { Width, Height };

                /*
                 * Corners of the view in screen coordinates, so dx/dy should not be allowed to
                 * push these beyond the canvas bounds.
                 */
                float[] scaledTopLeft     = screenPointsToScaledPoints(topLeft);
                float[] scaledBottomRight = screenPointsToScaledPoints(bottomRight);

                dx = Math.Min(Math.Max(dx, scaledBottomRight[0] - mCanvasWidth), scaledTopLeft[0]);
                dy = Math.Min(Math.Max(dy, scaledBottomRight[1] - mCanvasHeight), scaledTopLeft[1]);

                mPosX += dx;
                mPosY += dy;

                mTranslateMatrix.PreTranslate(dx, dy);
                mTranslateMatrix.Invert(mTranslateMatrixInverse);

                mLastTouchX = x;
                mLastTouchY = y;

                Invalidate();
                break;
            }

            case MotionEventActions.Up:
            {
                mActivePointerId = INVALID_POINTER_ID;
                break;
            }

            case MotionEventActions.Cancel:
            {
                mActivePointerId = INVALID_POINTER_ID;
                break;
            }

            case MotionEventActions.Pointer1Up:
            {
                // Extract the index of the pointer that left the touch sensor
                int pointerIndex = ev.ActionIndex;
                int pointerId    = ev.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      = ev.GetX(newPointerIndex);
                    mLastTouchY      = ev.GetY(newPointerIndex);
                    mActivePointerId = ev.GetPointerId(newPointerIndex);
                }
                break;
            }
            }
            Invalidate();
            return(true);
        }
示例#11
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            Log.Debug("PullToZoomListView", "action = " + (0xFF & (int)e.Action));
            if (_headerView != null && !_isHideHeader && _isEnableZoom)
            {
                switch ((MotionEventActions)0xFF & e.Action)
                {
                case MotionEventActions.Down:
                case MotionEventActions.Outside:
                    if (!_scalingRunnable.IsFinished())
                    {
                        _scalingRunnable.AbortAnimation();
                    }
                    _lastMotionY     = e.GetY();
                    _activePointerId = e.GetPointerId(0);
                    _maxScale        = (_screenHeight / _headerHeight);
                    _lastScale       = (_headerContainer.Bottom / _headerHeight);
                    break;

                case MotionEventActions.Move:
                    Log.Debug("PullToZoomListView", "_activePointerId" + _activePointerId);
                    int j = e.FindPointerIndex(_activePointerId);
                    if (j == -1)
                    {
                        Log.Error("PullToZoomListView", "Invalid pointerId=" + _activePointerId + " in onTouchEvent");
                    }
                    else
                    {
                        if (_lastMotionY == -1.0F)
                        {
                            _lastMotionY = e.GetY(j);
                        }
                        if (_headerContainer.Bottom >= _headerHeight)
                        {
                            ViewGroup.LayoutParams localLayoutParams = _headerContainer.LayoutParameters;
                            float f = ((e.GetY(j) - _lastMotionY + _headerContainer.Bottom) / _headerHeight - _lastScale) / 2.0F + _lastScale;
                            if ((_lastScale <= 1.0D) && (f < _lastScale))
                            {
                                localLayoutParams.Height          = _headerHeight;
                                _headerContainer.LayoutParameters = localLayoutParams;
                                return(base.OnTouchEvent(e));
                            }
                            _lastScale = Java.Lang.Math.Min(Java.Lang.Math.Max(f, 1.0F), _maxScale);
                            localLayoutParams.Height = ((int)(_headerHeight * _lastScale));
                            if (localLayoutParams.Height < _screenHeight)
                            {
                                _headerContainer.LayoutParameters = localLayoutParams;
                            }
                            _lastMotionY = e.GetY(j);
                            return(true);
                        }
                        _lastMotionY = e.GetY(j);
                    }
                    break;

                case MotionEventActions.Up:
                    Reset();
                    EndScaling();
                    break;

                case MotionEventActions.Cancel:
                    int i = e.ActionIndex;
                    _lastMotionY     = e.GetY(i);
                    _activePointerId = e.GetPointerId(i);
                    break;

                case MotionEventActions.PointerDown:
                    OnSecondaryPointerUp(e);
                    _lastMotionY = e.GetY(e.FindPointerIndex(_activePointerId));
                    break;
                }
            }
            return(base.OnTouchEvent(e));
        }
示例#12
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            var action = ev.Action;

            if (_returningToStart && action == MotionEventActions.Down)
            {
                _returningToStart = false;
            }

            if (!Enabled || _returningToStart || CanChildScrollUp())
            {
                // Fail fast if we're not in a state where a swipe is possible
                return(false);
            }

            switch (action)
            {
            case MotionEventActions.Down:
                _activePointerId = ev.GetPointerId(0);
                _isBeingDragged  = false;
                break;

            case MotionEventActions.Move:
                var pointerIndex = ev.FindPointerIndex(_activePointerId);
                if (pointerIndex < 0)
                {
                    Log.Error(LogTag, "Got ACTION_MOVE event but have an invalid active pointer id.");
                    return(false);
                }

                var y             = ev.GetY(pointerIndex);
                var overscrollTop = (y - _initialMotionY) * DragRate;
                if (_isBeingDragged)
                {
                    _progress.ShowArrow(true);
                    var originalDragPercent = overscrollTop / _totalDragDistance;
                    if (originalDragPercent < 0)
                    {
                        return(false);
                    }

                    var dragPercent     = System.Math.Min(1f, System.Math.Abs(originalDragPercent));
                    var adjustedPercent = (float)System.Math.Max(dragPercent - .4, 0) * 5 / 3;
                    var extraOS         = System.Math.Abs(overscrollTop) - _totalDragDistance;
                    var slingshotDist   = _usingCustomStart
                            ? _spinnerFinalOffset
                                          - OriginalOffsetTop
                            : _spinnerFinalOffset;
                    var tensionSlingshotPercent = System.Math.Max(0,
                                                                  System.Math.Min(extraOS, slingshotDist * 2) / slingshotDist);
                    var tensionPercent = (float)((tensionSlingshotPercent / 4) - System.Math.Pow(
                                                     (tensionSlingshotPercent / 4), 2)) * 2f;
                    var extraMove = (slingshotDist) * tensionPercent * 2;

                    var targetY = OriginalOffsetTop
                                  + (int)((slingshotDist * dragPercent) + extraMove);
                    // where 1.0f is a full circle
                    if (_circleView.Visibility != ViewStates.Visible)
                    {
                        _circleView.Visibility = ViewStates.Visible;
                    }

                    if (!_scale)
                    {
                        ViewCompat.SetScaleX(_circleView, 1f);
                        ViewCompat.SetScaleY(_circleView, 1f);
                    }

                    if (overscrollTop < _totalDragDistance)
                    {
                        if (_scale)
                        {
                            SetAnimationProgress(overscrollTop / _totalDragDistance);
                        }

                        if (_progress.Alpha > StartingProgressAlpha &&
                            !IsAnimationRunning(_alphaStartAnimation))
                        {
                            // Animate the alpha
                            StartProgressAlphaStartAnimation();
                        }

                        var strokeStart = adjustedPercent * .8f;
                        _progress.SetStartEndTrim(0f, System.Math.Min(MaxProgressAngle, strokeStart));
                        _progress.SetArrowScale(System.Math.Min(1f, adjustedPercent));
                    }
                    else
                    {
                        if (_progress.Alpha < MaxAlpha &&
                            !IsAnimationRunning(_alphaMaxAnimation))
                        {
                            // Animate the alpha
                            StartProgressAlphaMaxAnimation();
                        }
                    }

                    var rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
                    _progress.SetProgressRotation(rotation);
                    SetTargetOffsetTopAndBottom(targetY - _currentTargetOffsetTop,
                                                true /* requires update */);
                }

                break;

            //case MotionEventActions.Down:
            //    int index = ev.ActionIndex;
            //    mActivePointerId = ev.GetPointerId(index);
            //    break;


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

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
            {
                if (_activePointerId == InvalidPointer)
                {
                    if (action == MotionEventActions.Up)
                    {
                        Log.Error(LogTag, "Got ACTION_UP event but don't have an active pointer id.");
                    }

                    return(false);
                }

                var pointerIndex0  = ev.FindPointerIndex(_activePointerId);
                var y0             = ev.GetY(pointerIndex0);
                var overscrollTop0 = (y0 - _initialMotionY) * DragRate;
                _isBeingDragged = false;
                if (overscrollTop0 > _totalDragDistance)
                {
                    SetRefreshing(true, true /* notify */);
                }
                else
                {
                    // cancel refresh
                    _refreshing = false;
                    _progress.SetStartEndTrim(0f, 0f);
                    IAnimationListener listener = null;
                    if (!_scale)
                    {
                        listener = new CustomCancelListener(this);
                    }

                    AnimateOffsetToStartPosition(_currentTargetOffsetTop, listener);
                    _progress.ShowArrow(false);
                }

                _activePointerId = InvalidPointer;
                return(false);
            }
            }

            return(true);
        }
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (!MainBuildingFragment.CheckFocus())
            {
                Utils.Utils.HideKeyboard(this, Context);
            }

            var action = e.Action & MotionEventActions.Mask;
            int pointerIndex;

            switch (action)
            {
            case MotionEventActions.Down:
                lastTouchX      = e.GetX();
                lastTouchY      = e.GetY();
                activePointerId = e.GetPointerId(0);
                break;

            case MotionEventActions.Move:
                pointerIndex = e.FindPointerIndex(activePointerId);
                var x = e.GetX(pointerIndex);
                var y = e.GetY(pointerIndex);

                var deltaX = x - lastTouchX;
                var deltaY = y - lastTouchY;
                PosX += deltaX;
                PosY += deltaY;

                var planScaleWidth  = imageWidth * ScaleFactor;
                var planScaleHeight = imageHeight * ScaleFactor;

                var right  = PosX + planScaleWidth;
                var left   = PosX;
                var top    = PosY;
                var bottom = PosY + planScaleHeight;

#if DEBUG
                LogCurrentCoordinates(right, left, top, bottom);     //TODO
#endif

                if (right < displayMetrics.WidthPixels)
                {
                    PosX -= deltaX;
                }

                if (left > 0)
                {
                    PosX -= deltaX;
                }

                if (top > 0)
                {
                    PosY -= deltaY;
                }

                if (bottom < imageHeight)
                {
                    PosY -= deltaY;
                }

                Invalidate();

                lastTouchX = x;
                lastTouchY = y;
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                activePointerId = InvalidPointerId;
                break;

            case MotionEventActions.PointerUp:
                pointerIndex = (int)(e.Action & MotionEventActions.PointerIndexMask) >>     //TODO ?
                               (int)MotionEventActions.PointerIndexShift;
                var pointerId = e.GetPointerId(pointerIndex);
                if (pointerId == activePointerId)
                {
                    var newPointerIndex = pointerIndex == 0 ? 1 : 0;
                    lastTouchX      = e.GetX(newPointerIndex);
                    lastTouchY      = e.GetY(newPointerIndex);
                    activePointerId = e.GetPointerId(newPointerIndex);
                }

                break;
            }

            return(true);
        }
示例#14
0
        private void HandleMotionEvent(MotionEvent e)
        {
            lastMotionEvent = e;
            switch (e.Action)
            {
            case MotionEventActions.Move:
                //Log.Info("DBG", string.Format("-----------------{0}", e));

                if (activePointerId == INVALID_POINTER_ID)
                {
                    break;
                }

                int pointerIndex = e.FindPointerIndex(activePointerId);

                lastEventY = (int)e.GetY(pointerIndex);
                lastEventX = (int)e.GetX(pointerIndex);
                int deltaY = lastEventY - downY;
                int deltaX = lastEventX - downX;

                if (cellIsMobile)
                {
                    hoverCellCurrentBounds.OffsetTo(hoverCellOriginalBounds.Left + deltaX + totalOffsetX,
                                                    hoverCellOriginalBounds.Top + deltaY + totalOffsetY);
                    hoverCell.SetBounds(
                        hoverCellCurrentBounds.Left,
                        hoverCellCurrentBounds.Top,
                        hoverCellCurrentBounds.Right,
                        hoverCellCurrentBounds.Bottom);
                    Invalidate();
                    var now = GetTimeStamp();
                    if (now - lastSwapTime > 500)
                    {
                        lastSwapTime = now;
                        handleCellSwitch();
                    }

                    handleMobileCellScroll();
                }
                break;

            case MotionEventActions.Up:
                TouchEventsEnded();
                break;

            case MotionEventActions.Cancel:
                TouchEventsCancelled();
                break;

            case MotionEventActions.PointerUp:
                /* If a multitouch event took place and the original touch dictating
                 * the movement of the hover cell has ended, then the dragging event
                 * ends and the hover cell is animated to its corresponding position
                 * in the listview. */
                pointerIndex = (int)(e.Action & MotionEventActions.PointerIdMask) >> (int)(MotionEventActions.PointerIndexShift);
                int pointerId = e.GetPointerId(pointerIndex);
                if (pointerId == activePointerId)
                {
                    TouchEventsEnded();
                }
                break;

            default:
                break;
            }
        }
示例#15
0
        public bool OnTouch(View v, MotionEvent Event)
        {
            try
            {
                MScaleGestureDetector.OnTouchEvent(v, Event);
                MGestureListener.OnTouchEvent(Event);

                if (!IsTranslateEnabled)
                {
                    return(true);
                }

                var action = Event.Action;

                int x = (int)Event.RawX;
                int y = (int)Event.RawY;

                switch (action & Event.ActionMasked)
                {
                case MotionEventActions.Down:
                    MPrevX           = Event.GetX();
                    MPrevY           = Event.GetY();
                    MPrevRawX        = Event.RawX;
                    MPrevRawY        = Event.RawY;
                    MActivePointerId = Event.GetPointerId(0);
                    if (DeleteView != null)
                    {
                        DeleteView.Visibility = ViewStates.Visible;
                    }
                    v.BringToFront();
                    FireNiceArtEditorSdkListener(v, true);
                    break;

                case MotionEventActions.Move:
                    int pointerIndexMove = Event.FindPointerIndex(MActivePointerId);
                    if (pointerIndexMove != -1)
                    {
                        float currX = Event.GetX(pointerIndexMove);
                        float currY = Event.GetY(pointerIndexMove);
                        if (!MScaleGestureDetector.IsInProgress())
                        {
                            AdjustTranslation(v, currX - MPrevX, currY - MPrevY);
                        }
                    }
                    break;

                case MotionEventActions.Cancel:
                    MActivePointerId = InvalidPointerId;
                    break;

                case MotionEventActions.Up:
                    MActivePointerId = InvalidPointerId;
                    if (DeleteView != null && IsViewInBounds(DeleteView, x, y))
                    {
                        OnMultiTouchListener?.OnRemoveViewListener(v);
                    }
                    else if (!IsViewInBounds(PhotoEditImageView, x, y))
                    {
                        //v.Animate().TranslationY(0).TranslationY(0);
                    }
                    if (DeleteView != null)
                    {
                        DeleteView.Visibility = ViewStates.Gone;
                    }
                    FireNiceArtEditorSdkListener(v, false);
                    break;

                case MotionEventActions.PointerUp:

                    int pointerIndex = (int)(Event.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                    int pointerId    = Event.GetPointerId(pointerIndex);
                    if (pointerId == MActivePointerId)
                    {
                        int newPointerIndex = pointerId == 0 ? 1 : 0;
                        MPrevX           = Event.GetX(newPointerIndex);
                        MPrevY           = Event.GetY(newPointerIndex);
                        MActivePointerId = Event.GetPointerId(newPointerIndex);
                    }
                    break;
                }

                return(true);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(false);
            }
        }
示例#16
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            mScaleDetector.OnTouchEvent(e);

            //int action = e.Action;
            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
                if (!mScaleDetector.IsInProgress)
                {
                    float x = e.GetX();
                    float y = e.GetY();

                    mLastTouchX      = x;
                    mLastTouchY      = y;
                    mActivePointerId = e.GetPointerId(0);
                }
                break;

            case MotionEventActions.Pointer1Down:
                if (mScaleDetector.IsInProgress)
                {
                    float gx = mScaleDetector.FocusX;
                    float gy = mScaleDetector.FocusY;

                    mLastGestureX = gx;
                    mLastGestureY = gy;
                }
                break;

            case MotionEventActions.Move:
                if (!mScaleDetector.IsInProgress)
                {
                    int   pointerIdx = e.FindPointerIndex(mActivePointerId);
                    float x          = e.GetX(pointerIdx);
                    float y          = e.GetY(pointerIdx);

                    float dx = x - mLastTouchX;
                    float dy = y - mLastTouchY;

                    mPosX += dx;
                    mPosY += dy;

                    Invalidate();

                    mLastTouchX = x;
                    mLastTouchY = y;
                }
                else
                {
                    float gx = mScaleDetector.FocusX;
                    float gy = mScaleDetector.FocusY;

                    float gdx = gx - mLastGestureX;
                    float gdy = gy - mLastGestureY;

                    mPosX += gdx;
                    mPosY += gdy;

                    Invalidate();

                    mLastGestureX = gx;
                    mLastGestureY = gy;
                }
                break;

            case MotionEventActions.Up:
                mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.Cancel:
                mActivePointerId = INVALID_POINTER_ID;
                break;

            case MotionEventActions.PointerUp:

                int pointerIdx2 = (int)(e.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId   = e.GetPointerId(pointerIdx2);

                if (pointerId == mActivePointerId)
                {
                    int NewPointerIndex = pointerIdx2 == 0 ? 1 : 0;
                    mLastTouchX      = e.GetX(NewPointerIndex);
                    mLastTouchY      = e.GetY(NewPointerIndex);
                    mActivePointerId = e.GetPointerId(NewPointerIndex);
                }
                else
                {
                    int TempPointerIdx = e.FindPointerIndex(mActivePointerId);
                    mLastTouchX = e.GetX(TempPointerIdx);
                    mLastTouchY = e.GetY(TempPointerIdx);
                }
                break;
            }

            return(true);
        }
示例#17
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (virtualButtons != null)
            {
                showVirtualButtons = true;

                MotionEventActions action = e.ActionMasked;
                if (action == MotionEventActions.Down || action == MotionEventActions.PointerDown)
                {
                    int   pointerIndex = e.ActionIndex;
                    float x            = e.GetX(pointerIndex);
                    float y            = e.GetY(pointerIndex);
                    float w            = e.GetTouchMajor(pointerIndex) * 0.5f;
                    float h            = e.GetTouchMinor(pointerIndex) * 0.5f;

                    bool vibrated = false;
                    for (int i = 0; i < virtualButtons.Length; i++)
                    {
                        ref VirtualButton button = ref virtualButtons[i];
                        if (button.KeyCode != Key.Unknown)
                        {
                            if (button.CurrentPointerId == -1 && IsOnButton(ref button, x, y, w, h))
                            {
                                int pointerId = e.GetPointerId(pointerIndex);

                                button.CurrentPointerId             = pointerId;
                                pressedButtons[(int)button.KeyCode] = true;

                                if (allowVibrations && !vibrated)
                                {
                                    vibrator.Vibrate(16);
                                    vibrated = true;
                                }
                            }
                        }
                    }
                }
                else if (action == MotionEventActions.Move)
                {
                    int pointerCount = e.PointerCount;

                    for (int i = 0; i < virtualButtons.Length; i++)
                    {
                        ref VirtualButton button = ref virtualButtons[i];
                        if (button.KeyCode != Key.Unknown)
                        {
                            if (button.CurrentPointerId != -1)
                            {
                                int pointerIndex = e.FindPointerIndex(button.CurrentPointerId);

                                if (!IsOnButton(ref button, e.GetX(pointerIndex), e.GetY(pointerIndex), e.GetTouchMajor(pointerIndex) * 0.5f, e.GetTouchMinor(pointerIndex) * 0.5f))
                                {
                                    button.CurrentPointerId             = -1;
                                    pressedButtons[(int)button.KeyCode] = false;
                                }
                            }
                            else
                            {
                                for (int j = 0; j < pointerCount; j++)
                                {
                                    if (IsOnButton(ref button, e.GetX(j), e.GetY(j), e.GetTouchMajor(j) * 0.5f, e.GetTouchMinor(j) * 0.5f))
                                    {
                                        int pointerId = e.GetPointerId(j);

                                        button.CurrentPointerId             = pointerId;
                                        pressedButtons[(int)button.KeyCode] = true;

                                        if (allowVibrations)
                                        {
                                            vibrator.Vibrate(11);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
示例#18
0
        public override bool OnTouchEvent(MotionEvent e)
        {
#if ENABLE_TOUCH
            if (TouchButtons != null)
            {
                ShowTouchButtons = true;

                MotionEventActions action = e.ActionMasked;
                if (action == MotionEventActions.Down || action == MotionEventActions.PointerDown)
                {
                    int   pointerIndex = e.ActionIndex;
                    float x            = e.GetX(pointerIndex) / (float)viewportWidth;
                    float y            = e.GetY(pointerIndex) / (float)viewportHeight;
                    if (x < 0.5f)
                    {
                        x -= LeftPadding;
                    }
                    else
                    {
                        x += RightPadding;
                    }

                    bool vibrated = false;
                    for (int i = 0; i < TouchButtons.Length; i++)
                    {
                        ref TouchButtonInfo button = ref TouchButtons[i];
                        if (button.Action != PlayerActions.None)
                        {
                            if (button.CurrentPointerId == -1 && IsOnButton(ref button, x, y))
                            {
                                int pointerId = e.GetPointerId(pointerIndex);

                                button.CurrentPointerId = pointerId;
                                ControlScheme.InternalTouchAction(button.Action, true);

                                if (AllowVibrations && !vibrated)
                                {
                                    vibrator.Vibrate(16);
                                    vibrated = true;
                                }
                            }
                        }
                    }
                }
                else if (action == MotionEventActions.Move)
                {
                    int pointerCount = e.PointerCount;

                    for (int i = 0; i < TouchButtons.Length; i++)
                    {
                        ref TouchButtonInfo button = ref TouchButtons[i];
                        if (button.Action != PlayerActions.None)
                        {
                            if (button.CurrentPointerId != -1)
                            {
                                int pointerIndex = e.FindPointerIndex(button.CurrentPointerId);

                                float x = e.GetX(pointerIndex) / (float)viewportWidth;
                                float y = e.GetY(pointerIndex) / (float)viewportHeight;
                                if (x < 0.5f)
                                {
                                    x -= LeftPadding;
                                }
                                else
                                {
                                    x += RightPadding;
                                }

                                if (!IsOnButton(ref button, x, y))
                                {
                                    button.CurrentPointerId = -1;
                                    ControlScheme.InternalTouchAction(button.Action, false);
                                }
                            }
                            else
                            {
                                for (int j = 0; j < pointerCount; j++)
                                {
                                    if (IsOnButton(ref button, e.GetX(j), e.GetY(j)))
                                    {
                                        int pointerId = e.GetPointerId(j);

                                        button.CurrentPointerId = pointerId;
                                        ControlScheme.InternalTouchAction(button.Action, true);

                                        if (AllowVibrations)
                                        {
                                            vibrator.Vibrate(11);
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
示例#19
0
        /**
         * Handles thumb selection and movement. Notifies listener callback on certain events.
         */
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (!this.Enabled)
            {
                return(false);
            }

            int pointerIndex;

            var action = ev.Action;

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

                this.pressedThumb = evalPressedThumb(mDownMotionX);

                // Only handle thumb presses.
                if (pressedThumb == Thumb.NULL)
                {
                    return(base.OnTouchEvent(ev));
                }

                this.Pressed = true;
                this.Invalidate();
                this.onStartTrackingTouch();
                this.trackTouchEvent(ev);
                this.attemptClaimDrag();

                break;

            case MotionEventActions.Move:
                if (pressedThumb != null)
                {
                    if (mIsDragging)
                    {
                        this.trackTouchEvent(ev);
                    }
                    else
                    {
                        // Scroll to follow the motion event
                        pointerIndex = ev.FindPointerIndex(mActivePointerId);
                        float x = ev.GetX(pointerIndex);

                        if (Java.Lang.Math.Abs(x - this.mDownMotionX) > this.mScaledTouchSlop)
                        {
                            this.Pressed = true;
                            this.Invalidate();
                            this.onStartTrackingTouch();
                            this.trackTouchEvent(ev);
                            this.attemptClaimDrag();
                        }
                    }

                    if (this.notifyWhileDragging && this.listener != null)
                    {
                        this.listener.onRangeSeekBarValuesChanged(this, this.getSelectedMinValue(), this.getSelectedMaxValue());
                    }
                }
                break;

            case MotionEventActions.Up:
                if (mIsDragging)
                {
                    this.trackTouchEvent(ev);

                    this.onStopTrackingTouch();

                    this.Pressed = false;
                }
                else
                {
                    // Touch up when we never crossed the touch slop threshold
                    // should be interpreted as a tap-seek to that location.
                    this.onStartTrackingTouch();

                    this.trackTouchEvent(ev);

                    this.onStopTrackingTouch();
                }

                this.pressedThumb = Thumb.NULL;

                this.Invalidate();
                if (this.listener != null)
                {
                    this.listener.onRangeSeekBarValuesChanged(this, this.getSelectedMinValue(), this.getSelectedMaxValue());
                }
                break;

            case MotionEventActions.PointerDown: {
                int index = ev.PointerCount - 1;
                // final int index = ev.getActionIndex();
                this.mDownMotionX     = ev.GetX(index);
                this.mActivePointerId = ev.GetPointerId(index);
                this.Invalidate();
                break;
            }

            case MotionEventActions.PointerUp:

                this.onSecondaryPointerUp(ev);

                this.Invalidate();
                break;

            case MotionEventActions.Cancel:
                if (mIsDragging)
                {
                    this.onStopTrackingTouch();

                    this.Pressed = false;
                }

                this.Invalidate();                 // see above explanation
                break;
            }
            return(true);
        }
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            int currenrMotionX;
            int currentMotionY;

            if (ev.Action == MotionEventActions.Move && this.isBeingDragged)
            {
                return(true);
            }

            if (this.ScrollX == 0 && !this.CanScrollVertically(1) &&
                this.ScrollY == 0 && !this.CanScrollHorizontally(1))
            {
                return(false);
            }

            switch (ev.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Move:
            {
                this.FindViewWhoScrolling((int)ev.GetX(), (int)ev.GetY(), 1, 1);
                if (this.childWhoScrolling != null)
                {
                    return(false);
                }

                if (this.activePointerId == InvalidPointerId)
                {
                    break;
                }

                int pointerIndex = ev.FindPointerIndex(this.activePointerId);
                if (pointerIndex == -1)
                {
                    break;
                }

                currenrMotionX = (int)ev.GetX(pointerIndex);
                currentMotionY = (int)ev.GetY(pointerIndex);
                int xDiff = Math.Abs(currenrMotionX - this.lastMotionX);
                int yDiff = Math.Abs(currentMotionY - this.lastMotionY);
                if (xDiff > this.touchSlop || yDiff > this.touchSlop)
                {
                    this.isBeingDragged = true;
                    this.lastMotionX    = currenrMotionX;
                    this.lastMotionY    = currentMotionY;
                    this.InitVelocityTrackerIfNotExists();
                    this.velocityTracker.AddMovement(ev);

                    if (this.Parent != null)
                    {
                        this.Parent.RequestDisallowInterceptTouchEvent(true);
                    }
                }
                break;
            }

            case MotionEventActions.Down:
            {
                this.FindViewWhoScrolling((int)ev.GetX(), (int)ev.GetY(), 1, 1);

                if (this.childWhoScrolling != null)
                {
                    return(false);
                }

                // Stop, if touched during movement on inertia
                if (!this.scroller.IsFinishedY)
                {
                    this.scroller.AbortAnimation();
                    ////FlingStrictSpan
                }

                currenrMotionX = (int)ev.GetX();
                currentMotionY = (int)ev.GetY();

                this.lastMotionX     = currenrMotionX;
                this.lastMotionY     = currentMotionY;
                this.activePointerId = ev.GetPointerId(0);

                ////if (this.inChild(x, y))
                {
                    this.isBeingDragged = false;
                    this.RecycleVelocityTracker();
                    ////break;
                }

                this.InitOrResetVelocityTracker();
                this.velocityTracker.AddMovement(ev);

                ////this.isBeingDragged = this.scroller.IsFinished;

                break;
            }

            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                if (this.childWhoScrolling != null)
                {
                    this.childWhoScrolling = null;
                    return(false);
                }
                this.isBeingDragged  = false;
                this.activePointerId = InvalidPointerId;
                this.RecycleVelocityTracker();

                //if (this.scroller.SpringBack(this.ScrollX, this.ScrollY, 0, 0, this.GetScrollRangeX(), this.GetScrollRangeY()))
                //{
                // TODO: possible something like postInvalidate (postInvalidateOnAnimation)
                //}
                break;

            case MotionEventActions.PointerUp:
                if (this.childWhoScrolling != null)
                {
                    return(false);
                }
                this.OnSecondaryPointerUp(ev);
                break;
            }

            return(this.isBeingDragged);
        }
        public void SetContext(View view, MotionEvent curr)
        {
            try
            {
                if (MCurrEvent != null)
                {
                    MCurrEvent.Recycle();
                }

                MCurrEvent = MotionEvent.Obtain(curr);

                MCurrLen     = -1;
                MPrevLen     = -1;
                MScaleFactor = -1;
                MCurrSpanVector.Set(0.0f, 0.0f);

                MotionEvent prev = MPrevEvent;

                int prevIndex0 = prev.FindPointerIndex(MActiveId0);
                int prevIndex1 = prev.FindPointerIndex(MActiveId1);
                int currIndex0 = curr.FindPointerIndex(MActiveId0);
                int currIndex1 = curr.FindPointerIndex(MActiveId1);

                if (prevIndex0 < 0 || prevIndex1 < 0 || currIndex0 < 0 || currIndex1 < 0)
                {
                    MInvalidGesture = true;
                    Log.Error(Tag, "Invalid MotionEvent stream detected.", new Throwable());
                    if (MGestureInProgress)
                    {
                        MListener.OnScaleEnd(view, this);
                    }

                    return;
                }

                float px0 = prev.GetX(prevIndex0);
                float py0 = prev.GetY(prevIndex0);
                float px1 = prev.GetX(prevIndex1);
                float py1 = prev.GetY(prevIndex1);
                float cx0 = curr.GetX(currIndex0);
                float cy0 = curr.GetY(currIndex0);
                float cx1 = curr.GetX(currIndex1);
                float cy1 = curr.GetY(currIndex1);

                float pvx = px1 - px0;
                float pvy = py1 - py0;
                float cvx = cx1 - cx0;
                float cvy = cy1 - cy0;

                MCurrSpanVector.Set(cvx, cvy);

                MPrevFingerDiffX = pvx;
                MPrevFingerDiffY = pvy;
                MCurrFingerDiffX = cvx;
                MCurrFingerDiffY = cvy;

                MFocusX    = cx0 + cvx * 0.5f;
                MFocusY    = cy0 + cvy * 0.5f;
                MTimeDelta = curr.EventTime - prev.EventTime;

                MCurrPressure = curr.GetPressure(currIndex0) + curr.GetPressure(currIndex1);
                MPrevPressure = prev.GetPressure(prevIndex0) + prev.GetPressure(prevIndex1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#22
0
        public bool OnTouch(global::Android.Views.View v, MotionEvent e)
        {
            int pointerIndex = ((int)(e.Action & MotionEventActions.PointerIdMask) >> (int)MotionEventActions.PointerIdShift);
            int pointerId    = e.GetPointerId(pointerIndex);

            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                // user touched the screen
                if (activeTouches.Count < MAX_TOUCH_COUNT)
                {
                    Touch touch = new Touch(pointerId, new Vector2(e.GetX(pointerIndex), e.GetY(pointerIndex)));
                    activeTouches.Add(touch);

                    for (int i = 0; i < Screen.Active.Elements.Count; i++)
                    {
                        Element item = Screen.Active.Elements[i];
                        if (item.Collides(touch.RelativePosition) && item.HandleTouch(Touch.Action.Begin, touch))
                        {
                            break;
                        }
                    }
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
            case MotionEventActions.PointerUp:
                // user lifted the finger of the screen
                int touchIndex = activeTouches.FindIndex((Touch touch) => touch.ID == pointerId);
                if (touchIndex != -1)
                {
                    for (int i = 0; i < Screen.Active.Elements.Count; i++)
                    {
                        Element item = Screen.Active.Elements[i];
                        if (item.Collides(activeTouches[touchIndex].RelativePosition) && item.HandleTouch(Touch.Action.End, activeTouches[touchIndex]))
                        {
                            break;
                        }
                    }
                    activeTouches.RemoveAt(touchIndex);
                }
                break;

            case MotionEventActions.Move:
                // user moved the finger
                for (int i = 0; i < activeTouches.Count; i++)
                {
                    int     activePointerIndex  = e.FindPointerIndex(activeTouches[i].ID);
                    Vector2 activeTouchPosition = new Vector2(e.GetX(activePointerIndex), e.GetY(activePointerIndex));
                    if (activeTouches[i].Position - activeTouchPosition != Vector2.Zero)
                    {
                        // touch moved
                        Vector2 activeTouchRelativePosition = new Vector2((activeTouchPosition.X / Window.Size.Width - 0.5f) * 2 * Window.Ratio, (activeTouchPosition.Y / Window.Size.Height - 0.5f) * -2);
                        for (int j = 0; j < Screen.Active.Elements.Count; j++)
                        {
                            Element item = Screen.Active.Elements[j];

                            bool current = item.Collides(activeTouchRelativePosition);
                            bool last    = item.Collides(activeTouches[i].RelativePosition);

                            if (current && !last)
                            {
                                // collides with the current position, but not with the last
                                if (item.HandleTouch(Touch.Action.Enter, activeTouches[i]))
                                {
                                    for (int k = j + 1; k < Screen.Active.Elements.Count; k++)
                                    {
                                        Element kitem = Screen.Active.Elements[k];
                                        if (kitem.Collides(activeTouches[i].RelativePosition))
                                        {
                                            kitem.HandleTouch(Touch.Action.Leave, activeTouches[i]);
                                        }
                                    }
                                }
                            }
                            else if (!current && last)
                            {
                                // collides with the last position, but not with the current -> touch moved out of UIelement
                                if (item.HandleTouch(Touch.Action.Leave, activeTouches[i]))
                                {
                                    for (int k = j + 1; k < Screen.Active.Elements.Count; k++)
                                    {
                                        Element kitem = Screen.Active.Elements[k];
                                        if (kitem.Collides(activeTouchRelativePosition))
                                        {
                                            kitem.HandleTouch(Touch.Action.Enter, activeTouches[i]);
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                            else if (current)
                            {
                                // touch moved inside UI
                                if (item.HandleTouch(Touch.Action.Move, activeTouches[i]))
                                {
                                    break;
                                }
                            }
                        }

                        activeTouches[i].Position         = activeTouchPosition;
                        activeTouches[i].RelativePosition = activeTouchRelativePosition;
                    }
                }
                break;
            }

            return(true);
        }