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


Java VelocityTrackerCompat.getXVelocity方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例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:fengshihao,項目名稱:WebPager,代碼行數:29,代碼來源:CustomViewPager.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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 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:henryblue,項目名稱:TeaCup,代碼行數:32,代碼來源:CenterViewPager.java

示例10: checkHorizontalSwipe

import android.support.v4.view.VelocityTrackerCompat; //導入方法依賴的package包/類
private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) {
    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;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:29,代碼來源:ItemTouchHelper.java

示例11: checkVerticalSwipe

import android.support.v4.view.VelocityTrackerCompat; //導入方法依賴的package包/類
private int checkVerticalSwipe(ViewHolder viewHolder, int flags) {
    if ((flags & (UP | DOWN)) != 0) {
        final int dirFlag = mDy > 0 ? DOWN : UP;
        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 = yVelocity > 0f ? DOWN : UP;
            final float absYVelocity = Math.abs(yVelocity);
            if ((velDirFlag & flags) != 0 && velDirFlag == dirFlag &&
                    absYVelocity >= mCallback.getSwipeEscapeVelocity(mSwipeEscapeVelocity) &&
                    absYVelocity > Math.abs(xVelocity)) {
                return velDirFlag;
            }
        }

        final float threshold = mRecyclerView.getHeight() * mCallback
                .getSwipeThreshold(viewHolder);
        if ((flags & dirFlag) != 0 && Math.abs(mDy) > threshold) {
            return dirFlag;
        }
    }
    return 0;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:28,代碼來源:ItemTouchHelper.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);

    final ItemInfo ii = infoForCurrentScrollPosition();
    final int currentPage = ii.position;

    int initialVelocity, totalDelta;
    float pageOffset;
    if (isOrientationHorizontal()) {
        initialVelocity = (int) VelocityTrackerCompat.getXVelocity(
                velocityTracker, mActivePointerId);
        mPopulatePending = true;
        final int width = getClientWidth();
        final int scrollX = getScrollX();
        pageOffset = (((float) scrollX / width) - ii.offset) / ii.sizeFactor;
        totalDelta = (int) (mLastMotionX - mInitialMotionX);
    } else {
        initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
                velocityTracker, mActivePointerId);
        mPopulatePending = true;
        final int height = getClientHeight();
        final int scrollY = getScrollY();
        pageOffset = (((float) scrollY / height) - ii.offset) / ii.sizeFactor;
        totalDelta = (int) (mLastMotionY - mInitialMotionY);
    }

    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
            totalDelta);
    setCurrentItemInternal(nextPage, true, true, initialVelocity);
    endDrag();

    mFakeDragging = false;
}
 
開發者ID:m4coding,項目名稱:Orientation-ViewPager,代碼行數:45,代碼來源:OrientationViewPager.java

示例13: onTouchEvent

import android.support.v4.view.VelocityTrackerCompat; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    float dx = x - mPrevX;
    float dy = y - mPrevY;
    int index = event.getActionIndex();
    int pointerId = event.getPointerId(index);

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

            if (!mScroller.isFinished()) {
                mScroller.abortAnimation();
            }

            mMode = MODE_RULER_DRAG;
            if (mIsVertical) {
                if (y - mViewportStart >= mHighlightStart &&
                        y - mViewportStart <= mHighlightStart + mHighlightSize) {
                    mMode = MODE_HIGHLIGHT_DRAG;
                }
            } else {
                if (x - mViewportStart >= mHighlightStart &&
                        x - mViewportStart <= mHighlightStart + mHighlightSize) {
                    mMode = MODE_HIGHLIGHT_DRAG;
                }
            }

            if (mVelocityTracker == null) {
                mVelocityTracker = VelocityTracker.obtain();
            } else {
                mVelocityTracker.clear();
            }
            mVelocityTracker.addMovement(event);

            break;
        case MotionEvent.ACTION_MOVE:
            mVelocityTracker.addMovement(event);

            if (mMode == MODE_RULER_DRAG) {
                if (mIsVertical) {
                    setViewportStart(getViewportStart() + dy);
                } else {
                    setViewportStart(getViewportStart() + dx);
                }
            } else if (mMode == MODE_HIGHLIGHT_DRAG) {
                if (mIsVertical) {
                    // Drag highlight by whole pixels for now
                    setHighlightStart(getHighlightStart() + Math.round(dy));
                } else {
                    setHighlightStart(getHighlightStart() + Math.round(dx));
                }
            }

            break;

        case MotionEvent.ACTION_UP:
            if (mMode == MODE_RULER_DRAG) {
                mVelocityTracker.computeCurrentVelocity(1000);
                int vx = (int) (VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId));
                int vy = (int) (VelocityTrackerCompat.getYVelocity(mVelocityTracker, pointerId));
                mScroller.fling((int) getViewportStart(), (int) getViewportStart(), vx, vy,
                        -10000, 10000, -10000, 10000);
                this.invalidate();
            }

            break;
    }

    mPrevX = x;
    mPrevY = y;

    return true;
}
 
開發者ID:google,項目名稱:spline,代碼行數:76,代碼來源:RulerView.java


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