Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

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

Prototype

int ACTION_MOVE

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

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int x = (int) (event.getX() + 0.5f);
    final int y = (int) (event.getY() + 0.5f);

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDownX = x;/*from www . j a va  2  s.c  o  m*/
        mDownY = y;

        mInitialTarget = getDayAtLocation(mDownX, mDownY);

        if (mInitialTarget < 0) {
            return false;
        }

        if (mPendingCheckForTap == null) {
            mPendingCheckForTap = new CheckForTap();
        }
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        break;
    case MotionEvent.ACTION_MOVE:
        if (!isStillAClick(x, y)) {
            if (mPendingCheckForTap != null) {
                removeCallbacks(mPendingCheckForTap);
            }

            mInitialTarget = -1;

            if (mTouchedItem >= 0) {
                mTouchedItem = -1;
                invalidate();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        onDayClicked(mInitialTarget);
        // Fall through.
    case MotionEvent.ACTION_CANCEL:
        if (mPendingCheckForTap != null) {
            removeCallbacks(mPendingCheckForTap);
        }
        // Reset touched day on stream end.
        mTouchedItem = -1;
        mInitialTarget = -1;
        invalidate();
        break;
    }
    return true;
}

From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!isEnabled() || (canChildScrollUp() && canChildScrollDown())
            || footerView.getSwipeStatus() == SwipeStatus.REFRESHING
            || headerView.getSwipeStatus() == SwipeStatus.REFRESHING
            || (swipeDownRefreshListener == null && swipeUpRefreshListener == null) || isAnimating()) {
        return false;
    }//w  w  w  . j  av a2  s.  c o m

    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        isDragging = false;

        //reset
        currentContentOffset = 0;
        headerView.setCurrentOffset(0);
        footerView.setCurrentOffset(0);
        headerView.updateStatus(SwipeStatus.NORMAL);
        footerView.updateStatus(SwipeStatus.NORMAL);

        activePointerId = MotionEventCompat.getPointerId(ev, ev.getActionIndex());
        initialMotionY = getMotionEventY(ev, activePointerId);
        break;
    case MotionEvent.ACTION_MOVE:
        if (activePointerId == INVALID_POINTER) {
            return false;
        }

        final float diffY = getMotionEventY(ev, activePointerId) - initialMotionY;

        //deal border
        if ((diffY > 0 && !canChildScrollUp() || (diffY < 0 && !canChildScrollDown()))) {
            if (Math.abs(diffY) > touchSlop && !isDragging) {
                isDragging = true;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        isDragging = false;
        activePointerId = INVALID_POINTER;
        break;
    }
    return isDragging;
}

From source file:com.am.pullview.swiperefresh.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*w ww. j  a  va 2 s . c  o  m*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    updateContentOffsetTop((int) (offsetTop));
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    } else {
                        updatePositionTimeout();
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*  w  ww.j a va  2s  . co  m*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    updateContentOffsetTop((int) (offsetTop));
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    }
                    //                            else {
                    //                                updatePositionTimeout();
                    //                            }
                    mPrevY = event.getY();
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
            updatePositionImmediately();
        }
        break;
    }
    return handled;
}

From source file:com.bxbxbai.zhuanlan.ui.widget.SwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;/*from  w w w . j av  a 2 s.c om*/
        mDownEvent = MotionEvent.obtain(event);
        mPrevY = mDownEvent.getY();
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    startRefresh();
                    handled = true;
                    break;
                } else {
                    // Just track the user's movement
                    setTriggerPercentage(
                            mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                    float offsetTop = yDiff;
                    if (mPrevY > eventY) {
                        offsetTop = yDiff - mTouchSlop;
                    }
                    updateContentOffsetTop();
                    if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) {
                        // If the user puts the view back at the top, we
                        // don't need to. This shouldn't be considered
                        // cancelling the gesture as the user can restart from the top.
                        removeCallbacks(mCancel);
                    } else {
                        updatePositionTimeout();
                    }
                    mPrevY = event.getY();
                    handled = true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.canyinghao.canrefresh.CanRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent e) {

    //     ??view
    if (!canChildScrollDown() && !canChildScrollUp()) {

        if (isUpOrDown == NO_SCROLL_UP) {
            if (canRefresh()) {

                return touch(e, true);

            }//w  ww . j a va2s. co  m
        } else if (isUpOrDown == NO_SCROLL_DOWN) {
            if (canLoadMore()) {

                return touch(e, false);
            }

        } else {

            switch (e.getAction()) {

            case MotionEvent.ACTION_DOWN:

                directionY = e.getY();
                directionX = e.getX();

                break;

            case MotionEvent.ACTION_MOVE:
                if (directionY <= 0 || directionX <= 0) {

                    break;
                }

                float eventY = e.getY();
                float eventX = e.getX();

                float offY = eventY - directionY;
                float offX = eventX - directionX;

                directionY = eventY;
                directionX = eventX;

                boolean moved = Math.abs(offY) > Math.abs(offX);

                if (offY > 0 && moved && canRefresh()) {
                    isUpOrDown = NO_SCROLL_UP;
                } else if (offY < 0 && moved && canLoadMore()) {

                    isUpOrDown = NO_SCROLL_DOWN;
                } else {
                    isUpOrDown = NO_SCROLL;
                }

                break;

            }

            return true;

        }

    } else {

        if (canRefresh()) {
            return touch(e, true);

        } else if (canLoadMore()) {

            return touch(e, false);
        }
    }

    return super.onTouchEvent(e);
}

From source file:com.android.mail.browse.ConversationContainer.java

/**
 * Touch slop code was copied from {@link ScrollView#onInterceptTouchEvent(MotionEvent)}.
 *//*from  w w w.j a v a 2 s .  co  m*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

    if (!mTouchInitialized) {
        mTouchInitialized = true;
    }

    // no interception when WebView handles the first DOWN
    if (mWebView.isHandlingTouch()) {
        return false;
    }

    boolean intercept = false;
    switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_POINTER_DOWN:
        LogUtils.d(TAG, "Container is intercepting non-primary touch!");
        intercept = true;
        mMissedPointerDown = true;
        requestDisallowInterceptTouchEvent(true);
        break;

    case MotionEvent.ACTION_DOWN:
        mLastMotionY = ev.getY();
        mActivePointerId = ev.getPointerId(0);
        break;

    case MotionEvent.ACTION_MOVE:
        final int pointerIndex = ev.findPointerIndex(mActivePointerId);
        final float y = ev.getY(pointerIndex);
        final int yDiff = (int) Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mLastMotionY = y;
            intercept = true;
        }
        break;
    }

    //        LogUtils.v(TAG, "in Container.InterceptTouch. action=%d x/y=%f/%f pointers=%d result=%s",
    //                ev.getActionMasked(), ev.getX(), ev.getY(), ev.getPointerCount(), intercept);
    return intercept;
}

From source file:com.biznow.ordernow.fragments.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);//  w w  w  .ja  v  a  2s  .  com
    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;
            return true;
        }
        break;

    case MotionEvent.ACTION_MOVE: {
        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Utilities.error(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;
        }
    }
    }

    return false;
}

From source file:com.bitflake.counter.HorizontalPicker.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    if (!isEnabled()) {
        return false;
    }/*from w ww .  j av a 2s  . co m*/

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

    int action = event.getActionMasked();
    switch (action) {
    case MotionEvent.ACTION_MOVE:

        float currentMoveX = event.getX();

        int deltaMoveX = (int) (lastDownEventX - currentMoveX);

        if (scrollingX || (Math.abs(deltaMoveX) > touchSlop) && values != null && values.length > 0) {

            if (!scrollingX) {
                deltaMoveX = 0;
                pressedItem = -1;
                scrollingX = true;
                getParent().requestDisallowInterceptTouchEvent(true);
                stopMarqueeIfNeeded();
            }

            final int range = getScrollRange();

            if (overScrollBy(deltaMoveX, 0, getScrollX(), 0, range, 0, overscrollDistance, 0, true)) {
                mVelocityTracker.clear();
            }

            final float pulledToX = getScrollX() + deltaMoveX;
            if (pulledToX < 0) {
                leftEdgeEffect.onPull((float) deltaMoveX / getWidth());
                if (!rightEdgeEffect.isFinished()) {
                    rightEdgeEffect.onRelease();
                }
            } else if (pulledToX > range) {
                rightEdgeEffect.onPull((float) deltaMoveX / getWidth());
                if (!leftEdgeEffect.isFinished()) {
                    leftEdgeEffect.onRelease();
                }
            }

            lastDownEventX = currentMoveX;
            invalidate();

        }

        break;
    case MotionEvent.ACTION_DOWN:

        if (!adjustScrollerX.isFinished()) {
            adjustScrollerX.forceFinished(true);
        } else if (!flingScrollerX.isFinished()) {
            flingScrollerX.forceFinished(true);
        } else {
            scrollingX = false;
        }

        lastDownEventX = event.getX();

        if (!scrollingX) {
            pressedItem = getPositionFromTouch(event.getX());
        }
        invalidate();

        break;
    case MotionEvent.ACTION_UP:

        VelocityTracker velocityTracker = mVelocityTracker;
        velocityTracker.computeCurrentVelocity(1000, maximumFlingVelocity);
        int initialVelocityX = (int) velocityTracker.getXVelocity();

        if (scrollingX && Math.abs(initialVelocityX) > mMinimumFlingVelocity) {
            flingX(initialVelocityX);
        } else if (values != null) {
            float positionX = event.getX();
            if (!scrollingX) {

                int itemPos = getPositionOnScreen(positionX);
                int relativePos = itemPos - sideItems;

                if (relativePos == 0) {
                    selectItem();
                } else {
                    smoothScrollBy(relativePos);
                }

            } else if (scrollingX) {
                finishScrolling();
            }
        }

        mVelocityTracker.recycle();
        mVelocityTracker = null;

        if (leftEdgeEffect != null) {
            leftEdgeEffect.onRelease();
            rightEdgeEffect.onRelease();
        }

    case MotionEvent.ACTION_CANCEL:
        pressedItem = -1;
        invalidate();

        if (leftEdgeEffect != null) {
            leftEdgeEffect.onRelease();
            rightEdgeEffect.onRelease();
        }

        break;
    }

    return true;
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*from  w  ww .j  a  va 2  s  .  c om*/
    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;
            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;
        }
    }
    }

    return false;
}