Exemplo n.º 1
0
        protected virtual void OnHeaderTouch(object sender, Android.Views.View.TouchEventArgs e)
        {
            Android.Widget.ListView listView = null;
            Android.Views.View      header   = null;

            try
            {
                var listViewRenderer = (Xamarin.Forms.Platform.Android.ViewRenderer <Xamarin.Forms.ListView, Android.Widget.ListView>)parallaxControl.CurrentListView.GetRenderer();
                listView = listViewRenderer.Control;
                header   = (Android.Views.View)parallaxControl.HeaderControl.GetRenderer();
                GenerateHeader(header);
            }
            catch (Exception ex)
            {
                return;
            }

            var evt = e.Event;

            //var eventConsumed = false;

            if (listView != null && header != null)
            {
                MotionEvent ev = MotionEvent.Obtain(
                    evt.DownTime,
                    evt.EventTime,
                    evt.Action,
                    evt.GetX(),
                    evt.GetY() + header.TranslationY,
                    evt.Pressure, evt.Size, evt.MetaState, evt.XPrecision, evt.YPrecision, evt.DeviceId, evt.EdgeFlags);
                var d = listView.DispatchTouchEvent(ev);
                //return;
                //switch (evt.Action)
                //{
                //    case MotionEventActions.Move:
                //        if (!downEventDispatched)
                //        {
                //            // if moving, create a fake down event for the scrollingView to start the scroll.
                //            // the y of the touch in the scrolling view is the y coordinate of the touch in the
                //            // header + the translation of the header
                //            MotionEvent downEvent = MotionEvent.Obtain(
                //                evt.DownTime - 1,
                //                evt.EventTime - 1,
                //                MotionEventActions.Down,
                //                evt.GetX(),
                //                evt.GetY() + header.TranslationY,
                //                evt.Pressure, evt.Size, evt.MetaState, evt.XPrecision, evt.YPrecision, evt.DeviceId, evt.EdgeFlags);
                //            //evt.Action = MotionEventActions.Down;
                //            listView.DispatchTouchEvent(downEvent);
                //            //  listView.DispatchTouchEvent(downEvent);
                //            downEventDispatched = true;
                //        }

                //        // dispatching the move event. we need to create a fake motionEvent using a different y
                //        // coordinate related to the scrolling view
                //        //MotionEvent moveEvent = MotionEvent.Obtain(
                //        //    evt.DownTime,
                //        //    evt.EventTime,
                //        //    MotionEventActions.Move,
                //        //    evt.GetX(),
                //        //    evt.GetY() + header.TranslationY,
                //        //    0);
                //        MotionEvent moveEvent = MotionEvent.Obtain(
                //               evt.DownTime,
                //               evt.EventTime,
                //               MotionEventActions.Move,
                //               evt.GetX(),
                //               evt.GetY() + header.TranslationY,
                //               evt.Pressure, evt.Size, evt.MetaState, evt.XPrecision, evt.YPrecision, evt.DeviceId, evt.EdgeFlags);
                //        //evt.Action = MotionEventActions.Down;
                //        listView.DispatchTouchEvent(moveEvent);
                //        //evt.Action = MotionEventActions.Move;
                //        //listView.DispatchTouchEvent(evt);
                //        //listView.DispatchTouchEvent(moveEvent);
                //        break;
                //    case MotionEventActions.Up:

                //        // when action up, dispatch an action cancel to avoid a possible click
                //        //MotionEvent cancelEvent = MotionEvent.Obtain(
                //        //    evt.DownTime,
                //        //    evt.EventTime,
                //        //    MotionEventActions.Cancel,
                //        //    evt.GetX(),
                //        //    evt.GetY(),
                //        //    0);
                //        evt.Action = MotionEventActions.Cancel;
                //        listView.DispatchTouchEvent(evt);
                //        //listView.DispatchTouchEvent(cancelEvent);
                //        downEventDispatched = false;
                //        break;
                //    case MotionEventActions.Cancel:
                //        listView.DispatchTouchEvent(evt);
                //        downEventDispatched = false;
                //        break;
                //}

                //eventConsumed = true;
            }

            // e.Handled = eventConsumed;
        }