当前位置: 首页>>代码示例>>Java>>正文


Java VelocityTracker.obtain方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:29,代码来源:DirectionalViewpager.java

示例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;
}
 
开发者ID:reyanshmishra,项目名称:Rey-MusicPlayer,代码行数:37,代码来源:VelocityViewPager.java

示例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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:36,代码来源:VerticalViewPager.java

示例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);
}
 
开发者ID:xieyangxuejun,项目名称:Views,代码行数:18,代码来源:CoverFlowView.java

示例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();

}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:18,代码来源:BannerView.java

示例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;
}
 
开发者ID:halohoop,项目名称:AndroidDigIn,代码行数:26,代码来源:VelocityTrackerDemoView.java

示例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);
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:19,代码来源:AbstractDragHandler.java

示例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);
    }
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:30,代码来源:CoverFlowView.java

示例9: initOrResetVelocityTracker

import android.view.VelocityTracker; //导入方法依赖的package包/类
private void initOrResetVelocityTracker() {
	if (mVelocityTracker == null) {
		mVelocityTracker = VelocityTracker.obtain();
	} else {
		mVelocityTracker.clear();
	}
}
 
开发者ID:junchenChow,项目名称:exciting-app,代码行数:8,代码来源:AbsHListView.java

示例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);
}
 
开发者ID:Jusenr,项目名称:RX_Demo,代码行数:12,代码来源:SwipeMenuLayout.java

示例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);
}
 
开发者ID:adithya321,项目名称:Instincts-2k17,代码行数:15,代码来源:WheelView.java

示例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);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:14,代码来源:SwipeHelper.java

示例13: initVelocityTrackerIfNotExists

import android.view.VelocityTracker; //导入方法依赖的package包/类
private void initVelocityTrackerIfNotExists() {
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
}
 
开发者ID:yangchong211,项目名称:YCCardView,代码行数:6,代码来源:CardViewLayout.java

示例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;
}
 
开发者ID:aohanyao,项目名称:HorizontalLoopView,代码行数:71,代码来源:HorizontalLoopView.java

示例15: obtainVelocityTracker

import android.view.VelocityTracker; //导入方法依赖的package包/类
private void obtainVelocityTracker() {
    if (mVelocityTracker != null) {
        mVelocityTracker.recycle();
    }
    mVelocityTracker = VelocityTracker.obtain();
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:7,代码来源:ItemTouchHelper.java


注:本文中的android.view.VelocityTracker.obtain方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。