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


Java VelocityTracker.getXVelocity方法代碼示例

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


在下文中一共展示了VelocityTracker.getXVelocity方法的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: handleTouchActionUp

import android.view.VelocityTracker; //導入方法依賴的package包/類
private void handleTouchActionUp(MotionEvent ev) {
    if (mIsBeingDragged) {
        mIsBeingDragged = false;
        mPointLast.set(ev.getX(), ev.getY());
        int velocityX = 0, velocityY = 0;
        final VelocityTracker velocityTracker = mVelocityTracker;
        if (velocityTracker != null) {
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            velocityX = (int) velocityTracker.getXVelocity();
            velocityY = (int) velocityTracker.getYVelocity();
        }
        if (!flingToWhere((int) (mPointLast.x - mPointDown.x), (int) (mPointLast.y - mPointDown.y), -velocityX, -velocityY)) {
            markAsWillIdle();
        }
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
        mVelocityTracker = null;
    }
}
 
開發者ID:rexyren,項目名稱:PageScrollView,代碼行數:21,代碼來源:PageScrollView.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: onTouchRelease

import android.view.VelocityTracker; //導入方法依賴的package包/類
private void onTouchRelease() {
    final StackCardsView.LayoutParams lp = (StackCardsView.LayoutParams) mTouchChild.getLayoutParams();
    if (lp.fastDismissAllowed) {
        final VelocityTracker velocityTracker2 = mVelocityTracker;
        velocityTracker2.computeCurrentVelocity(1000, mMaxVelocity);
        float xv = velocityTracker2.getXVelocity(mActivePointerId);
        float yv = velocityTracker2.getYVelocity(mActivePointerId);
        if (doFastDisappear(xv, yv)) {
            resetTouch();
            return;
        }
    }
    if (isDistanceAllowDismiss() && isDirectionAllowDismiss()) {
        doSlowDisappear();
    } else {
        animateToInitPos();
    }
    resetTouch();
    mSwipeView.onCoverStatusChanged(isCoverIdle());
}
 
開發者ID:wensefu,項目名稱:StackCardsView,代碼行數:21,代碼來源:SwipeTouchHelper.java

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

示例6: computeOverScroll

import android.view.VelocityTracker; //導入方法依賴的package包/類
/**
 */
@Override
float computeOverScroll(int scrollX, int scrollY, boolean clampedX, boolean clampedY, VelocityTracker tracker, int units) {
	if (scrollX != 0 && clampedX) {
		return tracker.getXVelocity() / (units * 0.05f);
	}
	return 0;
}
 
開發者ID:universum-studios,項目名稱:android_ui,代碼行數:10,代碼來源:HorizontalPullHelper.java

示例7: getXVelocity

import android.view.VelocityTracker; //導入方法依賴的package包/類
protected float getXVelocity(VelocityTracker velocityTracker) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        return velocityTracker.getXVelocity(mActivePointerId);
    }

    return velocityTracker.getXVelocity();
}
 
開發者ID:ultrasonic,項目名稱:ultrasonic,代碼行數:8,代碼來源:DraggableDrawer.java

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

示例9: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    mVelocityTracker.addMovement(event);
    int action = event.getActionMasked();
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            // 此處說明底層沒有子View願意消費Touch事件
            break;

        case MotionEvent.ACTION_MOVE:
            int currentX = (int) event.getX();
            int dx = (int) (currentX - lastX);
            requireScrollChange(dx);
            lastX = currentX;
            break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int velocity = (int) velocityTracker.getXVelocity();
            recycleVelocityTracker();

            onRelease(event.getX(), velocity);
            break;
    }
    return true;
}
 
開發者ID:yangchong211,項目名稱:YCCardView,代碼行數:29,代碼來源:CardViewLayout.java

示例10: getVelocity

import android.view.VelocityTracker; //導入方法依賴的package包/類
private float getVelocity(VelocityTracker vt) {
    return mSwipeDirection == X ? vt.getXVelocity() :
            vt.getYVelocity();
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:5,代碼來源:SwipeHelper.java

示例11: getPerpendicularVelocity

import android.view.VelocityTracker; //導入方法依賴的package包/類
private float getPerpendicularVelocity(VelocityTracker vt) {
    return mSwipeDirection == X ? vt.getYVelocity() :
            vt.getXVelocity();
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:5,代碼來源:SwipeHelper.java

示例12: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (mVelocityTracker == null) {
		mVelocityTracker = VelocityTracker.obtain();
	}
	mVelocityTracker.addMovement(event);
	final int action = event.getAction();
	final float x = event.getX();
	switch (action) {
	case MotionEvent.ACTION_DOWN:
		if (!mScroller.isFinished()) {
			mScroller.abortAnimation();
		}
		mLastMotionX = x;
		break;

	case MotionEvent.ACTION_MOVE:
		int deltaX = (int) (mLastMotionX - x);
		mLastMotionX = x;
		if (!(mCurScreen == 0 && deltaX < 0 || mCurScreen == getChildCount() - 1
				&& deltaX > 0)) {
			scrollBy(deltaX, 0);
		}
		break;

	case MotionEvent.ACTION_UP:
		final VelocityTracker velocityTracker = mVelocityTracker;
		velocityTracker.computeCurrentVelocity(1000);
		int velocityX = (int) velocityTracker.getXVelocity();
		if (velocityX > SNAP_VELOCITY && mCurScreen > 0) {
			snapToScreen(mCurScreen - 1);
		} else if (velocityX < -SNAP_VELOCITY
				&& mCurScreen < getChildCount() - 1) {
			snapToScreen(mCurScreen + 1);
		} else {
			snapToDestination();
		}
		if (mVelocityTracker != null) {
			mVelocityTracker.recycle();
			mVelocityTracker = null;
		}
		mTouchState = TOUCH_STATE_REST;
		break;

	case MotionEvent.ACTION_CANCEL:
		mTouchState = TOUCH_STATE_REST;
		break;
	}
	return true;
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:51,代碼來源:ScrollLayout.java

示例13: getXVelocity

import android.view.VelocityTracker; //導入方法依賴的package包/類
public float getXVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getXVelocity();
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:4,代碼來源:VelocityTrackerCompat.java

示例14: onTouchEvent

import android.view.VelocityTracker; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mShowAll) {
        return false;
    }
    acquireVelocityTracker(event);
    final VelocityTracker velocityTracker = mVelocityTracker;
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mLastX = (int) event.getRawX();
            break;
        case MotionEvent.ACTION_MOVE:
            int offset = (int) (mOffsetX + (event.getRawX() - mLastX));
            offset = checkOffset(offset);
            setOffsetX(offset);
            mLastX = (int) event.getRawX();
            invalidate();
            break;
        case MotionEvent.ACTION_UP:
            velocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
            final float velocityX = velocityTracker.getXVelocity();
            final int initialOffset = mOffsetX;
            ValueAnimator animator = ValueAnimator.ofFloat(velocityX, 0);
            final int duration = 300;
            animator.setDuration(duration);
            animator.setInterpolator(new DecelerateInterpolator());
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float v = (Float) animation.getAnimatedValue();
                    int t = (int) animation.getCurrentPlayTime();
                    int d = (int) (velocityX * duration * 1.0f / 1000 / 2 - v * (duration - t) * 1.0f / 1000 / 2);
                    setOffsetX(checkOffset(initialOffset + d));
                    invalidate();
                }
            });
            animator.start();
            break;
    }
    return true;
}
 
開發者ID:auv1107,項目名稱:CurveView,代碼行數:42,代碼來源:CurveView.java

示例15: getXVelocity

import android.view.VelocityTracker; //導入方法依賴的package包/類
public static float getXVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getXVelocity(pointerId);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:VelocityTrackerCompatHoneycomb.java


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