/// <summary>MotionEvent has no getRawY(int) method; simulate it pending future API approval.
        ///     </summary>
        /// <remarks>MotionEvent has no getRawY(int) method; simulate it pending future API approval.
        ///     </remarks>
        private static float getRawY(android.view.MotionEvent @event, int pointerIndex)
        {
            if (pointerIndex < 0)
            {
                return(float.MinValue);
            }
            if (pointerIndex == 0)
            {
                return(@event.getRawY());
            }
            float offset = @event.getRawY() - @event.getY();

            return(@event.getY(pointerIndex) + offset);
        }
Esempio n. 2
0
        public virtual bool onTouch(android.view.View v, android.view.MotionEvent @event)
        {
            int action = @event.getAction();

            if (@event.getPointerCount() > 1)
            {
                // ZoomButtonsController doesn't handle mutitouch. Give up control.
                return(false);
            }
            if (mReleaseTouchListenerOnUp)
            {
                // The controls were dismissed but we need to throw away all events until the up
                if (action == android.view.MotionEvent.ACTION_UP || action == android.view.MotionEvent
                    .ACTION_CANCEL)
                {
                    mOwnerView.setOnTouchListener(null);
                    setTouchTargetView(null);
                    mReleaseTouchListenerOnUp = false;
                }
                // Eat this event
                return(true);
            }
            dismissControlsDelayed(ZOOM_CONTROLS_TIMEOUT);
            android.view.View targetView = mTouchTargetView;
            switch (action)
            {
            case android.view.MotionEvent.ACTION_DOWN:
            {
                targetView = findViewForTouch((int)@event.getRawX(), (int)@event.getRawY());
                setTouchTargetView(targetView);
                break;
            }

            case android.view.MotionEvent.ACTION_UP:
            case android.view.MotionEvent.ACTION_CANCEL:
            {
                setTouchTargetView(null);
                break;
            }
            }
            if (targetView != null)
            {
                // The upperleft corner of the target view in raw coordinates
                int targetViewRawX = mContainerRawLocation[0] + mTouchTargetWindowLocation[0];
                int targetViewRawY = mContainerRawLocation[1] + mTouchTargetWindowLocation[1];
                android.view.MotionEvent containerEvent = android.view.MotionEvent.obtain(@event);
                // Convert the motion event into the target view's coordinates (from
                // owner view's coordinates)
                containerEvent.offsetLocation(mOwnerViewRawLocation[0] - targetViewRawX, mOwnerViewRawLocation
                                              [1] - targetViewRawY);
                // These are floats because we need to potentially offset away this exact amount
                float containerX = containerEvent.getX();
                float containerY = containerEvent.getY();
                if (containerX < 0 && containerX > -ZOOM_CONTROLS_TOUCH_PADDING)
                {
                    containerEvent.offsetLocation(-containerX, 0);
                }
                if (containerY < 0 && containerY > -ZOOM_CONTROLS_TOUCH_PADDING)
                {
                    containerEvent.offsetLocation(0, -containerY);
                }
                bool retValue = targetView.dispatchTouchEvent(containerEvent);
                containerEvent.recycle();
                return(retValue);
            }
            else
            {
                return(false);
            }
        }