List of usage examples for android.view MotionEvent offsetLocation
public final void offsetLocation(float deltaX, float deltaY)
From source file:com.kerkr.edu.recycleView.SwipeToDismissTouchListener.java
@Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { motionEvent.offsetLocation(mTranslationX, 0); switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_UP: { up(motionEvent);/* www .j ava 2 s. c om*/ break; } case MotionEvent.ACTION_CANCEL: { cancel(); break; } case MotionEvent.ACTION_MOVE: { move(motionEvent); break; } } }
From source file:org.telegram.ui.Cells.ArchivedStickerSetCell.java
@Override public boolean onTouchEvent(MotionEvent event) { if (checkBox != null) { checkBox.getHitRect(rect);// ww w . java2 s . c o m if (rect.contains((int) event.getX(), (int) event.getY())) { event.offsetLocation(-checkBox.getX(), -checkBox.getY()); return checkBox.onTouchEvent(event); } } if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) { if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { getBackground().setHotspot(event.getX(), event.getY()); } } return super.onTouchEvent(event); }
From source file:akhil.alltrans.NestedScrollingListView.java
/** * * @see android.support.v4.widget.NestedScrollView#onTouchEvent(MotionEvent) *//* www . java 2 s. c om*/ @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:android.support.v7.widget.ForwardingListener.java
/** * Emulates View.toLocalMotionEvent(). This implementation does not handle transformations * (scaleX, scaleY, etc)./*from ww w . j a v a 2 s. com*/ */ private boolean toLocalMotionEvent(View view, MotionEvent event) { final int[] loc = mTmpLocation; view.getLocationOnScreen(loc); event.offsetLocation(-loc[0], -loc[1]); return true; }
From source file:android.support.v7.widget.ForwardingListener.java
/** * Emulates View.toGlobalMotionEvent(). This implementation does not handle transformations * (scaleX, scaleY, etc).// w w w.j a v a 2s .c o m */ private boolean toGlobalMotionEvent(View view, MotionEvent event) { final int[] loc = mTmpLocation; view.getLocationOnScreen(loc); event.offsetLocation(loc[0], loc[1]); return true; }
From source file:com.github.takahirom.zerobrowser.view.webview.ZeroBrowserWebView.java
@Override public boolean onTouchEvent(MotionEvent ev) { boolean returnValue = true; MotionEvent event = MotionEvent.obtain(ev); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsetY = 0;//from w ww . j a v a2s . com } 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); 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:org.mozilla.focus.web.NestedGeckoView.java
@Override public boolean onTouchEvent(MotionEvent ev) { boolean eventHandled = false; final MotionEvent event = MotionEvent.obtain(ev); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { mNestedOffsetY = 0;//from w ww . j a v a 2 s .c om } final int eventY = (int) event.getY(); event.offsetLocation(0, mNestedOffsetY); switch (action) { case MotionEvent.ACTION_MOVE: int deltaY = mLastY - eventY; if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) { deltaY -= mScrollConsumed[1]; mLastY = eventY - mScrollOffset[1]; event.offsetLocation(0, -mScrollOffset[1]); mNestedOffsetY += mScrollOffset[1]; } eventHandled = super.onTouchEvent(event); if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) { event.offsetLocation(0, mScrollOffset[1]); mNestedOffsetY += mScrollOffset[1]; mLastY -= mScrollOffset[1]; } break; case MotionEvent.ACTION_DOWN: eventHandled = super.onTouchEvent(event); mLastY = eventY; startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: eventHandled = super.onTouchEvent(event); stopNestedScroll(); break; default: // We don't care about other touch events } return eventHandled; }
From source file:com.fangzp.daily.widget.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 . j av a2 s . 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); 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.github.fo2rist.mclaren.ui.widgets.NestedWebView.java
@SuppressLint("ClickableViewAccessibility") @Override//from w ww . j av a 2 s. c om public boolean onTouchEvent(MotionEvent ev) { boolean returnValue = false; MotionEvent event = MotionEvent.obtain(ev); final int action = MotionEventCompat.getActionMasked(event); if (action == MotionEvent.ACTION_DOWN) { nestedOffsetY = 0; } int eventY = (int) event.getY(); event.offsetLocation(0, nestedOffsetY); switch (action) { case MotionEvent.ACTION_MOVE: int deltaY = lastY - eventY; // NestedPreScroll if (dispatchNestedPreScroll(0, deltaY, scrollConsumed, scrollOffset)) { deltaY -= scrollConsumed[1]; lastY = eventY - scrollOffset[1]; event.offsetLocation(0, -scrollOffset[1]); nestedOffsetY += scrollOffset[1]; } returnValue = super.onTouchEvent(event); // NestedScroll if (dispatchNestedScroll(0, scrollOffset[1], 0, deltaY, scrollOffset)) { event.offsetLocation(0, scrollOffset[1]); nestedOffsetY += scrollOffset[1]; lastY -= scrollOffset[1]; } break; case MotionEvent.ACTION_DOWN: returnValue = super.onTouchEvent(event); lastY = 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; default: //ignore other actions break; } return returnValue; }
From source file:com.github.shareme.gwsswwipetodismiss.library.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 ww w .j ava 2s . co m*/ } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { // TODO: ensure this is a finger, and set a flag mDownX = motionEvent.getRawX(); mDownY = motionEvent.getRawY(); mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); view.onTouchEvent(motionEvent); return false; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = motionEvent.getRawX() - mDownX; float deltaY = motionEvent.getRawY() - mDownY; mVelocityTracker.addMovement(motionEvent); mVelocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(mVelocityTracker.getXVelocity()); float velocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean dismiss = false; boolean dismissRight = false; if (Math.abs(deltaY) < Math.abs(deltaX)) { if (Math.abs(deltaX) > Math.round(mViewWidth * SWIPE_SENSITIVITY)) { dismiss = true; dismissRight = deltaX > 0; } else if (Math.abs(deltaX) > mSlop && mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX) { dismiss = true; dismissRight = mVelocityTracker.getXVelocity() > 0; } } if (dismiss) { // dismiss mView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0) .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { performDismiss(); } }); } else { // cancel mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null); } mVelocityTracker = null; mTranslationX = 0; mDownX = 0; mDownY = 0; mSwiping = false; break; } case MotionEvent.ACTION_MOVE: { if (mVelocityTracker == null) { break; } mVelocityTracker.addMovement(motionEvent); float deltaX = motionEvent.getRawX() - mDownX; if (Math.abs(deltaX) > mSlop) { mSwiping = true; mView.getParent().requestDisallowInterceptTouchEvent(true); // Cancel listview's touch MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); mView.onTouchEvent(cancelEvent); } if (mSwiping) { mTranslationX = deltaX; setTranslationX(mView, deltaX); // TODO: use an ease-out interpolator or such setAlpha(mView, Math.max(0f, Math.min(1f, 1f - Math.abs(deltaX) / SWIPE_SENSITIVITY * mViewWidth))); return true; } break; } } return false; }