public bool OnSingleTapConfirmed(Android.Views.MotionEvent e)
        {
            if (this.photoViewAttacher == null)
                return false;
            ImageView imageView = photoViewAttacher.GetImageView();
            if (null != photoViewAttacher.GetOnPhotoTapListener ()) {
                RectF displayRect = photoViewAttacher.GetDisplayRect();
                if (null != displayRect) {
                    float x = e.GetX(), y = e.GetY();

                    if (displayRect.Contains(x, y)) {

                        float xResult = (x - displayRect.Left)
                            / displayRect.Width();
                        float yResult = (y - displayRect.Top)
                            / displayRect.Height();

                        photoViewAttacher.GetOnPhotoTapListener().OnPhotoTap(imageView, xResult, yResult);
                        return true;
                    }
                }
            }
            if (null != photoViewAttacher.GetOnViewTapListener()) {
                photoViewAttacher.GetOnViewTapListener().OnViewTap(imageView, e.GetX(), e.GetY());
            }

            return false;
        }
        public bool OnDoubleTap(Android.Views.MotionEvent ev)
        {
            if (photoViewAttacher == null)
                return false;
            try {
                float scale = photoViewAttacher.GetScale();
                float x = ev.GetX();
                float y = ev.GetY();

                if (scale > photoViewAttacher.GetMinimumScale())
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMinimumScale(), x, y, true);
                }
                else
                {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMediumScale(), x, y, true);
                }

                /*
                if (scale < photoViewAttacher.GetMediumScale()) {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMediumScale(), x, y, true);
                } else if (scale >= photoViewAttacher.GetMediumScale() && scale < photoViewAttacher.GetMaximumScale()) {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMaximumScale(), x, y, true);
                } else {
                    photoViewAttacher.SetScale(photoViewAttacher.GetMinimumScale(), x, y, true);
                }*/
            } catch (Java.Lang.ArrayIndexOutOfBoundsException e) {
                // Can sometimes happen when getX() and getY() is called
            }

            return true;
        }
		public override bool OnTouchEvent (Android.Views.MotionEvent e)
		{
			var touchX = e.GetX();
			var touchY = e.GetY();
			switch (e.Action) 
			{
				case MotionEventActions.Down:
					drawPath.MoveTo(touchX, touchY);
					break;
				case MotionEventActions.Move:
					drawPath.LineTo(touchX, touchY);
					break;
				default:
					return false;
			}
			Invalidate();
			return true;
		}
        public override bool OnTouchEvent(Android.Views.MotionEvent ev)
        {
            
            if (base.OnTouchEvent(ev))
            {
                return true;
            }
            if ((mViewPager == null) || (mViewPager.Adapter.Count == 0))
            {
                return false;
            }

            MotionEventActions action = ev.Action & MotionEventActions.Mask;
            switch (action)
            {
                case MotionEventActions.Down:
                    mActivePointerId = MotionEventCompat.GetPointerId(ev, 0);
                    mLastMotionX = ev.GetX();
                    break;

                case MotionEventActions.Move:
                    {
                        int activePointerIndex = MotionEventCompat.FindPointerIndex(ev, mActivePointerId);
                        float x = MotionEventCompat.GetX(ev, activePointerIndex);
                        float deltaX = x - mLastMotionX;

                        if (!mIsDragging)
                        {
                            if (Math.Abs(deltaX) > mTouchSlop)
                            {
                                mIsDragging = true;
                            }
                        }

                        if (mIsDragging)
                        {
                            mLastMotionX = x;
                            if (mViewPager.IsFakeDragging || mViewPager.BeginFakeDrag())
                            {
                                mViewPager.FakeDragBy(deltaX);
                            }
                        }

                        break;
                    }

                case MotionEventActions.Cancel:
                case MotionEventActions.Up:
                    if (!mIsDragging)
                    {
                        int count = mViewPager.Adapter.Count;
                        int width = Width;
                        float halfWidth = width / 2f;
                        float sixthWidth = width / 6f;

                        if ((mCurrentPage > 0) && (ev.GetX() < halfWidth - sixthWidth))
                        {
                            if (action != MotionEventActions.Cancel)
                            {
                                mViewPager.SetCurrentItem(mCurrentPage - 1, true);
                            }
                            return true;
                        }
                        else if ((mCurrentPage < count - 1) && (ev.GetX() > halfWidth + sixthWidth))
                        {
                            if (action != MotionEventActions.Cancel)
                            {
                                mViewPager.SetCurrentItem(mCurrentPage + 1, true);
                            }
                            return true;
                        }
                    }

                    mIsDragging = false;
                    mActivePointerId = INVALID_POINTER;
                    if (mViewPager.IsFakeDragging) mViewPager.EndFakeDrag();
                    break;

                case MotionEventActions.PointerDown:
                    {
                        int index = MotionEventCompat.GetActionIndex(ev);
                        mLastMotionX = MotionEventCompat.GetX(ev, index);
                        mActivePointerId = MotionEventCompat.GetPointerId(ev, index);
                        break;
                    }

                case MotionEventActions.PointerUp:
                    int pointerIndex = MotionEventCompat.GetActionIndex(ev);
                    int pointerId = MotionEventCompat.GetPointerId(ev, pointerIndex);
                    if (pointerId == mActivePointerId)
                    {
                        int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                        mActivePointerId = MotionEventCompat.GetPointerId(ev, newPointerIndex);
                    }
                    mLastMotionX = MotionEventCompat.GetX(ev, MotionEventCompat.FindPointerIndex(ev, mActivePointerId));
                    break;
            }

            return true;
        }
		public override bool OnInterceptTouchEvent (Android.Views.MotionEvent ev)
		{
//			
			switch (ev.Action) {
			case MotionEventActions.Down:
				deltaX = 0;
				deltaY = 0;

				lastX = ev.GetX ();
				lastY = ev.GetY ();

				return false;
				break;
			case MotionEventActions.Move:
				float moveX = ev.GetX ();
				float moveY = ev.GetY ();
		
				deltaX += Math.Abs (moveX - lastX);
				deltaY += Math.Abs (moveY - lastY);

				lastX = moveX;
				lastY = moveY;

				if (deltaX > deltaY) {
					return false;
				}
				break;
			case MotionEventActions.Up:
				if (deltaX > deltaY) {
					return false;
				}
				break;
			}

			var test = base.OnInterceptTouchEvent (ev);

			return test;

//			if (x1 == 0)
//				x1 = ev.GetX ();
//
//			if (ev.Action == Android.Views.MotionEventActions.Move) {
//				Console.WriteLine ("x1 = {0}, x2 = {1}", x1, ev.GetX ());
//				x2 = ev.GetX ();
//				counter = counter + Math.Abs (x2 - x1);
//				Console.WriteLine ("New Counter Value = {0}", counter);
//				x1 = x2;
//			}
//
//			if (counter > 100 && ev.Action == Android.Views.MotionEventActions.Up) {
//				Console.WriteLine (ev.Action);
//				Console.WriteLine ("Reset Counter and Return True");
//				counter = 0;
//			}
//
//			Console.WriteLine (ev.Action);
//			Console.WriteLine ("Get X: {0}", ev.GetX());
//
//			if (counter == 0) {
//				return true;
//			} else {
//				return base.OnInterceptTouchEvent (ev);
//			}
		}
Esempio n. 6
0
            public bool OnTouch( Android.Views.View v, Android.Views.MotionEvent e )
            {
                Android.Views.MotionEventActions action = e.Action;

                if ( ( action & Android.Views.MotionEventActions.Mask ) != Android.Views.MotionEventActions.Move )
                {
                    TouchPointer tec = new TouchPointer ();

                    switch ( action & Android.Views.MotionEventActions.Mask )
                    {
                        case Android.Views.MotionEventActions.Down:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( 0 ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Pressed );
                            break;
                        case Android.Views.MotionEventActions.PointerDown:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( ( int ) ( action & Android.Views.MotionEventActions.PointerIdMask ) >> ( int ) Android.Views.MotionEventActions.PointerIdShift ) ),
                                                     new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Pressed );
                            break;
                        case Android.Views.MotionEventActions.Up:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( 0 ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Released );
                            break;
                        case Android.Views.MotionEventActions.PointerUp:
                            tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( ( int ) ( action & Android.Views.MotionEventActions.PointerIdMask ) >> ( int ) Android.Views.MotionEventActions.PointerIdShift ) ),
                                                    new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Released );
                            break;
                    }

                    bool isChanged = false;
                    for ( int i = 0; i < touchPointers.Count; i++ )
                    {
                        if ( touchPointers [ i ].Id == tec.Id )
                        {
                            touchPointers [ i ] = tec;
                            isChanged = true;
                            break;
                        }
                    }

                    if ( !isChanged )
                        touchPointers.Add ( tec );
                }
                else if ( ( action & Android.Views.MotionEventActions.Mask ) == Android.Views.MotionEventActions.Move )
                {
                    for ( int i = 0; i < e.PointerCount; i++ )
                    {
                        TouchPointer tec = new TouchPointer ( new IntPtr ( e.GetPointerId ( i ) ), new Vector2 ( e.GetX (), e.GetY () ), PointerMode.Moved );
                        touchPointers [ i ] = tec;
                    }
                }

                return true;
            }