Example usage for android.support.v4.view MotionEventCompat getActionIndex

List of usage examples for android.support.v4.view MotionEventCompat getActionIndex

Introduction

In this page you can find the example usage for android.support.v4.view MotionEventCompat getActionIndex.

Prototype

public static int getActionIndex(MotionEvent event) 

Source Link

Document

Call MotionEvent#getAction , returning only the pointer index portion

Usage

From source file:com.rsen.github.swiperefresh.HnSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    try {//from www.  j a va2  s. c  om
        final int action = MotionEventCompat.getActionMasked(ev);

        if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
            mReturningToStart = false;
        }

        switch (mDirection) {
        case BOTTOM:
            if (!isEnabled() || mReturningToStart || canChildScrollDown() || mRefreshing) {
                // Fail fast if we're not in a state where a swipe is possible
                return false;
            }
            break;
        case TOP:
        default:
            if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) {
                // Fail fast if we're not in a state where a swipe is possible
                return false;
            }
            break;
        }

        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            mIsBeingDragged = false;
            break;

        case MotionEvent.ACTION_MOVE: {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex < 0) {
                return false;
            }

            final float y = MotionEventCompat.getY(ev, pointerIndex);

            float overscrollTop;
            switch (mDirection) {
            case BOTTOM:
                overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
                break;
            case TOP:
            default:
                overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
                break;
            }
            if (mIsBeingDragged) {
                mProgress.showArrow(true);
                float originalDragPercent = overscrollTop / mTotalDragDistance;
                if (originalDragPercent < 0) {
                    return false;
                }
                float dragPercent = Math.min(1f, Math.abs(originalDragPercent));
                float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3;
                float extraOS = Math.abs(overscrollTop) - mTotalDragDistance;
                float slingshotDist = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop
                        : mSpinnerFinalOffset;
                float tensionSlingshotPercent = Math.max(0,
                        Math.min(extraOS, slingshotDist * 2) / slingshotDist);
                float tensionPercent = (float) ((tensionSlingshotPercent / 4)
                        - Math.pow((tensionSlingshotPercent / 4), 2)) * 2f;
                float extraMove = (slingshotDist) * tensionPercent * 2;

                // int targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
                int targetY;
                if (mDirection == SwipeRefreshLayoutDirection.TOP) {
                    targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove);
                } else {
                    targetY = mOriginalOffsetTop - (int) ((slingshotDist * dragPercent) + extraMove);
                }
                // where 1.0f is a full circle
                if (mCircleView.getVisibility() != View.VISIBLE) {
                    mCircleView.setVisibility(View.VISIBLE);
                }
                if (!mScale) {
                    ViewCompat.setScaleX(mCircleView, 1f);
                    ViewCompat.setScaleY(mCircleView, 1f);
                }
                if (overscrollTop < mTotalDragDistance) {
                    if (mScale) {
                        setAnimationProgress(overscrollTop / mTotalDragDistance);
                    }
                    if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA
                            && !isAnimationRunning(mAlphaStartAnimation)) {
                        // Animate the alpha
                        startProgressAlphaStartAnimation();
                    }
                    float strokeStart = (float) (adjustedPercent * .8f);
                    mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart));
                    mProgress.setArrowScale(Math.min(1f, adjustedPercent));
                } else {
                    if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) {
                        // Animate the alpha
                        startProgressAlphaMaxAnimation();
                    }
                }
                float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f;
                mProgress.setProgressRotation(rotation);
                setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /* requires update */);
            }
            break;
        }
        case MotionEventCompat.ACTION_POINTER_DOWN: {
            final int index = MotionEventCompat.getActionIndex(ev);
            mActivePointerId = MotionEventCompat.getPointerId(ev, index);
            break;
        }

        case MotionEventCompat.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            if (mActivePointerId == INVALID_POINTER) {
                if (action == MotionEvent.ACTION_UP) {
                }
                return false;
            }
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float y = MotionEventCompat.getY(ev, pointerIndex);

            float overscrollTop;
            switch (mDirection) {
            case BOTTOM:
                overscrollTop = (mInitialMotionY - y) * DRAG_RATE;
                break;
            case TOP:
            default:
                overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
                break;
            }
            mIsBeingDragged = false;
            if (overscrollTop > mTotalDragDistance) {
                setRefreshing(true, true /* notify */);
            } else {
                // cancel refresh
                mRefreshing = false;
                mProgress.setStartEndTrim(0f, 0f);
                AnimationListener listener = null;
                if (!mScale) {
                    listener = new AnimationListener() {

                        @Override
                        public void onAnimationStart(Animation animation) {
                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            if (!mScale) {
                                startScaleDownAnimation(null);
                            }
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {
                        }

                    };
                }
                animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener);
                mProgress.showArrow(false);
            }
            mActivePointerId = INVALID_POINTER;
            return false;
        }
        }
    } catch (Exception e) {
        Log.e(TAG, "An exception occured during SwipyRefreshLayout onTouchEvent " + e.toString());
    }

    return true;
}

From source file:cn.org.eshow.framwork.view.slidingmenu.CustomViewAbove.java

/**
 * On secondary pointer up./*ww  w  .j  a  va 2 s. c om*/
 *
 * @param ev the ev
 */
private void onSecondaryPointerUp(MotionEvent ev) {
    if (DEBUG)
        Log.v(TAG, "onSecondaryPointerUp called");
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
        mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}

From source file:bhav.swipeaction.SwipeAction.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    int pointerIndex;
    if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
        mReturningToStart = false;// w w  w. j a v a  2 s  .co  m
    }
    if (!isEnabled() || mReturningToStart || canChildScrollUp() || mNestedScrollInProgress) {
        // Fail fast if we're not in a state where a swipe is possible
        return false;
    }
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mIsBeingDragged = false;
        break;
    case MotionEvent.ACTION_MOVE: {
        pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        if (mIsBeingDragged) {
            if (overscrollTop > 0) {
                moveSpinner(overscrollTop);
            } else {
                return false;
            }
        }
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        pointerIndex = MotionEventCompat.getActionIndex(ev);
        if (pointerIndex < 0) {
            Log.e(TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index.");
            return false;
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        break;
    case MotionEvent.ACTION_UP: {
        pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (pointerIndex < 0) {
            Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id.");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE;
        mIsBeingDragged = false;
        finishSpinner(overscrollTop);
        mActivePointerId = INVALID_POINTER;
        return false;
    }
    case MotionEvent.ACTION_CANCEL:
        return false;
    }
    return true;
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    final int pointerIndex = MotionEventCompat.getActionIndex(event);
    final int pointCnt = mWrap.getPointerCount(event);
    final int pointerId = MotionEventCompat.getPointerId(event, pointerIndex);
    if (pointCnt < MAX_POINT_CNT) {
        //if (pointerIndex <= MAX_POINT_CNT - 1){
        {/*from w w w.  ja v  a 2 s.c om*/
            for (int i = 0; i < pointCnt; i++) {
                int id = MotionEventCompat.getPointerId(event, i);
                if (id < MAX_POINT_CNT) {
                    x_last[id] = x[id];
                    y_last[id] = y[id];
                    x[id] = mWrap.getX(event, i);
                    y[id] = mWrap.getY(event, i);
                }
            }
            switch (MotionEventCompat.getActionMasked(event)) {
            case MotionEvent.ACTION_DOWN:
            case MotionEventCompat.ACTION_POINTER_DOWN:
                int button = -1;
                // Save the ID of this pointer
                if (mInputMode == INPUT_MODE_MOUSE) {
                } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) {
                    int buttonState = mWrap.getButtonState(event);
                    if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) {
                        button = BTN_A;
                    } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) {
                        button = BTN_B;
                    }
                    DosBoxControl.nativeJoystick(0, 0, ACTION_DOWN, button);
                } else if (mInputMode == INPUT_MODE_REAL_MOUSE) {
                    int buttonState = mWrap.getButtonState(event);
                    if ((buttonState & TouchEventWrapper.BUTTON_PRIMARY) != 0) {
                        button = BTN_A;
                    } else if ((buttonState & TouchEventWrapper.BUTTON_SECONDARY) != 0) {
                        button = BTN_B;
                    } else if (buttonState == 0) {
                        // handle trackpad presses as button clicks
                        button = BTN_A;
                    }
                    DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_DOWN, button);
                }
                mButtonDown[pointerId] = button;
                break;
            case MotionEvent.ACTION_UP:
            case MotionEventCompat.ACTION_POINTER_UP:
                if (mInputMode == INPUT_MODE_MOUSE) {
                    if (mLongClick) {
                        // single tap long click release
                        DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP,
                                mGestureSingleClick - GESTURE_LEFT_CLICK);
                        mLongClick = false;
                        Log.i("DosBoxTurbo", "SingleTap Long Click Release");
                        return true;
                    } else if (mDoubleLong) {
                        // double tap long click release
                        try {
                            Thread.sleep(CLICK_DELAY);
                        } catch (InterruptedException e) {
                        }
                        DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP,
                                mGestureDoubleClick - GESTURE_LEFT_CLICK);
                        Log.i("DosBoxTurbo", "DoubleTap Long Click Release");
                        mDoubleLong = false;
                        //return true;
                    } else if (pointCnt == 2) {
                        // handle 2 finger tap gesture
                        if (mLongPress) {
                            if (!mTwoFingerAction) {
                                // press button down
                                Log.i("DosBoxTurbo", "2-Finger Long Click Down");
                                DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN,
                                        mGestureTwoFinger - GESTURE_LEFT_CLICK);
                                mTwoFingerAction = true;
                            } else {
                                // already pressing button - release and press again
                                Log.i("DosBoxTurbo", "2-Finger Long Click - AGAIN");
                                DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP,
                                        mGestureTwoFinger - GESTURE_LEFT_CLICK);
                                try {
                                    Thread.sleep(CLICK_DELAY);
                                } catch (InterruptedException e) {
                                }
                                DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_DOWN,
                                        mGestureTwoFinger - GESTURE_LEFT_CLICK);
                            }
                        } else {
                            Log.i("DosBoxTurbo", "2-Finger Long Click Down-UP");
                            mouseClick(mGestureTwoFinger - GESTURE_LEFT_CLICK);
                        }
                        return true;
                    } else if ((pointCnt == 1) && mTwoFingerAction) {
                        // release two finger gesture
                        Log.i("DosBoxTurbo", "2-Finger Long Click Release");
                        DosBoxControl.nativeMouse(0, 0, -1, -1, ACTION_UP,
                                mGestureTwoFinger - GESTURE_LEFT_CLICK);
                        mTwoFingerAction = false;
                        //return true;
                    }
                } else if (mInputMode == INPUT_MODE_REAL_MOUSE) {
                    //Log.v("Mouse","BUTTON UP: " + (mButtonDown[pointerId]));
                    DosBoxControl.nativeMouse(0, 0, 0, 0, ACTION_UP, mButtonDown[pointerId]);
                    if (mWrap.getButtonState(event) > 0) {
                        return true; // capture button touches, pass screen touches through to gesture detetor
                    }
                } else if (mInputMode == INPUT_MODE_REAL_JOYSTICK) {
                    DosBoxControl.nativeJoystick(0, 0, ACTION_UP, (mButtonDown[pointerId]));
                    if (mWrap.getButtonState(event) > 0) {
                        return true;
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                //isTouch[pointerId] = true;
                switch (mInputMode) {
                case INPUT_MODE_SCROLL:
                    mScroll_x += (int) (x[pointerId] - x_last[pointerId]);
                    mScroll_y += (int) (y[pointerId] - y_last[pointerId]);
                    forceRedraw();
                    break;
                case INPUT_MODE_MOUSE:
                case INPUT_MODE_REAL_MOUSE:
                    if (event.getEventTime() + EVENT_THRESHOLD_DECAY < SystemClock.uptimeMillis()) {
                        Log.i("DosBoxTurbo", "eventtime: " + event.getEventTime() + " systemtime: "
                                + SystemClock.uptimeMillis());
                        return true; // get rid of old events
                    }
                    int idx = (!virtButton[0]) ? 0 : 1;
                    if (mAbsolute) {
                        DosBoxControl.nativeMouseWarp(x[idx], y[idx], mRenderer.x, mRenderer.y, mRenderer.width,
                                mRenderer.height);
                    } else {
                        DosBoxControl.nativeMouse((int) (x[idx] * mMouseSensitivityX),
                                (int) (y[idx] * mMouseSensitivityY), (int) (x_last[idx] * mMouseSensitivityX),
                                (int) (y_last[idx] * mMouseSensitivityY), ACTION_MOVE, -1);
                    }
                    if (mDebug) {
                        Log.d("DosBoxTurbo",
                                "mAbsolute=" + mAbsolute + " MotionEvent MOVE(" + pointerId + ")" + " x[idx]="
                                        + x[idx] + " y[idx]" + y[idx] + " mRenderer.x=" + mRenderer.x
                                        + " mRenderer.y=" + mRenderer.y + " mRenderer.width=" + mRenderer.width
                                        + " mRenderer.height=" + mRenderer.height);
                    }
                    try {
                        if (!mInputLowLatency)
                            Thread.sleep(95);
                        else
                            Thread.sleep(65);
                    } catch (InterruptedException e) {
                    }

                    break;
                default:
                }
                break;
            }
        }
    }
    try {
        Thread.sleep(15);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    //Thread.yield();
    return gestureScanner.onTouchEvent(event);
}

From source file:com.coleman.demo.view.page.DirectionalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong
        // to one of our
        // descendants.
        return false;
    }/*from   w w w  .  jav  a 2s.  c  o m*/

    if (mAdapter == null || mAdapter.getCount() == 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }

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

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        completeScroll();

        // Remember where the motion event started
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = mInitialMotion = ev.getX();
        } else {
            mLastMotionY = mInitialMotion = ev.getY();
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }
    case MotionEvent.ACTION_MOVE:
        if (!mIsBeingDragged) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            float primaryDiff;
            float secondaryDiff;

            if (mOrientation == HORIZONTAL) {
                primaryDiff = xDiff;
                secondaryDiff = yDiff;
            } else {
                primaryDiff = yDiff;
                secondaryDiff = xDiff;
            }

            if (DEBUG)
                Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
            if (primaryDiff > mTouchSlop && primaryDiff > secondaryDiff) {
                if (DEBUG)
                    Log.v(TAG, "Starting drag!");
                mIsBeingDragged = true;
                if (mOrientation == HORIZONTAL) {
                    mLastMotionX = x;
                } else {
                    mLastMotionY = y;
                }
                setScrollState(SCROLL_STATE_DRAGGING);
                setScrollingCacheEnabled(true);
            }
        }
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);

            int size;
            float scroll;

            if (mOrientation == HORIZONTAL) {
                size = getWidth();
                scroll = getScrollX() + (mLastMotionX - x);
                mLastMotionX = x;
            } else {
                size = getHeight();
                scroll = getScrollY() + (mLastMotionY - y);
                mLastMotionY = y;
            }

            final float lowerBound = Math.max(0, (mCurItem - 1) * size);
            final float upperBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * size;
            if (scroll < lowerBound) {
                scroll = lowerBound;
            } else if (scroll > upperBound) {
                scroll = upperBound;
            }
            if (mOrientation == HORIZONTAL) {
                // Don't lose the rounded component
                mLastMotionX += scroll - (int) scroll;
                scrollTo((int) scroll, getScrollY());
            } else {
                // Don't lose the rounded component
                mLastMotionY += scroll - (int) scroll;
                scrollTo(getScrollX(), (int) scroll);
            }
            if (mOnPageChangeListener != null) {
                final int position = (int) scroll / size;
                final int positionOffsetPixels = (int) scroll % size;
                final float positionOffset = (float) positionOffsetPixels / size;
                mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity;
            float lastMotion;
            int sizeOverThree;

            if (mOrientation == HORIZONTAL) {
                initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
                lastMotion = mLastMotionX;
                sizeOverThree = getWidth() / 3;
            } else {
                initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
                lastMotion = mLastMotionY;
                sizeOverThree = getHeight() / 3;
            }

            mPopulatePending = true;
            if ((Math.abs(initialVelocity) > mMinimumVelocity)
                    || Math.abs(mInitialMotion - lastMotion) >= sizeOverThree) {
                if (lastMotion > mInitialMotion) {
                    setCurrentItemInternal(mCurItem - 1, true, true);
                } else {
                    setCurrentItemInternal(mCurItem + 1, true, true);
                }
            } else {
                setCurrentItemInternal(mCurItem, true, true);
            }

            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged) {
            setCurrentItemInternal(mCurItem, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = MotionEventCompat.getX(ev, index);
        } else {
            mLastMotionY = MotionEventCompat.getY(ev, index);
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = MotionEventCompat.getX(ev, index);
        } else {
            mLastMotionY = MotionEventCompat.getY(ev, index);
        }
        break;
    }
    return true;
}

From source file:cn.com.zzwfang.view.directionalviewpager.DirectionalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
        // Don't handle edge touches immediately -- they may actually belong to one of our
        // descendants.
        return false;
    }//ww  w.  ja va 2  s .  c  o m

    if (mAdapter == null || mAdapter.getCount() == 0) {
        // Nothing to present or scroll; nothing to touch.
        return false;
    }

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

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        completeScroll();

        // Remember where the motion event started
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = mInitialMotion = ev.getX();
        } else {
            mLastMotionY = mInitialMotion = ev.getY();
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }
    case MotionEvent.ACTION_MOVE:
        if (!mIsBeingDragged) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastMotionX);
            final float yDiff = Math.abs(y - mLastMotionY);
            float primaryDiff;
            float secondaryDiff;

            if (mOrientation == HORIZONTAL) {
                primaryDiff = xDiff;
                secondaryDiff = yDiff;
            } else {
                primaryDiff = yDiff;
                secondaryDiff = xDiff;
            }

            if (DEBUG)
                Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
            if (primaryDiff > mTouchSlop && primaryDiff > secondaryDiff) {
                if (DEBUG)
                    Log.v(TAG, "Starting drag!");
                mIsBeingDragged = true;
                if (mOrientation == HORIZONTAL) {
                    mLastMotionX = x;
                } else {
                    mLastMotionY = y;
                }
                setScrollState(SCROLL_STATE_DRAGGING);
                setScrollingCacheEnabled(true);
            }
        }
        if (mIsBeingDragged) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);

            int size;
            float scroll;

            if (mOrientation == HORIZONTAL) {
                size = getWidth();
                scroll = getScrollX() + (mLastMotionX - x);
                mLastMotionX = x;
            } else {
                size = getHeight();
                scroll = getScrollY() + (mLastMotionY - y);
                mLastMotionY = y;
            }

            final float lowerBound = Math.max(0, (mCurItem - 1) * size);
            final float upperBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * size;
            if (scroll < lowerBound) {
                scroll = lowerBound;
            } else if (scroll > upperBound) {
                scroll = upperBound;
            }
            if (mOrientation == HORIZONTAL) {
                // Don't lose the rounded component
                mLastMotionX += scroll - (int) scroll;
                scrollTo((int) scroll, getScrollY());
            } else {
                // Don't lose the rounded component
                mLastMotionY += scroll - (int) scroll;
                scrollTo(getScrollX(), (int) scroll);
            }
            if (mOnPageChangeListener != null) {
                final int position = (int) scroll / size;
                final int positionOffsetPixels = (int) scroll % size;
                final float positionOffset = (float) positionOffsetPixels / size;
                mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity;
            float lastMotion;
            int sizeOverThree;

            if (mOrientation == HORIZONTAL) {
                initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId);
                lastMotion = mLastMotionX;
                sizeOverThree = getWidth() / 3;
            } else {
                initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
                lastMotion = mLastMotionY;
                sizeOverThree = getHeight() / 3;
            }

            mPopulatePending = true;
            if ((Math.abs(initialVelocity) > mMinimumVelocity)
                    || Math.abs(mInitialMotion - lastMotion) >= sizeOverThree) {
                if (lastMotion > mInitialMotion) {
                    setCurrentItemInternal(mCurItem - 1, true, true);
                } else {
                    setCurrentItemInternal(mCurItem + 1, true, true);
                }
            } else {
                setCurrentItemInternal(mCurItem, true, true);
            }

            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged) {
            setCurrentItemInternal(mCurItem, true, true);
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = MotionEventCompat.getX(ev, index);
        } else {
            mLastMotionY = MotionEventCompat.getY(ev, index);
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = MotionEventCompat.getX(ev, index);
        } else {
            mLastMotionY = MotionEventCompat.getY(ev, index);
        }
        break;
    }
    return true;
}

From source file:com.peerless2012.twowaynestedscrollview.TwoWayNestedScrollView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    initVelocityTrackerIfNotExists();/*from  ww w.j a  v  a 2s  .c om*/

    MotionEvent vtev = MotionEvent.obtain(ev);

    final int actionMasked = MotionEventCompat.getActionMasked(ev);

    if (actionMasked == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;
        mNestedXOffset = 0;
    }
    vtev.offsetLocation(mNestedXOffset, mNestedYOffset);

    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN: {
        if (getChildCount() == 0) {
            return false;
        }
        if ((mIsBeingDragged = !mScroller.isFinished())) {
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }

        /*
         * If being flinged and user touches, stop the fling. isFinished
         * will be false if being flinged.
         */
        if (!mScroller.isFinished()) {
            mScroller.abortAnimation();
        }
        // Remember where the motion event started
        mLastMotionX = (int) ev.getX();
        mLastMotionY = (int) ev.getY();
        mIsBeingDragged = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    }
    case MotionEvent.ACTION_MOVE:
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (activePointerIndex == -1) {
            Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
            break;
        }

        final int x = (int) MotionEventCompat.getX(ev, activePointerIndex);
        int deltaX = mLastMotionX - x;
        final int y = (int) MotionEventCompat.getY(ev, activePointerIndex);
        int deltaY = mLastMotionY - y;
        if (dispatchNestedPreScroll(deltaX, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaX -= mScrollConsumed[0];
            deltaY -= mScrollConsumed[1];
            vtev.offsetLocation(mScrollOffset[0], mScrollOffset[1]);
            mNestedXOffset += mScrollOffset[0];
            mNestedYOffset += mScrollOffset[1];
        }

        if (!mIsBeingDragged) {
            if (Math.abs(deltaY) > mTouchSlop) {
                final ViewParent parent = getParent();
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
                mIsBeingDragged = true;
                if (deltaY > 0) {
                    deltaY -= mTouchSlop;
                } else {
                    deltaY += mTouchSlop;
                }
                scrollDirection = DIRECTION_VERTICAL;
            } else if (Math.abs(deltaX) > mTouchSlop) {
                final ViewParent parent = getParent();
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
                mIsBeingDragged = true;
                if (deltaX > 0) {
                    deltaX -= mTouchSlop;
                } else {
                    deltaX += mTouchSlop;
                }
                scrollDirection = DIRECTION_HORIZONTAL;
            } else {
                scrollDirection = DIRECTION_INVALIDATE;
            }
        }
        if (mIsBeingDragged && scrollDirection != DIRECTION_INVALIDATE) {
            if (scrollDirection == DIRECTION_VERTICAL) {
                // Scroll to follow the motion event
                mLastMotionY = y - mScrollOffset[1];

                final int oldY = getScrollY();
                final int horizontalRange = getHorizontalScrollRange();
                final int verticalRange = getVerticalScrollRange();
                final int overscrollMode = ViewCompat.getOverScrollMode(this);
                boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS
                        || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && verticalRange > 0);

                // Calling overScrollByCompat will call onOverScrolled, which
                // calls onScrollChanged if applicable.
                if (overScrollByCompat(0, deltaY, getScrollX(), getScrollY(), horizontalRange, verticalRange, 0,
                        0, true) && !hasNestedScrollingParent()) {
                    // Break our velocity if we hit a scroll barrier.
                    mVelocityTracker.clear();
                }

                final int scrolledDeltaY = getScrollY() - oldY;
                final int unconsumedY = deltaY - scrolledDeltaY;
                if (dispatchNestedScroll(0, scrolledDeltaY, 0, unconsumedY, mScrollOffset)) {
                    mLastMotionY -= mScrollOffset[1];
                    vtev.offsetLocation(0, mScrollOffset[1]);
                    mNestedYOffset += mScrollOffset[1];
                } else if (canOverscroll) {
                    ensureGlows();
                    final int pulledToY = oldY + deltaY;
                    if (pulledToY < 0) {
                        mEdgeGlowTop.onPull((float) deltaY / getHeight(),
                                MotionEventCompat.getX(ev, activePointerIndex) / getWidth());
                        if (!mEdgeGlowBottom.isFinished()) {
                            mEdgeGlowBottom.onRelease();
                        }
                    } else if (pulledToY > verticalRange) {
                        mEdgeGlowBottom.onPull((float) deltaY / getHeight(),
                                1.f - MotionEventCompat.getX(ev, activePointerIndex) / getWidth());
                        if (!mEdgeGlowTop.isFinished()) {
                            mEdgeGlowTop.onRelease();
                        }
                    }
                    if (mEdgeGlowTop != null && (!mEdgeGlowTop.isFinished() || !mEdgeGlowBottom.isFinished())) {
                        ViewCompat.postInvalidateOnAnimation(this);
                    }
                }
            } else if (scrollDirection == DIRECTION_HORIZONTAL) {
                // Scroll to follow the motion event
                mLastMotionX = x - mScrollOffset[0];

                final int oldX = getScrollX();
                final int horizontalRange = getHorizontalScrollRange();
                final int verticalRange = getVerticalScrollRange();
                final int overscrollMode = ViewCompat.getOverScrollMode(this);
                boolean canOverscroll = overscrollMode == ViewCompat.OVER_SCROLL_ALWAYS
                        || (overscrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS && horizontalRange > 0);

                // Calling overScrollByCompat will call onOverScrolled, which
                // calls onScrollChanged if applicable.
                if (overScrollByCompat(deltaX, 0, getScrollX(), getScrollY(), horizontalRange, verticalRange, 0,
                        0, true) && !hasNestedScrollingParent()) {
                    // Break our velocity if we hit a scroll barrier.
                    mVelocityTracker.clear();
                }

                final int scrolledDeltaX = getScrollX() - oldX;
                final int unconsumedX = deltaX - scrolledDeltaX;
                if (dispatchNestedScroll(scrolledDeltaX, 0, unconsumedX, 0, mScrollOffset)) {
                    mLastMotionX -= mScrollOffset[0];
                    vtev.offsetLocation(mScrollOffset[0], 0);
                    mNestedXOffset += mScrollOffset[0];
                } else if (canOverscroll) {
                    ensureGlows();
                    final int pulledToX = oldX + deltaX;
                    if (pulledToX < 0) {
                        mEdgeGlowLeft.onPull((float) deltaX / getWidth(),
                                MotionEventCompat.getX(ev, activePointerIndex) / getHeight());
                        if (!mEdgeGlowRight.isFinished()) {
                            mEdgeGlowRight.onRelease();
                        }
                    } else if (pulledToX > horizontalRange) {
                        mEdgeGlowRight.onPull((float) deltaX / getWidth(),
                                1.f - MotionEventCompat.getX(ev, activePointerIndex) / getHeight());
                        if (!mEdgeGlowLeft.isFinished()) {
                            mEdgeGlowLeft.onRelease();
                        }
                    }
                    if (mEdgeGlowLeft != null
                            && (!mEdgeGlowLeft.isFinished() || !mEdgeGlowRight.isFinished())) {
                        ViewCompat.postInvalidateOnAnimation(this);
                    }
                }
            }

        }
        break;
    case MotionEvent.ACTION_UP:
        if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int verticalInitialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            int horizontalInitialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);

            if (scrollDirection == DIRECTION_VERTICAL) {
                if ((Math.abs(verticalInitialVelocity) > mMinimumVelocity)) {
                    flingWithNestedDispatchVertical(-verticalInitialVelocity);
                }
            } else if (scrollDirection == DIRECTION_HORIZONTAL) {
                if ((Math.abs(horizontalInitialVelocity) > mMinimumVelocity)) {
                    flingWithNestedDispatchHorizontal(-horizontalInitialVelocity);
                }
            }
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsBeingDragged && getChildCount() > 0) {
            mActivePointerId = INVALID_POINTER;
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = (int) MotionEventCompat.getX(ev, index);
        mLastMotionY = (int) MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastMotionX = (int) MotionEventCompat.getX(ev,
                MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastMotionY = (int) MotionEventCompat.getY(ev,
                MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(vtev);
    }
    vtev.recycle();
    return true;
}

From source file:com.mylikes.likes.etchasketch.Slate.java

@SuppressLint("NewApi")
@Override/*from w w  w . j a  va2s  .  c  o m*/
public boolean onTouchEvent(MotionEvent event) {
    final int action = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) ? event.getActionMasked()
            : event.getAction();
    int N = event.getHistorySize();
    int P = event.getPointerCount();
    long time = event.getEventTime();

    mEmpty = false;

    // starting a new touch? commit the previous state of the canvas
    if (action == MotionEvent.ACTION_DOWN) {
        commitStroke();
    }

    if (mZoomMode) {
        return false;
    }

    int pointerIndex = MotionEventCompat.getActionIndex(event);
    int pointerId = event.getPointerId(pointerIndex);
    if (moveMode) {
        if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN) {
            if (firstFinger != null) {
                MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords();
                event.getPointerCoords(0, coords1);
                Log.d(TAG, "coords1: " + coords1.x + " " + coords1.y);
                MotionEvent.PointerCoords coords2 = new MotionEvent.PointerCoords();
                event.getPointerCoords(1, coords2);
                firstFinger.set(coords1.x, coords1.y);
                secondFinger = new PointF(coords2.x, coords2.y);
            } else {
                touchStartTime = System.currentTimeMillis();
                moveDrawingStartX = event.getX();
                moveDrawingStartY = event.getY();
                int i = 0;
                moveDrawingIndex = -1;
                resizeDrawingIndex = -1;
                resizeDrawingCorner = null;
                if (selectedDrawing != null) {
                    moveDrawingIndex = 0;
                }
                if (i >= overlays.size()) {
                    return true;
                }
                Log.d(TAG, "Start dragging overlay");
                firstFinger = new PointF(event.getX(), event.getY());
            }
            return true;
        } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
            if (secondFinger != null) {
                secondFinger = null;
                MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords();
                event.getPointerCoords(0, coords1);
                moveDrawingStartX = coords1.x;
                moveDrawingStartY = coords1.y;
                return true;
            }
            if (firstFinger != null) {
                firstFinger = null;
            }
            if (moveDrawingIndex == -1 && resizeDrawingIndex == -1
                    && System.currentTimeMillis() - touchStartTime < 400
                    && Math.abs(event.getX() - moveDrawingStartX)
                            + Math.abs(event.getY() - moveDrawingStartY) < 8) {
                if (resizeDrawingCorner != null && selectedDrawing != null) {
                    if (resizeDrawingCorner == "tl" && selectedDrawing instanceof TextDrawing) {
                        //promptForText((TextDrawing)selectedDrawing);
                    } else if (resizeDrawingCorner == "tr") {
                        //maybeRemoveDrawing(selectedDrawing);
                    }
                } else {
                    //promptForText((int) event.getX(), (int) event.getY());
                }
            }
            moveDrawingIndex = -1;
            Log.d(TAG, "Stop dragging overlay");
            // TODO: add to undo stack
            return true;
        } else if (firstFinger != null && secondFinger != null && action == MotionEvent.ACTION_MOVE) {
            MotionEvent.PointerCoords coords1 = new MotionEvent.PointerCoords();
            event.getPointerCoords(0, coords1);
            Log.d(TAG, "coords1: " + coords1.x + " " + coords1.y);
            MotionEvent.PointerCoords coords2 = new MotionEvent.PointerCoords();
            event.getPointerCoords(1, coords2);
            Log.d(TAG, "coords2: " + coords2.x + " " + coords2.y);
            float xDist = firstFinger.x - secondFinger.x, yDist = firstFinger.y - secondFinger.y;
            float origAngle = (float) Math.atan2(yDist, xDist);
            if (origAngle < 0)
                origAngle += Math.PI * 2;
            float lastDistance = (float) Math.sqrt(xDist * xDist + yDist * yDist);

            xDist = coords2.x - coords1.x;
            yDist = coords2.y - coords1.y;
            float newDistance = (float) Math.sqrt(xDist * xDist + yDist * yDist);
            float newAngle = (float) Math.atan2(yDist, xDist);
            if (newAngle < 0)
                newAngle += Math.PI * 2;
            if (newAngle - origAngle > Math.PI / 2) {
                origAngle += Math.PI;
            } else if (origAngle - newAngle > Math.PI / 2) {
                newAngle += Math.PI;
            }

            firstFinger.set(coords1.x, coords1.y);
            secondFinger = new PointF(coords2.x, coords2.y);
            if (selectedDrawing != null) {
                selectedDrawing.resizeBy(newDistance / lastDistance);
                selectedDrawing.rotateBy(newAngle - origAngle);
                invalidate();
            }
        } else if (moveDrawingIndex >= 0 && moveDrawingIndex < overlays.size()
                && action == MotionEvent.ACTION_MOVE) {
            float x = event.getX();
            float y = event.getY();
            overlays.get(moveDrawingIndex).moveBy((int) ((x - moveDrawingStartX) * getDrawingDensity()),
                    (int) ((y - moveDrawingStartY) * getDrawingDensity()));
            // TODO: only invalidate relevant Rect
            invalidate();
            moveDrawingStartX = x;
            moveDrawingStartY = y;
            return true;
        } else if (resizeDrawingIndex >= 0 && resizeDrawingIndex < overlays.size()
                && action == MotionEvent.ACTION_MOVE) {
            float x = event.getX();
            float y = event.getY();
            overlays.get(resizeDrawingIndex).resizeCorner(resizeDrawingCorner, (int) (x - moveDrawingStartX),
                    (int) (y - moveDrawingStartY));
            // TODO: only invalidate relevant Rect
            invalidate();
            moveDrawingStartX = x;
            moveDrawingStartY = y;
            return true;
        }
        return false;
    }

    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_POINTER_DOWN
            || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
        int j = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) ? event.getActionIndex() : 0;

        mTmpSpot.update(event.getX(j), event.getY(j), event.getSize(j), event.getPressure(j) + event.getSize(j),
                time, getToolTypeCompat(event, j));
        mStrokes[event.getPointerId(j)].add(mTmpSpot);
        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
            mStrokes[event.getPointerId(j)].finish(time);
        }
    } else if (action == MotionEvent.ACTION_MOVE) {
        if (dbgX >= 0) {
            dbgRect.set(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1);
        }

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < P; j++) {
                mTmpSpot.update(event.getHistoricalX(j, i), event.getHistoricalY(j, i),
                        event.getHistoricalSize(j, i),
                        event.getHistoricalPressure(j, i) + event.getHistoricalSize(j, i),
                        event.getHistoricalEventTime(i), getToolTypeCompat(event, j));
                if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) {
                    if (dbgX >= 0) {
                        //mTiledCanvas.drawLine(dbgX, dbgY, mTmpSpot.x, mTmpSpot.y, mDebugPaints[3]);
                    }
                    dbgX = mTmpSpot.x;
                    dbgY = mTmpSpot.y;
                    dbgRect.union(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1);
                }
                mStrokes[event.getPointerId(j)].add(mTmpSpot);
            }
        }
        for (int j = 0; j < P; j++) {
            mTmpSpot.update(event.getX(j), event.getY(j), event.getSize(j),
                    event.getPressure(j) + event.getSize(j), time, getToolTypeCompat(event, j));
            if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) {
                if (dbgX >= 0) {
                    //mTiledCanvas.drawLine(dbgX, dbgY, mTmpSpot.x, mTmpSpot.y, mDebugPaints[3]);
                }
                dbgX = mTmpSpot.x;
                dbgY = mTmpSpot.y;
                dbgRect.union(dbgX - 1, dbgY - 1, dbgX + 1, dbgY + 1);
            }
            mStrokes[event.getPointerId(j)].add(mTmpSpot);
        }

        if ((mDebugFlags & FLAG_DEBUG_STROKES) != 0) {
            Rect dirty = new Rect();
            dbgRect.roundOut(dirty);
            invalidate(dirty);
        }
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        for (int j = 0; j < P; j++) {
            mStrokes[event.getPointerId(j)].finish(time);
        }
        dbgX = dbgY = -1;
    }
    return true;
}

From source file:cn.com.zzwfang.view.directionalviewpager.DirectionalViewPager.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        if (mOrientation == HORIZONTAL) {
            mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
        } else {/*from w  w w . j  a v  a2 s. com*/
            mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex);
        }
        mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}

From source file:com.ray.appchallenge.view.SwipeRefreshLayoutBottom.java

private void onSecondaryPointerUp(final MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
    if (pointerId == mActivePointerId) {

        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
    }/*from w  w  w. j ava 2s.c o  m*/
}