Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

In this page you can find the example usage for android.view MotionEvent getY.

Prototype

public final float getY() 

Source Link

Document

#getY(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:dk.ciid.android.infobooth.activities.SubscriptionFinalActivity.java

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    try {/*from  w  w  w  .  ja  v a2  s .  c  o  m*/
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
            return false;
        // right to left swipe, previous
        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            // go to the next screen
            changeActivity("dk.ciid.android.infobooth.activities.INTRODUCTIONACTIVITY");

        }
        // left to right swipe, next 
        else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            // go to the next screen
            changeActivity("dk.ciid.android.infobooth.activities.INTRODUCTIONACTIVITY");
        }
        // bottom to top swipe            
        else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        }
        // top to bottom swipe      
        else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        }
    } catch (Exception e) {
        // nothing
    }

    return true;
}

From source file:android.support.designox.widget.HeaderBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//from  ww  w.j  a  va  2  s . co m

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) MotionEventCompat.getY(ev, activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(ev);
    }

    return true;
}

From source file:cn.ieclipse.af.view.ScrollLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (debug) {//from  ww w  . j a v a2  s. com
        Log.e(TAG, "onInterceptTouchEvent-slop:" + mTouchSlop);
    }

    final int action = ev.getAction();
    if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
        return true;
    }

    final float x = ev.getX();
    final float y = ev.getY();

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        final int xDiff = (int) Math.abs(mLastMotionX - x);
        if (xDiff > mTouchSlop) {
            mTouchState = TOUCH_STATE_SCROLLING;

        }
        break;

    case MotionEvent.ACTION_DOWN:
        mLastMotionX = x;
        mLastMotionY = y;
        mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
        break;

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        mTouchState = TOUCH_STATE_REST;
        break;
    }

    return mTouchState != TOUCH_STATE_REST;
}

From source file:android.support.design.widget.HeaderBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }/* w w w. java2  s .c om*/

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();

        if (parent.isPointInChildBounds(child, x, y) && canDragView(child)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        } else {
            return false;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
        if (activePointerIndex == -1) {
            return false;
        }

        final int y = (int) ev.getY(activePointerIndex);
        int dy = mLastMotionY - y;

        if (!mIsBeingDragged && Math.abs(dy) > mTouchSlop) {
            mIsBeingDragged = true;
            if (dy > 0) {
                dy -= mTouchSlop;
            } else {
                dy += mTouchSlop;
            }
        }

        if (mIsBeingDragged) {
            mLastMotionY = y;
            // We're being dragged so scroll the ABL
            scroll(parent, child, dy, getMaxDragOffset(child), 0);
        }
        break;
    }

    case MotionEvent.ACTION_UP:
        if (mVelocityTracker != null) {
            mVelocityTracker.addMovement(ev);
            mVelocityTracker.computeCurrentVelocity(1000);
            float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
            fling(parent, child, -getScrollRangeForDragFling(child), 0, yvel);
        }
        // $FALLTHROUGH
    case MotionEvent.ACTION_CANCEL: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(ev);
    }

    return true;
}

From source file:android.support.design.widget.SwipeDismissBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    boolean dispatchEventToHelper = mInterceptingEvents;

    switch (MotionEventCompat.getActionMasked(event)) {
    case MotionEvent.ACTION_DOWN:
        mInterceptingEvents = parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY());
        dispatchEventToHelper = mInterceptingEvents;
        break;//from www.  j  a v  a2 s .  c  o  m
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        // Reset the ignore flag for next time
        mInterceptingEvents = false;
        break;
    }

    if (dispatchEventToHelper) {
        ensureViewDragHelper(parent);
        return mViewDragHelper.shouldInterceptTouchEvent(event);
    }
    return false;
}

From source file:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    initVelocityTrackerIfNotExists();//from  w w w. j a va2s. c o  m
    mVelocityTracker.addMovement(event);

    float currentTouchY = event.getY();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mOverScroller.isFinished()) {
            mOverScroller.abortAnimation();
        }

        mLastTouchY = currentTouchY;
        break;
    case MotionEvent.ACTION_MOVE:
        float differentY = currentTouchY - mLastTouchY;
        mLastTouchY = currentTouchY;
        if (Math.abs(differentY) > 0) {
            scrollBy(0, (int) -differentY);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        recycleVelocityTracker();
        if (!mOverScroller.isFinished()) {
            mOverScroller.abortAnimation();
        }
        break;
    case MotionEvent.ACTION_UP:
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        int initialVelocity = (int) mVelocityTracker.getYVelocity();
        if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
            fling(-initialVelocity);
        }
        recycleVelocityTracker();
        break;
    }
    return true;
}

From source file:cn.colink.commumication.swipelistview.SwipeListView.java

/**
 * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent)
 *///  ww  w. ja  v a2  s.c  om
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (touchState == TOUCH_STATE_SCROLLING_X) {
        return touchListener.onTouch(this, ev);
    }

    switch (action) {
    case MotionEvent.ACTION_MOVE:
        checkInMoving(x, y);
        return touchState == TOUCH_STATE_SCROLLING_Y;
    case MotionEvent.ACTION_DOWN:
        touchListener.onTouch(this, ev);
        touchState = TOUCH_STATE_REST;
        lastMotionX = x;
        lastMotionY = y;
        return false;
    case MotionEvent.ACTION_CANCEL:
        touchState = TOUCH_STATE_REST;
        break;
    case MotionEvent.ACTION_UP:
        touchListener.onTouch(this, ev);
        return touchState == TOUCH_STATE_SCROLLING_Y;
    default:
        break;
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

private void trackTouchEvent(MotionEvent event) {
    final int paddingTop = super.getPaddingTop();
    final int paddingBottom = super.getPaddingBottom();
    final int height = getHeight();

    final int available = height - paddingTop - paddingBottom;
    int y = (int) event.getY();

    final float scale;
    float value = 0;

    switch (mRotationAngle) {
    case ROTATION_ANGLE_CW_90:
        value = y - paddingTop;/*from   w ww.j ava  2  s  . c  o  m*/
        break;
    case ROTATION_ANGLE_CW_270:
        value = (height - paddingTop) - y;
        break;
    }

    if (value < 0 || available == 0) {
        scale = 0.0f;
    } else if (value > available) {
        scale = 1.0f;
    } else {
        scale = value / (float) available;
    }

    final int max = getMax();
    final float progress = scale * max;

    setProgress((int) progress, true);
}

From source file:com.jest.phone.PhoneActivity.java

@Override
public boolean onTouch(View arg0, MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // Start gesture
        firstFinger = new PointF(event.getX(), event.getY());
        mode = ONE_FINGER_DRAG;// w  w  w  .j a v  a  2 s  . c  o m
        stopThread = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_POINTER_DOWN: // second finger
        distBetweenFingers = spacing(event);
        // the distance check is done to avoid false alarms
        if (distBetweenFingers > 5f) {
            mode = TWO_FINGERS_DRAG;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == ONE_FINGER_DRAG) {
            PointF oldFirstFinger = firstFinger;
            firstFinger = new PointF(event.getX(), event.getY());
            scroll(oldFirstFinger.x - firstFinger.x);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();

        } else if (mode == TWO_FINGERS_DRAG) {
            float oldDist = distBetweenFingers;
            distBetweenFingers = spacing(event);
            zoom(oldDist / distBetweenFingers);
            sensorHistoryPlot.setDomainBoundaries(minXY.x, maxXY.x, BoundaryMode.FIXED);
            sensorHistoryPlot.redraw();
        }
        break;
    }
    return true;
}

From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    try {//from  www .jav  a  2s. co  m
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
            return false;

        // right to left swipe
        if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            // go to the next screen
            changeActivity("dk.ciid.android.infobooth.activities.INFORMATIONSERVICEACTIVITY");
        }
        // left to right swipe    
        else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        }
        // bottom to top swipe            
        else if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            // top to bottom swipe               
        } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        }
    } catch (Exception e) {
        // nothing
    }

    return true;
}