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.canyinghao.canrefresh.CanRefreshLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {

    switch (e.getAction()) {

    case MotionEvent.ACTION_DOWN:

        directionY = e.getY();
        directionX = e.getX();/*  w w w.  j  a  v a2  s.  c  om*/

        break;

    case MotionEvent.ACTION_MOVE:

        if (directionY <= 0 || directionX <= 0) {

            break;
        }

        float eventY = e.getY();
        float eventX = e.getX();

        float offY = eventY - directionY;
        float offX = eventX - directionX;

        directionY = eventY;
        directionX = eventX;

        boolean moved = Math.abs(offY) > Math.abs(offX);

        if (offY > 0 && moved && canRefresh()) {
            isUpOrDown = NO_SCROLL_UP;
        } else if (offY < 0 && moved && canLoadMore()) {

            isUpOrDown = NO_SCROLL_DOWN;
        } else {
            isUpOrDown = NO_SCROLL;
        }

        if (isUpOrDown == NO_SCROLL_DOWN || isUpOrDown == NO_SCROLL_UP) {

            return true;
        }

        break;

    }

    return super.onInterceptTouchEvent(e);

}

From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;/*from   w w  w  . j  a va  2s . com*/
    Timepoint value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = null;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mIs24HourMode) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT
            // in case the user moves their finger quickly.
            mController.tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, TAP_TIMEOUT);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = mAccessibilityManager.isTouchExplorationEnabled();
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            Timepoint selectedTime = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
            if (mController.isOutOfRange(selectedTime, getCurrentItemShowing()))
                mDownDegrees = -1;
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // TAP_TIMEOUT in case the user moves their finger quickly.
                mController.tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        mLastValueSelected = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
                        mLastValueSelected = roundToValidTime(mLastValueSelected, getCurrentItemShowing());
                        // Redraw
                        reselectSelector(mLastValueSelected, true, getCurrentItemShowing());
                        mListener.onValueSelected(mLastValueSelected);
                    }
                }, TAP_TIMEOUT);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = roundToValidTime(getTimeFromDegrees(degrees, isInnerCircle[0], false),
                    getCurrentItemShowing());
            reselectSelector(value, true, getCurrentItemShowing());
            if (value != null && mLastValueSelected != null && !mLastValueSelected.equals(value)) {
                mController.tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(value);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.enablePicker();
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    Timepoint newSelection = new Timepoint(mCurrentTime);
                    if (mIsTouchingAmOrPm == AM)
                        newSelection.setAM();
                    else if (mIsTouchingAmOrPm == PM)
                        newSelection.setPM();
                    newSelection = roundToValidTime(newSelection, HOUR_INDEX);
                    reselectSelector(newSelection, false, HOUR_INDEX);
                    mCurrentTime = newSelection;
                    mListener.onValueSelected(newSelection);

                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = getTimeFromDegrees(degrees, isInnerCircle[0], !mDoingMove);
                value = roundToValidTime(value, getCurrentItemShowing());
                reselectSelector(value, false, getCurrentItemShowing());
                mCurrentTime = value;
                mListener.onValueSelected(value);
                mListener.advancePicker(getCurrentItemShowing());
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private void touchMoved(MotionEvent event) {
    float pos = (event.getX() / mWidth) * MOVE_POS_MULTIPLE - 5;
    pos /= 2;//  w  w  w . j ava  2 s .co m

    if (!mTouchMoved) {
        float dx = Math.abs(event.getX() - mTouchStartX);
        float dy = Math.abs(event.getY() - mTouchStartY);

        if (dx < TOUCH_MINIMUM_MOVE && dy < TOUCH_MINIMUM_MOVE) {
            return;
        }

        mTouchMoved = true;

        stopLongClick();
    }

    mOffset = mStartOffset + mTouchStartPos - pos;

    invalidate();
    mVelocity.addMovement(event);
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int x = (int) (event.getX() + 0.5f);
    final int y = (int) (event.getY() + 0.5f);

    final int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDownX = x;/*w w w.  j  av  a 2  s .c o m*/
        mDownY = y;

        mInitialTarget = getDayAtLocation(mDownX, mDownY);

        if (mInitialTarget < 0) {
            return false;
        }

        if (mPendingCheckForTap == null) {
            mPendingCheckForTap = new CheckForTap();
        }
        postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        break;
    case MotionEvent.ACTION_MOVE:
        if (!isStillAClick(x, y)) {
            if (mPendingCheckForTap != null) {
                removeCallbacks(mPendingCheckForTap);
            }

            mInitialTarget = -1;

            if (mTouchedItem >= 0) {
                mTouchedItem = -1;
                invalidate();
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        onDayClicked(mInitialTarget);
        // Fall through.
    case MotionEvent.ACTION_CANCEL:
        if (mPendingCheckForTap != null) {
            removeCallbacks(mPendingCheckForTap);
        }
        // Reset touched day on stream end.
        mTouchedItem = -1;
        mInitialTarget = -1;
        invalidate();
        break;
    }
    return true;
}

From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.time.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;/* w ww  .j av a2 s . co m*/
    Timepoint value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = null;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mIs24HourMode) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT
            // in case the user moves their finger quickly.
            mController.tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, TAP_TIMEOUT);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = mAccessibilityManager.isTouchExplorationEnabled();
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            Timepoint selectedTime = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
            if (mController.isOutOfRange(selectedTime, getCurrentItemShowing()))
                mDownDegrees = -1;
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // TAP_TIMEOUT in case the user moves their finger quickly.
                mController.tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        mLastValueSelected = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false);
                        mLastValueSelected = roundToValidTime(mLastValueSelected, getCurrentItemShowing());
                        // Redraw
                        reselectSelector(mLastValueSelected, true, getCurrentItemShowing());
                        mListener.onValueSelected(mLastValueSelected);
                    }
                }, TAP_TIMEOUT);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = roundToValidTime(getTimeFromDegrees(degrees, isInnerCircle[0], false),
                    getCurrentItemShowing());
            reselectSelector(value, true, getCurrentItemShowing());
            if (value != null && (mLastValueSelected == null || !mLastValueSelected.equals(value))) {
                mController.tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(value);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.enablePicker();
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    Timepoint newSelection = new Timepoint(mCurrentTime);
                    if (mIsTouchingAmOrPm == AM)
                        newSelection.setAM();
                    else if (mIsTouchingAmOrPm == PM)
                        newSelection.setPM();
                    newSelection = roundToValidTime(newSelection, HOUR_INDEX);
                    reselectSelector(newSelection, false, HOUR_INDEX);
                    mCurrentTime = newSelection;
                    mListener.onValueSelected(newSelection);

                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = getTimeFromDegrees(degrees, isInnerCircle[0], !mDoingMove);
                value = roundToValidTime(value, getCurrentItemShowing());
                reselectSelector(value, false, getCurrentItemShowing());
                mCurrentTime = value;
                mListener.onValueSelected(value);
                mListener.advancePicker(getCurrentItemShowing());
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.android.screenspeak.contextmenu.RadialMenuView.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_HOVER_ENTER:
        // Fall-through to movement events.
        onEnter(event.getX(), event.getY());
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_HOVER_MOVE:
        onMove(event.getX(), event.getY());
        break;//  w  ww . j av  a  2 s . co  m
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_HOVER_EXIT:
        onUp(event.getX(), event.getY());
        break;
    default:
        // Don't handle other types of events.
        return false;
    }

    mHandler.onTouch(this, event);

    return true;
}

From source file:com.codeim.coxin.LoginActivity.java

private boolean isShouldHideInput(View v, MotionEvent event) {
    if (v != null && (v instanceof EditText)) {
        int[] l1 = { 0, 0 };
        int[] l2 = { 0, 0 };
        mUsernameEdit.getLocationInWindow(l1);
        mPasswordEdit.getLocationInWindow(l2);
        // int left = l[0], top = l[1], bottom = top + v.getHeight(), right = left + v.getWidth();
        int left = l1[0], top = l1[1], bottom = l2[1] + mPasswordEdit.getHeight(),
                right = l2[0] + mPasswordEdit.getWidth();
        if (event.getX() > left && event.getX() < right && event.getY() > top && event.getY() < bottom) {
            // EditText
            return false;
        } else {//from  w ww.  jav  a 2 s . c o  m
            return true;
        }
    }
    // ?EditText??EditView?
    return false;
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

private void touchMoved(MotionEvent event) {
    float pos = (event.getX() / mWidth) * MOVE_POS_MULTIPLE - 5;
    pos /= 2;//from  w  ww.j  a  v a2 s  . c  o m

    if (!mTouchMoved) {
        float dx = Math.abs(event.getX() - mTouchStartX);
        float dy = Math.abs(event.getY() - mTouchStartY);

        if (dx < TOUCH_MINIMUM_MOVE && dy < TOUCH_MINIMUM_MOVE)
            return;

        mTouchMoved = true;

        stopLongClick();
    }

    mOffset = mStartOffset + mTouchStartPos - pos;

    invalidate();
    mVelocity.addMovement(event);
}

From source file:com.canyinghao.canrefresh.CanRefreshLayout.java

/**
 * ?//from  ww  w . j  av  a  2s. c  o m
 *
 * @param e
 * @param isHead
 * @return
 */
private boolean touch(MotionEvent e, boolean isHead) {

    switch (e.getAction()) {

    case MotionEvent.ACTION_DOWN:

        lastY = e.getY();
        return true;

    case MotionEvent.ACTION_MOVE:

        if (lastY > 0) {
            currentOffSetY = (int) (e.getY() - lastY);
            offsetSum += currentOffSetY;
        }
        lastY = e.getY();

        boolean isCanMove;
        if (isHead) {
            isCanMove = offsetSum > 0;
        } else {
            isCanMove = offsetSum < 0;
        }

        if (isCanMove) {

            float ratio = getRatio();

            if (ratio < 0) {
                ratio = 0;
            }

            int scrollNum = -((int) (currentOffSetY * ratio));

            scrollSum += scrollNum;

            if (isHead) {

                smoothMove(true, true, scrollNum, scrollSum);

                if (Math.abs(scrollSum) > mHeaderHeight) {

                    getHeaderInterface().onPrepare();
                }

                getHeaderInterface().onPositionChange(Math.abs(scrollSum) / (float) mHeaderHeight);
            } else {

                smoothMove(false, true, scrollNum, scrollSum);

                if (Math.abs(scrollSum) > mFooterHeight) {

                    getFooterInterface().onPrepare();
                }

                getFooterInterface().onPositionChange(Math.abs(scrollSum) / (float) mFooterHeight);

            }

        }

        return true;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:

        if (Math.abs(scrollSum) > 3) {

            if (isHead) {
                if (Math.abs(scrollSum) > mHeaderHeight) {

                    smoothMove(true, false, -mHeaderHeight, mHeaderHeight);
                    getHeaderInterface().onRelease();
                    refreshing();
                } else {

                    smoothMove(true, false, 0, 0);
                }

            } else {

                if (Math.abs(scrollSum) > mFooterHeight) {

                    smoothMove(false, false,
                            mContentView.getMeasuredHeight() - getMeasuredHeight() + mFooterHeight,
                            mFooterHeight);
                    getFooterInterface().onRelease();
                    loadingMore();
                } else {

                    smoothMove(false, false, mContentView.getMeasuredHeight() - getMeasuredHeight(), 0);

                }

            }

        }

        resetParameter();

        break;

    }

    return super.onTouchEvent(e);

}

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

public void touchesBegan(MotionEvent event) {
    isTouched = true;/*  www  . ja v  a  2  s .co m*/
    isTouchMoved = false;
    startPositionX = event.getX();
    startPositionY = event.getY();
    //Log.i("========startPositionX==========", startPositionX+">>>>>>>>>>");
    //Log.i("========startPositionY==========", startPositionY+">>>>>>>>>>");
}