private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange
            };

            var type    = _nativeEvent.GetToolType(_pointerIndex);
            var action  = _nativeEvent.Action;
            var isDown  = action.HasFlag(MotionEventActions.Down) || action.HasFlag(MotionEventActions.PointerDown);
            var isUp    = action.HasFlag(MotionEventActions.Up) || action.HasFlag(MotionEventActions.PointerUp);
            var updates = _none;

            switch (type)
            {
            case MotionEventToolType.Finger:
                props.IsLeftButtonPressed = Pointer.IsInContact;
                updates = isDown ? _fingerDownUpdates : isUp ? _fingerUpUpdates : _none;
                break;

            case MotionEventToolType.Mouse:
                props.IsLeftButtonPressed   = _nativeEvent.IsButtonPressed(MotionEventButtonState.Primary);
                props.IsMiddleButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.Tertiary);
                props.IsRightButtonPressed  = _nativeEvent.IsButtonPressed(MotionEventButtonState.Secondary);
                updates = isDown ? _mouseDownUpdates : isUp ? _mouseUpUpdates : _none;
                break;

            case MotionEventToolType.Stylus:
                props.IsBarrelButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary);
                props.IsLeftButtonPressed   = Pointer.IsInContact && !props.IsBarrelButtonPressed;
                break;

            case MotionEventToolType.Eraser:
                props.IsEraser = true;
                break;

            case MotionEventToolType.Unknown:                     // used by Xamarin.UITest
                props.IsLeftButtonPressed = true;
                break;

            default:
                break;
            }

            if (Android.OS.Build.VERSION.SdkInt >= BuildVersionCodes.M &&          // ActionButton was introduced with API 23 (https://developer.android.com/reference/android/view/MotionEvent.html#getActionButton())
                updates.TryGetValue(_nativeEvent.ActionButton, out var update))
            {
                props.PointerUpdateKind = update;
            }

            return(props);
        }
示例#2
0
        private PointerPointProperties GetProperties()
        {
            var props = new PointerPointProperties
            {
                IsPrimary = true,
                IsInRange = Pointer.IsInRange
            };

            var type    = _nativeEvent.GetToolType(_nativeEvent.ActionIndex);
            var action  = _nativeEvent.Action;
            var isDown  = action.HasFlag(MotionEventActions.Down) || action.HasFlag(MotionEventActions.PointerDown);
            var isUp    = action.HasFlag(MotionEventActions.Up) || action.HasFlag(MotionEventActions.PointerUp);
            var updates = _none;

            switch (type)
            {
            case MotionEventToolType.Finger:
                props.IsLeftButtonPressed = Pointer.IsInContact;
                updates = isDown ? _fingerDownUpdates : isUp ? _fingerUpUpdates : _none;
                break;

            case MotionEventToolType.Mouse:
                props.IsLeftButtonPressed   = _nativeEvent.IsButtonPressed(MotionEventButtonState.Primary);
                props.IsMiddleButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.Tertiary);
                props.IsRightButtonPressed  = _nativeEvent.IsButtonPressed(MotionEventButtonState.Secondary);
                updates = isDown ? _mouseDownUpdates : isUp ? _mouseUpUpdates : _none;
                break;

            case MotionEventToolType.Stylus:
                props.IsBarrelButtonPressed = _nativeEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary);
                props.IsLeftButtonPressed   = Pointer.IsInContact && !props.IsBarrelButtonPressed;
                break;

            case MotionEventToolType.Eraser:
                props.IsEraser = true;
                break;

            case MotionEventToolType.Unknown:                     // used by Xamarin.UITest
                props.IsLeftButtonPressed = true;
                break;

            default:
                break;
            }

            if (updates.TryGetValue(_nativeEvent.ActionButton, out var update))
            {
                props.PointerUpdateKind = update;
            }

            return(props);
        }
示例#3
0
 protected override void OnHover(MotionEvent hoverEvent)
 {
     PendingInputs.Enqueue(new MousePositionAbsoluteInput {
         Position = getEventPosition(hoverEvent)
     });
     PendingInputs.Enqueue(new MouseButtonInput(MouseButton.Right, hoverEvent.IsButtonPressed(MotionEventButtonState.StylusPrimary)));
 }