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.android.audiorecorder.gallery.widget.GalleryViewPager.java

private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;//from  w  w  w  .  j a va2 s .  co m
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:cn.dreamtobe.touchgallery.GalleryWidget.GalleryViewPager.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private float[] handleMotionEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        last = new PointF(event.getX(0), event.getY(0));
        break;/* w  w  w  . j av a2 s. co m*/
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        PointF curr = new PointF(event.getX(0), event.getY(0));
        return new float[] { curr.x - last.x, curr.y - last.y };

    }
    return null;
}

From source file:android.support.designox.widget.HeaderBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from  ww w .  j a  va  2  s.  c  o  m

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        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 = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            break;
        }

        final int y = (int) MotionEventCompat.getY(ev, pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

From source file:android.support.design.widget.HeaderBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }/*from  w ww.jav a2  s  . c  om*/

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        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) {
            break;
        }

        final int y = (int) ev.getY(pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

From source file:com.commonsware.cwac.crossport.design.widget.HeaderBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from  ww  w. j  av a  2  s  . co  m

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (ev.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        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) {
            break;
        }

        final int y = (int) ev.getY(pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

From source file:akhil.alltrans.NestedScrollingListView.java

/**
 *
 * @see android.support.v4.widget.NestedScrollView#onTouchEvent(MotionEvent)
 *//*from ww w .  j  a v  a2 s.  c o  m*/
@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean returnValue = false;

    MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;
    }
    event.offsetLocation(0, mNestedOffsetY);
    int eventY = (int) event.getY();
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;
        // NestedPreScroll
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }
        returnValue = super.onTouchEvent(event);

        // NestedScroll
        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;
    case MotionEvent.ACTION_DOWN:
        returnValue = super.onTouchEvent(event);
        mLastY = eventY;
        // start NestedScroll
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    case MotionEvent.ACTION_UP:
        // TODO: fling
        returnValue = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_CANCEL:
        returnValue = super.onTouchEvent(event);
        // end NestedScroll
        stopNestedScroll();
        break;
    }
    return returnValue;
}

From source file:akhil.alltrans.NestedScrollingMarkDownView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;/*from  w  w w . jav a  2  s. c o  m*/
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        result = super.onTouchEvent(trackedEvent);
        trackedEvent.recycle();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:com.aohuan.dodo.dispatchevent_about.dummy_demo.view1.NestedScrollWebView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;/*w ww .ja v  a  2s  . c om*/
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        trackedEvent.recycle();
        result = super.onTouchEvent(trackedEvent);
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:com.aprz.easy_iosched.ui.widget.MultiSwipeRefreshLayout.java

/**
 * @return false if the scrolled horizontal distance is bigger than the vertical one
 */// w  w w.j  ava  2 s .  com
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mStartGestureX = event.getX();
        mStartGestureY = event.getY();
        mHorizontalScrollDetected = false;
        break;

    case MotionEvent.ACTION_MOVE:
        mHorizontalScrollDetected = Math.abs(event.getX() - mStartGestureX) > Math
                .abs(event.getY() - mStartGestureY);
        if (mHorizontalScrollDetected) {
            return false;
        }
        break;
    }

    return super.onInterceptTouchEvent(event);
}

From source file:cn.limc.androidcharts.event.SlipGestureDetector.java

public boolean onTouchEvent(MotionEvent event) {
    int pointers = event.getPointerCount();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    // ?// w w w.j av a2  s .  c o  m
    case MotionEvent.ACTION_DOWN:
        initalX = event.getX();
        if (pointers > 1) {
            touchMode = TOUCH_MODE_MULTI;
        } else {
            touchMode = TOUCH_MODE_SINGLE;
        }
        break;
    case MotionEvent.ACTION_UP:
        startPointA = null;
        startPointB = null;
        break;
    case MotionEvent.ACTION_POINTER_UP:
        startPointA = null;
        startPointB = null;
    case MotionEvent.ACTION_POINTER_DOWN:
        olddistance = calcDistance(event);
        if (olddistance > MIN_DISTANCE) {
            touchMode = TOUCH_MODE_MULTI;
            startPointA = new PointF(event.getX(0), event.getY(0));
            startPointB = new PointF(event.getX(1), event.getY(1));
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (touchMode == TOUCH_MODE_SINGLE) {
            final float finalX = event.getX();
            // MotionEvent finalEvent = event;
            if (performLongClick) {
                return super.onTouchEvent(event);
            } else {
                if (finalX - initalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveRight((ISlipable) instance, event);
                    }
                } else if (initalX - finalX >= mStickScaleValue) {
                    if (onSlipGestureListener != null) {
                        onSlipGestureListener.onMoveLeft((ISlipable) instance, event);
                    }
                }
                initalX = finalX;
                // initalEvent = finalEvent;
                return true;
            }
        } else if (touchMode == TOUCH_MODE_MULTI) {
            newdistance = calcDistance(event);
            if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) {
                if (onZoomGestureListener != null) {
                    if (newdistance > olddistance) {
                        onZoomGestureListener.onZoomIn((IZoomable) instance, event);
                    } else {
                        onZoomGestureListener.onZoomOut((IZoomable) instance, event);
                    }
                }
            }
            olddistance = newdistance;
            return true;
            // startPointA = new PointF(event.getX(), event.getY());
            // startPointB = new PointF(event.getX(1), event.getY(1));
        }
        break;
    }
    return super.onTouchEvent(event);
}