Пример #1
0
		private MotionEvent SwapTouchEvent(MotionEvent ev)
		{
			float width = Width;
			float height = Height;

			float swappedX = (ev.GetY() / height) * width;
			float swappedY = (ev.GetX() / width) * height;

		    ev.SetLocation(swappedX, swappedY);

			return ev;
		}
		public override bool OnTouchEvent (MotionEvent e)
		{
	
	        UpdateSourcePartial();
	
	        // The logic below is mostly copied from the parent class, since we
	        // can't update private mBounds variable.
	
	        // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;
	        // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98
	
	        Rect sourcePartial = mSourcePartial;
	        View target = mTarget;
	
	        int x = (int)e.GetX();
	        int y = (int)e.GetY();
	
	        bool sendToDelegate = false;
	        bool hit = true;
	        bool handled = false;
	
	        switch (e.Action) {
	        case MotionEventActions.Down:
	            if (sourcePartial.Contains(x, y)) {
	                mDelegateTargeted = true;
	                sendToDelegate = true;
	            }
	            break;
	        case MotionEventActions.Up:
	        case MotionEventActions.Move:
	            sendToDelegate = mDelegateTargeted;
	            if (sendToDelegate) {
	                if (!sourcePartial.Contains(x, y)) {
	                    hit = false;
	                }
	            }
	            break;
	        case MotionEventActions.Cancel:
	            sendToDelegate = mDelegateTargeted;
	            mDelegateTargeted = false;
	            break;
	        }
	
	        if (sendToDelegate) {
	            if (hit) {
	                e.SetLocation(target.Width / 2, target.Height / 2);
	            } else {
	                e.SetLocation(-1, -1);
	            }
	            handled = target.DispatchTouchEvent(e);
	        }
	        return handled;
		}
Пример #3
0
        private void ProcessSingleTouchOutsideMinimap(MotionEvent ev)
        {
            float x = ev.GetX();
            float y = ev.GetY();
            float lx = x - touchStartX;
            float ly = y - touchStartY;
            float l = (float)Math.Sqrt(lx * lx + ly * ly);
            float dx = x - touchLastX;
            float dy = y - touchLastY;
            touchLastX = x;
            touchLastY = y;

            switch (ev.Action)
            {
                case MotionEventActions.Down:
                    touchStartX = x;
                    touchStartY = y;
                    touchLastX = x;
                    touchLastY = y;
                    scrolling = false;
                    break;

                case MotionEventActions.Move:
                    if (scrolling || (smoothZoom > 1.0f && l > 30.0f))
                    {
                        if (!scrolling)
                        {
                            scrolling = true;
                            ev.Action = MotionEventActions.Cancel;
                            base.DispatchTouchEvent(ev);
                        }
                        smoothZoomX -= dx / zoom;
                        smoothZoomY -= dy / zoom;
                        return;
                    }
                    break;

                case MotionEventActions.Outside:
                case MotionEventActions.Up:

                    // tap
                    if (l < 30.0f)
                    {
                        // check double tap
                        if (SystemClock.ElapsedRealtime() - lastTapTime < 500)
                        {
                            if (smoothZoom == 1.0f)
                                SmoothZoomTo(maxZoom, x, y);
                            else
                                SmoothZoomTo(1.0f, Width / 2.0f, Height / 2.0f);
                            lastTapTime = 0;
                            ev.Action = MotionEventActions.Cancel;
                            base.DispatchTouchEvent(ev);
                            return;
                        }

                        lastTapTime = SystemClock.ElapsedRealtime();

                        PerformClick();
                    }
                    break;
            }

            ev.SetLocation(zoomX + (x - 0.5f * Width) / zoom, zoomY + (y - 0.5f * Height) / zoom);
            try
            {
                base.DispatchTouchEvent(ev);
            }
            // Analysis disable once EmptyGeneralCatchClause
            catch
            {
            }
        }