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.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private TouchableUrlSpan getPressedSpan(Spannable spannable, MotionEvent event) {

    int x = (int) event.getX();
    int y = (int) event.getY();

    x -= getPaddingLeft();/*from   w w  w .j av a 2  s .  co  m*/
    y -= getPaddingTop();

    x += getScrollX();
    y += getScrollY();

    int line = layout.getLineForVertical(y);
    int off = layout.getOffsetForHorizontal(line, x);

    TouchableUrlSpan[] link = spannable.getSpans(off, off, TouchableUrlSpan.class);
    TouchableUrlSpan touchedSpan = null;
    if (link.length > 0) {
        touchedSpan = link[0];
    }
    return touchedSpan;
}

From source file:com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Receives hover events when touch exploration is turned on in SDK versions
 * ICS and higher.//from   www  .j  a  va  2s .  c  om
 *
 * @param event The hover event.
 * @return {@code true} if the event is handled
 */
public boolean dispatchHoverEvent(MotionEvent event, PointerTracker tracker) {
    final int x = (int) event.getX();
    final int y = (int) event.getY();
    final Key previousKey = mLastHoverKey;
    final Key key;

    if (pointInView(x, y)) {
        key = tracker.getKeyOn(x, y);
    } else {
        key = null;
    }

    mLastHoverKey = key;

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_EXIT:
        // Make sure we're not getting an EXIT event because the user slid
        // off the keyboard area, then force a key press.
        if (key != null) {
            getAccessibilityNodeProvider().simulateKeyPress(key);
        }
        //$FALL-THROUGH$
    case MotionEvent.ACTION_HOVER_ENTER:
        return onHoverKey(key, event);
    case MotionEvent.ACTION_HOVER_MOVE:
        if (key != previousKey) {
            return onTransitionKey(key, previousKey, event);
        } else {
            return onHoverKey(key, event);
        }
    }

    return false;
}

From source file:com.barchart.tester.pager.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    // We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mInitialTouch.x = (int) ev.getX();
        mInitialTouch.y = (int) ev.getY();
    default://  www .  jav  a 2  s.co m
        ev.offsetLocation(mCenter.x - mInitialTouch.x, mCenter.y - mInitialTouch.y);
        break;
    }

    return mPager.dispatchTouchEvent(ev);
}

From source file:br.com.cybereagle.androidwidgets.view.PagerContainer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    //We capture any touches not already handled by the ViewPager
    // to implement scrolling from a touch outside the pager bounds.
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        initialTouch.x = (int) ev.getX();
        initialTouch.y = (int) ev.getY();
    default:/*from ww  w .  j ava  2  s .  c  o  m*/
        ev.offsetLocation(center.x - initialTouch.x, center.y - initialTouch.y);
        break;
    }

    return pager.dispatchTouchEvent(ev);
}

From source file:com.android.calculator2.CalculatorPadViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean shouldIntercept = super.onInterceptTouchEvent(ev);

    // Only allow the current item to receive touch events.
    if (!shouldIntercept && ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
        final int x = (int) ev.getX() + getScrollX();
        final int y = (int) ev.getY() + getScrollY();

        final int childCount = getChildCount();
        for (int i = childCount - 1; i >= 0; --i) {
            final int childIndex = getChildDrawingOrder(childCount, i);
            final View child = getChildAt(childIndex);
            if (child.getVisibility() == View.VISIBLE && x >= child.getLeft() && x < child.getRight()
                    && y >= child.getTop() && y < child.getBottom()) {
                shouldIntercept = (childIndex != getCurrentItem());
                break;
            }/*from   w  w w .  ja v a  2  s  .c o  m*/
        }
    }

    return shouldIntercept;
}

From source file:akhil.alltrans.NestedScrollingListView.java

/**
 *
 * @see android.support.v4.widget.NestedScrollView#onTouchEvent(MotionEvent)
 *///from w  w w .j  ava  2  s  .c  o  m
@Override
public boolean onTouchEvent(MotionEvent ev) {
    boolean returnValue = false;

    MotionEvent event = MotionEvent.obtain(ev);
    final int action = MotionEventCompat.getActionMasked(event);
    if (action == MotionEvent.ACTION_DOWN) {
        mNestedOffsetY = 0;
    }
    event.offsetLocation(0, mNestedOffsetY);
    int eventY = (int) event.getY();
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastY - eventY;
        // NestedPreScroll
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            mLastY = eventY - mScrollOffset[1];
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
        }
        returnValue = super.onTouchEvent(event);

        // NestedScroll
        if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
            event.offsetLocation(0, mScrollOffset[1]);
            mNestedOffsetY += mScrollOffset[1];
            mLastY -= mScrollOffset[1];
        }
        break;
    case MotionEvent.ACTION_DOWN:
        returnValue = super.onTouchEvent(event);
        mLastY = eventY;
        // start NestedScroll
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    case MotionEvent.ACTION_UP:
        // TODO: fling
        returnValue = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_CANCEL:
        returnValue = super.onTouchEvent(event);
        // end NestedScroll
        stopNestedScroll();
        break;
    }
    return returnValue;
}

From source file:com.cssweb.android.view.FTrendView.java

public void touchesEnded(MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();
    if (x < axisLabelWidth || x > width)
        return;/*from www. j a  va  2  s .com*/
    if (y < this.axisLabelHeight || y > height - this.axisLabelHeight)
        return;
    isTouched = false;
    if (isTouchMoved == false) {
        isTouchMoved = false;
        isTrackStatus = !isTrackStatus;
        if (isTrackStatus) {//??
            if (x > axisLabelWidth && x < width)
                trackLineV = x;

            int idx = (int) ((x - axisLabelWidth) / SPACE);
            if (idx < dataLen && idx >= 0) {
                isTrackNumber = begin + idx;
                trackLineV = (int) (axisLabelWidth + idx * SPACE);
            } else {
                if (idx < 0) {
                    isTrackNumber = 0;
                    trackLineV = axisLabelWidth;
                }
                if (idx >= dataLen) {
                    isTrackNumber = dataLen - 1;
                    trackLineV = (int) (axisLabelWidth + (dataLen - 1) * SPACE);
                }
            }
        }
    }
    /**
     * ?Android SDK api
     *   invalidate ?View
     */
    this.invalidate();
}

From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardViewWithMiniKeyboard.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent me) {
    if (getMiniKeyboard() != null && mMiniKeyboardPopup.isShowing()) {
        final int miniKeyboardX = (int) me.getX();
        final int miniKeyboardY = (int) me.getY();
        final int action = MotionEventCompat.getActionMasked(me);

        MotionEvent translated = generateMiniKeyboardMotionEvent(action, miniKeyboardX, miniKeyboardY,
                me.getEventTime());//from  w w  w.  jav a  2  s  .  c  om
        getMiniKeyboard().onTouchEvent(translated);
        translated.recycle();
        return true;
    }

    return super.onTouchEvent(me);
}

From source file:akhil.alltrans.NestedScrollingMarkDownView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean result = false;

    MotionEvent trackedEvent = MotionEvent.obtain(event);

    final int action = MotionEventCompat.getActionMasked(event);

    if (action == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;/*from  w  ww. j a  v  a  2 s . c  om*/
    }

    int y = (int) event.getY();

    event.offsetLocation(0, mNestedYOffset);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        result = super.onTouchEvent(event);
        break;
    case MotionEvent.ACTION_MOVE:
        int deltaY = mLastMotionY - y;

        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            trackedEvent.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }

        int oldY = getScrollY();
        mLastMotionY = y - mScrollOffset[1];
        if (deltaY < 0) {
            int newScrollY = Math.max(0, oldY + deltaY);
            deltaY -= newScrollY - oldY;
            if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
                mLastMotionY -= mScrollOffset[1];
                trackedEvent.offsetLocation(0, mScrollOffset[1]);
                mNestedYOffset += mScrollOffset[1];
            }
        }

        result = super.onTouchEvent(trackedEvent);
        trackedEvent.recycle();
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        stopNestedScroll();
        result = super.onTouchEvent(event);
        break;
    }
    return result;
}

From source file:com.cssweb.android.view.FTrendView.java

public void touchesMoved(MotionEvent event) {
    currentPositionX = event.getX();//from  www . j  a  v a 2  s . co m
    currentPositionY = event.getY();
    float deltaX = startPositionX - currentPositionX;
    float deltaY = startPositionY - currentPositionY;
    if (Math.abs(deltaX) < 8 && Math.abs(deltaY) < 8) {
        isTouchMoved = false;
    } else {
        isTouchMoved = true;
    }
    if (isTrackStatus) {
        double sep = SPACE;
        int idx = (int) ((currentPositionX - axisLabelWidth) / sep);
        if (idx < dataLen && idx >= 0) {
            if (currentPositionX >= axisLabelWidth || currentPositionX <= width) {
                trackLineV = (int) (axisLabelWidth + idx * SPACE);
            }
            isTrackNumber = begin + idx;
            if (isTrackNumber >= dataLen) {
                isTrackNumber = dataLen - 1;
            }
        } else {
            if (idx < 0) {
                idx = 0;
                isTrackNumber = begin + idx;
                trackLineV = axisLabelWidth;
            }
            if (idx >= dataLen) {
                isTrackNumber = dataLen - 1;
                trackLineV = (int) (axisLabelWidth + (dataLen - 1) * SPACE);
            }
        }
    }
    /**
     * ?Android SDK api
     *   invalidate ?View
     */
    this.invalidate();
}