Example usage for android.view MotionEvent getRawX

List of usage examples for android.view MotionEvent getRawX

Introduction

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

Prototype

public final float getRawX() 

Source Link

Document

Returns the original raw X coordinate of this event.

Usage

From source file:se.oort.clockify.widget.sgv.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/* w ww  . j  a va2s . c om*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mOffsetToAbsoluteX = (int) (ev.getRawX() - ev.getX());
        mOffsetToAbsoluteY = (int) (ev.getRawY() - ev.getY());

        // Per bug 7377413, event.getX() and getY() returns rawX and rawY when accessed in
        // dispatchDragEvent, so since an action down is required before a drag can be
        // initiated, initialize mTouchDownForDragStartX/Y here for the most accurate value.
        mTouchDownForDragStartX = (int) ev.getX();
        mTouchDownForDragStartY = (int) ev.getY();

        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(LOG_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:app.umitems.greenclock.widget.sgv.StaggeredGridView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*from w w  w . j  a va 2s . c  om*/
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mOffsetToAbsoluteX = (int) (ev.getRawX() - ev.getX());
        mOffsetToAbsoluteY = (int) (ev.getRawY() - ev.getY());

        // Per bug 7377413, event.getX() and getY() returns rawX and rawY when accessed in
        // dispatchDragEvent, so since an action down is required before a drag can be
        // initiated, initialize mTouchDownForDragStartX/Y here for the most accurate value.
        mTouchDownForDragStartX = (int) ev.getX();
        mTouchDownForDragStartY = (int) ev.getY();

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