// ---------------------------------------------------------

        #region Private Methods

        private void HandleTouchDown(Android.Views.MotionEvent e)
        {
            // Set values from settings
            _currentPaint.Color = _formsView.PaintColor.ToAndroid();
            _currentPaint.StrokeWidth = _formsView.LineWidth * _deviceDensity;

            // Init storage for pointers and historical coords
            _pointerIds = new List<int>();
            _lastPointers = new List<PaintPointer>();

            // Loop all pointers
            for(int i = 0; i < e.PointerCount; i++)
            {
                // Get and store the pointer
                var pointerId = e.GetPointerId(i);

                _pointerIds.Add(pointerId);

                // Get the pointer coords
                var currentPoint = GetPointerCoords(e, pointerId);

                // Store the coord in the historical list
                _lastPointers.Add(new PaintPointer() { PointerId = pointerId, Coords = currentPoint });

                // Draw the line
                DrawLine(currentPoint, currentPoint);
            }
        }
Esempio n. 2
0
            public bool OnTouch( Android.Views.View v, Android.Views.MotionEvent e )
            {
                Android.Views.MotionEventActions action = e.Action;

                if ( ( action & Android.Views.MotionEventActions.Mask ) != Android.Views.MotionEventActions.Move )
                {
                    TouchPointer tec = new TouchPointer ();

                    switch ( action & Android.Views.MotionEventActions.Mask )
                    {
                        case Android.Views.MotionEventActions.Down:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( 0 ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Pressed );
                            break;
                        case Android.Views.MotionEventActions.PointerDown:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( ( int ) ( action & Android.Views.MotionEventActions.PointerIdMask ) >> ( int ) Android.Views.MotionEventActions.PointerIdShift ) ),
                                                     new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Pressed );
                            break;
                        case Android.Views.MotionEventActions.Up:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( 0 ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Released );
                            break;
                        case Android.Views.MotionEventActions.PointerUp:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( ( int ) ( action & Android.Views.MotionEventActions.PointerIdMask ) >> ( int ) Android.Views.MotionEventActions.PointerIdShift ) ),
                                                    new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Released );
                            break;
                    }

                    bool isChanged = false;
                    for ( int i = 0; i < touchPointers.Count; i++ )
                    {
                        if ( touchPointers [ i ].Id == tec.Id )
                        {
                            touchPointers [ i ] = tec;
                            isChanged = true;
                            break;
                        }
                    }

                    if ( !isChanged )
                        touchPointers.Add ( tec );
                }
                else if ( ( action & Android.Views.MotionEventActions.Mask ) == Android.Views.MotionEventActions.Move )
                {
                    for ( int i = 0; i < e.PointerCount; i++ )
                    {
                        TouchPointer tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( i ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Moved );
                        touchPointers [ i ] = tec;
                    }
                }

                return true;
            }