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


Java VelocityTracker.computeCurrentVelocity方法代碼示例

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


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

示例1: velocityTrackerPointerUpCleanUpIfNecessary

import android.view.VelocityTracker; //導入方法依賴的package包/類
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
                                                              VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();
            break;
        }
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:26,代碼來源:Utils.java

示例2: endFakeDragHorizontally

import android.view.VelocityTracker; //導入方法依賴的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: run

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public void run() {
	final int activeId = mActivePointerId;
	final VelocityTracker vt = mVelocityTracker;
	final OverScroller scroller = mScroller;
	if (vt == null || activeId == INVALID_POINTER) {
		return;
	}

	vt.computeCurrentVelocity(1000, mMaximumVelocity);
	final float xvel = -vt.getXVelocity(activeId);

	if (Math.abs(xvel) >= mMinimumVelocity
			&& scroller.isScrollingInDirection(xvel, 0)) {
		// Keep the fling alive a little longer
		postDelayed(this, FLYWHEEL_TIMEOUT);
	} else {
		endFling();
		mTouchMode = TOUCH_MODE_SCROLL;
		reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
	}
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:23,代碼來源:AbsHListView.java

示例4: getCurrentState

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public int getCurrentState(View selectedView, View targetView, int x, int y,
                           VelocityTracker velocityTracker, int selectedPosition,
                           int targetPosition) {
    if(velocityTracker == null) return ClassifyView.MOVE_STATE_NONE;
    int left = x;
    int top = y;
    int right = left + selectedView.getWidth();
    int bottom = top + selectedView.getHeight();
    if((Math.abs(left - targetView.getLeft())+Math.abs(right - targetView.getRight())+
            Math.abs(top - targetView.getTop())+ Math.abs(bottom - targetView.getBottom()))
            <(targetView.getWidth()+targetView.getHeight()
    )/2){
        velocityTracker.computeCurrentVelocity(100);
        float xVelocity = velocityTracker.getXVelocity();
        float yVelocity = velocityTracker.getYVelocity();
        float limit = getVelocity(targetView.getContext());
        if(xVelocity < limit && yVelocity < limit){
            return ClassifyView.MOVE_STATE_MOVE;
        }
    }
    return ClassifyView.MOVE_STATE_NONE;
}
 
開發者ID:AlphaBoom,項目名稱:ClassifyView,代碼行數:24,代碼來源:BaseSubAdapter.java

示例5: endFakeDrag

import android.view.VelocityTracker; //導入方法依賴的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

示例6: getXVelocity

import android.view.VelocityTracker; //導入方法依賴的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

示例7: endFakeDrag

import android.view.VelocityTracker; //導入方法依賴的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

示例8: endFakeDrag

import android.view.VelocityTracker; //導入方法依賴的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

示例9: endFakeDrag

import android.view.VelocityTracker; //導入方法依賴的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

示例10: endFakeDrag

import android.view.VelocityTracker; //導入方法依賴的package包/類
public void endFakeDrag() {
    if (this.mFakeDragging) {
        if (this.mAdapter != null) {
            VelocityTracker velocityTracker = this.mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, (float) this.mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, this.mActivePointerId);
            this.mPopulatePending = true;
            int width = getClientWidth();
            int scrollX = getScrollX();
            ItemInfo ii = infoForCurrentScrollPosition();
            setCurrentItemInternal(determineTargetPage(ii.position, ((((float) scrollX) / ((float) width)) - ii.offset) / ii.widthFactor, initialVelocity, (int) (this.mLastMotionX - this.mInitialMotionX)), true, true, initialVelocity);
        }
        endDrag();
        this.mFakeDragging = false;
        return;
    }
    throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:19,代碼來源:ViewPager.java

示例11: getCurrentState

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public int getCurrentState(View selectedView, View targetView, int x, int y,
                           VelocityTracker velocityTracker, int selectedPosition,
                           int targetPosition) {
    if (velocityTracker == null) return ClassifyView.MOVE_STATE_NONE;
    int left = x;
    int top = y;
    int right = left + selectedView.getWidth();
    int bottom = top + selectedView.getHeight();
    if (canMergeItem(selectedPosition, targetPosition)) {
        if ((Math.abs(left - targetView.getLeft()) + Math.abs(right - targetView.getRight()) +
                Math.abs(top - targetView.getTop()) + Math.abs(bottom - targetView.getBottom()))
                < (targetView.getWidth() + targetView.getHeight()
        ) / 3) {
            return ClassifyView.MOVE_STATE_MERGE;
        }
    }
    if ((Math.abs(left - targetView.getLeft()) + Math.abs(right - targetView.getRight()) +
            Math.abs(top - targetView.getTop()) + Math.abs(bottom - targetView.getBottom()))
            < (targetView.getWidth() + targetView.getHeight()
    ) / 2) {
        velocityTracker.computeCurrentVelocity(100);
        float xVelocity = velocityTracker.getXVelocity();
        float yVelocity = velocityTracker.getYVelocity();
        float limit = getVelocity(targetView.getContext());
        if (xVelocity < limit && yVelocity < limit) {
            return ClassifyView.MOVE_STATE_MOVE;
        }
    }
    return ClassifyView.MOVE_STATE_NONE;
}
 
開發者ID:AlphaBoom,項目名稱:ClassifyView,代碼行數:32,代碼來源:BaseMainAdapter.java

示例12: checkOnFlingGesture

import android.view.VelocityTracker; //導入方法依賴的package包/類
private boolean checkOnFlingGesture(MotionEvent ev) {
    final VelocityTracker velocityTracker = this.velocityTracker;
    final int pointerId = ev.getPointerId(0);
    velocityTracker.computeCurrentVelocity(1000, MAX_FLING_VELOCITY);
    final float velocityY = velocityTracker.getYVelocity(pointerId);
    final float velocityX = velocityTracker.getXVelocity(pointerId);
    if ((Math.abs(velocityY) >= MIN_FLING_VELOCITY) || (Math.abs(velocityX) >= MIN_FLING_VELOCITY)) {
        return gestureListener.onFling(currentDownEvent, ev, velocityX, velocityY);
    } else {
        return false;
    }
}
 
開發者ID:xyzxqs,項目名稱:XphotoView,代碼行數:13,代碼來源:GooglePhotosGestureDetector.java

示例13: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent ev) {
    final int action = ev.getActionMasked();
    final int actionIndex = ev.getActionIndex();

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action){
        case MotionEvent.ACTION_POINTER_DOWN:
            mActivePointerId = ev.getPointerId(actionIndex);

            mLastMotionX = ev.getX(actionIndex);
            mLastMotionY = ev.getY(actionIndex);
            break;

        case MotionEvent.ACTION_POINTER_UP:
            final int pointerId = ev.getPointerId(actionIndex);
            if(pointerId==mActivePointerId){
                final int newIndex = actionIndex == 0 ? 1 : 0;
                mActivePointerId = ev.getPointerId(newIndex);

                mLastMotionX = ev.getX(newIndex);
                mLastMotionY = ev.getY(newIndex);
            }
            break;

        //down時,已經將capture item定下來了。所以,後麵可以安心考慮event處理
        case MotionEvent.ACTION_MOVE: {
            final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
            if (activePointerIndex == -1)
                break;

            final float x = ev.getX(activePointerIndex);
            final float y = (int) ev.getY(activePointerIndex);

            int deltaX = (int) (x - mLastMotionX);

            if(mCaptureItem!=null && mCaptureItem.getTouchMode()== Mode.DRAG){
                mLastMotionX = x;
                mLastMotionY = y;

                //對capture item進行拖拽
                mCaptureItem.trackMotionScroll(deltaX);
            }
            break;
        }

        case MotionEvent.ACTION_UP:
            if(mCaptureItem!=null){
                Mode touchMode = mCaptureItem.getTouchMode();
                if(touchMode== Mode.DRAG){
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    int xVel = (int) velocityTracker.getXVelocity(mActivePointerId);
                    mCaptureItem.fling(xVel);
                }
            }
            cancel();
            break;

        case MotionEvent.ACTION_CANCEL:
            if(mCaptureItem!=null)
                mCaptureItem.revise();

            cancel();
            break;

    }
}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:73,代碼來源:SwipeItemLayout.java

示例14: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    if(mItemHeight == 0) return true;

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    currY = event.getY();

    switch(event.getAction()){
        case MotionEvent.ACTION_DOWN:
            mFlagMayPress = true;
            mHandlerInNewThread.removeMessages(HANDLER_WHAT_REFRESH);
            stopScrolling();
            downY = currY;
            downYGlobal = mCurrDrawGlobalY;
            onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            getParent().requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_MOVE:
            float spanY = downY - currY;

            if(mFlagMayPress && (-mScaledTouchSlop < spanY && spanY < mScaledTouchSlop)){

            }else{
                mFlagMayPress = false;
                mCurrDrawGlobalY = limitY((int)(downYGlobal + spanY));
                calculateFirstItemParameterByGlobalY();
                invalidate();
            }
            onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            break;
        case MotionEvent.ACTION_UP:
            if(mFlagMayPress){
                click(event);
            }else {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000);
                int velocityY = (int) (velocityTracker.getYVelocity() * mFriction);
                if (Math.abs(velocityY) > mMiniVelocityFling) {
                    mScroller.fling(0, mCurrDrawGlobalY, 0, -velocityY,
                            Integer.MIN_VALUE, Integer.MAX_VALUE, limitY(Integer.MIN_VALUE), limitY(Integer.MAX_VALUE));
                    invalidate();
                    onScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                }
                mHandlerInNewThread.sendMessageDelayed(getMsg(HANDLER_WHAT_REFRESH), 0);
                releaseVelocityTracker();
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            downYGlobal = mCurrDrawGlobalY;
            stopScrolling();
            mHandlerInNewThread.sendMessageDelayed(getMsg(HANDLER_WHAT_REFRESH), 0);
            break;
    }
    return true ;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:59,代碼來源:PickerView.java

示例15: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
    public boolean onTouchEvent(MotionEvent ev) {

        initVelocityTrackerIfNotExists();
        mVelocityTracker.addMovement(ev);

        final int action = ev.getAction();
        switch (action & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_DOWN:
                mIsBeingDragged = false;
                mLastMotionY = (int) ev.getY();
                mActivePointerId = ev.getPointerId(0);
                break;
            case MotionEvent.ACTION_MOVE:
                final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
                if (activePointerIndex == -1) {
//                    Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
                    break;
                }

                final int y = (int) ev.getY(activePointerIndex);
                int deltaY = mLastMotionY - y;

                if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {
                    mIsBeingDragged = true;
                    if (deltaY > 0) {
                        deltaY -= mTouchSlop;
                    } else {
                        deltaY += mTouchSlop;
                    }
                }
                if (mIsBeingDragged) {
                    // Scroll to follow the motion event
                    mLastMotionY = y;
                    mFlexibleEffect.onPull((float) deltaY / getHeight());
                    if(!mFlexibleEffect.isFinished()){
                        return true;
                    }

                }

                break;
            case MotionEvent.ACTION_UP:
                if (mIsBeingDragged) {
                    mActivePointerId = INVALID_POINTER;
                    mIsBeingDragged = false;
                    if (mFlexibleEffect != null&&mFlexibleEffect.isPulling()) {
                        mFlexibleEffect.onAbsorb(-1);
                    }
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    currentVelocity = mVelocityTracker.getYVelocity(mActivePointerId);
                    Log.d(TAG, "currentVelocity:"+mVelocityTracker.getYVelocity(mActivePointerId) );
                    recycleVelocityTracker();
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                break;
        }

        return super.onTouchEvent(ev);
    }
 
開發者ID:teisun,項目名稱:SunmiUI,代碼行數:63,代碼來源:FlexibleScrollView.java


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