本文整理匯總了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();
}