当前位置: 首页>>代码示例>>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;未经允许,请勿转载。