List of usage examples for android.view MotionEvent recycle
@Override public final void recycle()
From source file:bw.com.yunifangstore.view.LazyViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()/* ww w. java 2 s. com*/ * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); if (mOnPageChangeListener != null) { final int position = (int) scrollX / widthWithMargin; final int positionOffsetPixels = (int) scrollX % widthWithMargin; final float positionOffset = (float) positionOffsetPixels / widthWithMargin; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.cnpeng.cnpeng_mydemosfrom2016_12.a_12_GetLocalFiles_VP_FM.CustomNoPreLoadViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()//from w w w .j a v a 2 s . co m * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); if (mOnPageChangeListener != null) { final int position = (int) scrollX / widthWithMargin; final int positionOffsetPixels = (int) scrollX % widthWithMargin; final float positionOffset = (float) positionOffsetPixels / widthWithMargin; mOnPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels); } // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
private boolean anyChildWantMotionEvent(MotionEvent ev, ViewGroup group) { MotionEvent event = MotionEvent.obtain(ev); event.offsetLocation(-group.getLeft(), -group.getTop()); //view//from www. java2 s. c o m int childCount = group.getChildCount(); final float x = event.getX(); final float y = event.getY(); for (int i = 0; i < childCount; i++) { View child = group.getChildAt(i); if (x >= child.getLeft() && x < child.getRight() && y >= child.getTop() && y < child.getBottom()) { if (child instanceof ViewGroup) { MotionEvent chileEvent = MotionEvent.obtain(event); chileEvent.offsetLocation(-child.getLeft(), -child.getTop()); if (anyChildWantMotionEvent(chileEvent, (ViewGroup) child)) { chileEvent.recycle(); return true; } } else if (child.onTouchEvent(event)) { return true; } } } event.recycle(); return false; }
From source file:com.xiaosu.lib.base.widget.drawerLayout.DrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // Log.i(TAG, "onInterceptTouchEvent: " + ev); final int action = ev.getAction(); boolean interceptForTap = false; boolean interceptForNonNestedScrollChild = false; boolean interceptForNoChildHandle = false; switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { if (mScrimOpacity > 0) { final float x = ev.getX(); final float y = ev.getY(); final View child = findTopChildUnder(this, (int) x, (int) y); if (child != null && child == mContentView) { interceptForTap = true;/*from ww w . j a v a 2s . c o m*/ } else if (child != null && child == mDrawerView) { if (child instanceof ViewGroup) { int insetX = (int) (x - child.getLeft()); int insetY = (int) (y - child.getTop()); View topChild = findTopChildUnder(child, insetX, insetY); if (null == topChild) interceptForNoChildHandle = true; if (topChild instanceof ViewGroup) { if (!ViewCompat.isNestedScrollingEnabled(topChild)) { MotionEvent event = MotionEvent.obtain(ev); event.offsetLocation(-child.getLeft(), -child.getTop()); if (!anyChildWantMotionEvent(event, (ViewGroup) topChild)) interceptForNoChildHandle = true; event.recycle(); } } else if (!ViewCompat.isNestedScrollingEnabled(topChild)) { //mDrawerView?View(?ViewGroup) interceptForNonNestedScrollChild = true; } } else if (!ViewCompat.isNestedScrollingEnabled(child)) { interceptForNonNestedScrollChild = true; } } } } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { } } return interceptForTap || interceptForNonNestedScrollChild || interceptForNoChildHandle; }
From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java
void cancelChildViewTouch() { // Cancel child touches if (!mChildrenCanceledTouch) { final long now = SystemClock.uptimeMillis(); final MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { getChildAt(i).dispatchTouchEvent(cancelEvent); }//from w w w .j ava 2 s. c om cancelEvent.recycle(); mChildrenCanceledTouch = true; } }
From source file:com.chenglong.muscle.ui.LazyViewPager.java
/** * Fake drag by an offset in pixels. You must have called * {@link #beginFakeDrag()} first./*from w w w.ja v a 2 s . c om*/ * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag() * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:org.immopoly.android.widget.ViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()//from w w w. ja v a 2s.c o m * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = forcedChildWidth > 0 ? forcedChildWidth : getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:beichen.douban.ui.view.LazyViewPager.java
/** * Fake drag by an offset in pixels. You must have called * {@link #beginFakeDrag()} first./*from www . j a v a 2 s. c o m*/ * * @param xOffset * Offset in pixels to drag by. * @see #beginFakeDrag() * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float scrollX = getScrollX() - xOffset; final int width = getWidth(); final int widthWithMargin = width + mPageMargin; final float leftBound = Math.max(0, (mCurItem - 1) * widthWithMargin); final float rightBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * widthWithMargin; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java
/** * Start a fake drag of the pager./*from www . j a v a2 s. co m*/ * * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager * with the touch scrolling of another view, while still letting the ViewPager * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call * {@link #endFakeDrag()} to complete the fake drag and fling as necessary. * * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag * is already in progress, this method will return false. * * @return true if the fake drag began successfully, false if it could not be started. * * @see #fakeDragBy(float) * @see #endFakeDrag() */ public boolean beginFakeDrag() { if (mIsBeingDragged) { return false; } /* end of if */ mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); // XXX ? mInitialMotionY = mLastMotionY = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } /* end of if */ final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); mFakeDragBeginTime = time; return true; }
From source file:administrator.example.com.myscrollview.VerticalViewPager.java
/** * Start a fake drag of the pager./*from ww w .j av a 2 s . c o m*/ * * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager * with the touch scrolling of another view, while still letting the ViewPager * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call * {@link #endFakeDrag()} to complete the fake drag and fling as necessary. * * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag * is already in progress, this method will return false. * * @return true if the fake drag began successfully, false if it could not be started. * * @see #fakeDragBy(float) * @see #endFakeDrag() */ public boolean beginFakeDrag() { if (mIsBeingDragged) { return false; } /* end of if */ mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); // XXX mInitialMotionY = mLastMotionY = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } /* end of if */ final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); mFakeDragBeginTime = time; return true; }