當前位置: 首頁>>代碼示例>>Java>>正文


Java VelocityTrackerCompat類代碼示例

本文整理匯總了Java中android.support.v4.view.VelocityTrackerCompat的典型用法代碼示例。如果您正苦於以下問題:Java VelocityTrackerCompat類的具體用法?Java VelocityTrackerCompat怎麽用?Java VelocityTrackerCompat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


VelocityTrackerCompat類屬於android.support.v4.view包,在下文中一共展示了VelocityTrackerCompat類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:30,代碼來源:VerticalViewPager.java

示例2: endFakeDragHorizontally

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
private void endFakeDragHorizontally() {
    if (mAdapter != null) {
        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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:BaseViewPager.java

示例3: endFakeDragVertically

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
private void endFakeDragVertically() {
    if (mAdapter != null) {
        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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:BaseViewPager.java

示例4: getXVelocity

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
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;
}
 
開發者ID:devzwy,項目名稱:KUtils,代碼行數:22,代碼來源:BGAViewPager.java

示例5: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:ruiqiao2017,項目名稱:Renrentou,代碼行數:30,代碼來源:XCCycleViewPager.java

示例6: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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.");
    }

    if (mAdapter != null) {
        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 ViewPager.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;
}
 
開發者ID:SimonCherryGZ,項目名稱:JewelryUI,代碼行數:32,代碼來源:ViewPager.java

示例7: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:fengshihao,項目名稱:WebPager,代碼行數:29,代碼來源:CustomViewPager.java

示例8: checkHorizontalSwipe

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
    if ((flags & 12) != 0) {
        int dirFlag = this.mDx > 0.0f ? 8 : 4;
        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 (xVelocity > 0.0f) {
                velDirFlag = 8;
            } else {
                velDirFlag = 4;
            }
            float absXVelocity = Math.abs(xVelocity);
            if ((velDirFlag & flags) != 0 && dirFlag == velDirFlag && absXVelocity >= this.mCallback.getSwipeEscapeVelocity(this.mSwipeEscapeVelocity) && absXVelocity > Math.abs(yVelocity)) {
                return velDirFlag;
            }
        }
        float threshold = ((float) this.mRecyclerView.getWidth()) * this.mCallback.getSwipeThreshold(viewHolder);
        if ((flags & dirFlag) != 0 && Math.abs(this.mDx) > threshold) {
            return dirFlag;
        }
    }
    return 0;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:ItemTouchHelper.java

示例9: checkVerticalSwipe

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
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;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:26,代碼來源:ItemTouchHelper.java

示例10: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * End a fake drawable_drag of the pager.
 *
 * @see #beginFakeDrag()
 * @see #fakeDragBy(float)
 */
public void endFakeDrag() {
    if (!mFakeDragging) {
        throw new IllegalStateException("No fake drawable_drag in progress. Call beginFakeDrag first.");
    }

    final VelocityTracker velocityTracker = mVelocityTracker;
    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
    int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
            velocityTracker, mActivePointerId);
    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;
}
 
開發者ID:reyanshmishra,項目名稱:Rey-MusicPlayer,代碼行數:29,代碼來源:VelocityViewPager.java

示例11: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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.");
    }

    if (mAdapter != null) {
        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;
}
 
開發者ID:joy-inc,項目名稱:core-ui,代碼行數:32,代碼來源:VerticalViewPager.java

示例12: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:smuyyh,項目名稱:SprintNBA,代碼行數:29,代碼來源:VerticalViewPager.java

示例13: endFakeDrag

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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 totalDelta = (int) (mLastMotionX - mInitialMotionX);
    final int scrollX = getScrollX();
    final int widthWithMargin = getWidth() + mPageMargin;
    final int currentPage = scrollX / widthWithMargin;
    final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
開發者ID:lujianzhao,項目名稱:AndroidBase,代碼行數:28,代碼來源:LazyViewPager.java

示例14: flingCapturedView

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
/**
 * 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);
}
 
開發者ID:houshuai0816,項目名稱:DragVideos,代碼行數:24,代碼來源:CustomViewDragHelper.java

示例15: releaseViewForPointerUp

import android.support.v4.view.VelocityTrackerCompat; //導入依賴的package包/類
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);
}
 
開發者ID:houshuai0816,項目名稱:DragVideos,代碼行數:11,代碼來源:CustomViewDragHelper.java


注:本文中的android.support.v4.view.VelocityTrackerCompat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。