List of usage examples for android.view MotionEvent obtain
static public MotionEvent obtain(long downTime, long eventTime, int action, float x, float y, int metaState)
From source file:com.bluetoothlamp.tiny.view.verticalview.VerticalViewPager.java
/** * Start a fake drag of the pager./*w w w . j a v a2 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; }
From source file:com.example.view.VerticalViewPager.java
/** * Start a fake drag of the pager.//from www . 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; } /* 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:interactive.view.pagereader.VerticalViewPager.java
/** * Start a fake drag of the pager./* www. ja v a 2s . 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
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param yOffset Offset in pixels to drag by. * @see #beginFakeDrag()/*www . j a v a 2 s. co m*/ * @see #endFakeDrag() */ public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } /* end of if */ mLastMotionY += yOffset; float scrollY = getScrollY() - yOffset; final int height = getHeight(); final int heightWithMargin = height + mPageMargin; final float topBound = Math.max(0, (mCurItem - 1) * heightWithMargin); final float bottomBound = Math.min(mCurItem + 1, mAdapter.getCount() - 1) * heightWithMargin; if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } /* end of if */ // 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:cn.ismartv.recyclerview.widget.RecyclerView.java
/** * Enable or disable layout and scroll. After <code>setLayoutFrozen(true)</code> is called, * Layout requests will be postponed until <code>setLayoutFrozen(false)</code> is called; * child views are not updated when RecyclerView is frozen, {@link #smoothScrollBy(int, int)}, * {@link #scrollBy(int, int)}, {@link #scrollToPosition(int)} and * {@link #smoothScrollToPosition(int)} are dropped; TouchEvents and GenericMotionEvents are * dropped; {@link LayoutManager#onFocusSearchFailed(View, int, Recycler, State)} will not be * called.//w ww. j a va 2 s .co m * * <p> * <code>setLayoutFrozen(true)</code> does not prevent app from directly calling {@link * LayoutManager#scrollToPosition(int)}, {@link LayoutManager#smoothScrollToPosition( * RecyclerView, State, int)}. * <p> * {@link #setAdapter(Adapter)} and {@link #swapAdapter(Adapter, boolean)} will automatically * stop frozen. * <p> * Note: Running ItemAnimator is not stopped automatically, it's caller's * responsibility to call ItemAnimator.end(). * * @param frozen true to freeze layout and scroll, false to re-enable. */ public void setLayoutFrozen(boolean frozen) { if (frozen != mLayoutFrozen) { assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll"); if (!frozen) { mLayoutFrozen = frozen; if (mLayoutRequestEaten && mLayout != null && mAdapter != null) { requestLayout(); } mLayoutRequestEaten = false; } else { final long now = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); onTouchEvent(cancelEvent); mLayoutFrozen = frozen; mIgnoreMotionEventTillDown = true; stopScroll(); } } }
From source file:org.bangbang.support.v4.widget.VerticalViewPager.java
/** * Start a fake drag of the pager./* w w w .ja v a2s . com*/ * * <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); // bangbang.S // mInitialMotionX = mLastMotionX = 0; 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.gome.ecmall.custom.VerticalViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * //from www . jav a 2s . c o m * @param xOffset * Offset in pixels to drag by. * @see #beginFakeDrag() * @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 = 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 * topBound; } 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:android.support.v71.widget.RecyclerView.java
/** * Enable or disable layout and scroll. After <code>setLayoutFrozen(true)</code> is called, * Layout requests will be postponed until <code>setLayoutFrozen(false)</code> is called; * child views are not updated when RecyclerView is frozen, {@link #smoothScrollBy(int, int)}, * {@link #scrollBy(int, int)}, {@link #scrollToPosition(int)} and * {@link #smoothScrollToPosition(int)} are dropped; TouchEvents and GenericMotionEvents are * dropped; {@link LayoutManager#onFocusSearchFailed(View, int, Recycler, State)} will not be * called.//from w w w. j a v a2 s.c o m * <p/> * <p/> * <code>setLayoutFrozen(true)</code> does not prevent app from directly calling {@link * LayoutManager#scrollToPosition(int)}, {@link LayoutManager#smoothScrollToPosition( *RecyclerView, State, int)}. * <p/> * {@link #setAdapter(Adapter)} and {@link #swapAdapter(Adapter, boolean)} will automatically * stop frozen. * <p/> * Note: Running ItemAnimator is not stopped automatically, it's caller's * responsibility to call ItemAnimator.end(). * <p/> * * * @param frozen true to freeze layout and scroll, false to re-enable. */ public void setLayoutFrozen(boolean frozen) { if (frozen != mLayoutFrozen) { // view assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll"); if (!frozen) { // mLayoutFrozen = frozen; //TODO mLayoutRequestEaten ??? if (mLayoutRequestEaten && mLayout != null && mAdapter != null) { // layoutManager adpater ?? ? requestLayout(); } mLayoutRequestEaten = false; } else { // final long now = SystemClock.uptimeMillis(); //? cancle MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); onTouchEvent(cancelEvent); mLayoutFrozen = frozen; // mIgnoreMotionEventTillDown = true; // ? stopScroll(); } } }
From source file:cn.ismartv.tvrecyclerview.widget.RecyclerView.java
/** * Enable or disable layout and scroll. After <code>setLayoutFrozen(true)</code> is called, * Layout requests will be postponed until <code>setLayoutFrozen(false)</code> is called; * child views are not updated when RecyclerView is frozen, {@link #smoothScrollBy(int, int)}, * {@link #scrollBy(int, int)}, {@link #scrollToPosition(int)} and * {@link #smoothScrollToPosition(int)} are dropped; TouchEvents and GenericMotionEvents are * dropped; {@link LayoutManager#onFocusSearchFailed(View, int, Recycler, State)} will not be * called./* www . ja v a 2 s . c o m*/ * * <p> * <code>setLayoutFrozen(true)</code> does not prevent app from directly calling {@link * LayoutManager#scrollToPosition(int)}, {@link LayoutManager#smoothScrollToPosition( * RecyclerView, State, int)}. * <p> * {@link #setAdapter(Adapter)} and {@link #swapAdapter(Adapter, boolean)} will automatically * stop frozen. * <p> * Note: Running ItemAnimator is not stopped automatically, it's caller's * responsibility to call ItemAnimator.end(). * * @param frozen true to freeze layout and scroll, false to re-enable. */ public void setLayoutFrozen(boolean frozen) { if (frozen != mLayoutFrozen) { assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll"); if (!frozen) { mLayoutFrozen = false; if (mLayoutRequestEaten && mLayout != null && mAdapter != null) { requestLayout(); } mLayoutRequestEaten = false; } else { final long now = SystemClock.uptimeMillis(); MotionEvent cancelEvent = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0); onTouchEvent(cancelEvent); mLayoutFrozen = true; mIgnoreMotionEventTillDown = true; stopScroll(); } } }
From source file:org.bangbang.support.v4.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()// 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 = getHeight(); float bottomBound = height * mFirstOffset; float topBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { bottomBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { topBound = lastItem.offset * height; } if (scrollY < bottomBound) { scrollY = bottomBound; } else if (scrollY > topBound) { scrollY = topBound; } // Don't lose the rounded component // bangbang.S // mLastMotionX += scrollX - (int) scrollX; 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(); }