Android VelocityTracker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android VelocityTracker class.

This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, getYVelocity, recycle
 
	public void ForwardTouchEvent(MotionEvent ev) {
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } 
        mVelocityTracker.addMovement(ev);
 
        if (ev.getAction() == MotionEvent.ACTION_UP) {
            mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int velocityX = (int) mVelocityTracker.getXVelocity();
            final int velocityY = (int) mVelocityTracker.getYVelocity();
 
            if (mListener != null) {
            	int Direction = FLING_NONE;
	            if (velocityX > SNAP_VELOCITY) {
	            	Direction = FLING_LEFT;
	            } else if (velocityX < -SNAP_VELOCITY) {
	            	Direction = FLING_RIGHT;
	            } else if (velocityY > SNAP_VELOCITY) {
	            	Direction = FLING_DOWN;

8
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, recycle
		} 
		 
		if (mVelocityTracker == null) {
			mVelocityTracker = VelocityTracker.obtain();
		} 
		mVelocityTracker.addMovement(event);
		final int action = event.getAction();
		final float x = event.getX();
		final float y = event.getY();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			//Log.e(TAG, "event down!"); 
			if (!mScroller.isFinished()) {
				mScroller.abortAnimation();
			} 
			mLastMotionX = x;
			 
			//---------------New Code---------------------- 
			mLastMotionY = y;
			//--------------------------------------------- 

8
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, getYVelocity, recycle
            return true; 
        } 
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } 
        mVelocityTracker.addMovement(event);
 
        final int height = getHeight();
 
        final int eventX = isHoriz() ?
                (int) event.getX():
                height - ((int) event.getY());
        final int hitWindow = mDimpleWidth;
 
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                if (DBG) log("touch-down");
                mTriggered = false;
                if (mGrabbedState != NOTHING_GRABBED) {

8
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity
        return x > thumbLeft && x < thumbRight && y > thumbTop && y < thumbBottom;
    } 
 
    @Override 
    public boolean onTouchEvent(MotionEvent ev) {
        mVelocityTracker.addMovement(ev);
        final int action = ev.getActionMasked();
        switch (action) {
            case MotionEvent.ACTION_DOWN: {
                final float x = ev.getX();
                final float y = ev.getY();
                if (isEnabled() && hitThumb(x, y)) {
                    mTouchMode = TOUCH_MODE_DOWN;
                    mTouchX = x;
                    mTouchY = y;
                } 
                break; 
            } 
 
            case MotionEvent.ACTION_MOVE: {

7
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, getYVelocity
7
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, recycle
        } 
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } 
 
        mVelocityTracker.addMovement(event);
 
        final int action = event.getAction();
        final float x = event.getX();
        final float y = event.getY();
 
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mLastMotionX = x;
            mLastMotionY = y;
            isDragging = true;
            break; 
        case MotionEvent.ACTION_MOVE:
            if (!isDragging) {
                final int xDiff = (int) Math.abs(x - mLastMotionX);

7
CodeRank
This code example shows how to use the following methods:addMovement
        addMotionEvent(vt, endX, endY, startime + duration, MotionEvent.ACTION_UP);
    } 
 
    private void addMotionEvent(VelocityTracker vt, int x, int y, long time, int action) {
        MotionEvent me = MotionEvent.obtain(time, time, action, x, y, 0);
        vt.addMovement(me);
        me.recycle();
    } 
 
    /** 
     * Float imprecision of the average computations and filtering 
     * (removing last MotionEvent for N > 3) implies that tests 
     *  accepts some approximated values. 
     */ 
    private void assertEqualFuzzy(float expected, float actual, float threshold) {
        boolean fuzzyEqual = actual >= expected - threshold && actual <= expected + threshold;
        Assert.assertTrue("Expected: <"+expected+"> but was: <"+actual+
                "> while accepting a variation of: <"+threshold+">", fuzzyEqual);
    } 
 
7
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, getYVelocity, recycle
        final float y = event.getY();
 
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } 
        mVelocityTracker.addMovement(event);
 
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                mZoomControl.stopFling();
                v.postDelayed(mLongPressRunnable, mLongPressTimeout);
                mDownX = x;
                mDownY = y;
                mX = x;
                mY = y;
                break; 
 
            case MotionEvent.ACTION_MOVE: {
                final float dx = (x - mX) / v.getWidth();
                final float dy = (y - mY) / v.getHeight();

7
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, getYVelocity
     * Feed all touch events we receive to the detector for 
     * processing. 
     */ 
    @Override 
    public boolean onTouchEvent(MotionEvent event) {
        mVelocityTracker.addMovement(event);
 
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // We've already stored the initial point, 
                // but if we got here a child view didn't capture 
                // the event, so we need to. 
                return true; 
            case MotionEvent.ACTION_MOVE:
                final float x = event.getX();
                final float y = event.getY();
                float deltaY = mLastTouchY - y;
                float deltaX = mLastTouchX - x;
                //Check for slop on direct events 
                if (!mDragging && (Math.abs(deltaY) > mTouchSlop || Math.abs(deltaX) > mTouchSlop) ) {

7
CodeRank
This code example shows how to use the following methods:addMovement, computeCurrentVelocity, getXVelocity, recycle
    public boolean onTouchEvent(final MotionEvent event) {
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } 
 
        mVelocityTracker.addMovement(event);
 
        final int action = event.getAction();
        final float x = event.getX();
        final float y = event.getY();
 
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            if (!scroller.isFinished()) {
                scroller.abortAnimation();
            } 
 
            mLastMotionX = x;
            mLastMotionY = y;
            isDragging = true;

7
CodeRank

Related Android VelocityTracker Questions & Answers:

See Code Examples for Android VelocityTracker Methods: