public override bool OnTouchEvent(MotionEvent ev)
        {
            MotionEventActions action = ev.Action;
            switch (action & MotionEventActions.Mask) {
            case MotionEventActions.Down:
                mActivePointerId = ev.GetPointerId(0);
                break;
            case MotionEventActions.Cancel:
            case MotionEventActions.Up:
                mActivePointerId = INVALID_POINTER_ID;
                break;
            case MotionEventActions.PointerUp:
                // Ignore deprecation, ACTION_POINTER_ID_MASK and
                // ACTION_POINTER_ID_SHIFT has same value and are deprecated
                // You can have either deprecation or lint target api warning
                int pointerIndex = Compat.GetPointerIndex(ev.Action);
                 int pointerId = ev.GetPointerId(pointerIndex);
                if (pointerId == mActivePointerId) {
                    // This was our active pointer going up. Choose a new
                    // active pointer and adjust accordingly.
                     int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                    mActivePointerId = ev.GetPointerId(newPointerIndex);
                    mLastTouchX = ev.GetX(newPointerIndex);
                    mLastTouchY = ev.GetY(newPointerIndex);
                }
                break;
            }

            mActivePointerIndex = ev
                .FindPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
                    : 0);
            return base.OnTouchEvent(ev);
        }
		public override bool OnTouchEvent (MotionEvent ev)
		{
			_scaleDetector.OnTouchEvent (ev);

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

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

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

				_lastTouchX = x;
				_lastTouchY = y;
				break;

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

			case MotionEventActions.PointerUp:
                    // We only want to update the last touch position if the the appropriate pointer
                    // has been lifted off the screen.
				pointerIndex = (int)(ev.Action & MotionEventActions.PointerIndexMask) >> (int)MotionEventActions.PointerIndexShift;
				int pointerId = ev.GetPointerId (pointerIndex);
				if (pointerId == _activePointerId) {
					// This was our active pointer going up. Choose a new
					// action pointer and adjust accordingly
					int newPointerIndex = pointerIndex == 0 ? 1 : 0;
					_lastTouchX = ev.GetX (newPointerIndex);
					_lastTouchY = ev.GetY (newPointerIndex);
					_activePointerId = ev.GetPointerId (newPointerIndex);
				}
				break;
			}
			return true;
		}
Ejemplo n.º 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;
        }
Ejemplo n.º 4
0
        // ---------------------------------------------------------

        #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);
            }
        }
        public void HandleDragEvent(MotionEvent ev)
        {
            MotionEventActions action = ev.Action & MotionEventActions.Mask;
            int pointerIndex;
            switch (action) {
            case MotionEventActions.Down:
                _lastTouchX = ev.RawX;
                _lastTouchY = ev.RawY;
                _activePointerId = ev.GetPointerId (0);
                _posX = _posX == 0 ? Shape.Center_X - Shape.Radius : _posX;
                _posY = _posY == 0 ? Shape.Center_Y - Shape.Radius : _posX;
                break;

            case MotionEventActions.Move:
                pointerIndex = ev.FindPointerIndex (_activePointerId);
                float x = ev.RawX;
                float y = ev.RawY;

                float deltaX = x - _lastTouchX;
                float deltaY = y - _lastTouchY;
                _posX += deltaX;
                _posY += deltaY;
                if (RequestLayout != null)
                    RequestLayout ((int)_posX, (int)_posY, (int)_posX + Shape.Radius * 2, (int)_posY + Shape.Radius * 2);

                _lastTouchX = x;
                _lastTouchY = y;
                break;

            case MotionEventActions.Up:
                _lastTouchX = ev.RawX;
                _lastTouchY = ev.RawY;
                Shape.Center_X = (int)_posX + Shape.Radius;
                Shape.Center_Y = (int)_posY + Shape.Radius;
                _posX = 0;
                _posY = 0;
                break;
            case MotionEventActions.Cancel:
                // We no longer need to keep track of the active pointer.
                _activePointerId = -1;
                break;

            case MotionEventActions.PointerUp:
                // check to make sure that the pointer 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 == _activePointerId) {

                    _lastTouchX = ev.RawX;
                    _lastTouchY = ev.RawY;
                    Shape.Center_X = (int)_posX + Shape.Radius;
                    Shape.Center_Y = (int)_posY + Shape.Radius;

                }
                break;

            }
        }
Ejemplo n.º 6
0
        public void OnTouchEvent(MotionEvent e)
        {
            if (!Enabled)
                return;

            Vector2 position = Vector2.Zero;
            position.X = e.GetX(e.ActionIndex);
            position.Y = e.GetY(e.ActionIndex);
            UpdateTouchPosition(ref position);
            int id = e.GetPointerId(e.ActionIndex);
            switch (e.ActionMasked)
            {
                // DOWN                
                case MotionEventActions.Down:
                case MotionEventActions.PointerDown:
                    TouchPanel.AddEvent(id, TouchLocationState.Pressed, position);
                    break;
                // UP                
                case MotionEventActions.Up:
                case MotionEventActions.PointerUp:
                    TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                    break;
                // MOVE                
                case MotionEventActions.Move:
                    for (int i = 0; i < e.PointerCount; i++)
                    {
                        id = e.GetPointerId(i);
                        position.X = e.GetX(i);
                        position.Y = e.GetY(i);
                        UpdateTouchPosition(ref position);
                        TouchPanel.AddEvent(id, TouchLocationState.Moved, position);
                    }
                    break;

                // CANCEL, OUTSIDE                
                case MotionEventActions.Cancel:
                case MotionEventActions.Outside:
                    for (int i = 0; i < e.PointerCount; i++)
                    {
                        id = e.GetPointerId(i);
                        TouchPanel.AddEvent(id, TouchLocationState.Released, position);
                    }
                    break;
            }
        }
Ejemplo n.º 7
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            _scaleDetector.OnTouchEvent(ev);

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

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

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

                    _lastTouchX = x;
                    _lastTouchY = y;
                    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) (ev.Action & MotionEventActions.PointerIndexMask) >> (int) MotionEventActions.PointerIndexShift;
                    int pointerId = ev.GetPointerId(pointerIndex);
                    if (pointerId == _activePointerId)
                    {
                        // This was our active pointer going up. Choose a new
                        // action pointer and adjust accordingly
                        int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                        _lastTouchX = ev.GetX(newPointerIndex);
                        _lastTouchY = ev.GetY(newPointerIndex);
                        _activePointerId = ev.GetPointerId(newPointerIndex);
                    }
                    break;

            }
            return true;
        }
Ejemplo n.º 8
0
        private bool OnTouch(MotionEvent e)
        {
            PointerState state;
            switch (e.ActionMasked)
            {
                case MotionEventActions.Cancel:
                    state = PointerState.Cancel;
                    break;
                case MotionEventActions.Move:
                    state = PointerState.Move;
                    break;
                case MotionEventActions.Outside:
                    state = PointerState.Out;
                    break;
                case MotionEventActions.Down:
                case MotionEventActions.PointerDown:
                    state = PointerState.Down;
                    break;
                case MotionEventActions.Up:
                case MotionEventActions.PointerUp:
                    state = PointerState.Up;
                    break;
                default:
                    // Not handled
                    return false;
            }

            var startIndex = 0;
            var endIndex = e.PointerCount;

            if (state == PointerState.Down || state == PointerState.Up || state == PointerState.Out)
            {
                startIndex = e.ActionIndex;
                endIndex = startIndex + 1;
            }

            for (var i = startIndex; i < endIndex; ++i)
            {
                var pointerId = e.GetPointerId(i);
                var pixelPosition = new Vector2(e.GetX(i), e.GetY(i));

                if(MultiTouchEnabled || pointerId == 0) // manually drop multi-touch events when disabled
                    HandlePointerEvents(pointerId, NormalizeScreenPosition(pixelPosition), state);
            }

            return true;
        }
Ejemplo n.º 9
0
        void HandleUpAction(Android.Views.MotionEvent e)
        {
            int id         = e.GetPointerId(e.ActionIndex);
            var touchIndex = Array.IndexOf(pointerIds, id);

            if (touchIndex < 0)
            {
                return;
            }
            pointerIds[touchIndex] = -1;
            if (touchIndex == 0)
            {
                input.SetKeyState(Key.Mouse0, false);
            }
            var key = (Key)((int)Key.Touch0 + touchIndex);

            input.SetKeyState(key, false);
        }
Ejemplo n.º 10
0
        void HandleDownAction(Android.Views.MotionEvent e)
        {
            var touchIndex = Array.IndexOf(pointerIds, -1);

            if (touchIndex < 0)
            {
                return;
            }
            int i = e.ActionIndex;

            pointerIds[touchIndex] = e.GetPointerId(i);
            if (touchIndex == 0)
            {
                input.SetKeyState(Key.Mouse0, true);
            }
            var key = (Key)((int)Key.Touch0 + touchIndex);

            input.SetKeyState(key, true);
        }
Ejemplo n.º 11
0
        void HandleMoveActions(Android.Views.MotionEvent e)
        {
            var pc = new Android.Views.MotionEvent.PointerCoords();

            for (int i = 0; i < e.PointerCount; i++)
            {
                int id         = e.GetPointerId(i);
                int touchIndex = Array.IndexOf(pointerIds, id);
                if (touchIndex < 0)
                {
                    continue;
                }
                e.GetPointerCoords(i, pc);
                var position = new Vector2(pc.X, pc.Y) * input.ScreenToWorldTransform / Window.Current.PixelScale;
                input.SetTouchPosition(touchIndex, position);
                if (touchIndex == 0)
                {
                    input.MousePosition = position;
                }
            }
        }
Ejemplo n.º 12
0
        void HandleMoveActions(Android.Views.MotionEvent e)
        {
            var pc = new Android.Views.MotionEvent.PointerCoords();

            for (int i = 0; i < e.PointerCount; i++)
            {
                int id         = e.GetPointerId(i);
                int touchIndex = Array.IndexOf(pointerIds, id);
                if (touchIndex < 0)
                {
                    continue;
                }
                e.GetPointerCoords(i, pc);
                var position = new Vector2(pc.X, pc.Y);
                input.SetDesktopTouchPosition(touchIndex, position);
                if (touchIndex == 0)
                {
                    input.DesktopMousePosition = position;
                }
            }
        }
Ejemplo n.º 13
0
        public override bool OnGenericMotionEvent(MotionEvent e)
        {
            for (var i = 0; i < e.PointerCount; i++)
            {
                var pointerId = e.GetPointerId(i);
                var x = e.GetX(i);
                var y = e.GetY(i);
                switch (e.ActionMasked)
                {
                    case MotionEventActions.Down:
                    case MotionEventActions.PointerDown:
                    case MotionEventActions.Move:
                        moveFingerTrace(pointerId, x, y);
                        break;

                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                    case MotionEventActions.Cancel:
                        hideFingerTrace(pointerId);
                        break;
                }
            }
            return false;
        }
Ejemplo n.º 14
0
        public override bool OnTouchEvent(MotionEvent evt)
        {
            if (gMitcRender.TransState || gMitcRender.RotAState)
            {
                if (evt.Action == MotionEventActions.Down)
                {
                    m_lastPos.Set(evt.GetX(), evt.GetY());
                    mMitcRender.GetWorldPoint(m_lastPos.X, m_lastPos.Y, ref m_lastwx, ref m_lastwy, ref m_lastwz);
                    m_curPos.X = m_lastPos.X;
                    m_curPos.Y = m_lastPos.Y;

                    m_curwx = m_lastwx;
                    m_curwy = m_lastwy;
                    m_curwz = m_lastwz;
                    Transing = true;
                    //gMitcRender.updateMatrix();
                    if (gMitcRender.RotAState)
                    {
                        Tuple2fT MousePt = new Tuple2fT();
                        MousePt.s.X = evt.GetX();
                        MousePt.s.Y = evt.GetY();
                        isDragging = true;

            //                         string strWp = String.Format("Down ThisRot Rot:({0},{1},{2})", ThisRot.s.M00, ThisRot.s.M11, ThisRot.s.M22);
            //                         Log.Debug(TAG, strWp);
                        LastRot = (Matrix3fT)ThisRot.Clone();
            //                         strWp = String.Format("After Down LastRot Rot:({0},{1},{2})", LastRot.s.M00, LastRot.s.M11, LastRot.s.M22);
            //                         Log.Debug(TAG, strWp);
                        m_arcball.click(MousePt);
                    }

                }
                else if (evt.Action == MotionEventActions.Up)
                {
                    Transing = false;
                    if (gMitcRender.RotAState)
                    {
                        isDragging = false;
                    }
                }
                else if (evt.Action == MotionEventActions.Move)
                {
                    m_curPos.Set(evt.GetX(), evt.GetY());
                    mMitcRender.GetWorldPoint(m_curPos.X, m_curPos.Y, ref m_curwx, ref m_curwy, ref m_curwz);
                    mMitcRender.buildTransform((m_curwx - m_lastwx), (m_curwy - m_lastwy), m_curwz - m_lastwz);
                    m_lastPos.X = m_curPos.X;
                    m_lastPos.Y = m_curPos.Y;
                    m_lastwx = m_curwx;
                    m_lastwy = m_curwy;
                    m_lastwz = m_curwz;

                    string strWp = String.Format("1.Move This Point:({0},{1},{2})", m_curwx, m_curwy, m_curwz);
                    Log.Debug(TAG, strWp);

                    if (gMitcRender.RotAState && isDragging)
                    {
                        Tuple4fT ThisQuat = new Tuple4fT();
                        Tuple2fT MousePt = new Tuple2fT();
                        MousePt.s.X = evt.GetX();
                        MousePt.s.Y = evt.GetY();
                        m_arcball.drag(MousePt, ref ThisQuat);
                        //string strWp = String.Format("1.Move This Rot:({0},{1},{2})", ThisRot.s.M00, ThisRot.s.M11, ThisRot.s.M22);
                        //Log.Debug(TAG, strWp);

                        CMatrixMath.Matrix3fSetRotationFromQuat4f(ref ThisRot, ThisQuat);
                        //strWp = String.Format("2.Move This Rot:({0},{1},{2})", ThisRot.s.M00, ThisRot.s.M11, ThisRot.s.M22);
                        //Log.Debug(TAG, strWp);
                        CMatrixMath.Matrix3fMulMatrix3f(ref ThisRot, LastRot);
                        //strWp = String.Format("3.Move This Rot:({0},{1},{2})", ThisRot.s.M00, ThisRot.s.M11, ThisRot.s.M22);
                        //Log.Debug(TAG, strWp);

                        //strWp = String.Format("Move Last Rot:({0},{1},{2})", LastRot.s.M00, LastRot.s.M11, LastRot.s.M22);
                        //Log.Debug(TAG, strWp);
                        Matrix4fT _tempTransform = mMitcRender.Transform;
                        CMatrixMath.Matrix4fSetRotationFromMatrix3f(ref _tempTransform, ThisRot);

                        m_arcball.upstate();
                    }
                    this.RequestRender();
                }
                return true;
            }
            else if (gMitcRender.ScaleState)
            {
                int nCnt = evt.PointerCount;

                if ((evt.Action & MotionEventActions.Mask) == MotionEventActions.PointerDown && 2 == nCnt)//<span style="color:#ff0000;">2��ʾ������ָ</span>
                {
                    m_lastPos.Set(evt.GetX(evt.GetPointerId(0)), evt.GetY(evt.GetPointerId(0)));
                    m_curPos.Set(evt.GetX(evt.GetPointerId(nCnt - 1)), evt.GetY(evt.GetPointerId(nCnt - 1)));
                    string strWp = String.Format("2 Down Point:({0}),({1})", m_lastPos.ToString(), m_curPos.ToString());
                    Log.Debug(TAG, strWp);

                    mOldCounts = 2;
                    mScaleFactor = 1.0f;
                    //gMitcRender.updateMatrix();
                }
                else if ((evt.Action & MotionEventActions.Mask) == MotionEventActions.PointerUp && 2 == nCnt)
                {
                    m_lastPos.Set(evt.GetX(evt.GetPointerId(0)), evt.GetY(evt.GetPointerId(0)));
                    m_curPos.Set(evt.GetX(evt.GetPointerId(nCnt - 1)), evt.GetY(evt.GetPointerId(nCnt - 1)));
                    string strWp = String.Format("2 Up Point:({0}),({1})", m_lastPos.ToString(), m_curPos.ToString());
                    Log.Debug(TAG, strWp);
                    mOldCounts = 0;
                    mScaleFactor = 1.0f;

                }
                else if (evt.Action == MotionEventActions.Move && 2 == nCnt)
                {
                    float lastlength = GetLength(m_lastPos, m_curPos);
                    m_lastPos.Set(evt.GetX(evt.GetPointerId(0)), evt.GetY(evt.GetPointerId(0)));
                    m_curPos.Set(evt.GetX(evt.GetPointerId(nCnt - 1)), evt.GetY(evt.GetPointerId(nCnt - 1)));
                    float curlength = GetLength(m_lastPos, m_curPos);
                    mScaleFactor = Math.Abs(lastlength) < 1.0e-6 ? 1.0f : (curlength / lastlength);
                    mMitcRender.buildScale(mScaleFactor);
                    this.RequestRender();
                    string strWp = String.Format("2 Move Point:({0}),({1})", m_lastPos.ToString(), m_curPos.ToString());
                    Log.Debug(TAG, strWp);
                }
            }
            return true;
        }
Ejemplo n.º 15
0
        /** Show an event in the LogCat view, for debugging */
        private void dumpEvent(MotionEvent evt)
        {
            String[] names = { "DOWN" , "UP" , "MOVE" , "CANCEL" , "OUTSIDE" ,
                "POINTER_DOWN" , "POINTER_UP" , "7?" , "8?" , "9?" };

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            int action = (int)evt.Action;
            int actionCode = action & (int)MotionEventActions.Mask;
            sb.Append("event ACTION_" ).Append(names[actionCode]);
            if (actionCode == (int)MotionEventActions.PointerDown
                    || actionCode == (int)MotionEventActions.PointerUp) {
                sb.Append("(pid " ).Append(
                action >> (int)MotionEventActions.PointerIdShift);
                sb.Append(")" );
            }
            sb.Append("[" );
            for (int i = 0; i < evt.PointerCount; i++) {
                sb.Append("#" ).Append(i);
                sb.Append("(pid " ).Append(evt.GetPointerId(i));
                sb.Append(")=" ).Append((int) evt.GetX(i));
                sb.Append("," ).Append((int) evt.GetY(i));
                if (i + 1 < evt.PointerCount)
                    sb.Append(";" );
            }
            sb.Append("] - ActionIndex: " + evt.ActionIndex + ", ActionIndexPointerId: " + evt.GetPointerId(evt.ActionIndex) );

            Console.WriteLine(sb.ToString());
        }
Ejemplo n.º 16
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            for (int i = 0; i != ApplicationEvent.TouchCount; ++i)
            {
                theEvent.TouchesOn[i] = false;
            }

            int count = (e.PointerCount <= ApplicationEvent.TouchCount) ? e.PointerCount : ApplicationEvent.TouchCount;
            for (int i = 0; i != count; ++i)
            {
                int id = e.GetPointerId(i);
                theEvent.TouchLocations[id] = new Vector2(e.GetX(i), e.GetY(i));
                theEvent.TouchesOn[id] = (e.Action != MotionEventActions.Up);
            }

            theEvent.Type = ApplicationEventTypes.Touch;
            application.handleEvent(theEvent);
            return true;
        }
Ejemplo n.º 17
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;
		}
Ejemplo n.º 18
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            // Get current position of pointer at index 0.
            // This will be the first pointer down and the last pointer up even if not the same
            System.Drawing.PointF curr = new System.Drawing.PointF(e.GetX(), e.GetY());

            switch (e.Action) {
                case MotionEventActions.PointerDown:
                    pointer2Index = 1;
                    break;
                case MotionEventActions.Down:
                    // Set the current box and add it to the List<Box> mBoxes
                    if (mCurrentBox == null) {
                        mCurrentBox = new Box(curr, e.GetPointerId(0));
                        mBoxes.Add(mCurrentBox);
                    }
                    break;
                case MotionEventActions.Pointer2Down:
                    // Handle 2nd touch. Set the start point of the rotation
                    if (mRotationStart == null) {
                        // Get coordinates of pointer 2
                        MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
                        e.GetPointerCoords(1, pCoords);
                        // Set the starting coordinates for the rotation
                        mRotationStart = new Box(new System.Drawing.PointF(pCoords.X, pCoords.Y), e.GetPointerId(1));
                        mInitialRotation = mCurrentBox.Rotation;
                        pointer2Index = 1;
                    }
                    break;
                case MotionEventActions.Move:
                    // Handle first pointer move, set end point for rectangle
                    if (mCurrentBox != null && mCurrentBox.PointerId == e.GetPointerId(0)) {
                        mCurrentBox.Current = curr;
                    }
                    // Handle second pointer move, set rotation amount
                    if (mRotationStart != null && mRotationStart.PointerId == e.GetPointerId(pointer2Index)) {
                        // Get coordinates of pointer 2
                        MotionEvent.PointerCoords pCoords = new MotionEvent.PointerCoords();
                        e.GetPointerCoords(pointer2Index, pCoords);
                        // Set the rotation of the box to the difference between the origin of mRotation and the current position of pointer 2
                        mCurrentBox.Rotation = mInitialRotation + pCoords.Y - mRotationStart.Origin.Y;
                    }
                    Invalidate();
                    break;
                case MotionEventActions.Pointer2Up:
                    mRotationStart = null;
                    break;
                case MotionEventActions.PointerUp:
                    pointer2Index = 0;
                    break;
                case MotionEventActions.Up:
                    mCurrentBox = null;
                    mRotationStart = null;
                    break;
                case MotionEventActions.Cancel:
                    mCurrentBox = null;
                    mRotationStart = null;
                    break;
            }

            return true;
        }
        /// <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>
        override public bool OnTouchEvent(MotionEvent e)
        {
            float xConversion = SparrowSharpApp.Stage.Width / Size.Width;
            float yConversion = SparrowSharpApp.Stage.Height / Size.Height;

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

            double now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

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

            switch (maskedAction)
            {
                case MotionEventActions.Down:
                case MotionEventActions.PointerDown:
                    // new pointer
                    Touch newTouch = new Touch();
                    newTouch.TouchID = pointerId;
                    newTouch.TimeStamp = now;
                    newTouch.GlobalX = e.GetX() * xConversion;
                    newTouch.GlobalY = e.GetY() * yConversion;
                    newTouch.InitialGlobalX = newTouch.GlobalX;
                    newTouch.InitialGlobalY = newTouch.GlobalY;
                    newTouch.Phase = TouchPhase.Began;
                    Point touchPosition = Point.Create(newTouch.GlobalX, newTouch.GlobalY);
                    newTouch.Target = SparrowSharpApp.Stage.HitTestPoint(touchPosition);

                    _touches.Add(newTouch.TouchID, newTouch);
                    break;
                case MotionEventActions.Move:
                    for (int size = e.PointerCount, i = 0; i < size; i++)
                    {
                        Touch movedTouch;
                        _touches.TryGetValue(e.GetPointerId(i), out movedTouch);
                        if (movedTouch != null)
                        {
                            // TODO: should we care about historical pointer events?
                            movedTouch.PreviousGlobalX = movedTouch.GlobalX;
                            movedTouch.PreviousGlobalY = movedTouch.GlobalY;
                            movedTouch.TimeStamp = now;
                            float xc = e.GetX(i) * xConversion;
                            float yc = e.GetY(i) * yConversion;
                            if (movedTouch.GlobalX == xc && movedTouch.GlobalY == yc)
                            {
                                movedTouch.Phase = TouchPhase.Stationary;
                            }
                            else
                            {
                                movedTouch.GlobalX = xc;
                                movedTouch.GlobalY = yc;
                                movedTouch.Phase = TouchPhase.Moved;
                            }
                            if (movedTouch.Target == null || movedTouch.Target.Stage == null)
                            {
                                // target could have been removed from stage -> find new target in that case
                                Point updatedTouchPosition = Point.Create(movedTouch.GlobalX, movedTouch.GlobalY);
                                movedTouch.Target = SparrowSharpApp.Root.HitTestPoint(updatedTouchPosition);
                            }
                        }
                    }
                    break;
                case MotionEventActions.Up:
                case MotionEventActions.PointerUp:
                    touchInFocus = _touches[pointerId];
                    touchInFocus.Phase = TouchPhase.Ended;
                    long downTime = Android.OS.SystemClock.UptimeMillis() - e.DownTime;
                    touchInFocus.TimeStamp = now;
                    double dist = Math.Sqrt(
                                      (touchInFocus.GlobalX - touchInFocus.InitialGlobalX) * (touchInFocus.GlobalX - touchInFocus.InitialGlobalX) +
                                      (touchInFocus.GlobalY - touchInFocus.InitialGlobalY) * (touchInFocus.GlobalY - touchInFocus.InitialGlobalY));
                    // TODO: move the time out to a constant, make dist DPI dependent
                    if (downTime < 300 && dist < 50)
                    {
                        touchInFocus.IsTap = true;
                    }
                    break;
                case MotionEventActions.Cancel:
                    touchInFocus = _touches[pointerId];
                    touchInFocus.Phase = TouchPhase.Cancelled;
                    break;
            }

            foreach (Touch tou in _touches.Values)
            {
                TouchEvent touchEvent = new TouchEvent(new List<Touch>(_touches.Values));
                if (tou.Target != null)
                {
                    tou.Target.InvokeTouch(touchEvent);
                }
                //Console.WriteLine ("phase:" + tou.Phase + " ID:" + tou.TouchID + 
                //    " target:" + tou.Target + " isTap:"+ tou.IsTap + " timestamp:" + tou.TimeStamp);
            }

            var touchList = new List<Touch>(_touches.Values);
            foreach (Touch tou in touchList)
            {
                if (tou.Phase == TouchPhase.Ended || tou.Phase == TouchPhase.Cancelled)
                {
                    _touches.Remove(tou.TouchID);
                }
            }
            return true;
        }
		void OnSecondaryPointerUp(MotionEvent paramMotionEvent) {
			int i = ((int)paramMotionEvent.Action) >> 8;
			if (paramMotionEvent.GetPointerId(i) == _activePointerId)
			if (i != 0) {
				_lastMotionY = paramMotionEvent.GetY(0);
				_activePointerId = paramMotionEvent.GetPointerId(0);
			}
		}
Ejemplo n.º 21
0
 private void OnSecondaryPointerUp(MotionEvent e)
 {
     int pointerIndex = (int)((object)(e.Action & MotionEventActions.PointerIndexMask)) >>
         (int)((object)MotionEventActions.PointerIndexShift);
     int pointerId = e.GetPointerId(pointerIndex);
     if (pointerId == this.activePointerId)
     {
         int newPointerIndex = pointerIndex == 0 ? 1 : 0;
         this.lastMotionX = (int)e.GetX(newPointerIndex);
         this.lastMotionY = (int)e.GetY(newPointerIndex);
         this.activePointerId = e.GetPointerId(newPointerIndex);
         if (this.velocityTracker != null)
         {
             this.velocityTracker.Clear();
         }
     }
 }
		//TODO: Step 5 - Subscribe to touch events in the view
        public override bool OnTouchEvent(MotionEvent ev)
        {
            Log.Debug(GetType().FullName, "Number of touches: {0}", ev.PointerCount);

            Log.Debug(GetType().FullName, "Touch Type: {0}", ev.Action);

            float width = _icon.IntrinsicWidth, height = _icon.IntrinsicHeight;

			//TODO: Step 6 - Detect scale events
            _scaleDetector.OnTouchEvent(ev);

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

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

				case MotionEventActions.Move:
					pointerIndex = ev.FindPointerIndex (_activePointerId);
					float x = ev.GetX (pointerIndex);
					float y = ev.GetY (pointerIndex);

					if (!_scaleDetector.IsInProgress) {
						// Only move the ScaleGestureDetector isn't already processing a gesture.
						float deltaX = x - _lastTouchX;
						float deltaY = y - _lastTouchY;
						_posX += deltaX;
						_posY += deltaY;
						Invalidate ();
					}

					_lastTouchX = x;
					_lastTouchY = y;
                    break;

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

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

            //Determine if the image is within the touch area
            if (Math.Abs(_scaleFactor - 1.0f) > 0.001) { width *= _scaleFactor; height *= _scaleFactor; }
            var rc = new RectF(_posX, _posY, _posX + width, _posY + height);
            float touchX = ev.GetX(), touchY = ev.GetY();
            bool contains = rc.Contains(touchX, touchY);
            Log.Debug(GetType().FullName, "{0} - ({1},{2}) - CONTAINS: {3}", rc, touchX, touchY, contains);

            return true;
        }
Ejemplo n.º 23
0
        public override bool OnTouchEvent(MotionEvent motionEvent)
        {
            var pointerIndex = ((int) (motionEvent.Action & MotionEventActions.PointerIdMask) >>
                                (int) MotionEventActions.PointerIdShift);
            var pointerId = motionEvent.GetPointerId(pointerIndex);
            var action = (motionEvent.Action & MotionEventActions.Mask);
            var pointCnt = motionEvent.PointerCount;

            if (pointCnt <= MaximumTouchCount)
            {
                if (pointerIndex <= MaximumTouchCount - 1)
                {
                    for (var i = 0; i < pointCnt; i++)
                    {
                        var id = motionEvent.GetPointerId(i);
                        _x[id] = (int) motionEvent.GetX(i);
                        _y[id] = (int) motionEvent.GetY(i);
                    }

                    switch (action)
                    {
                        case MotionEventActions.Down:
                        case MotionEventActions.PointerDown:
                        case MotionEventActions.Move:
                            _isTouch[pointerId] = true;
                            break;
                        default:
                            _isTouch[pointerId] = false;
                            break;
                    }
                }
            }
            Invalidate();
            return true;
        }
Ejemplo n.º 24
0
        public bool OnTouch(View v, MotionEvent @event)
        {
            lock (this)
            {
                int action = @event.Action & MotionEvent.ACTION_MASK;
                int pointerIndex = (@event.Action & MotionEvent.ACTION_POINTER_ID_MASK) >>
                                   MotionEvent.ACTION_POINTER_ID_SHIFT;
                int pointerCount = @event.PointerCount;
                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.Action != 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;
            }
        }
Ejemplo n.º 25
0
        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;
        }
		public override bool OnTouchEvent (MotionEvent e)
		{
			Log.Debug("PullToZoomListView", "action = " + (0xFF & (int)e.Action));
			if (_headerView != null && !_isHideHeader && _isEnableZoom) {
				switch ((MotionEventActions)0xFF & e.Action) {
				case MotionEventActions.Down:
				case MotionEventActions.Outside:
					if (!_scalingRunnable.IsFinished()) {
						_scalingRunnable.AbortAnimation();
					}
					_lastMotionY = e.GetY();
					_activePointerId = e.GetPointerId(0);
					_maxScale = (_screenHeight / _headerHeight);
					_lastScale = (_headerContainer.Bottom / _headerHeight);
					break;
				case MotionEventActions.Move:
					Log.Debug("PullToZoomListView", "_activePointerId" + _activePointerId);
					int j = e.FindPointerIndex(_activePointerId);
					if (j == -1) {
						Log.Error("PullToZoomListView", "Invalid pointerId=" + _activePointerId + " in onTouchEvent");
					} else {
						if (_lastMotionY == -1.0F) {
							_lastMotionY = e.GetY(j);
						}
						if (_headerContainer.Bottom >= _headerHeight) {
							ViewGroup.LayoutParams localLayoutParams = _headerContainer.LayoutParameters;
							float f = ((e.GetY(j) - _lastMotionY + _headerContainer.Bottom) / _headerHeight - _lastScale) / 2.0F + _lastScale;
							if ((_lastScale <= 1.0D) && (f < _lastScale)) {
								localLayoutParams.Height = _headerHeight;
								_headerContainer.LayoutParameters=localLayoutParams;
								return base.OnTouchEvent(e);
							}
							_lastScale = Java.Lang.Math.Min(Java.Lang.Math.Max(f, 1.0F), _maxScale);
							localLayoutParams.Height = ((int) (_headerHeight * _lastScale));
							if (localLayoutParams.Height < _screenHeight) {
								_headerContainer.LayoutParameters=localLayoutParams;
							}
							_lastMotionY = e.GetY(j);
							return true;
						}
						_lastMotionY = e.GetY(j);
					}
					break;
				case MotionEventActions.Up:
					Reset();
					EndScaling();
					break;
				case MotionEventActions.Cancel:
					int i = e.ActionIndex;
					_lastMotionY = e.GetY(i);
					_activePointerId = e.GetPointerId(i);
					break;
				case MotionEventActions.PointerDown:
					OnSecondaryPointerUp(e);
					_lastMotionY = e.GetY(e.FindPointerIndex(_activePointerId));
					break;
				}
			}
			return base.OnTouchEvent (e);
		}
Ejemplo n.º 27
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            int touchesCount = e.PointerCount;
            List<Point> TouchPlace = new List<Point>();

            for (int i = 0; i < touchesCount; i++)
            {
                TouchPlace.Add(new Point((int)e.GetX(i), (int)e.GetY(i)));
            }

            switch (e.ActionMasked)
            {
                case MotionEventActions.PointerDown:
                case MotionEventActions.Down:
                    foreach (Point touch in TouchPlace)
                    {
                        foreach (CirclePaint circle in _touches)
                        {
                            if (circle.IsTouched(touch))
                            {
                                circle.Touched = TouchPlace.IndexOf(touch);
                            }
                        }
                    }
                    break;
                case MotionEventActions.Move:
                    foreach (CirclePaint circle in _touches)
                    {
                        if (circle.Touched >= 0)
                        {
                            circle.MoveTo(TouchPlace[e.FindPointerIndex(circle.Touched)]);
                            Invalidate();
                        }
                    }
                    break;
                case MotionEventActions.PointerUp:
                case MotionEventActions.Up:
                case MotionEventActions.Cancel:
                    foreach (CirclePaint circle in _touches)
                    {
                        if (circle.Touched == e.GetPointerId(e.ActionIndex))
                        {
                            circle.Touched = -1;
                        }

                    }
                    break;
                default:
                    break;
            }

            return true;
        }
		public override bool OnTouchEvent (MotionEvent ev)
		{
			Log.Debug("PullToZoomScrollView", "onTouchEvent --> action = " + (0xFF & (int)ev.Action));
			if (_isHeaderTop && _isEnableZoom) {
				switch ((MotionEventActions)0xFF & ev.Action) {
				case MotionEventActions.Down:
				case MotionEventActions.Outside:
					if (!_scalingRunnable.IsFinished()) {
						_scalingRunnable.AbortAnimation();
					}
					_lastMotionY = ev.GetY();
					_activePointerId = ev.GetPointerId(0);
					_maxScale = (_screenHeight / _zoomHeight);
					_lastScale = (_zoomContainer.Bottom / _zoomHeight);
					if (_onScrollViewZoomListener != null) {
						_onScrollViewZoomListener.onStart();
					}
					break;
				case MotionEventActions.Move:
					Log.Debug("PullToZoomScrollView", "_activePointerId = " + _activePointerId);
					int j = ev.FindPointerIndex(_activePointerId);
					if (j == -1) {
						Log.Error("PullToZoomScrollView", "Invalid pointerId = " + _activePointerId + " in onTouchEvent");
					} else {
						if (_lastMotionY == -1.0F) {
							_lastMotionY = ev.GetY(j);
						}
						if (_zoomContainer.Bottom >= _zoomHeight) {
							FrameLayout.LayoutParams localLayoutParams = (FrameLayout.LayoutParams) _zoomContainer.LayoutParameters;
							ViewGroup.LayoutParams headLayoutParams = _headerContainer.LayoutParameters;
							float f = ((ev.GetY(j) - _lastMotionY + _zoomContainer.Bottom) / _zoomHeight - _lastScale) / 2.0F + _lastScale;
							if ((_lastScale <= 1.0D) && (f < _lastScale)) {
								localLayoutParams.Height = _zoomHeight;
								localLayoutParams.Width = _zoomWidth;
								localLayoutParams.Gravity = GravityFlags.Center;
								headLayoutParams.Height = _zoomHeight;
								_zoomContainer.LayoutParameters=localLayoutParams;
								_headerContainer.LayoutParameters=headLayoutParams;
								return base.OnTouchEvent(ev);
							}
							_lastScale = Math.Min(Math.Max(f, 1.0F), _maxScale);
							localLayoutParams.Height = ((int) (_zoomHeight * _lastScale));
							localLayoutParams.Width = ((int) (_zoomWidth * _lastScale));
							localLayoutParams.Gravity = GravityFlags.Center;
							headLayoutParams.Height = ((int) (_zoomHeight * _lastScale));
							if (localLayoutParams.Height < _screenHeight) {
								_zoomContainer.LayoutParameters=localLayoutParams;
								_headerContainer.LayoutParameters=headLayoutParams;
							}
							_lastMotionY = ev.GetY(j);
							return true;
						}
						_lastMotionY = ev.GetY(j);
					}
					break;
				case MotionEventActions.Up:
					Reset();
					EndScaling();
					if (_onScrollViewZoomListener != null) {
						_onScrollViewZoomListener.onFinish();
					}
					break;
				case MotionEventActions.Cancel:
					int i = ev.ActionIndex;
					_lastMotionY = ev.GetY(i);
					_activePointerId = ev.GetPointerId(i);
					break;
				case MotionEventActions.PointerDown:
					OnSecondaryPointerUp(ev);
					_lastMotionY = ev.GetY(ev.FindPointerIndex(_activePointerId));
					break;
				}
			}
			return base.OnTouchEvent (ev);
		}
Ejemplo n.º 29
0
        public override bool OnInterceptTouchEvent(MotionEvent ev)
        {
            int currenrMotionX;
            int currentMotionY;

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

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

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

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

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

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

                            if (this.Parent != null)
                            {
                                this.Parent.RequestDisallowInterceptTouchEvent(true);
                            }
                        }
                        break;
                    }
                case MotionEventActions.Down:
                    {
                        this.FindViewWhoScrolling((int)ev.GetX(), (int)ev.GetY(), 1, 1);

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

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

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

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

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

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

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

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

                    //if (this.scroller.SpringBack(this.ScrollX, this.ScrollY, 0, 0, this.GetScrollRangeX(), this.GetScrollRangeY()))
                    //{
                        // TODO: possible something like postInvalidate (postInvalidateOnAnimation)
                    //}
                    break;
                case MotionEventActions.PointerUp:
                    if (this.childWhoScrolling != null)
                    {
                        return false;
                    }
                    this.OnSecondaryPointerUp(ev);
                    break;
            }

            return this.isBeingDragged;
        }
Ejemplo n.º 30
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            // This runs on a different thread to the main game loop (note the locking)
            // TODO: does this contribute to input lag?

            Monitor.Enter(TouchInputManager.lockObject); // Convert to lock?
            try
            {
                bool processed = false; // Event has been processed

                int count = e.PointerCount;
                MotionEventActions a = e.Action;
                MotionEventActions action = a & MotionEventActions.Mask;
                // According to the docs, this does not actually produce the "Id" (despite the name), but the "Index"!
                int actionPointerIndex = ((int)a & MotionEvent.ActionPointerIdMask) >> MotionEvent.ActionPointerIdShift;

                for(int i = 0; i < count; i++) // for each pointer (unordered)
                {
                    int id = e.GetPointerId(i);

                    var location = new System.Drawing.PointF(e.GetX(i), e.GetY(i));
                    Point position = inputScaler.TouchToLogical((int)location.X, (int)location.Y);

                    switch(action)
                    {
                    case MotionEventActions.Down:
                        TouchInputManager.SanityCheckAllTouchesUp();
                        goto case MotionEventActions.PointerDown; // Fall through
                    case MotionEventActions.PointerDown:
                        TouchInputManager.BeginTouch(id, position);
                        processed = true;
                        break;

                    case MotionEventActions.Move:
                        TouchInputManager.MoveTouch(id, position);
                        processed = true;
                        break;

                    case MotionEventActions.Up:
                    case MotionEventActions.PointerUp:
                    case MotionEventActions.Cancel:
                        TouchInputManager.EndTouch(id, position, action == MotionEventActions.Cancel);
                        processed = true;
                        break;
                    }
                }

                if(processed)
                    return true;
                else
                    return base.OnTouchEvent(e);
            }
            finally
            {
                Monitor.Exit(TouchInputManager.lockObject);

                // http://stackoverflow.com/questions/792185/why-are-touch-events-destroying-my-android-framerate
                // http://stackoverflow.com/questions/4342464/android-touch-seriously-slowing-my-application
                // Thread.Sleep(16); // TODO: is this necessary?
            }
        }
Ejemplo n.º 31
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            base.OnTouchEvent(ev);

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

            switch (ev.Action & MotionEventActions.Mask)
            {
                case MotionEventActions.Down:
                    {
                        if (this.childWhoScrolling != null)
                        {
                            this.childWhoScrolling.OnTouchEvent(ev);
                            return false;
                        }

                        if (this.ChildCount == 0)
                        {
                            return false;
                        }

                        this.isBeingDragged = !this.scroller.IsFinishedY;
                        if (this.isBeingDragged)
                        {
                            if (this.Parent != null)
                            {
                                this.Parent.RequestDisallowInterceptTouchEvent(true);
                            }
                        }

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

                        this.lastMotionX = (int)ev.GetX();
                        this.lastMotionY = (int)ev.GetY();
                        this.activePointerId = ev.GetPointerId(0);
                        break;
                    }
                case MotionEventActions.Move:
                    {
                        if (this.childWhoScrolling != null)
                        {
                            this.childWhoScrolling.OnTouchEvent(ev);
                            return false;
                        }

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

                        int x = (int)ev.GetX();
                        int y = (int)ev.GetY();
                        int deltaX = this.lastMotionX - x;
                        int deltaY = this.lastMotionY - y;

                        if (!this.isBeingDragged && (Math.Abs(deltaX) > this.touchSlop || Math.Abs(deltaY) > this.touchSlop))
                        {
                            if (this.Parent != null)
                            {
                                this.Parent.RequestDisallowInterceptTouchEvent(true);
                            }

                            this.isBeingDragged = true;
                        }

                        if (this.isBeingDragged)
                        {
                            // scroll after touch motions
                            this.lastMotionX = x;
                            this.lastMotionY = y;

                            int oldX = this.ScrollX;
                            int oldY = this.ScrollY;
                            int rangeX = this.GetScrollRangeX();
                            int rangeY = this.GetScrollRangeY();

                            // OverScroll is ignored for now
                            // bool canOverscrollX = this.OverScrollMode == Android.Views.OverScrollMode.Always ||
                            //     (this.OverScrollMode == Android.Views.OverScrollMode.IfContentScrolls && rangeX > 0);
                            // bool canOverscrollY = this.OverScrollMode == Android.Views.OverScrollMode.Always ||
                            //    (this.OverScrollMode == Android.Views.OverScrollMode.IfContentScrolls && rangeY > 0);

                            if (this.OverScrollBy(deltaX, deltaY, this.ScrollX, this.ScrollY, rangeX, rangeY, this.overflingDistance, this.overflingDistance, true))
                            {
                                ////this.velocityTracker.Clear();
                            }
                            //this.OnScrollChanged(this.ScrollX, this.ScrollY, oldX, oldY);
                        }

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

                    if (this.isBeingDragged)
                    {
                        this.velocityTracker.ComputeCurrentVelocity(1000, this.maximumVelocity);

                        int initialVelocityX = (int)this.velocityTracker.GetXVelocity(this.activePointerId);
                        int initialVelocityY = (int)this.velocityTracker.GetYVelocity(this.activePointerId);
                        ////int initialVelocityX = this.velocityTracker.XVelocity;
                        ////int initialVelocityY

                        if (this.ChildCount > 0)
                        {
                            initialVelocityX = (int)this.velocityTracker.XVelocity;  ////Math.Abs(initialVelocityX) > this.minimumVelocity ? initialVelocityX : 0;
                            initialVelocityY = (int)this.velocityTracker.YVelocity; ////Math.Abs(initialVelocityY) > this.minimumVelocity ? initialVelocityY : 0;

                            if (initialVelocityX != 0 || initialVelocityY != 0)
                            {
                                this.Fling(-initialVelocityX, -initialVelocityY);
                            }
                            // else if (this.scroller.SpringBack(this.ScrollX, this.ScrollY, 0, 0, this.GetScrollRangeX(), this.GetScrollRangeY()))
                            // {
                                // TODO: possible something like postInvalidate (postInvalidateOnAnimation)
                            // }
                        }

                        this.activePointerId = InvalidPointerId;
                        this.EndDrag();
                    }
                    break;
                case MotionEventActions.Cancel:
                    if (this.childWhoScrolling != null)
                    {
                        this.childWhoScrolling.OnTouchEvent(ev);
                        return false;
                    }

                    if (this.isBeingDragged && this.ChildCount > 0)
                    {
                        if (this.scroller.SpringBack(this.ScrollX, this.ScrollY, 0, 0, this.GetScrollRangeX(), this.GetScrollRangeY()))
                        {
                            // TODO: possible something like postInvalidate (postInvalidateOnAnimation)
                        }
                        this.activePointerId = InvalidPointerId;
                    }
                    break;
                case MotionEventActions.PointerDown:
                    if (this.childWhoScrolling != null)
                    {
                        this.childWhoScrolling.OnTouchEvent(ev);
                        return false;
                    }

                    int index = ev.ActionIndex;
                    this.lastMotionX = (int)ev.GetX(index);
                    this.lastMotionY = (int)ev.GetY(index);
                    this.activePointerId = ev.GetPointerId(index);
                    break;
                case MotionEventActions.PointerUp:
                    if (this.childWhoScrolling != null)
                    {
                        this.childWhoScrolling.OnTouchEvent(ev);
                        return false;
                    }

                    this.OnSecondaryPointerUp(ev);
                    break;
            }

            return true;
        }
Ejemplo n.º 32
0
 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;
 }
Ejemplo n.º 33
0
        public override bool OnTouchEvent(MotionEvent e)
        {
            MotionEvent.PointerCoords mepc = new MotionEvent.PointerCoords();

            int iEventPointerIndex = (int)(e.Action & MotionEventActions.PointerIdMask) >> (int)MotionEventActions.PointerIdShift;
            int iEventPointerId = e.GetPointerId(iEventPointerIndex);
            MotionEventActions action = e.Action & MotionEventActions.Mask;

            switch (action)
            {
                case MotionEventActions.Down:
                case MotionEventActions.PointerDown:
                    Log.Debug(tag, String.Format("Point Down"));
                    //DataClass.Drawables[iEventPointerId].Visible = true;
                    e.GetPointerCoords(iEventPointerIndex, mepc);
                    bool bFound = false;
                    foreach (var item in DataClass.Sources)
                    {
                        if (item.Collision(mepc.X, mepc.Y))
                        {
                            var nc = new Circle(item) { Visible = true };
                            DataClass.Drawables.Add(nc);
                            dctControlable.Add(iEventPointerId, nc);
                            bFound = true;
                            break;
                        }
                    }
                    if (bFound) break;
                    foreach (var item in DataClass.Drawables)
                    {
                        if (item.Collision(mepc.X, mepc.Y))
                        {
                            dctControlable.Add(iEventPointerId, item);
                            break;
                        }
                    }
                    break;
                case MotionEventActions.Move:
                    var l = new List<string>();
                    for (int iPointerIndex = 0; iPointerIndex < e.PointerCount; iPointerIndex++)
                    {
                        int iPointerId = e.GetPointerId(iPointerIndex);
                        l.Add(String.Format("{0} => {1}", iPointerIndex, iPointerId));
                        try
                        {
                            e.GetPointerCoords(iPointerIndex, mepc);

                            dctControlable[iPointerId].X = mepc.X;
                            dctControlable[iPointerId].Y = mepc.Y;

                        }
                        catch
                        {
                            l.Add(String.Format("ex", iPointerIndex, iPointerId));
                        }
                    }

                    Log.Debug(tag, string.Format("{0}, {1}", iEventPointerIndex, string.Join(", ", l)));
                    break;
                case MotionEventActions.Up:
                case MotionEventActions.PointerUp:
                    Log.Debug(tag, String.Format("Point Up"));
                    //DataClass.Drawables[iEventPointerId].Visible = false;
                    dctControlable.Remove(iEventPointerId);
                    break;
            }

            this.Invalidate();
            return true;
        }
Ejemplo n.º 34
0
        public override bool OnTouchEvent(MotionEvent e)
        {			
            TouchLocation tlocation;
            TouchCollection collection = TouchPanel.Collection;            
            Vector2 position = Vector2.Zero;            
            position.X = e.GetX(e.ActionIndex);            
            position.Y = e.GetY(e.ActionIndex);     
			UpdateTouchPosition(ref position);
			int id = e.GetPointerId(e.ActionIndex);            
            int index;
            switch (e.ActionMasked)
            {
                // DOWN                
                case MotionEventActions.Down:
                case MotionEventActions.PointerDown:
                    index = collection.FindIndexById(e.GetPointerId(e.ActionIndex), out tlocation);
                    if (index < 0)
                    {
                        tlocation = new TouchLocation(id, TouchLocationState.Pressed, position);
                        collection.Add(tlocation);
                    }
                    else
                    {
                        tlocation.State = TouchLocationState.Pressed;
                        tlocation.Position = position;
                    }
                    break;
                // UP                
                case MotionEventActions.Up:
                case MotionEventActions.PointerUp:
                    index = collection.FindIndexById(e.GetPointerId(e.ActionIndex), out tlocation);
                    if (index >= 0)
                    {
                        tlocation.State = TouchLocationState.Released;
                        collection[index] = tlocation;
                    }	
				break;
                // MOVE                
                case MotionEventActions.Move:
                    for (int i = 0; i < e.PointerCount; i++)
                    {
                        id = e.GetPointerId(i);
                        position.X = e.GetX(i);
                        position.Y = e.GetY(i);
                        UpdateTouchPosition(ref position);
                        index = collection.FindIndexById(id, out tlocation);
                        if (index >= 0)
                        {
                            tlocation.State = TouchLocationState.Moved;
                            tlocation.Position = position;
                            collection[index] = tlocation;
                        }
                    }
					break;
                // CANCEL, OUTSIDE                
                case MotionEventActions.Cancel:
                case  MotionEventActions.Outside:
                    index = collection.FindIndexById(id, out tlocation);
                    if (index >= 0)
                    {
                        tlocation.State = TouchLocationState.Invalid;
                        collection[index] = tlocation;
                    }
                    break;
            }
			
			
			if (gesture != null)
			{
				GestureListener.CheckForDrag(e, position);
				gesture.OnTouchEvent(e);
			}

            return true;
        }
Ejemplo n.º 35
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;
        }