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:com.example.tt.pullrefresh.widget.CurveLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    currentX = ev.getRawX();
    sheetDragHelper.processTouchEvent(ev);
    return sheetDragHelper.getCapturedView() != null || super.onTouchEvent(ev);
}

From source file:com.example.tt.pullrefresh.widget.CurveLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    currentX = ev.getRawX();
    Log.e(TAG, "BottomSheet onInterceptTouchEvent: " + currentX);
    if (isExpanded()) {
        sheetDragHelper.cancel();/*w  w  w  . ja  va 2s.  c o m*/
        return false;
    }
    hasInteractedWithSheet = true;

    final int action = MotionEventCompat.getActionMasked(ev);
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        sheetDragHelper.cancel();
        return false;
    }
    return isDraggableViewUnder((int) ev.getX(), (int) ev.getY())
            && (sheetDragHelper.shouldInterceptTouchEvent(ev));
}

From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionMove(MotionEvent motionEvent) {
    mVelocityTracker.addMovement(motionEvent);
    float deltaX = motionEvent.getRawX() - mDownX;
    float deltaY = motionEvent.getRawY() - mDownY;
    if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
        mSwiping = true;//from w ww  .  j a  va 2 s .  c om
        int mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
        mRecyclerView.requestDisallowInterceptTouchEvent(true);

        // Cancel ListView's touch (un-highlighting the item)
        MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
        cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
        mRecyclerView.onTouchEvent(cancelEvent);
        cancelEvent.recycle();
        if (mSwiping) {
            setTranslationX(mDownView, deltaX - mSwipingSlop);
            setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
        }
    }
}

From source file:com.malinskiy.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionMove(MotionEvent motionEvent) {
    mVelocityTracker.addMovement(motionEvent);
    float deltaX = motionEvent.getRawX() - mDownX;
    float deltaY = motionEvent.getRawY() - mDownY;
    if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
        mSwiping = true;/*from w w  w . j  a va 2 s.  c  o m*/
        mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
        mRecyclerView.requestDisallowInterceptTouchEvent(true);

        // Cancel ListView's touch (un-highlighting the item)
        MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
        cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
        mRecyclerView.onTouchEvent(cancelEvent);
        cancelEvent.recycle();
        if (mSwiping) {
            setTranslationX(mDownView, deltaX - mSwipingSlop);
            setAlpha(mDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
        }
    }
}

From source file:com.pbi.live.VideoView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mLivePlayer != null && mMediaController != null) {
        toggleMediaControlsVisiblity();/*www  .ja  v  a 2  s. c  om*/
        Log.d(TAG, "x " + ev.getRawX() + " y " + ev.getRawY());
    }
    return false;
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (!mSwipeBackEnable) {
        return super.onInterceptTouchEvent(event);
    }/*  w  w w  .  j  ava 2  s.  c o  m*/

    final int action = event.getActionMasked();
    final float x = event.getRawX();
    final float y = event.getRawY();
    final float horzOffset = Math.abs(x - mLastX);
    final float vertOffset = Math.abs(y - mLastY);

    if (action == MotionEvent.ACTION_DOWN) {
        mLastX = x;
        mLastY = y;
        mDownTimestamp = System.currentTimeMillis();
        mSlideState = SlideState.None;
    }

    if (mSlideState == SlideState.SkipThisRound) {
        return super.onInterceptTouchEvent(event);
    }

    if (action == MotionEvent.ACTION_MOVE && handleTouchMove(x, y, horzOffset, vertOffset)) {
        return true;
    }

    return super.onInterceptTouchEvent(event);
}

From source file:com.jungle.toolbaractivity.layout.HorizontalSwipeBackLayout.java

public boolean handleRootTouchEvent(MotionEvent event) {
    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN || mSlideState == SlideState.SkipThisRound) {
        return false;
    }/*from   w  w w.ja  v  a  2 s.  co m*/

    final float x = event.getRawX();
    final float y = event.getRawY();
    final float horzOffset = Math.abs(x - mLastX);
    final float vertOffset = Math.abs(y - mLastY);

    if (action == MotionEvent.ACTION_MOVE && handleTouchMove(x, y, horzOffset, vertOffset)) {
        return true;
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        int width = getMeasuredWidth();
        long timeOffset = System.currentTimeMillis() - mDownTimestamp;
        mSlideState = SlideState.None;

        if (horzOffset > width / 2 || (timeOffset <= 600 && horzOffset > width / 6)) {
            continueAnimation(horzOffset, width);
        } else {
            updateSlideOffset(0);
        }

        return true;
    }

    return false;
}

From source file:com.tjych.swip.vertical_t.VerticalViewPager.java

public boolean onTouchEvent(MotionEvent event) {
    super.onTouchEvent(event);

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }//  w  w w  . j  ava2 s. c o  m
    mVelocityTracker.addMovement(event);

    float currentY = event.getRawY();
    float currentX = event.getRawX();
    switch (event.getAction() & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mLastY = currentY;
        mLastX = currentX;
        mMoved = false;
        return false;
    case MotionEvent.ACTION_MOVE:
        float x = event.getRawX() - mLastX;
        float y = event.getRawY() - mLastY;

        System.out.println(x + " : " + y);

        if (Math.abs(x) > Math.abs(y)) {
            // getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        } else {
            mMoved = true;
            return true;
        }

    case MotionEvent.ACTION_UP:
        x = event.getRawX() - mLastX;
        y = event.getRawY() - mLastY;
        System.out.println(x + " : " + y);
        if (Math.abs(x) > Math.abs(y)) {
            // getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
        if (mMoved) {
            mVelocityTracker.computeCurrentVelocity(1000);
            int velocity = (int) mVelocityTracker.getYVelocity();
            float moveDistance = currentY - mLastY;
            int nextPage = mCurrentPage;
            if (moveDistance < 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity < 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                ++nextPage;
            } else if (moveDistance > 0 && Math.abs(moveDistance) >= SCROLL_PERCENTAGE * mSinglePageHeight
                    || velocity > 0 && Math.abs(velocity) > MIN_FLING_VELOCITY) {
                --nextPage;
            }
            setCurrentItem(nextPage);
        }
        return true;
    }
    return true;
}

From source file:tu.tracking.system.activities.TargetsListActivity.java

private TargetModel getTargetFromList(MotionEvent e) {
    ListAdapter listAdapter = listViewTargets.getAdapter();
    float x = e.getX();
    float y = e.getY();
    float rx = e.getRawX();
    float ry = e.getRawY();
    int index = listViewTargets.pointToPosition(Math.round(x), Math.round(y));
    if (index < 0 || index >= targets.size()) {
        return null;
    }/*www. j  a va 2s . c o m*/

    return (TargetModel) listAdapter.getItem(index);
}

From source file:io.syng.fragment.WebViewFragment.java

@Override
public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX, float velocityY) {
    float gapX = start.getRawX() - finish.getRawX();
    float gapY = start.getRawY() - finish.getRawY();
    float distanceX = Math.abs(gapX);
    float distanceY = Math.abs(gapY);

    if (distanceY > distanceX) { // up downs
        if (gapY > 0) {
            // up
            System.out.println("Swipe up");
        } else {//w w w.j a  v  a2 s .c  om
            // down
            System.out.println("Swipe down");
            BaseActivity activity = (BaseActivity) getActivity();
            activity.showToolbar(0);
            activity.hideToolbar(2);
        }
    } else { // left right
        if (gapX > 0) {
            // left
            System.out.println("Swipe left");
        } else {
            // rights
            System.out.println("Swipe right");
        }
    }

    return false;
}