List of usage examples for android.view MotionEvent recycle
@Override public final void recycle()
From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param yOffset Offset in pixels to drag by. * @see #beginFakeDrag()/*from w w w . ja v a 2 s . c o m*/ * @see #endFakeDrag() */ // BrantApps Change: Replaced all "X"s with "Y"s (except one noted later), "width"s with "height"s, "left"s with "top"s, "right"s with "bottom"s public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; // BrantApps Changed: Was scrollTo((int) scrollX, getScrollY()); scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); // BrantApps Change: Was final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:android.support.designox.widget.CoordinatorLayout.java
/** * Reset all Behavior-related tracking records either to clean up or in preparation * for a new event stream. This should be called when attached or detached from a window, * in response to an UP or CANCEL event, when intercept is request-disallowed * and similar cases where an event stream in progress will be aborted. *///from w w w.ja va 2s.c om private void resetTouchBehaviors() { if (mBehaviorTouchView != null) { final Behavior b = ((LayoutParams) mBehaviorTouchView.getLayoutParams()).getBehavior(); if (b != null) { final long now = SystemClock.uptimeMillis(); final MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); b.onTouchEvent(this, mBehaviorTouchView, cancelEvent); cancelEvent.recycle(); } mBehaviorTouchView = null; } final int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final View child = getChildAt(i); final LayoutParams lp = (LayoutParams) child.getLayoutParams(); lp.resetTouchBehaviorTracking(); } }
From source file:com.isapp.android.circularviewpager.CircularViewPager.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 ww w. ja v a 2 s . 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 oldScrollX = getScrollX(); float scrollX = oldScrollX - xOffset; final int width = getClientWidth(); float leftBound = width * mFirstOffset; float rightBound = width * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { leftBound = firstItem.offset * width; } if (lastItem.position != mAdapter.getCount() - 1) { rightBound = lastItem.offset * width; } 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:android.support.custom.view.VerticalViewPager.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. ja va 2 s.c o m*/ * @see #endFakeDrag() */ // public void fakeDragBy(float xOffset) { public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:VerticalViewPager.java
/** * Start a fake drag of the pager.//from w ww . j a v a 2 s. c o m * * <p>A fake drag can be useful if you want to synchronize the motion of the VerticalViewPager * with the touch scrolling of another view, while still letting the VerticalViewPager * 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 VerticalViewPager 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; } mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); mInitialMotionY = mLastMotionY = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } 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:com.suning.boxcontroller.control.ExViewPager.java
/** * Start a fake drag of the pager./*from ww w . j a v a 2 s . c om*/ * * <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; } mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); mInitialMotionX = 0; mLastMotionX = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } 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:org.ohmage.widget.VerticalViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param yOffset Offset in pixels to drag by. * @see #beginFakeDrag()/*from w w w . j ava 2s. c o m*/ * @see #endFakeDrag() */ public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionY += yOffset; float oldScrollY = getScrollY(); double scrollY = oldScrollY - yOffset; final int height = getHeight(); double topBound = height * mFirstOffset; double bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.edgar.banner.LoopViewPager.java
/** * Start a fake drag of the pager.//from ww w. j ava 2 s . c om * * <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; } if (mVelocityTracker == null) return false; mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); mInitialMotionX = mLastMotionX = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } 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:VerticalViewPager.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 va 2 s.c o m * @see #endFakeDrag() */ public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getClientHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.stone.card.VerticalViewPager.java
/** * Fake drag by an offset in pixels. You must have called * {@link #beginFakeDrag()} first./*from ww w.j a va 2 s . c o m*/ * * @param xOffset * Offset in pixels to drag by. * @see #beginFakeDrag() * @see #endFakeDrag() */ // public void fakeDragBy(float xOffset) { public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }