Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

catch all swipes in an app

$
0
0

Hello,

i would like to catch all swipe gestures on my app and switch ModelView when it happens.

Some of the Views have scroll-able (or clickable) content on them, and as soon as it does, i don't seem to receive the many TouchEvents that i receive when i do the swipe on an empty screen. So i think the scroll-able/clickable content 'eats' the events.

As an attempt to work around i place a cusom View over the top of the whole screen, and try to catch the events before they are passed down below:

    <MyApp.Droid.Views.GestureCatcherView
        android:id="@+id/GestureCapturer"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


        public class GestureCatcherView : View , GestureDetector.IOnGestureListener
        {
            private GestureDetector _GestureDetector;

            #region Constructors
            public GestureCatcherView(Context context) : base(context)
            {
                _GestureDetector = new GestureDetector(this);
            }
            public GestureCatcherView(Context context, IAttributeSet attrs) : base(context, attrs)
            {
                _GestureDetector = new GestureDetector(this);
            }
            public GestureCatcherView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
            {
                _GestureDetector = new GestureDetector(this);
            }
            #endregion

            public override bool DispatchGenericMotionEvent(MotionEvent e)
            {
                _GestureDetector.OnGenericMotionEvent(e);
                System.Diagnostics.Debug.WriteLine("TS> GestureCatcher: generic motiom eevent1+");
                base.DispatchGenericMotionEvent(e);
                return false;
            }
            public override bool OnTouchEvent(MotionEvent e)
            {
                _GestureDetector.OnTouchEvent(e);
                System.Diagnostics.Debug.WriteLine("TS> GestureCatcher: touchevent 1+");
                base.OnTouchEvent(e);
                return false;
            }
            public bool OnDown(MotionEvent e)
            {
                return false;
            }
            public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("TS> OnFling velocityX {0} velocityY {1}", velocityX, velocityY));
                return false;
            }
            public void OnLongPress(MotionEvent e)
            {

            }
            public bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
            {
                return false;
            }
            public void OnShowPress(MotionEvent e)
            {

            }
            public bool OnSingleTapUp(MotionEvent e)
            {
                return false;
            }
        }

But OnFling never gets thown if i swipe

am i going about it the wrong way ?
any help appreciated.

thanks,
tom


Viewing all articles
Browse latest Browse all 204402

Trending Articles