コード例 #1
0
ファイル: InfoPane.cs プロジェクト: JacopoP85/Moyeu
        /*public override bool OnInterceptTouchEvent (MotionEvent ev)
        {
            // Only accept single touch
            if (ev.PointerCount != 1)
                return false;
            ev.OffsetLocation (0, TranslationY);
            return CaptureMovementCheck (ev);
        }*/
        public override bool OnTouchEvent(MotionEvent e)
        {
            if (paneGestureDetector == null) {
                var l = new DoubleTapListener (() => SetState (Opened && FullyOpened ? State.Opened : State.FullyOpened));
                paneGestureDetector = new GestureDetector (Context, l);
            }
            paneGestureDetector.OnTouchEvent (e);

            e.OffsetLocation (0, TranslationY);
            if (e.Action == MotionEventActions.Down) {
                CaptureMovementCheck (e);
                return true;
            }
            if (!isTracking && !CaptureMovementCheck (e))
                return true;

            if (e.Action != MotionEventActions.Move || MoveDirectionTest (e))
                velocityTracker.AddMovement (e);

            if (e.Action == MotionEventActions.Move) {
                var y = e.GetY ();
                // We don't want to go beyond startY
                if (state == State.Opened && y > startY
                    || state == State.FullyOpened && y < startY)
                    return true;
                // We reset the velocity tracker in case a movement goes back to its origin
                if (state == State.Opened && y > oldY
                    || state == State.FullyOpened && y < oldY)
                    velocityTracker.Clear ();

                var traveledDistance = (int)Math.Round (Math.Abs (y - startY));
                if (state == State.Opened)
                    traveledDistance = OffsetForState (State.Opened) - traveledDistance;
                SetNewOffset (traveledDistance);
                oldY = y;
            } else if (e.Action == MotionEventActions.Up) {
                velocityTracker.ComputeCurrentVelocity (1000, maxFlingVelocity);
                if (Math.Abs (velocityTracker.YVelocity) > minFlingVelocity
                    && Math.Abs (velocityTracker.YVelocity) < maxFlingVelocity)
                    SetState (state == State.FullyOpened ? State.Opened : State.FullyOpened);
                else if (state == State.FullyOpened && contentOffsetY > Height / 2)
                    SetState (State.Opened);
                else if (state == State.Opened && contentOffsetY < Height / 2)
                    SetState (State.FullyOpened);
                else
                    SetState (state);

                preTracking = isTracking = false;
                velocityTracker.Clear ();
                velocityTracker.Recycle ();
            }

            return true;
        }
 public bool ConsumesActivityTouch(MotionEvent ev)
 {
     //TODO work out if it's our view in here, then update the coordinates
     var offset = GetOffsetInNativeView (ev.GetX (), ev.GetY ());
     Console.WriteLine ("location " + ev.GetX () + ", " + ev.GetY () + " offset " + offset);
     ev.OffsetLocation (-offset.X, -offset.Y);
     Console.WriteLine ("ofseeted " + ev.GetX () + ", " + ev.GetY ());
     if (ev.GetX () < 0 || ev.GetY () < 0 || ev.GetX () > NativeView.Width || ev.GetY () > NativeView.Height) {
         return false;
     } else {
         //next check children
     //				var isConsumedByChild = IsTouchConsumedByChildren (NativeView as ViewGroup, ev);
         //we need to check all views to see if they ate the touch
         OnTouch (this.NativeView, ev);
     }
     return false;
 }