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:com.android.gallery3d.filtershow.FilterShowActivity.java

public boolean dispatchTouchEvent(MotionEvent ev) {
    if (mHandlingSwipeButton) {
        int direction = CategoryView.HORIZONTAL;
        if (mHandledSwipeView instanceof CategoryView) {
            direction = ((CategoryView) mHandledSwipeView).getOrientation();
        }/*w  w w.j a  v  a  2  s.  c o  m*/
        if (ev.getActionMasked() == MotionEvent.ACTION_MOVE) {
            float delta = ev.getY() - mSwipeStartY;
            float distance = mHandledSwipeView.getHeight();
            if (direction == CategoryView.VERTICAL) {
                delta = ev.getX() - mSwipeStartX;
                mHandledSwipeView.setTranslationX(delta);
                distance = mHandledSwipeView.getWidth();
            } else {
                mHandledSwipeView.setTranslationY(delta);
            }
            delta = Math.abs(delta);
            float transparency = Math.min(1, delta / distance);
            mHandledSwipeView.setAlpha(1.f - transparency);
            mHandledSwipeViewLastDelta = delta;
        }
        if (ev.getActionMasked() == MotionEvent.ACTION_CANCEL
                || ev.getActionMasked() == MotionEvent.ACTION_UP) {
            mHandledSwipeView.setTranslationX(0);
            mHandledSwipeView.setTranslationY(0);
            mHandledSwipeView.setAlpha(1.f);
            mHandlingSwipeButton = false;
            float distance = mHandledSwipeView.getHeight();
            if (direction == CategoryView.VERTICAL) {
                distance = mHandledSwipeView.getWidth();
            }
            if (mHandledSwipeViewLastDelta > distance) {
                ((SwipableView) mHandledSwipeView).delete();
            }
        }
        return true;
    }
    return super.dispatchTouchEvent(ev);
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        mIgnoreEvents = true;/*from   w w w . j a  v a2s.  c  o  m*/
        return false;
    }
    int action = MotionEventCompat.getActionMasked(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchingScrollingChild = false;
        mActivePointerId = MotionEvent.INVALID_POINTER_ID;
        // Reset the ignore flag
        if (mIgnoreEvents) {
            mIgnoreEvents = false;
            return false;
        }
        break;
    case MotionEvent.ACTION_DOWN:
        int initialX = (int) event.getX();
        mInitialY = (int) event.getY();
        for (WeakReference<View> scrollableView : scrollableViews) {
            View scroll = scrollableView.get();
            if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) {
                mActivePointerId = event.getPointerId(event.getActionIndex());
                mTouchingScrollingChild = true;
                break;
            }
        }

        mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID
                && !parent.isPointInChildBounds(child, initialX, mInitialY);
        break;
    }
    if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    boolean isPointInChildBounds = false;

    for (WeakReference<View> scrollableView : scrollableViews) {
        isPointInChildBounds = scrollableView.get() != null
                && parent.isPointInChildBounds(scrollableView.get(), (int) event.getX(), (int) event.getY());
        if (isPointInChildBounds) {
            break;
        }
    }

    return action == MotionEvent.ACTION_MOVE && !mIgnoreEvents && mState != STATE_DRAGGING
            && !isPointInChildBounds && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop();
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected boolean isInChartBounds(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    if (x >= (drawingBounds.left + fretNumberBounds.width()) && x < drawingBounds.right) {
        if (y >= (drawingBounds.top + stringMarkerBounds.height()) && y < drawingBounds.bottom) {
            return true;
        }//  ww  w  .  ja  v  a2s .  c  o m
    }
    return false;
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected boolean isInStringMarkerBounds(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    if (x >= drawingBounds.left && x < drawingBounds.right) {
        if (y >= drawingBounds.top && y < (drawingBounds.top + stringMarkerBounds.height())) {
            return true;
        }//from  w w w .j  a  va 2 s. com
    }
    return false;
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected int getSelectedFret(MotionEvent event) {
    int fretStart = chord.getFretStart();
    float y = event.getY();
    int i;/* www .ja va 2s  . c  o m*/
    for (i = 0; i < chord.getFretCount(); i++) {
        if (y < (stringMarkerBounds.bottom + (i * fretSize) + (i * fretMarkerSize))) {
            break;
        }
    }
    i = (fretStart < 0) ? i : (fretStart - 1) + i;
    return i;
}

From source file:com.android.mail.browse.ConversationItemView.java

/**
 * ConversationItemView is given the first chance to handle touch events.
 *///from  w ww .  ja  v  a  2s.co  m
@Override
public boolean onTouchEvent(MotionEvent event) {
    Utils.traceBeginSection("on touch event");
    int x = (int) event.getX();
    int y = (int) event.getY();
    if (!mSwipeEnabled) {
        Utils.traceEndSection();
        return onTouchEventNoSwipe(event);
    }
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (isTouchInContactPhoto(x, y) || isTouchInInfoIcon(x, y) || isTouchInStar(x, y)) {
            mDownEvent = true;
            Utils.traceEndSection();
            return true;
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mDownEvent) {
            if (isTouchInContactPhoto(x, y)) {
                // Touch on the check mark
                Utils.traceEndSection();
                mDownEvent = false;
                toggleCheckedState();
                Utils.traceEndSection();
                return true;
            } else if (isTouchInInfoIcon(x, y)) {
                // Touch on the info icon
                mDownEvent = false;
                if (mConversationItemAreaClickListener != null) {
                    mConversationItemAreaClickListener.onInfoIconClicked();
                }
                Utils.traceEndSection();
                return true;
            } else if (isTouchInStar(x, y)) {
                // Touch on the star
                mDownEvent = false;
                if (mConversationItemAreaClickListener == null) {
                    toggleStar();
                } else {
                    mConversationItemAreaClickListener.onStarClicked();
                }
                Utils.traceEndSection();
                return true;
            }
        }
        break;
    }
    // Let View try to handle it as well.
    boolean handled = super.onTouchEvent(event);
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        Utils.traceEndSection();
        return true;
    }
    Utils.traceEndSection();
    return handled;
}

From source file:androidVNC.VncCanvasActivity.java

boolean trackballMouse(MotionEvent evt) {
    int dx = convertTrackballDelta(evt.getX());
    int dy = convertTrackballDelta(evt.getY());

    evt.offsetLocation(vncCanvas.mouseX + dx - evt.getX(), vncCanvas.mouseY + dy - evt.getY());

    if (vncCanvas.processPointerEvent(evt, trackballButtonDown)) {
        return true;
    }//from   w  ww. ja  v  a2  s .c  o  m
    return VncCanvasActivity.super.onTouchEvent(evt);
}

From source file:com.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (!isEnabled() || !mIsSlidingEnabled || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();//from www.j a  v a 2  s  .  com
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

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

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int dragSlop = mDragHelper.getTouchSlop();

        // Handle any horizontal scrolling on the drag view.
        if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) {
            return super.onInterceptTouchEvent(ev);
        }

        if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, (int) mInitialMotionY)) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
        break;
    }
    }

    return mDragHelper.shouldInterceptTouchEvent(ev);
}

From source file:aksha.upcomingdemo.HorizontalListView.java

protected boolean onDown(MotionEvent e) {
    // If the user just caught a fling, then disable all touch actions until they release their finger
    mBlockTouchAction = !mFlingTracker.isFinished();

    // Allow a finger down event to catch a fling
    mFlingTracker.forceFinished(true);/*from  www .  ja  va2s  .co  m*/
    setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE);

    unpressTouchedChild();

    if (!mBlockTouchAction) {
        // Find the child that was pressed
        final int index = getChildIndex((int) e.getX(), (int) e.getY());
        if (index >= 0) {
            // Save off view being touched so it can later be released
            mViewBeingTouched = getChildAt(index);

            if (mViewBeingTouched != null) {
                // Set the view as pressed
                mViewBeingTouched.setPressed(true);
                refreshDrawableState();
            }
        }
    }

    return true;
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

protected boolean isInFretNumberBounds(MotionEvent event) {
    if (showFretNumbers) {
        float x = event.getX();
        float y = event.getY();
        if (x >= drawingBounds.left && x < (drawingBounds.left + fretNumberBounds.width())) {
            if (y >= drawingBounds.top && y < drawingBounds.bottom) {
                return true;
            }/*from   www.ja  va 2 s . c om*/
        }
    }
    return false;
}