bool HandleMotionEvent(MotionEvent e)
        {
            //if (_debugEvents) System.Diagnostics.Debug.WriteLine("[{0}.{1}] [{2}] [{3}]", GetType().Name, Debug.CurrentMethod(), _id, _element);
            //ShareMotionEvent (_element, e, _element);
            if (!_element.IsVisible)
            {
                return(false);
            }
            if (MatchesLastMotionEvent(e))
            {
                return(false);
            }
            lastEventHandled &= e.Action != MotionEventActions.Down;
            if (nativeDetector != null)
            {
                lastEventHandled |= nativeDetector.OnTouchEvent(e);
            }
            //if (!lastEventHandled)
            //if (!lastEventHandled) {
            object scrollEnabled = _element.GetPropertyValue("ScrollEnabled");

            if (scrollEnabled == null || ((bool)scrollEnabled) || e.Action != MotionEventActions.Move)
            {
                var view = Renderer?.View;
                //var view = (Android.Views.View)_weakReferenceView?.Get();
                if (view != null)
                {
                    var renderer = Platform.GetRenderer(_element);
                    //var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.ViewGroup;
                    var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.View;
                    if (currentView != null && view == currentView)
                    {
                        view.OnTouchEvent(e);
                    }
                }
            }
            //}
            return(true);  // we want to be sure we get the updates to this element's events
        }
예제 #2
0
        public bool OnTouch(Android.Views.View v, MotionEvent e)
        {
            //System.Diagnostics.Debug.WriteLine(GetType()+"."+P42.Utils.ReflectionExtensions.CallerMemberName() + " e:" + e.Action);
            //System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + " e:" + e.Action + " " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture));

            if (!_nativeGestureHandler.Element.IsVisible)
            {
                return(false);
            }
            if (MatchesLastMotionEvent(e))
            {
                return(false);
            }
            _lastEventHandled &= e.Action != MotionEventActions.Down;


            // the following has me confused.  It is preventing an OnUp event from being delivered to NativeGestureDetector
            //if (nativeDetector != null)
            //    lastEventHandled = lastEventHandled || nativeDetector.OnTouchEvent(e);

            if (_nativeDetector != null)
            {
                _lastEventHandled = _nativeDetector.OnTouchEvent(e) || _lastEventHandled;
            }

            /*
             * object scrollEnabled = _nativeGestureHandler.Element.GetPropertyValue("ScrollEnabled");
             * if (scrollEnabled == null || ((bool)scrollEnabled) || e.Action != MotionEventActions.Move)
             * {
             *  //var view = _nativeGestureHandler.Renderer.View;
             *  //var view = (Android.Views.View)_weakReferenceView?.Get();
             *  if (_nativeGestureHandler.Renderer?.View is Android.Views.View view)
             *  {
             *      var renderer = Platform.GetRenderer(_nativeGestureHandler.Element);
             *      //var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.ViewGroup;
             *      var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.View;
             *      if (currentView != null && view == currentView)
             *          view.OnTouchEvent(e);
             *  }
             * }
             */

            if (_nativeGestureHandler.Element is Xamarin.Forms.Button && _nativeGestureHandler.Renderer?.View is Android.Views.View view)
            {
                var renderer = Platform.GetRenderer(_nativeGestureHandler.Element);
                //var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.ViewGroup;
                var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.View;
                if (currentView != null && view == currentView)
                {
                    view.OnTouchEvent(e);
                }
            }

            //System.Diagnostics.Debug.WriteLine(GetType() + "\t _lastEventHandled=["+_lastEventHandled+"]");
            return(_lastEventHandled);  // we want to be sure we get the updates to this element's events



            //return _nativeGestureDetector.OnTouchEvent(e);


            /*
             * if (e.Action == MotionEventActions.Down)
             * {
             *  // do stuff
             *  return true;
             * }
             * if (e.Action == MotionEventActions.Up)
             * {
             *  // do other stuff
             *  return true;
             * }
             *
             * return false;
             */
        }
예제 #3
0
        /*
         * MotionEvent _downEvent;
         * MotionEvent _secondEvent;
         * Android.Views.View _scrollableView;
         */

        public bool OnTouch(Android.Views.View v, MotionEvent e)
        {
            //P42.Utils.DebugExtensions.Message("ENTER Action[" + e.Action + "] [" + e.EventTime + "]");
            //System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + " e:" + e.Action + " Element:[" + _nativeGestureHandler.Element.Id + "] x:[" + e.RawX + "," + e.GetX() + "," + e.GetAxisValue(Axis.X) + "] y:[" + e.RawY + "," + e.GetY() + "," + e.GetAxisValue(Axis.Y) + "] count:" + e.PointerCount);
            //System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + " e:" + e.Action + " Element:[" + _nativeGestureHandler.Element.Id + "] x:[" + e.RawX + "," + e.GetX() + "," + e.GetAxisValue(Axis.X) + "] y:[" + e.RawY + "," + e.GetY() + "," + e.GetAxisValue(Axis.Y) + "] count:" + e.PointerCount);
            //System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + " e:" + e.Action + " " + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture));

            if (_nativeGestureHandler?.Element == null || !_nativeGestureHandler.Element.IsVisible)
            {
                return(false);
            }
            if (MatchesLastMotionEvent(e))
            {
                return(false);
            }
            _lastEventHandled &= e.Action != MotionEventActions.Down;

            bool thisEventHandled = false;

            if (_nativeDetector != null)
            {
                _lastEventHandled = (thisEventHandled = _nativeDetector.OnTouchEvent(e)) || _lastEventHandled;
            }

            /*
             * object scrollEnabled = _nativeGestureHandler.Element.GetPropertyValue("ScrollEnabled");
             * if (scrollEnabled == null || ((bool)scrollEnabled) || e.Action != MotionEventActions.Move)
             * {
             *  //var view = _nativeGestureHandler.Renderer.View;
             *  //var view = (Android.Views.View)_weakReferenceView?.Get();
             *  if (_nativeGestureHandler.Renderer?.View is Android.Views.View view)
             *  {
             *      var renderer = Platform.GetRenderer(_nativeGestureHandler.Element);
             *      //var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.ViewGroup;
             *      var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.View;
             *      if (currentView != null && view == currentView)
             *          view.OnTouchEvent(e);
             *  }
             * }
             */

            if (e.EventTime > _lastEventTime && _nativeGestureHandler.Renderer?.View is Android.Views.View view)
            {
                if (_nativeGestureHandler.Element is Xamarin.Forms.Button)
                {
                    //System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + ": Action:[" + e.Action + "] Element [" + _nativeGestureHandler.Element + "]");
                    var renderer = Platform.GetRenderer(_nativeGestureHandler.Element);
                    //var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.ViewGroup;
                    var currentView = (renderer?.GetPropertyValue("Control") as Android.Views.View) ?? renderer?.View;
                    if (currentView != null && view == currentView)
                    {
                        view.OnTouchEvent(e);
                    }
                }

                /*
                 * if (e.Action == MotionEventActions.Down && _scrollableView == null && ScrollableAncestor(view) is Android.Views.View scrollableView)
                 * {
                 *  _scrollableView = scrollableView;
                 *  scrollableView.Touch += OnScrollableAncestorTouch;
                 * }
                 *
                 * view.Parent?.RequestDisallowInterceptTouchEvent(true);
                 *
                 * if (e.Action == MotionEventActions.Down)
                 * {
                 *  _secondEvent = null;
                 *  _downEvent = MotionEvent.Obtain(e);
                 * }
                 * else
                 * {
                 *  _secondEvent = _secondEvent ?? MotionEvent.Obtain(e);
                 *  // ignore a move that happens immediately after a down
                 *  if (_secondEvent.Action != MotionEventActions.Move || _downEvent == null || _secondEvent.EventTime - _downEvent.EventTime > 50)
                 *  //if (_nativeListener.ScrollTriggered && !thisEventHandled)
                 *  {
                 *      // if FormsGestures.Listener doesn't handle tap events -or- this isn't a tap event
                 *      if ((_secondEvent.Action != MotionEventActions.Up && _secondEvent.Action != MotionEventActions.Cancel)
                 || !_nativeListener.HandlesPressTapEvents)
                 ||     {
                 ||         if (_downEvent != null)
                 ||         {
                 ||             if (e.Action == MotionEventActions.Move)
                 ||                 System.Diagnostics.Debug.WriteLine(GetType() + "." + P42.Utils.ReflectionExtensions.CallerMemberName() + ": [" + null + "]");
                 ||             DispatchEventToScrollableAncestor(view, _downEvent);
                 ||             _downEvent = null;
                 ||         }
                 ||         DispatchEventToScrollableAncestor(view, e);
                 ||     }
                 || }
                 ||}
                 */
            }
            //System.Diagnostics.Debug.WriteLine(GetType() + "\t _lastEventHandled=[" + _lastEventHandled + "]");
            //P42.Utils.DebugExtensions.Message("EXIT [" + null + "]");
            //_lastEventTime = e.EventTime;
            return(_lastEventHandled);  // we want to be sure we get the updates to this element's events
        }