android.support.v4.view.VelocityTrackerCompat Java Examples

The following examples show how to use android.support.v4.view.VelocityTrackerCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HorizontalViewPager.java    From DoubleViewPager with Apache License 2.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int width = getWidth();
    final int scrollX = getScrollX();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor;
    final int totalDelta = (int) (mLastMotionX - mInitialMotionX);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #2
Source File: VerticalViewPager.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int height = getClientHeight();
    final int scrollY = getScrollY();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
    final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #3
Source File: VerticalViewPager.java    From TLint with Apache License 2.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity =
            (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int height = getClientHeight();
    final int scrollY = getScrollY();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
    final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #4
Source File: BGAViewPager.java    From JD-Test with Apache License 2.0 6 votes vote down vote up
private float getXVelocity() {
    float xVelocity = 0;
    Class viewpagerClass = ViewPager.class;
    try {
        Field velocityTrackerField = viewpagerClass.getDeclaredField("mVelocityTracker");
        velocityTrackerField.setAccessible(true);
        VelocityTracker velocityTracker = (VelocityTracker) velocityTrackerField.get(this);

        Field activePointerIdField = viewpagerClass.getDeclaredField("mActivePointerId");
        activePointerIdField.setAccessible(true);

        Field maximumVelocityField = viewpagerClass.getDeclaredField("mMaximumVelocity");
        maximumVelocityField.setAccessible(true);
        int maximumVelocity = maximumVelocityField.getInt(this);

        velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
        xVelocity = VelocityTrackerCompat.getXVelocity(velocityTracker, activePointerIdField.getInt(this));
    } catch (Exception e) {
    }
    return xVelocity;
}
 
Example #5
Source File: BGAViewPager.java    From KUtils with Apache License 2.0 6 votes vote down vote up
private float getXVelocity() {
    float xVelocity = 0;
    Class viewpagerClass = ViewPager.class;
    try {
        Field velocityTrackerField = viewpagerClass.getDeclaredField("mVelocityTracker");
        velocityTrackerField.setAccessible(true);
        VelocityTracker velocityTracker = (VelocityTracker) velocityTrackerField.get(this);

        Field activePointerIdField = viewpagerClass.getDeclaredField("mActivePointerId");
        activePointerIdField.setAccessible(true);

        Field maximumVelocityField = viewpagerClass.getDeclaredField("mMaximumVelocity");
        maximumVelocityField.setAccessible(true);
        int maximumVelocity = maximumVelocityField.getInt(this);

        velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
        xVelocity = VelocityTrackerCompat.getXVelocity(velocityTracker, activePointerIdField.getInt(this));
    } catch (Exception e) {
    }
    return xVelocity;
}
 
Example #6
Source File: ItemTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
private int checkVerticalSwipe(ViewHolder viewHolder, int flags) {
    if ((flags & 3) != 0) {
        int dirFlag = this.mDy > 0.0f ? 2 : 1;
        if (this.mVelocityTracker != null && this.mActivePointerId > -1) {
            int velDirFlag;
            this.mVelocityTracker.computeCurrentVelocity(1000, this.mCallback.getSwipeVelocityThreshold(this.mMaxSwipeVelocity));
            float xVelocity = VelocityTrackerCompat.getXVelocity(this.mVelocityTracker, this.mActivePointerId);
            float yVelocity = VelocityTrackerCompat.getYVelocity(this.mVelocityTracker, this.mActivePointerId);
            if (yVelocity > 0.0f) {
                velDirFlag = 2;
            } else {
                velDirFlag = 1;
            }
            float absYVelocity = Math.abs(yVelocity);
            if ((velDirFlag & flags) != 0 && velDirFlag == dirFlag && absYVelocity >= this.mCallback.getSwipeEscapeVelocity(this.mSwipeEscapeVelocity) && absYVelocity > Math.abs(xVelocity)) {
                return velDirFlag;
            }
        }
        float threshold = ((float) this.mRecyclerView.getHeight()) * this.mCallback.getSwipeThreshold(viewHolder);
        if ((flags & dirFlag) != 0 && Math.abs(this.mDy) > threshold) {
            return dirFlag;
        }
    }
    return 0;
}
 
Example #7
Source File: NineOldViewPager.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int width = getClientWidth();
    final int scrollX = getScrollX();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor;
    final int totalDelta = (int) (mLastMotionX - mInitialMotionX);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #8
Source File: VerticalViewPager.java    From ankihelper with GNU General Public License v3.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int height = getClientHeight();
    final int scrollY = getScrollY();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
    final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #9
Source File: ViewPagerEx.java    From LoyalNativeSlider with MIT License 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int width = getClientWidth();
    final int scrollX = getScrollX();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor;
    final int totalDelta = (int) (mLastMotionX - mInitialMotionX);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #10
Source File: VerticalViewPager.java    From DoubleViewPager with Apache License 2.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int width = getClientWidth();
    final int scrollX = getScrollX();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollX / width) - ii.offset) / ii.widthFactor;
    final int totalDelta = (int) (mLastMotionX - mInitialMotionX);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #11
Source File: VerticalViewPager.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int height = getClientHeight();
    final int scrollY = getScrollY();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
    final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #12
Source File: VerticalViewPager.java    From SprintNBA with Apache License 2.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
  if (!mFakeDragging) {
    throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
  }

  final VelocityTracker velocityTracker = mVelocityTracker;
  velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
  int initialVelocity =
      (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
  mPopulatePending = true;
  final int height = getClientHeight();
  final int scrollY = getScrollY();
  final ItemInfo ii = infoForCurrentScrollPosition();
  final int currentPage = ii.position;
  final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
  final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
  int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
  setCurrentItemInternal(nextPage, true, true, initialVelocity);
  endDrag();

  mFakeDragging = false;
}
 
Example #13
Source File: VerticalViewPager.java    From InfiniteCycleViewPager with Apache License 2.0 6 votes vote down vote up
/**
 * End a fake drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
            velocityTracker, mActivePointerId);
    mPopulatePending = true;
    final int height = getClientHeight();
    final int scrollY = getScrollY();
    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;
    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
    final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
Example #14
Source File: ViewDragHelper.java    From UltimateSwipeTool with Apache License 2.0 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #15
Source File: ViewDragHelper.java    From UltimateSwipeTool with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each
 * subsequent frame to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop  Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop  Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to "
                + "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #16
Source File: ViewDragHelper.java    From Dragger with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame
 * to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
  if (!mReleaseInProgress) {
    throw new IllegalStateException("Cannot flingCapturedView outside of a call to "
        + "Callback#onViewReleased");
  }

  mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
      (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
      (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
      minLeft, maxLeft, minTop, maxTop);

  setDragState(STATE_SETTLING);
}
 
Example #17
Source File: CustomViewDragHelper.java    From DragVideo with Apache License 2.0 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #18
Source File: CustomViewDragHelper.java    From DragVideo with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame
 * to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to " +
                "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #19
Source File: ViewDragHelper.java    From MaterialQQLite with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each
 * subsequent frame to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop  Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop  Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to "
                + "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #20
Source File: ViewDragHelper.java    From MaterialQQLite with Apache License 2.0 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #21
Source File: ViewDragHelper.java    From CoreModule with Apache License 2.0 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #22
Source File: ViewDragHelper.java    From CoreModule with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each
 * subsequent frame to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop  Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop  Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to "
                + "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #23
Source File: ViewDragHelper.java    From MicroReader with MIT License 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #24
Source File: ViewDragHelper.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean settleCapturedViewAt(int i1, int j1)
{
    if (!x)
    {
        throw new IllegalStateException("Cannot settleCapturedViewAt outside of a call to Callback#onViewReleased");
    } else
    {
        return a(i1, j1, (int)VelocityTrackerCompat.getXVelocity(p, g), (int)VelocityTrackerCompat.getYVelocity(p, g));
    }
}
 
Example #25
Source File: ViewDragHelper.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #26
Source File: ViewDragHelper.java    From Muzesto with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame
 * to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop  Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop  Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to " +
                "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #27
Source File: ViewDragHelper.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each
 * subsequent frame to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop  Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop  Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to "
                + "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}
 
Example #28
Source File: ViewDragHelper.java    From imsdk-android with MIT License 5 votes vote down vote up
private void releaseViewForPointerUp() {
    mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
    final float xvel = clampMag(
            VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    final float yvel = clampMag(
            VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            mMinVelocity, mMaxVelocity);
    dispatchViewReleased(xvel, yvel);
}
 
Example #29
Source File: ReItemTouchHelper.java    From ReSwipeCard with Apache License 2.0 5 votes vote down vote up
private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
    boolean isLeft = mDx < 0;
    if (mCallback.isForbidLeftSwipeOut() && isLeft) {
        return 0;
    }
    if (mCallback.isForbidRightSwipeOut() && !isLeft) {
        return 0;
    }
    if ((flags & (LEFT | RIGHT)) != 0) {
        final int dirFlag = mDx > 0 ? RIGHT : LEFT;
        if (mVelocityTracker != null && mActivePointerId > -1) {
            mVelocityTracker.computeCurrentVelocity(PIXELS_PER_SECOND,
                    mCallback.getSwipeVelocityThreshold(mMaxSwipeVelocity));
            final float xVelocity = VelocityTrackerCompat
                    .getXVelocity(mVelocityTracker, mActivePointerId);
            final float yVelocity = VelocityTrackerCompat
                    .getYVelocity(mVelocityTracker, mActivePointerId);
            final int velDirFlag = xVelocity > 0f ? RIGHT : LEFT;
            final float absXVelocity = Math.abs(xVelocity);
            if ((velDirFlag & flags) != 0 && dirFlag == velDirFlag &&
                    absXVelocity >= mCallback.getSwipeEscapeVelocity(mSwipeEscapeVelocity) &&
                    absXVelocity > Math.abs(yVelocity)) {
                return velDirFlag;
            }
        }

        final float threshold = mRecyclerView.getWidth() * mCallback
                .getSwipeThreshold(viewHolder);

        if ((flags & dirFlag) != 0 && Math.abs(mDx) > threshold) {
            return dirFlag;
        }
    }
    return 0;
}
 
Example #30
Source File: ViewDragHelper.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
/**
 * Settle the captured view based on standard free-moving fling behavior.
 * The caller should invoke {@link #continueSettling(boolean)} on each subsequent frame
 * to continue the motion until it returns false.
 *
 * @param minLeft Minimum X position for the view's left edge
 * @param minTop Minimum Y position for the view's top edge
 * @param maxLeft Maximum X position for the view's left edge
 * @param maxTop Maximum Y position for the view's top edge
 */
public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop) {
    if (!mReleaseInProgress) {
        throw new IllegalStateException("Cannot flingCapturedView outside of a call to " +
                "Callback#onViewReleased");
    }

    mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
            (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
            (int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
            minLeft, maxLeft, minTop, maxTop);

    setDragState(STATE_SETTLING);
}