本文整理汇总了Java中android.view.VelocityTracker.obtain方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityTracker.obtain方法的具体用法?Java VelocityTracker.obtain怎么用?Java VelocityTracker.obtain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.VelocityTracker
的用法示例。
在下文中一共展示了VelocityTracker.obtain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beginFakeDrag
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* Start a fake drag of the pager.
*
* @return true if the fake drag began successfully, false if it could not be started.
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
if (isHorizontal()) {
mInitialMotionX = mLastMotionX = 0;
} else {
mInitialMotionY = mLastMotionY = 0;
}
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例2: beginFakeDrag
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* Start a fake drawable_drag of the pager.
*
* <p>A fake drawable_drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drawable_drag motion. Call
* {@link #endFakeDrag()} to complete the fake drawable_drag and fling as necessary.
*
* <p>During a fake drawable_drag the ViewPager will ignore all touch events. If a real drawable_drag
* is already in progress, this method will return false.
*
* @return true if the fake drawable_drag began successfully, false if it could not be started.
*
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionX = mLastMotionX = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例3: beginFakeDrag
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* Start a fake drag of the pager.
* <p/>
* <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
* with the touch scrolling of another view, while still letting the ViewPager
* control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
* Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
* {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
* <p/>
* <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
* is already in progress, this method will return false.
*
* @return true if the fake drag began successfully, false if it could not be started.
* @see #fakeDragBy(float)
* @see #endFakeDrag()
*/
public boolean beginFakeDrag() {
if (mIsBeingDragged) {
return false;
}
mFakeDragging = true;
setScrollState(SCROLL_STATE_DRAGGING);
mInitialMotionY = mLastMotionY = 0;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
final long time = SystemClock.uptimeMillis();
final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
mVelocityTracker.addMovement(ev);
ev.recycle();
mFakeDragBeginTime = time;
return true;
}
示例4: touchBegan
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void touchBegan(MotionEvent event) {
endAnimation();
float x = event.getX();
mTouchStartX = x;
mTouchStartY = event.getY();
mStartTime = AnimationUtils.currentAnimationTimeMillis();
mStartOffset = mOffset;
mTouchMoved = false;
mTouchStartPos = (x / mWidth) * MOVE_POS_MULTIPLE - 5;
mTouchStartPos /= 2;
mVelocity = VelocityTracker.obtain();
mVelocity.addMovement(event);
}
示例5: BannerView
import android.view.VelocityTracker; //导入方法依赖的package包/类
public BannerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setOnClickListener(this);
mScroller = new Scroller(context);
mVelocityTracker = VelocityTracker.obtain();
final ViewConfiguration configuration = ViewConfiguration.get(context);
final float density = context.getResources().getDisplayMetrics().density;
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.BannerView);
mHorizontalOffset = array.getDimension(R.styleable.BannerView_horizontal_offset, 0);
mVerticalOffset = array.getDimension(R.styleable.BannerView_vertical_offset, 0);
duration = array.getInt(R.styleable.BannerView_scroll_duration, 500);
array.recycle();
}
示例6: onTouchEvent
import android.view.VelocityTracker; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mVelocityTracker != null) {
mVelocityTracker.addMovement(event);
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mVelocityTracker = VelocityTracker.obtain();
mMaxVelocity = ViewConfiguration.get(getContext()).getMaximumFlingVelocity();
mPointerId = event.getPointerId(0);
break;
case MotionEvent.ACTION_MOVE:
//求伪瞬时速度
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
final float velocityX = mVelocityTracker.getXVelocity(mPointerId);
final float velocityY = mVelocityTracker.getYVelocity(mPointerId);
updateData(velocityX, velocityY);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
releaseVelocityTracker();
break;
}
return true;
}
示例7: handleDown
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* Handles, when a drag gesture has been started.
*
* @param event
* The motion event, which started the drag gesture, as an instance of the class {@link
* MotionEvent}. The motion event may not be null
*/
private void handleDown(@NonNull final MotionEvent event) {
pointerId = event.getPointerId(0);
if (velocityTracker == null) {
velocityTracker = VelocityTracker.obtain();
} else {
velocityTracker.clear();
}
velocityTracker.addMovement(event);
}
示例8: touchBegan
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void touchBegan(MotionEvent event) {
endAnimation();
float x = event.getX();
mTouchStartX = x;
mTouchStartY = event.getY();
mStartTime = AnimationUtils.currentAnimationTimeMillis();
mStartOffset = mOffset;
mTouchMoved = false;
mTouchStartPos = (mTouchStartY / mHeight) * MOVE_POS_MULTIPLE - 5;
mTouchStartPos /= 2;
mVelocity = VelocityTracker.obtain();
mVelocity.addMovement(event);
// float x = event.getX();
// mTouchStartX = x;
// mTouchStartY = event.getY();
// mStartTime = AnimationUtils.currentAnimationTimeMillis();
// mStartOffset = mOffset;
//
// mTouchMoved = false;
//
// mTouchStartPos = (x / mWidth) * MOVE_POS_MULTIPLE - 5;
// mTouchStartPos /= 2;
//
// mVelocity = VelocityTracker.obtain();
// mVelocity.addMovement(event);
}
示例9: initOrResetVelocityTracker
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void initOrResetVelocityTracker() {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
}
示例10: acquireVelocityTracker
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* @param event 向VelocityTracker添加MotionEvent
* @see VelocityTracker#obtain()
* @see VelocityTracker#addMovement(MotionEvent)
*/
private void acquireVelocityTracker(final MotionEvent event) {
if (null == mVelocityTracker) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
}
示例11: startWheelDrag
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void startWheelDrag(MotionEvent event, float x, float y) {
mIsDraggingWheel = true;
mDraggedAngle = 0f;
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
} else {
mVelocityTracker.clear();
}
mVelocityTracker.addMovement(event);
mAngularVelocity = 0f;
mLastTouchAngle = mWheelBounds.angleToDegrees(x, y);
}
示例12: SwipeHelper
import android.view.VelocityTracker; //导入方法依赖的package包/类
SwipeHelper(int swipeDirection, Callback callback, Context context) {
mCallback = callback;
mHandler = new Handler();
mSwipeDirection = swipeDirection;
mVelocityTracker = VelocityTracker.obtain();
mDensityScale = context.getResources().getDisplayMetrics().density;
mPagingTouchSlop = ViewConfiguration.get(context).getScaledPagingTouchSlop();
mLongPressTimeout = (long) (ViewConfiguration.getLongPressTimeout() * 1.5f); // extra long-press!
mFalsingThreshold = context.getResources().getDimensionPixelSize(
R.dimen.swipe_helper_falsing_threshold);
mFlingAnimationUtils = new FlingAnimationUtils(context, getMaxEscapeAnimDuration() / 1000f);
}
示例13: initVelocityTrackerIfNotExists
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void initVelocityTrackerIfNotExists() {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
}
示例14: onTouchEvent
import android.view.VelocityTracker; //导入方法依赖的package包/类
/**
* finding whether to scroll or not
*/
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
final int x = (int) ev.getX();
//按下
if (action == MotionEvent.ACTION_DOWN) {
stateMode = CLICK_MODE;
//动画未完成 直接结束
if (!mScroller.isFinished()) {
mScroller.abortAnimation();
}
}
if (stateMode == NO_MODE)
return super.onTouchEvent(ev);
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(ev);
switch (action) {
case MotionEvent.ACTION_DOWN:
mFirstX = x;
break;
case MotionEvent.ACTION_MOVE:
//偏移量大于10 代表是在滑动找那个
if (Math.abs(mFirstX - x) > 10) {
stateMode = DRAG_MODE;
}
//计算滚动位置
mScrollX += mLastX - x;
//滚动到相应的位置
reScrollTo(mScrollX, 0);
break;
case MotionEvent.ACTION_UP:
//获得速度追踪器
final VelocityTracker velocityTracker = mVelocityTracker;
//调用滑动 300ms
velocityTracker.computeCurrentVelocity(300);
//获得初始速度
int initialVelocity = (int) Math.min(velocityTracker.getXVelocity(), mMaximumVelocity);
//当前的初始速度大于最小速度->滚动
if (getChildCount() > 0 && Math.abs(initialVelocity) > mMinimumVelocity) {
//滚动
fling(-initialVelocity);
//赋值当前模式为滑动模式
stateMode = FLING_MODE;
} else {
//点击
if (stateMode == CLICK_MODE) {
//处理点击
clickFunction(ev);
} else {
//移动一格
stateMode = MOVE_CENTER_MODE;
//选中位置
selectPosition(getChildCount() / 2);
}
}
case MotionEvent.ACTION_CANCEL:
default:
}
mLastX = x;
return true;
}
示例15: obtainVelocityTracker
import android.view.VelocityTracker; //导入方法依赖的package包/类
private void obtainVelocityTracker() {
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
}
mVelocityTracker = VelocityTracker.obtain();
}