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