Example usage for android.view MotionEvent ACTION_POINTER_UP

List of usage examples for android.view MotionEvent ACTION_POINTER_UP

Introduction

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

Prototype

int ACTION_POINTER_UP

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

Click Source Link

Document

Constant for #getActionMasked : A non-primary pointer has gone up.

Usage

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public boolean onTouchEvent(MotionEvent ev) {
    if (!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
        if (fragmentsStack.size() > 1) {
            if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking
                    && !maybeStartTracking) {
                BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
                if (!currentFragment.swipeBackEnabled) {
                    return false;
                }/* ww w. ja va  2  s.c o m*/
                startedTrackingPointerId = ev.getPointerId(0);
                maybeStartTracking = true;
                startedTrackingX = (int) ev.getX();
                startedTrackingY = (int) ev.getY();
                if (velocityTracker != null) {
                    velocityTracker.clear();
                }
            } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE
                    && ev.getPointerId(0) == startedTrackingPointerId) {
                if (velocityTracker == null) {
                    velocityTracker = VelocityTracker.obtain();
                }
                int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
                int dy = Math.abs((int) ev.getY() - startedTrackingY);
                velocityTracker.addMovement(ev);
                if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.getPixelsInCM(0.4f, true)
                        && Math.abs(dx) / 3 > dy) {
                    prepareForMoving(ev);
                } else if (startedTracking) {
                    if (!beginTrackingSent) {
                        if (parentActivity.getCurrentFocus() != null) {
                            AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
                        }
                        BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
                        currentFragment.onBeginSlide();
                        beginTrackingSent = true;
                    }
                    containerView.setTranslationX(dx);
                    setInnerTranslationX(dx);
                }
            } else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId
                    && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP
                            || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                if (velocityTracker == null) {
                    velocityTracker = VelocityTracker.obtain();
                }
                velocityTracker.computeCurrentVelocity(1000);
                if (!startedTracking && fragmentsStack.get(fragmentsStack.size() - 1).swipeBackEnabled) {
                    float velX = velocityTracker.getXVelocity();
                    float velY = velocityTracker.getYVelocity();
                    if (velX >= 3500 && velX > Math.abs(velY)) {
                        prepareForMoving(ev);
                        if (!beginTrackingSent) {
                            if (((Activity) getContext()).getCurrentFocus() != null) {
                                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
                            }
                            beginTrackingSent = true;
                        }
                    }
                }
                if (startedTracking) {
                    float x = containerView.getX();
                    AnimatorSet animatorSet = new AnimatorSet();
                    float velX = velocityTracker.getXVelocity();
                    float velY = velocityTracker.getYVelocity();
                    final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f
                            && (velX < 3500 || velX < velY);
                    float distToMove;
                    if (!backAnimation) {
                        distToMove = containerView.getMeasuredWidth() - x;
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(containerView, "translationX",
                                        containerView.getMeasuredWidth()),
                                ObjectAnimator.ofFloat(this, "innerTranslationX",
                                        (float) containerView.getMeasuredWidth()));
                    } else {
                        distToMove = x;
                        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationX", 0),
                                ObjectAnimator.ofFloat(this, "innerTranslationX", 0.0f));
                    }

                    animatorSet.setDuration(
                            Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
                    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
                        @Override
                        public void onAnimationEnd(Animator animator) {
                            onSlideAnimationEnd(backAnimation);
                        }
                    });
                    animatorSet.start();
                    animationInProgress = true;
                } else {
                    maybeStartTracking = false;
                    startedTracking = false;
                }
                if (velocityTracker != null) {
                    velocityTracker.recycle();
                    velocityTracker = null;
                }
            } else if (ev == null) {
                maybeStartTracking = false;
                startedTracking = false;
                if (velocityTracker != null) {
                    velocityTracker.recycle();
                    velocityTracker = null;
                }
            }
        }
        return startedTracking;
    }
    return false;
}

From source file:au.gov.ga.worldwind.androidremote.client.Remote.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (controlling) {
        velocityTracker.addMovement(event);
        velocityTracker.computeCurrentVelocity(1);

        boolean down = event.getActionMasked() == MotionEvent.ACTION_DOWN
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
        boolean up = event.getActionMasked() == MotionEvent.ACTION_UP
                || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
        Finger[] fingers = new Finger[event.getPointerCount()];
        for (int i = 0; i < event.getPointerCount(); i++) {
            fingers[i] = new Finger(event.getPointerId(i), event.getX(i), event.getY(i),
                    velocityTracker.getXVelocity(i), velocityTracker.getYVelocity(i),
                    !(event.getActionIndex() == i && up));
        }// www .ja va  2  s.c o  m

        FingerMessage<?> message = up ? new UpMessage(fingers)
                : down ? new DownMessage(fingers) : new MoveMessage(fingers);
        communicator.sendMessage(message);
    }
    return super.onTouchEvent(event);
}

From source file:com.xiaoyu.erbao.cctrls.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        return false;
    }//from w  w w .ja va2s .c  om

    if (!mEnabled || !mIsDragging && !touchPointIsWithinBounds(mInitialX, mInitialY)) {
        return false;
    }

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

    final int action = ev.getAction();

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

        // Remember where the motion event started
        mLastX = mInitialRawX = getViewX(ev);
        mLastY = mInitialRawY = getViewY(ev);
        mInitialX = ev.getX();
        mInitialY = ev.getY();
        mActivePointerId = ev.getPointerId(0);
        break;
    }

    case MotionEvent.ACTION_MOVE: {

        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);

        if (!touchPointIsWithinBounds(ev.getX(), ev.getY(), false))
            return false;

        final float x = getViewX(ev);
        final float y = getViewY(ev);

        final float deltaX = mLastX - x;
        final float deltaY = mLastY - y;

        mLastX = x;
        mLastY = y;
        if (!mIsDragging) {

            final float xDiff = Math.abs(x - mInitialRawX);
            final float yDiff = Math.abs(y - mInitialRawY);

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

            if (validHorizontalDrag || validVerticalDrag) {
                mIsDragging = true;
                setDrawingCacheEnabled(true);
            }
        }

        if (mIsDragging) {

            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:
                bottomBound = -(getHeight() - computeOffsetDistance());
                topBound = rightBound = leftBound = 0;
                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 pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = getViewX(ev);
            final float y = getViewY(ev);

            int nextState = determineNextStateForDrag(scrollX, scrollY, initialVelocityX, initialVelocityY,
                    (int) mInitialRawX, (int) mInitialRawY, (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 MotionEvent.ACTION_POINTER_DOWN: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        mActivePointerId = ev.getPointerId(pointerIndex);
        mLastX = getViewX(ev);
        mLastY = getViewY(ev);
        break;

    }
    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        mLastX = getViewX(ev);
        mLastY = getViewY(ev);
        break;
    }
    }

    return true;
}

From source file:info.tellmetime.TellmetimeActivity.java

/**
 * Processes touch events for FrameLayout overlaying whole activity.
 *
 * If the touch was not on the panel then it changes background color according to the touch
 * position as long as the touch event was recognized as a movement,
 * or toggles panel visibility if it was a tap.
 *
 * @return true if the touch event was consumed.
 *//*from  w  w  w .j  a  v a2 s .co  m*/
@Override
public boolean onTouch(View view, MotionEvent event) {
    // Coordinates of current touch point.
    final float rawX = event.getRawX();
    final float rawY = event.getRawY();

    switch (MotionEventCompat.getActionMasked(event)) {
    case (MotionEvent.ACTION_DOWN):
        // This action signals that a new touch gesture begins, so we cache its starting point.
        mStartX = rawX;
        mStartY = rawY;

        // Schedule a Runnable to run in 1 second.
        mLongPressHandler.postDelayed(mLongPressed, 1000);

        return true;
    case (MotionEvent.ACTION_MOVE):
        // Distance between starting point and current one.
        final double distance = Math.sqrt(Math.pow(rawX - mStartX, 2) + Math.pow(rawY - mStartY, 2));

        if (distance > mTouchSlop) {
            // If the user exceeded the slop value, then we start to track the movement.
            isSlopped = true;

            // Cancel scheduled Runnable.
            mLongPressHandler.removeCallbacks(mLongPressed);

            if (mHider.isVisible()) {
                // Hide panel to present only the clock.
                mHider.hide();
            } else {
                if (mBackgroundMode != MODE_BACKGROUND_SOLID)
                    return true;

                // Change the background color according to the touch position.

                if (event.getPointerCount() > 1) {
                    // If the user is using more than one finger, then we change saturation.

                    // Saturation depends on top <-> bottom movement of second finger.
                    mHSV[1] = MotionEventCompat.getY(event, 1) / mScreenHeight;
                } else {
                    // If it's a single finger gesture, then we change hue and value.

                    // Hue depends on left <-> right movement.
                    mHSV[0] = (float) Math.floor(rawX / mScreenWidth * 360);
                    // Value depends on up <-> down movement.
                    mHSV[2] = rawY / mScreenHeight;
                }

                mBackgroundColor = Color.HSVToColor(mHSV);
                mSurface.setBackgroundColor(mBackgroundColor);
            }
        } else {
            // If required distance is not exceeded, we only unset the slop flag.
            isSlopped = false;
        }

        return true;
    case (MotionEvent.ACTION_UP):
        mLongPressHandler.removeCallbacks(mLongPressed);

        // This action ends every touch interaction, so if the event was just a tap,
        // i.e. distance hasn't exceed the slop value, then it concerns panel.

        if (!isSlopped && !wasModeToggled) {
            // If the touch gesture was just a tap then toggle panel visibility.
            mHider.toggle();
        }

        // As the gesture ended, we need to unset the slop and toggle flag.
        isSlopped = false;
        wasModeToggled = false;

        return true;
    case (MotionEvent.ACTION_POINTER_UP):
        // Action occurs when second or farther finger goes up.

        isSlopped = true;

        return true;
    default:
        return super.onTouchEvent(event);
    }
}

From source file:com.example.piechart3d.PieChart3DView.java

@SuppressLint("NewApi")
@Override/*from   ww w  .ja  v  a 2s  . c  o  m*/
public boolean onTouchEvent(MotionEvent event) {
    getParent().requestDisallowInterceptTouchEvent(true);
    float xxx = event.getX() - centerx;
    float yyy = event.getY() - centery;

    {
        mDetector.onTouchEvent(event);
        String direction;
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case (MotionEvent.ACTION_DOWN):
            if (mZAnimator != null)
                mZAnimator.cancel();
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            x1 = event.getX();
            y1 = event.getY();
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            Log.d("appAS", "Pointer down");
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            d = rotation(event);
            break;
        case MotionEvent.ACTION_POINTER_UP:
            inix = mRenderer.angle_x;
            iniz = mRenderer.angle_z;
            iniMAngle = (float) java.lang.Math.atan2(yyy, xxx);
            break;
        case (MotionEvent.ACTION_MOVE): {
            if (event.getPointerCount() == 1) {
                x2 = event.getX();
                y2 = event.getY();
                dx = x2 - x1;
                dy = y2 - y1;
                if (Math.abs(dx) < Math.abs(dy) && Math.abs(dy) > 25) {
                    iniz = mRenderer.angle_z;
                    if (dy > 0)
                        direction = "down";
                    else
                        direction = "up";
                    this.requestDoRender(inix - (dy / 3), iniz);
                } else {
                    mAngle = (float) java.lang.Math.atan2(yyy, xxx);
                    inix = mRenderer.angle_x;
                    if (dx > 0)
                        direction = "right";
                    else
                        direction = "left";
                    this.requestDoRender(inix, /* iniz + (dx / 3) */
                            iniz + (float) Math.toDegrees((mAngle - iniMAngle)));
                    Log.d("ang", "" + iniz + " " + (iniz + (float) Math.toDegrees((mAngle - iniMAngle))));
                }
            } else if (event.getPointerCount() == 2) {
                Log.d("app", "Rotating " + event.getPointerCount());
                float rot = rotation(event) - d;
                this.requestDoRender(inix, iniz + rot);
            }
        }
        }
    }
    return true;
}

From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;//from  w w w.  j  a v a 2 s .  c  o  m

    /*if (mPositionScroller != null) {
    mPositionScroller.stop();
    }
            
    if (!isAttachedToWindow()) {
    // Something isn't right.
    // Since we rely on being attached to get data set change notifications,
    // don't risk doing anything where we might try to resync and find things
    // in a bogus state.
    return false;
    }
            
    if (mFastScroller != null && mFastScroller.onInterceptTouchEvent(ev)) {
    return true;
    }*/

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;
        if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
            mMotionCorrection = 0;
            return true;
        }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionRow(y);
        if (touchMode != TOUCH_MODE_FLINGING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            //mMotionViewOriginalTop = v.getTop();
            mLastTouchX = x;
            mLastTouchY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mTouchRemainderY = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLINGING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int y = (int) MotionEventCompat.getY(ev, pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(y)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    /*mVelocityTracker.addMovement(ev);
    final int action=ev.getAction()&MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mVelocityTracker.clear();
        //mScroller.abortAnimation();
        mLastTouchY=ev.getY();
        mActivePointerId=MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY=0;
        if (mTouchMode==TOUCH_MODE_FLINGING) {
            // Catch!
            mTouchMode=TOUCH_MODE_DRAGGING;
            reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            return true;
        }
        break;
            
    case MotionEvent.ACTION_MOVE: {
        final int index=MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index<0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id "+
                mActivePointerId+" - did StaggeredGridView receive an inconsistent "+
                "event stream?");
            return false;
        }
        final float y=MotionEventCompat.getY(ev, index);
        final float dy=y-mLastTouchY+mTouchRemainderY;
        final int deltaY=(int) dy;
        mTouchRemainderY=dy-deltaY;
            
        if (Math.abs(dy)>mTouchSlop) {
            mTouchMode=TOUCH_MODE_DRAGGING;
            return true;
        }
    }
            
    case MotionEvent.ACTION_UP: {
        mTouchMode=TOUCH_MODE_REST;
        mVelocityTracker.clear();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
    }
    }*/

    return false;
}

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mEnabled) {
        return false;
    }/*from w w w.j a v a 2s  .  c  om*/

    final int action = ev.getAction() & MotionEvent.ACTION_MASK;

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mIsDragging = false;
        mIsUnableToDrag = false;
        mActivePointerId = INVALID_VALUE;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        return false;
    }

    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsDragging) {
            return true;
        } else if (mIsUnableToDrag) {
            return false;
        }
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:

        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_VALUE) {
            break;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = getViewX(ev);
        final float dx = x - mLastX;
        final float xDiff = Math.abs(dx);
        final float y = getViewY(ev);
        final float dy = y - mLastY;
        final float yDiff = Math.abs(dy);

        if ((dx != 0 || dy != 0) && canScroll(this, false, (int) dx, (int) dy, (int) x, (int) y)) {
            mLastX = mInitialRawX = x;
            mLastY = mInitialRawY = y;
            mInitialX = ev.getX(pointerIndex);
            mInitialY = ev.getY(pointerIndex);
            return false;
        }

        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);
        }
        break;

    case MotionEvent.ACTION_DOWN:
        mLastX = mInitialRawX = getViewX(ev);
        mLastY = mInitialRawY = getViewY(ev);
        mInitialX = ev.getX(0);
        mInitialY = ev.getY(0);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);

        if (touchPointIsWithinBounds(ev.getX(), ev.getY())) {
            mIsDragging = false;
            mIsUnableToDrag = false;
            // We don't want to do anything, send the event up
            return super.onInterceptTouchEvent(ev);
        } else {
            completeScroll();
            mIsDragging = false;
            mIsUnableToDrag = true;
        }
        break;
    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    }

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

    return mIsDragging;
}

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.
 * /*  ww  w.j av a2  s  .  com*/
 * @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.android.leanlauncher.Workspace.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        break;/*  w  ww  .  ja va  2s  .  co m*/
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
        if (mTouchState == PagedView.TOUCH_STATE_REST) {
            final CellLayout currentPage = mWorkspace;
            if (currentPage != null) {
                onWallpaperTap(ev);
            }
        }
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:com.hippo.widget.BothScrollView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    /*/*from   www . j a va 2s.  c  om*/
     * This method JUST determines whether we want to intercept the motion.
     * If we return true, onMotionEvent will be called and we do the actual
     * scrolling there.
     */

    /*
    * Shortcut the most recurring case: the user is in the dragging
    * state and he is moving his finger.  We want to intercept this
    * motion.
    */
    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mIsBeingDragged)) {
        return true;
    }

    /*
     * Don't try to intercept touch if we can't scroll anyway.
     */
    if (getScrollX() == 0 && !canScrollHorizontally(1) && getScrollY() == 0 && !canScrollVertically(1)) {
        return false;
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_MOVE: {
        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }

        final int pointerIndex = ev.findPointerIndex(activePointerId);
        if (pointerIndex == -1) {
            Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent");
            break;
        }

        final int x = (int) ev.getX(pointerIndex);
        final int y = (int) ev.getY(pointerIndex);
        final int xDiff = Math.abs(x - mLastMotionX);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (xDiff > mTouchSlop || yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionX = x;
            mLastMotionY = y;
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }

        break;
    }

    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (!inChild(x, y)) {
            mIsBeingDragged = false;
            recycleVelocityTracker();
            break;
        }

        /*
         * Remember location of down touch.
         * ACTION_DOWN always refers to pointer index 0.
         */
        mLastMotionX = x;
        mLastMotionY = y;
        mActivePointerId = ev.getPointerId(0);

        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);

        /*
        * If being flinged and user touches the screen, initiate drag;
        * otherwise don't.  mScroller.isFinished should be false when
        * being flinged.
        */
        mIsBeingDragged = !mScroller.isFinished();
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        /* Release the drag */
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mScroller.springBack(getScrollX(), getScrollY(), 0, getHorizontalScrollRange(), 0,
                getVerticalScrollRange())) {
            ViewCompat.postInvalidateOnAnimation(this);
        }
        break;
    case MotionEvent.ACTION_POINTER_DOWN: {
        final int index = ev.getActionIndex();
        mLastMotionX = (int) ev.getX(index);
        mLastMotionY = (int) ev.getY(index);
        mActivePointerId = ev.getPointerId(index);
        break;
    }
    case MotionEvent.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        final int index = ev.findPointerIndex(mActivePointerId);
        mLastMotionX = (int) ev.getX(index);
        mLastMotionY = (int) ev.getY(index);
        break;
    }

    /*
    * The only time we want to intercept motion events is if we are in the
    * drag mode.
    */
    return mIsBeingDragged;
}