本文整理汇总了Java中android.support.v4.view.VelocityTrackerCompat.getYVelocity方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityTrackerCompat.getYVelocity方法的具体用法?Java VelocityTrackerCompat.getYVelocity怎么用?Java VelocityTrackerCompat.getYVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.VelocityTrackerCompat
的用法示例。
在下文中一共展示了VelocityTrackerCompat.getYVelocity方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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.getYVelocity(
velocityTracker, mActivePointerId);
mPopulatePending = true;
final int height = getClientHeight();
final int scrollY = getScrollY();
final ItemInfo ii = infoForCurrentScrollPosition();
final int currentPage = ii.position;
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
endDrag();
mFakeDragging = false;
}
示例2: endFakeDragVertically
import android.support.v4.view.VelocityTrackerCompat; //导入方法依赖的package包/类
private void endFakeDragVertically() {
if (mAdapter != null) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
velocityTracker, mActivePointerId);
mPopulatePending = true;
final int height = getClientHeight();
final int scrollY = getScrollY();
final ItemInfo ii = infoForCurrentScrollPosition();
final int currentPage = ii.position;
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
}
endDrag();
mFakeDragging = false;
}
示例3: 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;
}
示例4: 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;
}
示例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.");
}
if (mAdapter != null) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
velocityTracker, mActivePointerId);
mPopulatePending = true;
final int height = getClientHeight();
final int scrollY = getScrollY();
final ItemInfo ii = infoForCurrentScrollPosition();
final int currentPage = ii.position;
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
}
endDrag();
mFakeDragging = false;
}
示例6: 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.getYVelocity(velocityTracker, mActivePointerId);
mPopulatePending = true;
final int height = getClientHeight();
final int scrollY = getScrollY();
final ItemInfo ii = infoForCurrentScrollPosition();
final int currentPage = ii.position;
final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
endDrag();
mFakeDragging = false;
}
示例7: 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.getYVelocity(
velocityTracker, mActivePointerId);
mPopulatePending = true;
final int totalDelta = (int) (mLastMotionX - mInitialMotionX);
final int scrollX = getScrollX();
final int widthWithMargin = getWidth() + mPageMargin;
final int currentPage = scrollX / widthWithMargin;
final float pageOffset = (float) (scrollX % widthWithMargin) / widthWithMargin;
int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, totalDelta);
setCurrentItemInternal(nextPage, true, true, initialVelocity);
endDrag();
mFakeDragging = false;
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: getYVelocity
import android.support.v4.view.VelocityTrackerCompat; //导入方法依赖的package包/类
private float getYVelocity() {
mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
return VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
}
示例12: 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;
}
示例13: getYVelocity
import android.support.v4.view.VelocityTrackerCompat; //导入方法依赖的package包/类
private float getYVelocity() {
this.mVelocityTracker.computeCurrentVelocity(1000, this.mMaximumVelocity);
return VelocityTrackerCompat.getYVelocity(this.mVelocityTracker, this.mActivePointerId);
}