コード例 #1
0
        /// <summary>
        /// This function handles touch events.
        /// It is responsible for maintaining the currently active touch events and dispatching events.
        /// For details see http://developer.android.com/reference/android/view/View.html#onTouchEvent(android.view.MotionEvent)
        /// </summary>
        public override bool OnTouchEvent(MotionEvent e)
        {
            float xConversion = SparrowSharp.Stage.StageWidth / Width;
            float yConversion = SparrowSharp.Stage.StageHeight / Height;

            // get pointer index from the event object
            int pointerIndex = e.ActionIndex;
            // get pointer ID
            int pointerId = e.GetPointerId(pointerIndex);

            // get masked (not specific to a pointer) action
            MotionEventActions maskedAction = e.ActionMasked;

            switch (maskedAction)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:
                touchProcessor.OnPointerDown(e.GetX() * xConversion, e.GetY() * yConversion, pointerId);
                break;

            case MotionEventActions.Move:
                for (int size = e.PointerCount, i = 0; i < size; i++)
                {
                    touchProcessor.OnPointerMove(e.GetX(i) * xConversion, e.GetY(i) * yConversion, e.GetPointerId(i));
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.PointerUp:
                touchProcessor.OnPointerUp(pointerId);
                break;

            case MotionEventActions.Cancel:
                touchProcessor.OnPointerUp(pointerId);
                break;
            }
            return(true);
        }
コード例 #2
0
        private void OnTouch(object sender, Android.Views.View.TouchEventArgs args)
        {
            gestureRecognizer?.OnTouchEvent(args.Event);

            // Two object common to all the events
            Android.Views.View senderView  = sender as Android.Views.View;
            MotionEvent        motionEvent = args.Event;

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

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

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

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

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:
                FireEvent(this, id, TouchActionType.Released, screenPointerCoords, false);
                break;

            case MotionEventActions.Cancel:
                FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                break;
            }
        }
コード例 #3
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            var index     = e.ActionIndex;
            var action    = (MotionEventActions)e.ActionMasked;
            var pointerId = e.GetPointerId(index);

            switch (action)
            {
            case MotionEventActions.Down:
                if (this._velocityTracket == null)
                {
                    this._velocityTracket = VelocityTracker.Obtain();
                }
                else
                {
                    this._velocityTracket.Clear();
                }
                this._velocityTracket.AddMovement(e);
                break;

            case MotionEventActions.Move:
                this._velocityTracket.AddMovement(e);
                this._velocityTracket.ComputeCurrentVelocity(1000);
                Log.Debug(DebugTag, "X velocity: " + VelocityTrackerCompat.GetXVelocity(this._velocityTracket, pointerId));
                Log.Debug(DebugTag, "Y velocity: " + VelocityTrackerCompat.GetYVelocity(this._velocityTracket, pointerId));
                break;

            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                this._velocityTracket.Recycle();
                break;

            default:
                break;
            }
            return(true);
        }
コード例 #4
0
        internal PointerRoutedEventArgs(MotionEvent nativeEvent, int pointerIndex, UIElement originalSource, UIElement receiver) : this()
        {
            _nativeEvent  = nativeEvent;
            _pointerIndex = pointerIndex;
            _receiver     = receiver;

            // Here we assume that usually pointerId is 'PointerIndexShift' bits long (8 bits / 255 ids),
            // and that usually the deviceId is [0, something_not_too_big_hopefully_less_than_0x00ffffff].
            // If deviceId is greater than 0x00ffffff, we might have a conflict but only in case of multi touch
            // and with a high variation of deviceId. We assume that's safe enough.

            // Note: Make sure to use the GetPointerId in order to make sure to keep the same id while: down_1 / down_2 / up_1 / up_2
            // otherwise up_2 will be with the id of 1
            var pointerId   = ((uint)nativeEvent.GetPointerId(pointerIndex) & _pointerIdsCount) << _pointerIdsShift | (uint)nativeEvent.DeviceId;
            var type        = nativeEvent.GetToolType(pointerIndex).ToPointerDeviceType();
            var isInContact = IsInContact(type, nativeEvent, pointerIndex);
            var keys        = nativeEvent.MetaState.ToVirtualKeyModifiers();

            FrameId           = (uint)_nativeEvent.EventTime;
            Pointer           = new Pointer(pointerId, type, isInContact, isInRange: true);
            KeyModifiers      = keys;
            OriginalSource    = originalSource;
            CanBubbleNatively = true;
        }
コード例 #5
0
ファイル: TouchEffect.cs プロジェクト: firstArachne0116/Iroai
        void OnTouch(object sender, Android.Views.View.TouchEventArgs args)
        {
            // Two object common to all the events
            Android.Views.View senderView  = sender as Android.Views.View;
            MotionEvent        motionEvent = args.Event;

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

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

            senderView.GetLocationOnScreen(twoIntArray);

            List <Point> points = new List <Point>();

            for (int i = 0; i < motionEvent.PointerCount; i++)
            {
                Point screenPointerCoords = new Point(twoIntArray[0] + motionEvent.GetX(i),
                                                      twoIntArray[1] + motionEvent.GetY(i));
                points.Add(screenPointerCoords);
            }

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

                idToEffectDictionary.Add(id, this);

                _capture = _pclTouchEffect.Capture;
                break;

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

                    if (_capture)
                    {
                        FireEvent(this, id, TouchActionType.Moved, points, true);
                    }
                    else
                    {
                        CheckForBoundaryHop(id, points);

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

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

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

            case MotionEventActions.Cancel:
                if (_capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, points, false);
                }
                else
                {
                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, points, false);
                    }
                }
                idToEffectDictionary.Clear();
                break;
            }
        }
コード例 #6
0
ファイル: GLView.cs プロジェクト: frodo5654/Samples
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (adapter == null)
            {
                return(true);
            }

            WaveEngine.Adapter.Input.InputManager inputManager = (WaveEngine.Adapter.Input.InputManager)adapter.InputManager;
            inputManager.TouchPanelState.Clear();

            float x, y;
            int   id;

            for (int i = 0; i < e.PointerCount; i++)
            {
                id = e.GetPointerId(i);
                x  = e.GetX(i);
                y  = e.GetY(i);
                TouchLocationState state;

                if (i == e.ActionIndex)
                {
                    switch (e.ActionMasked)
                    {
                    //DOWN
                    case MotionEventActions.Down:
                    case MotionEventActions.PointerDown:
                        state = TouchLocationState.Pressed;
                        break;

                    //UP
                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                        state = TouchLocationState.Release;
                        break;

                    //MOVE
                    case MotionEventActions.Move:
                        state = TouchLocationState.Moved;
                        break;

                    //CANCEL, OUTSIDE
                    case MotionEventActions.Cancel:
                    case MotionEventActions.Outside:
                    default:
                        state = TouchLocationState.Invalid;
                        break;
                    }
                }
                else
                {
                    state = TouchLocationState.Moved;
                }

                if (state != TouchLocationState.Invalid && state != TouchLocationState.Release)
                {
                    inputManager.TouchPanelState.AddTouchLocation(id, TouchLocationState.Moved, x, y);
                }
            }

            return(true);
        }
コード例 #7
0
 private Touch getEventTouch(MotionEvent e, int index) => new Touch((TouchSource)e.GetPointerId(index), getEventPosition(e, index));
コード例 #8
0
        /** Private methods **/
        public bool OnTouch(View v, MotionEvent e)
        {
            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
            {
                // http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
                _activePointerId = e.GetPointerId(0);

                // starting point
                _downX = e.GetX(_activePointerId);
                _downY = e.GetY(_activePointerId);

                // to check for long click
                _downTime = new Date().Time;

                // which item are we touching
                ResolveItem(_downX, _downY);

                break;
            }

            case MotionEventActions.Up:
            {
                _upX             = e.GetX();
                _upY             = e.GetY();
                _upTime          = new Date().Time;
                _activePointerId = INVALID_POINTER_ID;

                ResolveState();
                break;
            }

            case MotionEventActions.PointerUp:
            {
                int pointerIndex = (int)(e.Action &
                                         MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId = e.GetPointerId(pointerIndex);

                if (pointerId == _activePointerId)
                {
                    int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                    _activePointerId = e.GetPointerId(newPointerIndex);
                }

                break;
            }

            case MotionEventActions.Move:
            {
                int pointerIndex = e.FindPointerIndex(_activePointerId);
                if (pointerIndex == INVALID_POINTER_ID)
                {
                    break;
                }
                float x  = e.GetX(pointerIndex);
                float dx = x - _downX;

                if (!ShouldMove(dx))
                {
                    break;
                }

                // current position. moving only over x-axis
                _frontViewLastX = _frontViewX + dx + (dx > 0 ? -REVEAL_THRESHOLD : REVEAL_THRESHOLD);
                _frontView.SetX(_frontViewLastX);

                if (_frontViewLastX > 0)
                {
                    RevealRight();
                }
                else
                {
                    RevealLeft();
                }

                break;
            }

            case MotionEventActions.Cancel:
            {
                _activePointerId = INVALID_POINTER_ID;
                ResolveState();

                break;
            }
            }

            return(false);
        }
コード例 #9
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            base.OnTouchEvent(e);
            _scaleDetector.OnTouchEvent(e);
            _moveDetector.OnTouchEvent(e);

            MotionEventActions 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);
                if (pointerIndex > 0)
                {
                    float x = e.GetX(pointerIndex);
                    float y = e.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;

                        if (_posX > 0.0f)
                        {
                            _posX = 0.0f;
                        }
                        else if (_posX < _maxWidth)
                        {
                            _posX = _maxWidth;
                        }

                        if (_posY > 0.0f)
                        {
                            _posY = 0.0f;
                        }
                        else if (_posY < _maxHeight)
                        {
                            _posY = _maxHeight;
                        }

                        _lastTouchX = x;
                        _lastTouchY = y;
                        Invalidate();
                    }
                }

                break;

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                // We no longer need to keep track of the active pointer.
                _activePointerId = InvalidPointerId;
                break;

            case MotionEventActions.PointerUp:
                // check to make sure that the pointer that went up is for the gesture we're tracking.
                pointerIndex = (int)(e.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId = e.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      = e.GetX(newPointerIndex);
                    _lastTouchY      = e.GetY(newPointerIndex);
                    _activePointerId = e.GetPointerId(newPointerIndex);
                }
                break;
            }
            return(true);
        }
コード例 #10
0
        //private Vector2 GetOffsetPosition(Vector2 position)
        //{
        //    Vector2 translatedPosition = position;
        //    switch (CurrentOrientation)
        //    {
        //        case DisplayOrientation.Portrait:
        //            break;
        //        case DisplayOrientation.LandscapeRight:
        //            translatedPosition = new Vector2(ClientBounds.Height - position.Y, position.X);
        //            break;
        //        case DisplayOrientation.LandscapeLeft:
        //            translatedPosition = new Vector2(position.Y, ClientBounds.Width - position.X);
        //            break;
        //        case DisplayOrientation.PortraitUpsideDown:
        //            translatedPosition = new Vector2(ClientBounds.Width - position.X, ClientBounds.Height - position.Y);
        //            break;
        //    }
        //    return translatedPosition * UIScreen.MainScreen.Scale;
        //}

        public bool OnTouch(View v, MotionEvent e)
        {
            TouchLocation   tlocation;
            TouchCollection collection = TouchPanel.Collection;

            Vector2 position = Vector2.Zero;

            position.X = e.GetX(e.ActionIndex);
            position.Y = e.GetY(e.ActionIndex);
            int id = e.GetPointerId(e.ActionIndex);
            int index;

            switch (e.ActionMasked)
            {
            // DOWN
            case 0:
            case 5:
                tlocation = new TouchLocation(id, TouchLocationState.Pressed, position);
                collection.Add(tlocation);
                break;

            // UP
            case 1:
            case 6:
                index = collection.FindById(e.GetPointerId(e.ActionIndex), out tlocation);
                if (index >= 0)
                {
                    tlocation.State   = TouchLocationState.Released;
                    collection[index] = tlocation;
                }
                break;

            // MOVE
            case 2:
                for (int i = 0; i < e.PointerCount; i++)
                {
                    id         = e.GetPointerId(i);
                    position.X = e.GetX(i);
                    position.Y = e.GetY(i);
                    index      = collection.FindById(id, out tlocation);
                    if (index >= 0)
                    {
                        tlocation.State    = TouchLocationState.Moved;
                        tlocation.Position = position;
                        collection[index]  = tlocation;
                    }
                }
                break;

            // CANCEL, OUTSIDE
            case 3:
            case 4:
                index = collection.FindById(id, out tlocation);
                if (index >= 0)
                {
                    tlocation.State   = TouchLocationState.Invalid;
                    collection[index] = tlocation;
                }
                break;
            }

            return(true);

            //for (int i = 0; i < e.PointerCount; i++)
            //{
            //    Vector2 position = Vector2.Zero;
            //    position.X = e.GetX(i);
            //    position.Y = e.GetY(i);

            //    TouchLocation tlocation;
            //    TouchCollection collection = TouchPanel.Collection;

            //    int index;
            //    int id = e.GetPointerId(i);

            //    switch (e.ActionMasked)
            //    {
            //        //case MotionEventActions.Down:
            //        case 0:
            //            //Log.Debug("TESTING", string.Format("DOWN: ActionIndex({5}) ActionMasked({6}) BlobCount=[{3}] BlobID=[{2}] BlobPos=({0:N},{1:N})", position.X, position.Y, id, e.PointerCount, e.Action, e.ActionIndex, e.ActionMasked));
            //            tlocation = new TouchLocation(id, TouchLocationState.Pressed, position);
            //            collection.Add(tlocation);
            //            break;
            //        //case MotionEventActions.PointerDown:
            //        case 5:
            //            //Log.Debug("TESTING", string.Format("DOWN: ActionIndex({5}) ActionMasked({6}) BlobCount=[{3}] BlobID=[{2}] BlobPos=({0:N},{1:N})", position.X, position.Y, id, e.PointerCount, e.Action, e.ActionIndex, e.ActionMasked));
            //            tlocation = new TouchLocation(e.GetPointerId(e.ActionIndex), TouchLocationState.Pressed, position);
            //            collection.Add(tlocation);
            //            break;
            //        //case MotionEventActions.Up:
            //        case 1:
            //            index = collection.FindById(id, out tlocation);
            //            if (index >= 0)
            //            {
            //                tlocation.State = TouchLocationState.Released;
            //                collection[index] = tlocation;
            //            }
            //            break;
            //        //case MotionEventActions.PointerUp:
            //        case 6:
            //            //Log.Debug("TESTING", string.Format("UP: ActionIndex({5}) ActionMasked({6}) BlobCount=[{3}] BlobID=[{2}] BlobPos=({0:N},{1:N})", position.X, position.Y, id, e.PointerCount, e.Action, e.ActionIndex, e.ActionMasked));
            //            index = collection.FindById(e.GetPointerId(e.ActionIndex), out tlocation);
            //            if (index >= 0)
            //            {
            //                tlocation.State = TouchLocationState.Released;
            //                collection[index] = tlocation;
            //            }
            //            break;
            //        //case MotionEventActions.Move:
            //        case 2:
            //            //Log.Debug("TESTING", string.Format("MOVE: Count=[{3}] ID=[{2}] ({0:N},{1:N})", position.X, position.Y, id, e.PointerCount));
            //            index = collection.FindById(id, out tlocation);
            //            if (index >= 0)
            //            {
            //                tlocation.State = TouchLocationState.Moved;
            //                tlocation.Position = position;
            //                collection[index] = tlocation;
            //            }
            //            break;
            //        default:
            //            //Log.Debug("TESTING", string.Format("OTHER {4}: ActionIndex({5}) ActionMasked({6}) BlobCount=[{3}] BlobID=[{2}] BlobPos=({0:N},{1:N})", position.X, position.Y, id, e.PointerCount, e.Action, e.ActionIndex, e.ActionMasked));
            //            index = collection.FindById(id, out tlocation);
            //            if (index >= 0)
            //            {
            //                tlocation.State = TouchLocationState.Released;
            //                collection[index] = tlocation;
            //            }
            //            break;
            //    }
            //}
            //return true;

            //TouchLocationState state = TouchLocationState.Invalid;

            //if (e.Action == MotionEventActions.Cancel)
            //{
            //    state = TouchLocationState.Invalid;
            //}
            //if (e.Action == MotionEventActions.Up)
            //{
            //    state = TouchLocationState.Released;
            //}
            //if (e.Action == MotionEventActions.Move)
            //{
            //    state = TouchLocationState.Moved;
            //    Mouse.SetPosition((int)e.GetX(), (int)e.GetY());
            //}
            //if (e.Action == MotionEventActions.Down)
            //{
            //    state = TouchLocationState.Pressed;
            //    Mouse.SetPosition((int)e.GetX(), (int)e.GetY());
            //}

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

            //TouchPanel.Collection.Clear();
            //TouchPanel.Collection.Add(tlocation);

            //if (state != TouchLocationState.Released)
            //    _previousTouches[e.Handle] = tlocation;
            //else
            //    _previousTouches.Remove(e.Handle);
            //return true;

            //////////
            //TouchLocationState state = TouchLocationState.Invalid;

            //if (e.Action == MotionEventActions.Cancel)
            //{
            //    state = TouchLocationState.Invalid;
            //}
            //if (e.Action == MotionEventActions.Up)
            //{
            //    state = TouchLocationState.Released;
            //}
            //if (e.Action == MotionEventActions.Move)
            //{
            //    state = TouchLocationState.Moved;
            //    Mouse.SetPosition((int)e.GetX(), (int)e.GetY());
            //}
            //if (e.Action == MotionEventActions.Down)
            //{
            //    state = TouchLocationState.Pressed;
            //    Mouse.SetPosition((int)e.GetX(), (int)e.GetY());
            //}

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

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


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

            //TouchPanel.Collection.Clear();
            //TouchPanel.Collection.Add(tlocation);

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

            //GamePad.Instance.Update(e);

            //return true;
        }
コード例 #11
0
ファイル: InnerView.Input.cs プロジェクト: razluta/jazz2
        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++)
                    {
                        VirtualButton button = virtualButtons[i];
                        if (button.KeyCode != Key.Unknown)
                        {
                            if (button.CurrentPointerId == -1 && IsOnButton(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++)
                    {
                        VirtualButton button = virtualButtons[i];
                        if (button.KeyCode != Key.Unknown)
                        {
                            if (button.CurrentPointerId != -1)
                            {
                                int pointerIndex = e.FindPointerIndex(button.CurrentPointerId);

                                if (!IsOnButton(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(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;
                                    }
                                }
                            }
                        }
                    }
                }
                else if (action == MotionEventActions.Up || action == MotionEventActions.Cancel)
                {
                    for (int i = 0; i < virtualButtons.Length; i++)
                    {
                        VirtualButton button = virtualButtons[i];
                        if (button.CurrentPointerId != -1)
                        {
                            button.CurrentPointerId             = -1;
                            pressedButtons[(int)button.KeyCode] = false;
                        }
                    }
                }
                else if (action == MotionEventActions.PointerUp)
                {
                    int pointerId = e.GetPointerId(e.ActionIndex);

                    for (int i = 0; i < virtualButtons.Length; i++)
                    {
                        VirtualButton button = virtualButtons[i];

                        if (button.CurrentPointerId == pointerId)
                        {
                            button.CurrentPointerId             = -1;
                            pressedButtons[(int)button.KeyCode] = false;
                        }
                    }
                }
            }

            //return base.OnTouchEvent(e);
            return(true);
        }
コード例 #12
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (!MainBuildingFragment.CheckFocus())
            {
                imm.HideSoftInputFromWindow(WindowToken, 0);
            }
            //_scaleDetector.OnTouchEvent(e);
            _doubleTapListener.OnTouchEvent(e);

            MotionEventActions 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);
                float x = e.GetX(pointerIndex);
                float y = e.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;

                float planScaleWidth  = imageWidth * _scaleFactor;
                float planScaleHeight = imageHeight * _scaleFactor;

                float right  = _posX + planScaleWidth;
                float left   = _posX;
                float top    = _posY;
                float bottom = _posY + planScaleHeight;

                Log.Debug("PLAN", "Right: " + right);
                Log.Debug("PLAN", "Left: " + left);
                Log.Debug("PLAN", "Top: " + top);
                Log.Debug("PLAN", "Bottom: " + bottom + " // IntristicHeight: " + _plan.IntrinsicHeight + " // ImageHeight: " + imageHeight);

                if (right < displ.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) >> (int)MotionEventActions.PointerIndexShift;
                int pointerId = e.GetPointerId(pointerIndex);
                if (pointerId == _activePointerId)
                {
                    int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                    _lastTouchX      = e.GetX(newPointerIndex);
                    _lastTouchY      = e.GetY(newPointerIndex);
                    _activePointerId = e.GetPointerId(newPointerIndex);
                }
                break;
            }
            return(true);
        }
コード例 #13
0
            public Boolean OnTouchEvent(MotionEvent e)
            {
                switch (e.Action)
                {
                case MotionEventActions.Down:
                case MotionEventActions.Pointer1Down:
                case MotionEventActions.Pointer2Down:
                case MotionEventActions.Pointer3Down:
                {
                    if (_Points.Count == 2)
                    {
                        return(false);
                    }

                    CPointF point = new CPointF(e.GetX(e.ActionIndex), e.GetY(e.ActionIndex));

                    switch (_Points.Count)
                    {
                    case 0:
                        _Points.Add(e.GetPointerId(e.ActionIndex), point);
                        _CallbackDown(point);
                        break;

                    case 1:
                        var i = _Points.GetEnumerator();
                        i.MoveNext();
                        _CallbackUp(i.Current.Value);

                        _Points.Add(e.GetPointerId(e.ActionIndex), point);
                        _BaseDistance = Distance;
                        _CallbackPinchDown(Center);
                        break;
                    }
                }
                break;

                case MotionEventActions.Up:
                case MotionEventActions.Pointer1Up:
                case MotionEventActions.Pointer2Up:
                case MotionEventActions.Pointer3Up:
                {
                    CPointF point;
                    if (!_Points.TryGetValue(e.GetPointerId(e.ActionIndex), out point))
                    {
                        return(false);
                    }

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

                    switch (_Points.Count)
                    {
                    case 1:
                    {
                        _CallbackUp(point);
                        _Points.Remove(e.GetPointerId(e.ActionIndex));
                    }
                    break;

                    case 2:
                    {
                        _CallbackPinchUp(Center, Scale);
                        _Points.Remove(e.GetPointerId(e.ActionIndex));

                        var i = _Points.GetEnumerator();
                        i.MoveNext();
                        _CallbackDown(i.Current.Value);
                    }
                    break;
                    }
                }
                break;

                case MotionEventActions.Move:
                {
                    for (Int32 i = 0; i < e.PointerCount; ++i)
                    {
                        CPointF TouchedPoint;
                        if (!_Points.TryGetValue(e.GetPointerId(i), out TouchedPoint))
                        {
                            continue;
                        }

                        TouchedPoint.X = e.GetX(i);
                        TouchedPoint.Y = e.GetY(i);
                    }

                    var center = Center;
                    switch (_Points.Count)
                    {
                    case 1:
                        _CallbackMove(center);
                        break;

                    case 2:
                        _CallbackPinchMove(center, Scale);
                        break;
                    }
                }
                break;

                case MotionEventActions.Cancel:
                    if (_Points.Count == 0)
                    {
                        return(false);
                    }

                    switch (_Points.Count)
                    {
                    case 1:
                        var i = _Points.GetEnumerator();
                        i.MoveNext();
                        _CallbackUp(i.Current.Value);
                        break;

                    case 2:
                        _CallbackPinchUp(Center, Scale);
                        break;
                    }
                    _Points.Clear();
                    break;

                case MotionEventActions.Outside: break;

                case MotionEventActions.HoverMove: break;

                case MotionEventActions.Scroll: break;

                case MotionEventActions.HoverEnter: break;

                case MotionEventActions.HoverExit: break;

                case MotionEventActions.Mask: break;

                case MotionEventActions.PointerIdMask: break;
                }

                return(true);
            }
コード例 #14
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            switch (e.ActionMasked)
            {
            case MotionEventActions.Down:
            {
                int id = e.GetPointerId(0);

                var start = new MotionEvent.PointerCoords();
                e.GetPointerCoords(id, start);
                coords.Add(id, start);

                return(true);
            }

            case MotionEventActions.PointerDown:
            {
                int id = e.GetPointerId(e.ActionIndex);

                var start = new MotionEvent.PointerCoords();
                e.GetPointerCoords(id, start);
                coords.Add(id, start);

                return(true);
            }

            case MotionEventActions.Move:
            {
                for (int index = 0; index < e.PointerCount; index++)
                {
                    var id = e.GetPointerId(index);

                    float x = e.GetX(index);
                    float y = e.GetY(index);

                    drawCanvas.DrawLine(coords[id].X, coords[id].Y, x, y, paint);

                    coords[id].X = x;
                    coords[id].Y = y;

                    if (LineDrawn != null)
                    {
                        LineDrawn(this, EventArgs.Empty);
                    }
                }

                Invalidate();

                return(true);
            }

            case MotionEventActions.PointerUp:
            {
                int id = e.GetPointerId(e.ActionIndex);
                coords.Remove(id);
                return(true);
            }

            case MotionEventActions.Up:
            {
                int id = e.GetPointerId(0);
                coords.Remove(id);
                return(true);
            }

            default:
                return(false);
            }
        }
コード例 #15
0
        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)
            {
                Console.WriteLine(e);
                return(false);
            }
        }
コード例 #16
0
        public bool OnTouchEvent(MotionEvent e)
        {
            bool result = false;

            if (e.PointerCount >= 2)
            {
                MotionEventActions action = e.Action;
                switch (action)
                {
                case MotionEventActions.Move:
                    if (Start == null)
                    {
                        Start = e;
                    }
                    if (!_gestureInProgress)
                    {
                        for (int i = 0; i < e.PointerCount; i++)
                        {
                            int num = Start.FindPointerIndex(e.GetPointerId(i));
                            if (num >= 0)
                            {
                                float num2 = Math.Abs(Start.GetX(num) - e.GetX(i));
                                float num3 = Math.Abs(Start.GetY(num) - e.GetY(i));
                                if (num2 > (float)touchSlop || num3 > (float)touchSlop)
                                {
                                    _gestureInProgress = true;
                                }
                            }
                        }
                    }
                    if (_gestureInProgress)
                    {
                        result = Listener.onMoving(e);
                        return(result);
                    }
                    return(result);

                case MotionEventActions.Cancel:
                    break;

                default:
                    switch (action)
                    {
                    case MotionEventActions.Pointer2Down:
                        Start = e;
                        return(result);

                    case MotionEventActions.Pointer2Up:
                        break;

                    default:
                        return(result);
                    }
                    break;
                }
                result = EndGesture(e);
            }
            else
            {
                result = EndGesture(e);
            }
            return(result);
        }
コード例 #17
0
        /// <summary>
        ///     Handles thumb selection and movement. Notifies listener callback on certain evs.
        /// </summary>
        public override bool OnTouchEvent(MotionEvent ev)
        {
            if (!Enabled)
            {
                return(false);
            }

            int pointerIndex;

            var action = ev.Action;

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

                _pressedThumb = EvalPressedThumb(_downMotionX);

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

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

                break;

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

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

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

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

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

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

            case MotionEventActions.Cancel:
                if (_isDragging)
                {
                    OnStopTrackingTouch();
                    Pressed = false;
                }
                Invalidate();     // see above explanation
                break;
            }
            return(true);
        }
コード例 #18
0
        // Overrides
        public override bool OnTouchEvent(MotionEvent args)
        {
            // Get the pointer index
            int pointerIndex = args.ActionIndex;

            // Get the id to identify a finger over the course of its progress
            int id = args.GetPointerId(pointerIndex);

            // Use ActionMasked here rather than Action to reduce the number of possibilities
            switch (args.ActionMasked)
            {
            case MotionEventActions.Down:
            case MotionEventActions.PointerDown:

                // Create a Polyline, set the initial point, and store it
                FingerPaintPolyline polyline = new FingerPaintPolyline
                {
                    Color       = StrokeColor,
                    StrokeWidth = StrokeWidth
                };

                polyline.Path.MoveTo(args.GetX(pointerIndex),
                                     args.GetY(pointerIndex));

                inProgressPolylines.Add(id, polyline);
                break;

            case MotionEventActions.Move:

                // Multiple Move events are bundled, so handle them differently
                for (pointerIndex = 0; pointerIndex < args.PointerCount; pointerIndex++)
                {
                    id = args.GetPointerId(pointerIndex);

                    inProgressPolylines[id].Path.LineTo(args.GetX(pointerIndex),
                                                        args.GetY(pointerIndex));
                }
                break;

            case MotionEventActions.Up:
            case MotionEventActions.Pointer1Up:

                inProgressPolylines[id].Path.LineTo(args.GetX(pointerIndex),
                                                    args.GetY(pointerIndex));

                // Transfer the in-progress polyline to a completed polyline
                completedPolylines.Add(inProgressPolylines[id]);
                inProgressPolylines.Remove(id);
                break;

            case MotionEventActions.Cancel:
                inProgressPolylines.Remove(id);
                break;
            }

            // Invalidate to update the view
            Invalidate();

            // Request continued touch input
            return(true);
        }
コード例 #19
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            // Let the detectors inspect the touch events.
            _scaleDetector.OnTouchEvent(e);

            switch (e.Action & MotionEventActions.Mask)
            {
            case MotionEventActions.Down:
                if (!_scaleDetector.IsInProgress)
                {
                    _lastTouchX      = e.GetX();
                    _lastTouchY      = e.GetY();
                    _activePointerId = e.GetPointerId(0);
                }
                break;

            case MotionEventActions.Pointer1Down:
                if (_scaleDetector.IsInProgress)
                {
                    _lastGestureX = _scaleDetector.FocusX;
                    _lastGestureY = _scaleDetector.FocusY;
                }
                break;

            case MotionEventActions.Move:
                // Only move if the ScaleGestureDetector isn't processing a gesture.
                if (!_scaleDetector.IsInProgress)
                {
                    var pointerIndex = e.FindPointerIndex(_activePointerId);
                    var x            = e.GetX(pointerIndex);
                    var y            = e.GetY(pointerIndex);

                    _posX += x - _lastTouchX;
                    _posY += y - _lastTouchY;

                    _lastTouchX = x;
                    _lastTouchY = y;
                }
                else
                {
                    var x = _scaleDetector.FocusX;
                    var y = _scaleDetector.FocusY;

                    _posX += x - _lastGestureX;
                    _posY += y - _lastGestureY;

                    _lastGestureX = x;
                    _lastGestureY = y;
                }

                Invalidate();

                break;

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

            case MotionEventActions.PointerUp:
                var index     = ((int)e.Action & (int)MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                var pointerId = e.GetPointerId(index);
                if (pointerId == _activePointerId)
                {
                    // This was our active pointer going up. Choose a new
                    // active pointer and adjust accordingly.
                    var pointerIndex = index == 0 ? 1 : 0;
                    _lastTouchX      = e.GetX(pointerIndex);
                    _lastTouchY      = e.GetY(pointerIndex);
                    _activePointerId = e.GetPointerId(pointerIndex);
                }
                else
                {
                    var tempPointerIndex = e.FindPointerIndex(_activePointerId);
                    _lastTouchX = e.GetX(tempPointerIndex);
                    _lastTouchY = e.GetY(tempPointerIndex);
                }
                break;
            }
            return(true);
        }
コード例 #20
0
        void OnTouch(object sender, Android.Views.View.TouchEventArgs args)
        {
            // Two object common to all the events
            Android.Views.View senderView  = sender as Android.Views.View;
            MotionEvent        motionEvent = args.Event;

            // Don't set as Handled to allow event propagation to child for ListView (ItemsView<Cell>) and  CarouselView, CollectionView (ItemsView)
            if ((Element is ItemsView <Cell>) || (Element is ItemsView))
            {
                args.Handled = false;
            }

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

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


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

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

                if (!idToEffectDictionary.ContainsKey(id))
                {
                    idToEffectDictionary.Add(id, this);
                }

                capture = libTouchEffect.Capture;
                break;

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

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

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

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

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

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

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

            case MotionEventActions.Cancel:
                if (capture)
                {
                    FireEvent(this, id, TouchActionType.Cancelled, screenPointerCoords, false);
                }
                else
                {
                    if (idToEffectDictionary[id] != null)
                    {
                        FireEvent(idToEffectDictionary[id], id, TouchActionType.Cancelled, screenPointerCoords, false);
                    }
                }
                idToEffectDictionary.Remove(id);
                break;
            }
        }
コード例 #21
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            // ReSharper disable once BitwiseOperatorOnEnumWithoutFlags
            MotionEventActions action = ev.Action & MotionEventActions.Mask;
            int pointerIndex;
            int fingersRemaining;

            switch (action)
            {
            case MotionEventActions.Down: // Primary Finger...
                HasSingleFinger       = true;
                HasTwoFingers         = false;
                HasMoreThanTwoFingers = false;
                TrackingFingerId      = ev.GetPointerId(0);
                AnchorLocation        = new PointF(ev.GetX(TrackingFingerId), ev.GetY(TrackingFingerId));
                UserHasBegunGesture   = true;
                State = GestureDetectorState.Began;
                //Debug.WriteLine ("Primary Finger Down with Id = {0}", TrackingFingerId);
                break;

            case MotionEventActions.PointerDown: // Secondary Finger(s)...

                if (ev.PointerCount == 2)
                {
                    SecondFingerId = ev.ActionIndex;
                    //Debug.WriteLine ("Second Finger Down with Id = {0}", SecondFingerId);
                    HasSingleFinger       = false;
                    HasTwoFingers         = true;
                    HasMoreThanTwoFingers = false;

                    var trackingFingerLocation = new PointF(ev.GetX(TrackingFingerId), ev.GetY(TrackingFingerId));
                    var secondFingerLocation   = new PointF(ev.GetX(SecondFingerId), ev.GetY(SecondFingerId));

                    MidpointLocation = MidPointBetween(trackingFingerLocation, secondFingerLocation);
                    StartLocation    = MidpointLocation;

                    break;
                }

                // Ignore any fingers above 2
                if (ev.PointerCount > 2)
                {
                    HasSingleFinger       = false;
                    HasTwoFingers         = false;
                    HasMoreThanTwoFingers = true;
                    //Debug.WriteLine ("More than two fingers down with new finger Id = {0}  IGNORING", ev.ActionIndex);
                    break;
                }
                break;

            case MotionEventActions.Move:
                if (HasSingleFinger || HasTwoFingers)
                {
                    pointerIndex    = ev.FindPointerIndex(TrackingFingerId);
                    CurrentLocation = new PointF(ev.GetX(pointerIndex), ev.GetY(pointerIndex));
                }

                if (HasTwoFingers)
                {
                    var trackingFingerLocation = new PointF(ev.GetX(TrackingFingerId), ev.GetY(TrackingFingerId));
                    var secondFingerLocation   = new PointF(ev.GetX(SecondFingerId), ev.GetY(SecondFingerId));
                    MidpointLocation = MidPointBetween(trackingFingerLocation, secondFingerLocation);
                }

                State = GestureDetectorState.Changed;
                break;


            case MotionEventActions.Cancel:
                fingersRemaining = ev.PointerCount - 1;
                if (fingersRemaining == 0)
                {
                    State = GestureDetectorState.Cancelled;
                    Reset();
                }
                break;

            case MotionEventActions.Up:
                TrackingFingerId = InvalidFingerId;
                //Debug.WriteLine ("All Fingers Up, Gesture Ended");
                Reset();
                State = GestureDetectorState.Ended;
                break;

            case MotionEventActions.PointerUp:
                fingersRemaining = ev.PointerCount - 1;
                //Debug.WriteLine ("Secondary Finger Up, fingers remaining = {0}", fingersRemaining);

                if (fingersRemaining == 1)
                {
                    // check to make sure that the finger that went up is for the gesture we're tracking.
                    pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
                    int pointerId = ev.GetPointerId(pointerIndex);
                    if (pointerId == TrackingFingerId)
                    {
                        // This was our tracking finger going up. Choose a new tracking finger and adjust accordingly
                        int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                        TrackingFingerId = ev.GetPointerId(newPointerIndex);
                    }

                    HasSingleFinger       = true;
                    HasTwoFingers         = false;
                    HasMoreThanTwoFingers = false;
                    AnchorLocation        = new PointF(ev.GetX(TrackingFingerId), ev.GetY(TrackingFingerId));
                    CurrentLocation       = new PointF(ev.GetX(TrackingFingerId), ev.GetY(TrackingFingerId));
                }

                if (fingersRemaining == 2)
                {
                    // stubbed
                }

                break;
            }

            return(true);
        }
コード例 #22
0
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            ensureTarget();

            MotionEventActions action = ev.Action;

            if (mReturningToStart && action == MotionEventActions.Down)
            {
                mReturningToStart = false;
            }
            if (!Enabled || mReturningToStart || canChildScrollUp() || mRefreshing)
            {
                // Fail fast if we're not in a state where a swipe is possible
                return(false);
            }
            switch (action)
            {
            case MotionEventActions.Down:
                setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.Top, true);
                mActivePointerId = ev.GetPointerId(0);
                mIsBeingDragged  = false;
                float initialDownY = getMotionEventY(ev, mActivePointerId);
                if (initialDownY == -1)
                {
                    return(false);
                }
                mInitialDownY = initialDownY;
                break;

            case MotionEventActions.Move:
                if (mActivePointerId == INVALID_POINTER)
                {
                    Log.Error(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
                    return(false);
                }

                float y = getMotionEventY(ev, mActivePointerId);
                if (y == -1)
                {
                    return(false);
                }
                float yDiff = y - mInitialDownY;
                if (yDiff > mTouchSlop && !mIsBeingDragged)
                {
                    mInitialMotionY = mInitialDownY + mTouchSlop;
                    mIsBeingDragged = true;
                    mProgress.SetAlpha(STARTING_PROGRESS_ALPHA);
                }
                break;

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

            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
                mIsBeingDragged  = false;
                mActivePointerId = INVALID_POINTER;
                break;
            }
            return(mIsBeingDragged);
        }
コード例 #23
0
 public int GetPointerId(int pointerIndex)
 {
     return(MotionEvent.GetPointerId(pointerIndex));
 }
コード例 #24
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            MotionEventActions action = ev.Action;

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

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

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

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

                float y             = ev.GetY(pointerIndex);
                float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
                if (mIsBeingDragged)
                {
                    mProgress.showArrow(true);
                    float originalDragPercent = overscrollTop / mTotalDragDistance;
                    if (originalDragPercent < 0)
                    {
                        return(false);
                    }
                    float dragPercent     = System.Math.Min(1f, System.Math.Abs(originalDragPercent));
                    float adjustedPercent = (float)System.Math.Max(dragPercent - .4, 0) * 5 / 3;
                    float extraOS         = System.Math.Abs(overscrollTop) - mTotalDragDistance;
                    float slingshotDist   = mUsingCustomStart ? mSpinnerFinalOffset
                                            - mOriginalOffsetTop : mSpinnerFinalOffset;
                    float tensionSlingshotPercent = System.Math.Max(0,
                                                                    System.Math.Min(extraOS, slingshotDist * 2) / slingshotDist);
                    float tensionPercent = (float)((tensionSlingshotPercent / 4) - System.Math.Pow(
                                                       (tensionSlingshotPercent / 4), 2)) * 2f;
                    float extraMove = (slingshotDist) * tensionPercent * 2;

                    int targetY = mOriginalOffsetTop
                                  + (int)((slingshotDist * dragPercent) + extraMove);
                    // where 1.0f is a full circle
                    if (mCircleView.Visibility != ViewStates.Visible)
                    {
                        mCircleView.Visibility = ViewStates.Visible;
                    }
                    if (!mScale)
                    {
                        ViewCompat.SetScaleX(mCircleView, 1f);
                        ViewCompat.SetScaleY(mCircleView, 1f);
                    }
                    if (overscrollTop < mTotalDragDistance)
                    {
                        if (mScale)
                        {
                            setAnimationProgress(overscrollTop / mTotalDragDistance);
                        }
                        if (mProgress.Alpha > STARTING_PROGRESS_ALPHA &&
                            !isAnimationRunning(mAlphaStartAnimation))
                        {
                            // Animate the alpha
                            startProgressAlphaStartAnimation();
                        }
                        float strokeStart = adjustedPercent * .8f;
                        mProgress.setStartEndTrim(0f, System.Math.Min(MAX_PROGRESS_ANGLE, strokeStart));
                        mProgress.setArrowScale(System.Math.Min(1f, adjustedPercent));
                    }
                    else
                    {
                        if (mProgress.Alpha < MAX_ALPHA &&
                            !isAnimationRunning(mAlphaMaxAnimation))
                        {
                            // Animate the alpha
                            startProgressAlphaMaxAnimation();
                        }
                    }
                    float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
                    mProgress.setProgressRotation(rotation);
                    setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop,
                                                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 (mActivePointerId == INVALID_POINTER)
                {
                    if (action == MotionEventActions.Up)
                    {
                        Log.Error(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
                    }
                    return(false);
                }
                int   pointerIndex0  = ev.FindPointerIndex(mActivePointerId);
                float y0             = ev.GetY(pointerIndex0);
                float overscrollTop0 = (y0 - mInitialMotionY) * DRAG_RATE;
                mIsBeingDragged = false;
                if (overscrollTop0 > mTotalDragDistance)
                {
                    setRefreshing(true, true /* notify */);
                }
                else
                {
                    // cancel refresh
                    mRefreshing = false;
                    mProgress.setStartEndTrim(0f, 0f);
                    IAnimationListener listener = null;
                    if (!mScale)
                    {
                        listener = new CustomCancelListener(this);
                    }
                    animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
                    mProgress.showArrow(false);
                }
                mActivePointerId = INVALID_POINTER;
                return(false);
            }
            }
            return(true);
        }
コード例 #25
0
ファイル: MapView.cs プロジェクト: ssqgrand/mobile-sdk
        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);
                        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: " + e);
                }
                return(true);
            }
        }
コード例 #26
0
        public bool OnTouch(View v, MotionEvent @event)
        {
            lock (this)
            {
                int action       = @event.GetAction() & MotionEvent.ACTION_MASK;
                int pointerIndex = (@event.GetAction() & MotionEvent.ACTION_POINTER_ID_MASK) >>
                                   MotionEvent.ACTION_POINTER_ID_SHIFT;
                int        pointerCount = @event.GetPointerCount();
                TouchEvent touchEvent;
                for (int i = 0; i < MAX_TOUCHPOINTS; i++)
                {
                    if (i >= pointerCount)
                    {
                        isTouched[i] = false;
                        id[i]        = -1;
                        continue;
                    }
                    int pointerId = @event.GetPointerId(i);
                    if (@event.GetAction() != MotionEvent.ACTION_MOVE && i != pointerIndex)
                    {
                        // if it's an up/down/cancel/out event, mask the id to see if we should process it for this touch
                        // point
                        continue;
                    }
                    switch (action)
                    {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_POINTER_DOWN:
                        touchEvent         = touchEventPool.newObject();
                        touchEvent.type    = TouchEvent.TOUCH_DOWN;
                        touchEvent.pointer = pointerId;
                        touchEvent.x       = touchX[i] = (int)(@event.GetX(i) * scaleX);
                        touchEvent.y       = touchY[i] = (int)(@event.GetY(i) * scaleY);
                        isTouched[i]       = true;
                        id[i] = pointerId;
                        touchEventsBuffer.Add(touchEvent);
                        break;

                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_POINTER_UP:
                    case MotionEvent.ACTION_CANCEL:
                        touchEvent         = touchEventPool.newObject();
                        touchEvent.type    = TouchEvent.TOUCH_UP;
                        touchEvent.pointer = pointerId;
                        touchEvent.x       = touchX[i] = (int)(@event.GetX(i) * scaleX);
                        touchEvent.y       = touchY[i] = (int)(@event.GetY(i) * scaleY);
                        isTouched[i]       = false;
                        id[i] = -1;
                        touchEventsBuffer.Add(touchEvent);
                        break;

                    case MotionEvent.ACTION_MOVE:
                        touchEvent         = touchEventPool.newObject();
                        touchEvent.type    = TouchEvent.TOUCH_DRAGGED;
                        touchEvent.pointer = pointerId;
                        touchEvent.x       = touchX[i] = (int)(@event.GetX(i) * scaleX);
                        touchEvent.y       = touchY[i] = (int)(@event.GetY(i) * scaleY);
                        isTouched[i]       = true;
                        id[i] = pointerId;
                        touchEventsBuffer.Add(touchEvent);
                        break;
                    }
                }
                return(true);
            }
        }
コード例 #27
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            mScaleDetector.OnTouchEvent(e);
            mgestureDetector.OnTouchEvent(e);

            var parent = Parent;

            int  n     = 0;
            bool check = false;

            while (n < 6)
            {
                if (parent.GetType() == typeof(ViewPager))
                {
                    check = true;
                    break;
                }

                parent = parent.Parent;
                n++;
            }

            if (check)
            {
                parent = parent as ViewPager;
            }
            else
            {
                parent = null;
            }

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

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

                break;
            }

            case MotionEventActions.PointerDown:
            {
                float gx = mScaleDetector.FocusX;
                float gy = mScaleDetector.FocusY;

                mLastGestureX = gx;
                mLastGestureY = gy;

                _IsZooming = true;

                break;
            }

            case MotionEventActions.Move:
            {
                if (mScaleFactor == 1.0f)
                {
                    break;
                }

                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;

                    this.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;

                    this.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);
                }
                _IsZooming = false;
                break;
            }

            if (parent != null)
            {
                if (mScaleFactor > 1 || _IsZooming)
                {
                    parent.RequestDisallowInterceptTouchEvent(true);
                }
                else
                {
                    parent.RequestDisallowInterceptTouchEvent(false);
                }
            }

            return(true);
        }
コード例 #28
0
        public bool OnTouch(MotionEvent e)
        {
            switch (e.ActionMasked)
            {
            case MotionEventActions.Up:
            {
                int id = e.GetPointerId(e.ActionIndex);
                if (id == pId1)
                {
                    pId1 = INVALID_ID;
                }
                if (id == pId2)
                {
                    pId2 = INVALID_ID;
                }
                break;
            }

            case MotionEventActions.PointerUp:
            {
                int id = e.GetPointerId(e.ActionIndex);
                if (id == pId1)
                {
                    pId1 = INVALID_ID;
                }
                if (id == pId2)
                {
                    pId2 = INVALID_ID;
                }
                break;
            }

            case MotionEventActions.Move:
            {
                if (e.PointerCount != 2 || pId1 == INVALID_ID || pId2 == INVALID_ID)
                {
                    return(false);
                }

                angle = GetAngle(e, pId1, pId2) - angleOffset;

                if (rotationListener != null)
                {
                    rotationListener.OnRotate(angle);
                }
                break;
            }

            case MotionEventActions.Down:
            {
                pId1 = e.GetPointerId(e.ActionIndex);
                break;
            }

            case MotionEventActions.PointerDown:
            {
                pId2        = e.GetPointerId(e.ActionIndex);
                angleOffset = GetAngle(e, pId1, pId2) - angle;
                break;
            }
            }
            return(true);
        }
コード例 #29
0
        public bool OnTouchEvent(MotionEvent evt)
        {
            var action = evt.ActionMasked;

            if (action == MotionEventActions.Down)
            {
                Reset();                 // Start fresh
            }

            bool handled = true;

            if (mInvalidGesture)
            {
                handled = false;
            }
            else if (!mGestureInProgress)
            {
                switch (action)
                {
                case MotionEventActions.Down: {
                    mActiveId0         = evt.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(evt);
                    mTimeDelta = 0;

                    int index1 = evt.ActionIndex;
                    int index0 = evt.FindPointerIndex(mActiveId0);
                    mActiveId1 = evt.GetPointerId(index1);
                    if (index0 < 0 || index0 == index1)
                    {
                        // Probably someone sending us a broken evt stream.
                        index0     = FindNewActiveIndex(evt, mActiveId1, -1);
                        mActiveId0 = evt.GetPointerId(index0);
                    }
                    mActive0MostRecent = false;

                    SetContext(evt);

                    mGestureInProgress = mListener.OnScaleBegin(this);
                    break;
                }
                }
            }
            else
            {
                // Transform gesture in progress - attempt to handle it
                switch (action)
                {
                case MotionEventActions.Down: {
                    // End the old gesture and begin a new one with the most recent two fingers.
                    mListener.OnScaleEnd(this);
                    int oldActive0 = mActiveId0;
                    int oldActive1 = mActiveId1;
                    Reset();

                    mPrevEvent         = MotionEvent.Obtain(evt);
                    mActiveId0         = mActive0MostRecent ? oldActive0 : oldActive1;
                    mActiveId1         = evt.GetPointerId(evt.ActionIndex);
                    mActive0MostRecent = false;

                    int index0 = evt.FindPointerIndex(mActiveId0);
                    if (index0 < 0 || mActiveId0 == mActiveId1)
                    {
                        index0     = FindNewActiveIndex(evt, mActiveId1, -1);
                        mActiveId0 = evt.GetPointerId(index0);
                    }

                    SetContext(evt);

                    mGestureInProgress = mListener.OnScaleBegin(this);
                }
                break;

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

                    bool gestureEnded = false;
                    if (pointerCount > 2)
                    {
                        if (actionId == mActiveId0)
                        {
                            int newIndex = FindNewActiveIndex(evt, mActiveId1, actionIndex);
                            if (newIndex >= 0)
                            {
                                mListener.OnScaleEnd(this);
                                mActiveId0         = evt.GetPointerId(newIndex);
                                mActive0MostRecent = true;
                                mPrevEvent         = MotionEvent.Obtain(evt);
                                SetContext(evt);
                                mGestureInProgress = mListener.OnScaleBegin(this);
                            }
                            else
                            {
                                gestureEnded = true;
                            }
                        }
                        else if (actionId == mActiveId1)
                        {
                            int newIndex = FindNewActiveIndex(evt, mActiveId0, actionIndex);
                            if (newIndex >= 0)
                            {
                                mListener.OnScaleEnd(this);
                                mActiveId1         = evt.GetPointerId(newIndex);
                                mActive0MostRecent = false;
                                mPrevEvent         = MotionEvent.Obtain(evt);
                                SetContext(evt);
                                mGestureInProgress = mListener.OnScaleBegin(this);
                            }
                            else
                            {
                                gestureEnded = true;
                            }
                        }
                        mPrevEvent.Recycle();
                        mPrevEvent = MotionEvent.Obtain(evt);
                        SetContext(evt);
                    }
                    else
                    {
                        gestureEnded = true;
                    }

                    if (gestureEnded)
                    {
                        // Gesture ended
                        SetContext(evt);

                        // Set focus point to the remaining finger
                        int activeId = actionId == mActiveId0 ? mActiveId1 : mActiveId0;
                        int index    = evt.FindPointerIndex(activeId);
                        mFocusX = evt.GetX(index);
                        mFocusY = evt.GetY(index);

                        mListener.OnScaleEnd(this);
                        Reset();
                        mActiveId0         = activeId;
                        mActive0MostRecent = true;
                    }
                }
                break;

                case MotionEventActions.Cancel:
                    mListener.OnScaleEnd(this);
                    Reset();
                    break;

                case MotionEventActions.Up:
                    Reset();
                    break;

                case MotionEventActions.Move: {
                    SetContext(evt);

                    // Only accept the evt if our relative pressure is within
                    // a certain limit - this can help filter shaky data as a
                    // finger is lifted.
                    if (mCurrPressure / mPrevPressure > PRESSURE_THRESHOLD)
                    {
                        bool updatePrevious = mListener.OnScale(this);

                        if (updatePrevious)
                        {
                            mPrevEvent.Recycle();
                            mPrevEvent = MotionEvent.Obtain(evt);
                        }
                    }
                }
                break;
                }
            }

            return(handled);
        }
コード例 #30
0
        public bool?DispatchTouchEvent(MotionEvent e, out bool callBase)
        {
            if (!HandleEvents)
            {
                callBase = true;
                return(null);
            }

            var eventTime = DateTime.Now;

            //Basic touch support
            var pointerEventType = e.Action switch
            {
                MotionEventActions.Down => RawPointerEventType.TouchBegin,
                MotionEventActions.Up => RawPointerEventType.TouchEnd,
                MotionEventActions.Cancel => RawPointerEventType.TouchCancel,
                _ => RawPointerEventType.TouchUpdate
            };

            if (e.Action.HasFlag(MotionEventActions.PointerDown))
            {
                pointerEventType = RawPointerEventType.TouchBegin;
            }

            if (e.Action.HasFlag(MotionEventActions.PointerUp))
            {
                pointerEventType = RawPointerEventType.TouchEnd;
            }

            for (int i = 0; i < e.PointerCount; i++)
            {
                //if point is in view otherwise it's possible avalonia not to find the proper window to dispatch the event
                var point = _getPointFunc(e, i);

                double x = _view.View.GetX();
                double y = _view.View.GetY();
                double r = x + _view.View.Width;
                double b = y + _view.View.Height;

                if (x <= point.X && r >= point.X && y <= point.Y && b >= point.Y)
                {
                    var inputRoot = _getInputRoot();

                    var mouseEvent = new RawTouchEventArgs(_touchDevice, (uint)eventTime.Ticks, inputRoot,
                                                           i == e.ActionIndex ? pointerEventType : RawPointerEventType.TouchUpdate, point, RawInputModifiers.None, e.GetPointerId(i));
                    _view.Input(mouseEvent);
                }
            }

            callBase = true;
            //if return false events for move and up are not received!!!
            return(e.Action != MotionEventActions.Up);
        }