public override bool OnTouchEvent(MotionEvent ev)
        {
            var hist = 0.0f;
            var deltaY = 0.0f;
            var listY = 0.0f;
            _historyEvent = ev;
            vT.AddMovement(ev);
            if (_overscrolling)
            {
                var firstOverscroll = _firstOverscroll;
                _firstOverscroll = false;
                    if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                    {
                        hist = ev.GetHistoricalY(0, 0);
                        deltaY = ev.GetY() - hist;
                        listY = _listView.GetY();

                        if (_header != null)
                        {
                            var headerY = _header.GetY();
                            if (deltaY > 0)
                            {
                                
                                if ((int)Math.Ceiling(headerY) == (0))
                                {
                                    return _listView.DispatchTouchEvent(ev);
                                }

                                if (headerY + deltaY <= (0))
                                {
                                    UpdateHeaderPosition(deltaY);
                                    _listView.SetY(_listView.GetY() + deltaY);
                                    _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                    _listView.Invalidate();
                                    return true;
                                }
                                if (headerY + deltaY > 0)
                                {
                                    deltaY = 0 - headerY;
                                    UpdateHeaderPosition(0 - headerY);
                                    _listView.SetY(_listView.GetY() + deltaY);
                                    _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height + deltaY);
                                    _listView.Invalidate();
                                    return true;
                                }
                            }
                            if (deltaY < 0)
                            {
                                _overscrolling = false;
                            }
                        }
                       

                        if (listY + deltaY <= 0)
                        {
                            deltaY = 0 - listY;
                            _overscrolling = false;
                        }
                        else if (deltaY > 0)
                        {
                            deltaY *= 0.4f;
                        }
                        Log.Info("OverScrollingIntercept", "{0}", deltaY);
                        _listView.SetY(_listView.GetY() + deltaY);
                        _lastHistory = ev.HistorySize;
                    }
                    else if (ev.Action == MotionEventActions.Up)
                    {
                        _overscrolling = false;
                        _lastHistory = 0;
                        _listView.Animate().Y(_header != null ? _header.Height : 0.0f).SetDuration(250).Start();
                    }
                

            Log.Info("Interceptor", "Overscrolling True");
                return true;
            }
            var hitRect = new Rect();
            _header.GetHitRect(hitRect);

            if (hitRect.Contains((int)Math.Ceiling(ev.GetX()), (int)Math.Ceiling(ev.GetY())))
            {
                return _header.DispatchTouchEvent(ev);
            }
            else
            {
                if (_header != null )
                {
                    var headerY = _header.GetY();
                    if (ev.Action == MotionEventActions.Move && ev.HistorySize >= 1)
                    {
                        hist = ev.GetHistoricalY(0, 0);
                        deltaY = ev.GetY() - hist;

                        if (deltaY < 0)
                        {
                            if ((int) Math.Ceiling(headerY) == (0 - _header.Height))
                            {
                                return _listView.DispatchTouchEvent(ev);
                            }

                            if (headerY + deltaY >= (0 - _header.Height))
                            {
                                UpdateHeaderPosition(deltaY);
                                _listView.SetY(_listView.GetY()+deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY);
                                _listView.RequestLayout();
                                return true;

                            }
                            else if (headerY + deltaY < (0 - _header.Height))
                            {
                                deltaY = 0 - ( headerY + _header.Height);
                                UpdateHeaderPosition(deltaY);
                                _listView.SetY(_listView.GetY() + deltaY);
                                _listView.LayoutParameters.Height = (int)Math.Ceiling(_listView.LayoutParameters.Height - deltaY);
                                _listView.RequestLayout();
                                _listView.DispatchTouchEvent(ev);
                                return true;
                            }
                        }
                        _listView.DispatchTouchEvent(ev);
                        return true;
                    }
                    else if(ev.Action == MotionEventActions.Up || ev.Action == MotionEventActions.Cancel)
                    {
                        vT.ComputeCurrentVelocity(1);
                        long duration = Math.Abs((long)Math.Ceiling(Math.Abs(_header.Height) / vT.GetYVelocity(0)));

                        if (duration < 750)
                        {
                            _header.Animate()
                                .Y(0 - _header.Height)
                                .SetDuration(duration)
                                .SetInterpolator(new DecelerateInterpolator(1.0f))
                                .Start();
                            _listView.Animate()
                                .Y(0)
                                .SetDuration(duration)
                                .SetInterpolator(new DecelerateInterpolator(1.0f))
                                .Start();
                        }
                        return _listView.DispatchTouchEvent(ev);
                    }
                }
                return _listView.DispatchTouchEvent(ev);
            }
        }
		//Iterate through the touch history since the last touch event and add them to the path and points list.
		void handleTouch (MotionEvent e)
		{
			float touchX = e.GetX ();
			float touchY = e.GetY ();

			System.Drawing.PointF touch = new System.Drawing.PointF (touchX, touchY);

			resetBounds (touchX, touchY);
			
			for (var i = 0; i < e.HistorySize; i++) {
				float historicalX = e.GetHistoricalX(i);
				float historicalY = e.GetHistoricalY(i);

				System.Drawing.PointF historical = new System.Drawing.PointF (historicalX, historicalY);

				updateBounds (historicalX, historicalY);

				currentPath.LineTo (historicalX, historicalY);
				currentPoints.Add (historical);
			}

			currentPath.LineTo (touchX, touchY);
			currentPoints.Add (touch);
		}
    private void ApplyHeaderPadding(MotionEvent ev)
    {
      int pointerCount = ev.HistorySize;
      for (int p = 0; p < pointerCount; p++)
      {
        if (mRefreshState == RELEASE_TO_REFRESH)
        {
          if (VerticalFadingEdgeEnabled)
            VerticalScrollBarEnabled = false;

          int historicalY = (int)ev.GetHistoricalY(p);
          int topPadding = (int)(((historicalY - mLastMotionY)
                      - mRefreshViewHeight) / 1.7);

          mRefreshView.SetPadding(
            mRefreshView.PaddingLeft,
            topPadding,
            mRefreshView.PaddingRight,
            mRefreshView.PaddingBottom);
        }
      }
    }
Beispiel #4
0
        public override bool OnTouchEvent(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();

            switch (ev.Action)
            {
                case MotionEventActions.Down:
                    touch_start(x, y);
                    Invalidate();
                    break;

                case MotionEventActions.Move:
                    for (int i = 0, n = ev.HistorySize; i < n; i++)
                    {
                        touch_move(ev.GetHistoricalX(i), ev.GetHistoricalY(i));
                    }
                    touch_move(x, y);
                    Invalidate();
                    break;

                case MotionEventActions.Up:
                    touch_up(x, y);
                    Invalidate();
                    break;
            }
            return true;
        }
			bool OnTouchOrHoverEvent (MotionEvent e, bool isTouch)
			{
				MotionEventButtonState buttonState = e.ButtonState;
				MotionEventButtonState pressedButtons = buttonState & ~mOldButtonState;
				mOldButtonState = buttonState;

				if ((pressedButtons & MotionEventButtonState.Secondary) != 0) {
					// Advance color when the right mouse button or first stylus button
					// is pressed.
					AdvanceColor ();
				}

				PaintMode mode;
				if ((buttonState & MotionEventButtonState.Tertiary) != 0) {
					// Splat paint when the middle mouse button or second stylus button is pressed.
					mode = PaintMode.Splat;
				} else if (isTouch || (buttonState & MotionEventButtonState.Primary) != 0) {
					// Draw paint when touching or if the primary button is pressed.
					mode = PaintMode.Draw;
				} else {
					// Otherwise, do not paint anything.
					return false;
				}

				MotionEventActions action = e.ActionMasked;
				if (action ==  MotionEventActions.Down || action == MotionEventActions.Move
					|| action == MotionEventActions.HoverMove) {
					int N = e.HistorySize;
					int P = e.PointerCount;
					for (int i = 0; i < N; i++) {
						for (int j = 0; j < P; j++) {
							Paint (GetPaintModeForTool (e.GetToolType (j), mode),
								e.GetHistoricalX (j, i),
								e.GetHistoricalY(j, i),
								e.GetHistoricalPressure (j, i),
								e.GetHistoricalTouchMajor (j, i),
								e.GetHistoricalTouchMinor (j, i),
								e.GetHistoricalOrientation (j, i),
								e.GetHistoricalAxisValue (Axis.Distance, j, i),
								e.GetHistoricalAxisValue (Axis.Tilt, j, i));
						}
					}
					for (int j = 0; j < P; j++) {
						Paint (GetPaintModeForTool (e.GetToolType (j), mode),
							e.GetX (j),
							e.GetY (j),
							e.GetPressure (j),
							e.GetTouchMajor (j),
							e.GetTouchMinor (j),
							e.GetOrientation (j),
							e.GetAxisValue (Axis.Distance, j),
							e.GetAxisValue (Axis.Tilt, j));
					}
					mCurX = e.GetX ();
					mCurY = e.GetY ();
				}
				return true;
			}
			public override bool OnTrackballEvent (MotionEvent e)
			{
				MotionEventActions action = e.ActionMasked;
				if (action == MotionEventActions.Down) {
					// Advance color when the trackball button is pressed.
					AdvanceColor ();
				}

				if (action == MotionEventActions.Down || action == MotionEventActions.Move) {
					int N = e.HistorySize;
					float scaleX = e.XPrecision * TRACKBALL_SCALE;
					float scaleY = e.YPrecision * TRACKBALL_SCALE;
					for (int i = 0; i < N; i++) {
						MoveTrackball (e.GetHistoricalX (i) * scaleX,
							e.GetHistoricalY (i) * scaleY);
					}
					MoveTrackball (e.GetX () * scaleX, e.GetY () * scaleY);
				}
				return true;
			}
Beispiel #7
0
		public override bool OnTouchEvent (MotionEvent e) {
			var spos = new Vector2 (e.GetX (), _size.Y - e.GetY ());
			var pos = this.NormalizeToViewport (spos);

			switch (e.Action) {
				case MotionEventActions.Down:
					_queue.Enqueue (new Touch (TouchState.Start, pos, spos));
					break;
				case MotionEventActions.Up:
					_queue.Enqueue (new Touch (TouchState.End, pos, spos));
					break;
				case MotionEventActions.Move:
					for (var i = 0; i < e.HistorySize; i++) {
						var shpos = new Vector2 (e.GetHistoricalX (i), _size.Y - e.GetHistoricalY (i));
						var hpos = this.NormalizeToViewport (shpos);
						_queue.Enqueue (new Touch (TouchState.Move, hpos, shpos));
					}
					_queue.Enqueue (new Touch (TouchState.Move, pos, spos));
					break;
				case MotionEventActions.Cancel:
					_queue.Enqueue (new Touch (TouchState.Cancel, pos, spos));
					break;
				default:
					break;
			}
			if (_gestureDetector != null)
				_gestureDetector.OnTouchEvent (e);
			return true;
		}