List of usage examples for android.view MotionEvent offsetLocation
public final void offsetLocation(float deltaX, float deltaY)
From source file:com.github.takahirom.webview_in_coodinator_layout.NestedWebView.java
@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;/*from ww w.j a va 2 s .co m*/ } int eventY = (int) event.getY(); event.offsetLocation(0, mNestedOffsetY); 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); if (firstScroll) { // dispatching first down scrolling properly by making sure that first deltaY will be -ve mLastY = eventY - 5; firstScroll = false; } else { mLastY = eventY; } // start NestedScroll startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: returnValue = super.onTouchEvent(event); // end NestedScroll stopNestedScroll(); break; } return returnValue; }
From source file:com.geofbot.views.web.NestedWebView.java
@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;/*from w w w.ja v a2s .c o m*/ } int eventY = (int) event.getY(); event.offsetLocation(0, mNestedOffsetY); 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); if (firstScroll) { // dispatching first down scrolling properly by making sure that first deltaY will be -ve mLastY = eventY - 5; firstScroll = false; } else { mLastY = eventY; } // start NestedScroll startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; default: returnValue = super.onTouchEvent(event); // end NestedScroll stopNestedScroll(); break; } return returnValue; }
From source file:com.kerkr.edu.recycleView.SwipeToDismissTouchListener.java
@Override public boolean onInterceptTouchEvent(final RecyclerView view, MotionEvent motionEvent) { if (mPaused)// w w w . j a va2 s.c o m return false; // offset because the view is translated during swipe motionEvent.offsetLocation(mTranslationX, 0); if (mViewWidth < 2) { mViewWidth = view.getWidth(); } switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: { return down(motionEvent); } case MotionEvent.ACTION_MOVE: { return move(motionEvent); } } return false; }
From source file:adapters.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { //We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int) ev.getX(); mInitialTouch.y = (int) ev.getY(); default:/*from w ww. jav a 2 s .c o m*/ ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); }
From source file:com.yanzhenjie.recyclerview.swipe.widget.StickyNestedScrollView.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (redirectTouchesToStickyView) { ev.offsetLocation(0, ((getScrollY() + stickyViewTopOffset) - getTopForViewRelativeOnlyChild(currentlyStickingView))); }/*from ww w . j av a 2s. c o m*/ if (ev.getAction() == MotionEvent.ACTION_DOWN) { hasNotDoneActionDown = false; } if (hasNotDoneActionDown) { MotionEvent down = MotionEvent.obtain(ev); down.setAction(MotionEvent.ACTION_DOWN); super.onTouchEvent(down); hasNotDoneActionDown = false; } if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { hasNotDoneActionDown = true; } return super.onTouchEvent(ev); }
From source file:com.techfiesta.stickyviewpager.view.PagerContainer.java
@SuppressLint("ClickableViewAccessibility") @Override//from w w w.j a va2 s .c om public boolean onTouchEvent(MotionEvent ev) { // We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int) ev.getX(); mInitialTouch.y = (int) ev.getY(); default: ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); }
From source file:com.nononsenseapps.feeder.ui.SwipeDismissTouchListener.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { // offset because the view is translated during swipe motionEvent.offsetLocation(mTranslationX, 0); if (mViewWidth < 2) { mViewWidth = mView.getWidth();/*from w w w . j ava2 s . c om*/ } switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: { // TODO: ensure this is a finger, and set a flag mDownX = motionEvent.getRawX(); mDownY = motionEvent.getRawY(); if (mCallbacks.canDismiss(mToken)) { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } return false; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = motionEvent.getRawX() - mDownX; mVelocityTracker.addMovement(motionEvent); mVelocityTracker.computeCurrentVelocity(1000); float velocityX = mVelocityTracker.getXVelocity(); float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean dismiss = false; boolean dismissRight = false; if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) { dismiss = true; dismissRight = deltaX > 0; } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX && absVelocityY < absVelocityX && mSwiping) { // dismiss only if flinging in the same direction as dragging dismiss = (velocityX < 0) == (deltaX < 0); dismissRight = mVelocityTracker.getXVelocity() > 0; } if (dismiss) { // dismiss mSwipingView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth) //.alpha(0) .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { performDismiss(); } }); } else if (mSwiping) { // cancel mSwipingView.animate().translationX(0) //.alpha(1) .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCallbacks.onSwipeCancelled(); } }); } mVelocityTracker.recycle(); mVelocityTracker = null; mTranslationX = 0; mDownX = 0; mDownY = 0; mSwiping = false; notNotifiedSwipeStart = true; break; } case MotionEvent.ACTION_CANCEL: { if (mVelocityTracker == null) { break; } mSwipingView.animate().translationX(0) //.alpha(1) .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCallbacks.onSwipeCancelled(); } }); mVelocityTracker.recycle(); mVelocityTracker = null; mTranslationX = 0; mDownX = 0; mDownY = 0; mSwiping = false; notNotifiedSwipeStart = true; break; } case MotionEvent.ACTION_MOVE: { if (mVelocityTracker == null) { break; } 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; mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop); mView.getParent().requestDisallowInterceptTouchEvent(true); // Cancel listview's touch MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mView.onTouchEvent(cancelEvent); cancelEvent.recycle(); } if (mSwiping) { if (notNotifiedSwipeStart) { notNotifiedSwipeStart = false; mCallbacks.onSwipeStarted(deltaX > 0); } mTranslationX = deltaX; mSwipingView.setTranslationX(deltaX - mSwipingSlop); //mView.setAlpha(mInterpolator.getInterpolation(1f - 1f * Math.abs(deltaX) / mViewWidth)); // mView.setAlpha(Math.max(0f, Math.min(1f, // 1f - 2f * Math.abs(deltaX) / mViewWidth))); return true; } break; } } return false; }
From source file:com.barchart.tester.pager.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { // We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mInitialTouch.x = (int) ev.getX(); mInitialTouch.y = (int) ev.getY(); default://from w w w .j ava2s . co m ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y); break; } return mPager.dispatchTouchEvent(ev); }
From source file:br.com.cybereagle.androidwidgets.view.PagerContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { //We capture any touches not already handled by the ViewPager // to implement scrolling from a touch outside the pager bounds. switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: initialTouch.x = (int) ev.getX(); initialTouch.y = (int) ev.getY(); default://from w ww . ja v a2s . c o m ev.offsetLocation(center.x - initialTouch.x, center.y - initialTouch.y); break; } return pager.dispatchTouchEvent(ev); }
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 www. j a va2 s. com } 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; }