/** * Emulates View.toLocalMotionEvent(). This implementation does not handle transformations * (scaleX, scaleY, etc). */ private boolean toLocalMotionEvent(View view, MotionEvent event) { final int[] loc = mTmpLocation; view.getLocationOnScreen(loc); event.offsetLocation(-loc[0], -loc[1]); return true; }
/** * Emulates View.toGlobalMotionEvent(). This implementation does not handle transformations * (scaleX, scaleY, etc). */ private boolean toGlobalMotionEvent(View view, MotionEvent event) { final int[] loc = mTmpLocation; view.getLocationOnScreen(loc); event.offsetLocation(loc[0], loc[1]); return true; }
@Override protected void translateViewAndEvent(View view, float offset, MotionEvent event) { view.setTranslationY(offset); event.offsetLocation(offset - event.getY(0), 0f); } }
@Override protected void translateViewAndEvent(View view, float offset, MotionEvent event) { view.setTranslationX(offset); event.offsetLocation(offset - event.getX(0), 0f); } }
@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: ev.offsetLocation(center.x - initialTouch.x, center.y - initialTouch.y); break; } return pager.dispatchTouchEvent(ev); }
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (mSeekBar == null) { return super.onTouchEvent(event); } else { ViewUtils.getLocationInAncestor(mSeekBar, mLocation, this); final float offsetX = -mLocation[0]; final float offsetY = -mLocation[1]; event.offsetLocation(offsetX, offsetY); mSeekBar.onTouchEvent(event); event.offsetLocation(-offsetX, -offsetY); return true; } }
if (pe != null) { MotionEvent peAdjusted = MotionEvent.obtainNoHistory(pe); peAdjusted.offsetLocation(offsetX, offsetY); consumed |= childView.dispatchTouchEvent(peAdjusted); event.offsetLocation(offsetX, offsetY); consumed |= childView.dispatchTouchEvent(event); if (consumed) {
event.offsetLocation(0, mNestedYOffset); trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1]; trackedEvent.offsetLocation(0, mScrollOffset[1]); mNestedYOffset += mScrollOffset[1];
event.offsetLocation(offsetX, offsetY);
event.offsetLocation(offsetX, offsetY);
event.offsetLocation(offsetX, offsetY);
event.offsetLocation(offsetX, offsetY);
event.offsetLocation(offsetX, offsetY);
protected boolean onTouchInternal(@NonNull View view, @NonNull MotionEvent event) { MotionEvent viewportEvent = MotionEvent.obtain(event); viewportEvent.offsetLocation(-view.getPaddingLeft(), -view.getPaddingTop());
if (state == State.PEEKED) { MotionEvent cancelEvent = MotionEvent.obtain(event); cancelEvent.offsetLocation(0, sheetTranslation - getHeight()); cancelEvent.setAction(MotionEvent.ACTION_CANCEL); getSheetView().dispatchTouchEvent(cancelEvent); event.offsetLocation(0, sheetTranslation - getHeight()); getSheetView().dispatchTouchEvent(event); } else { event.offsetLocation(isTablet ? getX() - sheetStartX : 0, sheetTranslation - getHeight()); getSheetView().dispatchTouchEvent(event);
/** * Call addMovement and restore MotionEvent coordinate * * @param event {@link MotionEvent} */ private void addMovement(@NonNull MotionEvent event) { final float deltaX = event.getRawX() - event.getX(); final float deltaY = event.getRawY() - event.getY(); event.offsetLocation(deltaX, deltaY); mVelocityTracker.addMovement(event); event.offsetLocation(-deltaX, -deltaY); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_DOWN) { mRedirectTouchToStickyView = true; } if (mRedirectTouchToStickyView) { mRedirectTouchToStickyView = mCurrentStickyView != null; if (mRedirectTouchToStickyView) { mRedirectTouchToStickyView = ev.getY() <= mCurrentStickyView.getHeight() && ev.getX() >= mCurrentStickyView.getLeft() && ev.getX() <= mCurrentStickyView.getRight(); } } if (mRedirectTouchToStickyView) { if (mScrollRect == null) { mScrollRect = new Rect(); getGlobalVisibleRect(mScrollRect); } mCurrentStickyView.getLocationOnScreen(stickyViewP); ev.offsetLocation(0, stickyViewP[1] - mScrollRect.top); } return super.dispatchTouchEvent(ev); }
event.offsetLocation(-3, -2);
@Test public void testOffsetLocation() { assertThat(motionEvent2).x().isWithin(TOLERANCE).of(X_3F); assertThat(motionEvent2).y().isWithin(TOLERANCE).of(Y_4F); float offsetX = 1.0f; float offsetY = 1.0f; motionEvent2.offsetLocation(offsetX, offsetY); assertThat(motionEvent2).x().isWithin(TOLERANCE).of(X_3F + offsetX); assertThat(motionEvent2).y().isWithin(TOLERANCE).of(Y_4F + offsetY); }
ev.offsetLocation(0, -(stickyViewP[1] - mScrollRect.top));