Example usage for android.view MotionEvent ACTION_OUTSIDE

List of usage examples for android.view MotionEvent ACTION_OUTSIDE

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_OUTSIDE.

Prototype

int ACTION_OUTSIDE

To view the source code for android.view MotionEvent ACTION_OUTSIDE.

Click Source Link

Document

Constant for #getActionMasked : A movement has happened outside of the normal bounds of the UI element.

Usage

From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    final int action = ev.getAction();

    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }//from ww  w  .ja  v a2  s  .  c om

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            } else if (yDiff > mTouchSlop && yDiff > xDiff) {
                mIsDragging = true;
                mLastY = y;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            if (mOnInteractListener != null) {
                mOnInteractListener.onActionMove(x, y);
            }
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]",
            // scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_MIDDLE:
                topBound = getHeight();
                bottomBound = -getHeight();
                leftBound = getWidth();
                rightBound = -getWidth();
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                topBound = rightBound = leftBound = 0;
                bottomBound = -getHeight();
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // TODO top/bottom bounds
            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollTo((int) scrollX, (int) scrollY);
        }
        break;
    case MotionEvent.ACTION_UP:

        if (mIsDragging) {

            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);

            boolean isControlled = false;
            if (isControlled) {
                break;
            }

            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            Log.d("", "end drag from action up");
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            Log.d(TAG, "end drag from action cancel");
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:com.example.lansosdk.util.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }//from  w  ww .j  av  a  2s  .  c  om

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            //                if (xDiff > mTouchSlop && xDiff > yDiff) {
            //                    mIsDragging = true;
            //                    mLastX = x;
            //                    setDrawingCacheEnabled(true);
            //                } else if (yDiff > mTouchSlop && yDiff > xDiff) {
            //                    mIsDragging = true;
            //                    mLastY = y;
            //                    setDrawingCacheEnabled(true);
            //                }
        }

        //            if (mIsDragging) {  ??
        //                // Scroll to follow the motion event
        //                final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        //                if (activePointerIndex == -1) {
        //                    mActivePointerId = INVALID_POINTER;
        //                    break;
        //                }
        //                final float x = MotionEventCompat.getX(ev, activePointerIndex);
        //                final float y = MotionEventCompat.getY(ev, activePointerIndex);
        //                final float deltaX = mLastX - x;
        //                final float deltaY = mLastY - y;
        //                mLastX = x;
        //                mLastY = y;
        //                final float oldScrollX = getScrollX();
        //                final float oldScrollY = getScrollY();
        //                float scrollX = oldScrollX + deltaX;
        //                float scrollY = oldScrollY + deltaY;
        //
        //                // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
        //                final float leftBound, rightBound;
        //                final float bottomBound, topBound;
        //                switch (mScreenSide) {
        //                case STICK_TO_LEFT:
        //                    topBound = bottomBound = rightBound = 0;
        //                    leftBound = getWidth(); // How far left we can scroll
        //                    break;
        //                case STICK_TO_MIDDLE:
        //                    topBound = getHeight();
        //                    bottomBound = -getHeight();
        //                    leftBound = getWidth();
        //                    rightBound = -getWidth();
        //                    break;
        //                case STICK_TO_RIGHT:
        //                    rightBound = -getWidth();
        //                    topBound = bottomBound = leftBound = 0;
        //                    break;
        //                case STICK_TO_TOP:
        //                    topBound = getHeight();
        //                    bottomBound = rightBound = leftBound = 0;
        //                    break;
        //                case STICK_TO_BOTTOM:
        //                    topBound = rightBound = leftBound = 0;
        //                    bottomBound = -getHeight();
        //                    break;
        //                default:
        //                    topBound = bottomBound = rightBound = leftBound = 0;
        //                    break;
        //                }
        //                if (scrollX > leftBound) {
        //                    scrollX = leftBound;
        //                } else if (scrollX < rightBound) {
        //                    scrollX = rightBound;
        //                }
        //                if (scrollY > topBound) {
        //                    scrollY = topBound;
        //                } else if (scrollY < bottomBound) {
        //                    scrollY = bottomBound;
        //                }
        //
        //                // Keep the precision
        //                mLastX += scrollX - (int) scrollX;
        //                mLastY += scrollY - (int) scrollY;
        //                scrollTo((int) scrollX, (int) scrollY);
        //            }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);
            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning())
        return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE)
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Action down touch
        mIsActionDown = true;/*from w w w  .j  a va2s  .  com*/
        if (!mIsViewPagerMode)
            break;
        // Detect if we touch down on tab, later to move
        mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex;
        break;
    case MotionEvent.ACTION_MOVE:
        // If tab touched, so move
        if (mIsTabActionDown) {
            mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true);
            break;
        }
        if (mIsActionDown)
            break;
    case MotionEvent.ACTION_UP:
        // Press up and set tab index relative to current coordinate
        if (mIsActionDown)
            setTabIndex((int) (event.getX() / mTabSize));
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    default:
        // Reset action touch variables
        mIsTabActionDown = false;
        mIsActionDown = false;
        break;
    }

    return true;
}

From source file:it.mb.whatshare.Utils.java

/**
 * Returns a string that represents the symbolic name of the specified
 * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent
 * numeric constant such as "35" if unknown. By Google.
 * /*from www.  ja v  a 2s.  c o m*/
 * @param action
 *            The action.
 * @return The symbolic name of the specified action.
 */
public static String actionToString(int action) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "ACTION_DOWN";
    case MotionEvent.ACTION_UP:
        return "ACTION_UP";
    case MotionEvent.ACTION_CANCEL:
        return "ACTION_CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "ACTION_OUTSIDE";
    case MotionEvent.ACTION_MOVE:
        return "ACTION_MOVE";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "ACTION_HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "ACTION_SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "ACTION_HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "ACTION_HOVER_EXIT";
    }
    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        return "ACTION_POINTER_DOWN(" + index + ")";
    case MotionEvent.ACTION_POINTER_UP:
        return "ACTION_POINTER_UP(" + index + ")";
    default:
        return Integer.toString(action);
    }
}

From source file:com.skyousuke.ivtool.windows.MainWindow.java

private void setTouchListener() {
    layout.setOnTouchListener(new View.OnTouchListener() {
        private WindowManager.LayoutParams latestParams = layoutParams;
        int x, y;
        float touchX, touchY;

        @Override//from w  w w.  j  a v  a  2  s  .c om
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_DOWN:

                x = latestParams.x;
                y = latestParams.y;

                touchX = motionEvent.getRawX();
                touchY = motionEvent.getRawY();
                break;
            case MotionEvent.ACTION_MOVE:
                latestParams.x = (int) (x + motionEvent.getRawX() - touchX);
                latestParams.y = (int) (y + motionEvent.getRawY() - touchY);

                WindowManagerUtils.keepInScreen(layout, latestParams, screenWidth, screenHeight);
                windowManager.updateViewLayout(layout, latestParams);
                break;
            case MotionEvent.ACTION_OUTSIDE:
                lostFocus(500);
                break;
            }
            return false;
        }
    });
}

From source file:com.hb.hkm.slidinglayer.SlidLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHere(mInitialX, mInitialY)) {
        return false;
    }/* ww  w. ja v a  2s .  c  o  m*/

    final int action = ev.getAction();

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == INVALID_VALUE) {
                mActivePointerId = INVALID_VALUE;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);

            final boolean validHorizontalDrag = xDiff > mTouchSlop && xDiff > yDiff;
            final boolean validVerticalDrag = yDiff > mTouchSlop && yDiff > xDiff;

            if (validHorizontalDrag) {
                mLastX = x;
            } else if (validVerticalDrag) {
                mLastY = y;
            }

            if (validHorizontalDrag || validVerticalDrag) {
                mIsDragging = true;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == INVALID_VALUE) {
                mActivePointerId = INVALID_VALUE;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                topBound = rightBound = leftBound = 0;
                bottomBound = -getHeight();
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollToAndNotify((int) scrollX, (int) scrollY);
        }
        break;
    case MotionEvent.ACTION_UP:

        if (mIsDragging) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);

            int nextState = determineNextStateForDrag(scrollX, scrollY, initialVelocityX, initialVelocityY,
                    (int) mInitialX, (int) mInitialY, (int) x, (int) y);
            setLayerState(nextState, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_VALUE;
            endDrag();

        } else if (changeStateOnTap) {
            int nextState = determineNextStateAfterTap();
            setLayerState(nextState, true, true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            setLayerState(mCurrentState, true, true);
            mActivePointerId = INVALID_VALUE;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_VALUE) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:com.gdgl.util.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;/*from  www . j a  v  a  2  s.  c  om*/
        mIsTapInContent = isTapInContent(x, y);
        mIsTapInEdgeSlide = isTapInEdgeSlide(x, y);

        if (mIsTapInContent) {
            mScroller.abortAnimation();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        mVelocityTracker.addMovement(event);

        if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) {
            return false;
        }

        if (Math.abs(x - mPressedX) >= mTouchSlop && mIsTapInContent && currentState != STATE_DRAG) {
            getParent().requestDisallowInterceptTouchEvent(true);
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }
        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (mIsTapInContent && MotionEvent.ACTION_UP == action) {
            performContentTap();
        }
        mVelocityTracker.clear();
        getParent().requestDisallowInterceptTouchEvent(false);
        mIsTapInContent = mIsTapInEdgeSlide = false;
        break;
    }
    return true;
}

From source file:com.stasbar.knowyourself.timer.CountingTimerView.java

public void registerVirtualButtonAction(final Runnable runnable) {
    if (!mAccessibilityManager.isEnabled()) {
        this.setOnTouchListener(new OnTouchListener() {
            @Override/*from   www  .ja v  a 2s.  c o m*/
            public boolean onTouch(View v, MotionEvent event) {
                if (mVirtualButtonEnabled) {
                    switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        if (withinVirtualButtonBounds(event.getX(), event.getY())) {
                            virtualButtonPressed(true);
                            return true;
                        } else {
                            virtualButtonPressed(false);
                            return false;
                        }
                    case MotionEvent.ACTION_CANCEL:
                        virtualButtonPressed(false);
                        return true;
                    case MotionEvent.ACTION_OUTSIDE:
                        virtualButtonPressed(false);
                        return false;
                    case MotionEvent.ACTION_UP:
                        virtualButtonPressed(false);
                        if (withinVirtualButtonBounds(event.getX(), event.getY())) {
                            runnable.run();
                        }
                        return true;
                    }
                }
                return false;
            }
        });
    } else {
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                runnable.run();
            }
        });
    }
}

From source file:com.base.view.slidemenu.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;/*from   w w w  .jav a 2  s. co m*/
        mPressedY = y;
        mIsTapInContent = isTapInContent(x, y);
        mIsTapInEdgeSlide = isTapInEdgeSlide(x, y);

        if (mIsTapInContent) {
            mScroller.abortAnimation();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        mVelocityTracker.addMovement(event);

        if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) {
            return false;
        }

        if (Math.abs(x - mPressedX) >= mTouchSlop && mIsTapInContent && currentState != STATE_DRAG) {
            getParent().requestDisallowInterceptTouchEvent(true);
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }
        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (mIsTapInContent && MotionEvent.ACTION_UP == action) {
            performContentTap();
        }
        mVelocityTracker.clear();
        getParent().requestDisallowInterceptTouchEvent(false);
        mIsTapInContent = mIsTapInEdgeSlide = false;
        break;
    }
    return true;
}

From source file:me.tangke.slidemenu.SlideMenu.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (!mCanSlide)
        return false;

    final float x = event.getX();
    final float y = event.getY();
    final int currentState = mCurrentState;

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mPressedX = mLastMotionX = x;/*from   w ww . j  a  va  2s .  c o  m*/
        mPressedY = y;
        mIsTapInContent = isTapInContent(x, y);
        mIsTapInEdgeSlide = isTapInEdgeSlide(x, y);

        if (mIsTapInContent) {
            mScroller.abortAnimation();
        }
        break;
    case MotionEvent.ACTION_MOVE:
        mVelocityTracker.addMovement(event);

        if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) {
            return false;
        }

        if (Math.abs(x - mPressedX) >= mTouchSlop && mIsTapInContent && currentState != STATE_DRAG) {
            getParent().requestDisallowInterceptTouchEvent(true);
            setCurrentState(STATE_DRAG);
        }
        if (STATE_DRAG != currentState) {
            mLastMotionX = x;
            return false;
        }
        drag(mLastMotionX, x);
        mLastMotionX = x;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
        if (STATE_DRAG == currentState) {
            mVelocityTracker.computeCurrentVelocity(1000);
            endDrag(x, mVelocityTracker.getXVelocity());
        } else if (mIsTapInContent && MotionEvent.ACTION_UP == action) {
            performContentTap();
        }
        mVelocityTracker.clear();
        getParent().requestDisallowInterceptTouchEvent(false);
        mIsTapInContent = mIsTapInEdgeSlide = false;
        break;
    }
    return true;
}