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.andview.refreshview.swipe.SwipeMenuLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    boolean isIntercepted = super.onInterceptTouchEvent(ev);
    int action = ev.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mDownX = mLastX = (int) ev.getX();
        mDownY = (int) ev.getY();
        isIntercepted = false;/*from   ww w.  j a  va2  s. c  o m*/
        break;
    case MotionEvent.ACTION_MOVE:
        int disX = (int) (ev.getX() - mDownX);
        int disY = (int) (ev.getY() - mDownY);
        isIntercepted = Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY);
        break;
    case MotionEvent.ACTION_UP:
        isIntercepted = false;
        if (isMenuOpen() && mSwipeCurrentHorizontal.isClickOnContentView(getWidth(), ev.getX())) {
            smoothCloseMenu();
            isIntercepted = true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        isIntercepted = false;
        if (!mScroller.isFinished())
            mScroller.abortAnimation();
        break;
    }
    return isIntercepted;
}

From source file:com.antew.redditinpictures.library.ui.ImageViewerFragment.java

/**
 * This handles receiving the touch events in the WebView so that we can
 * toggle between fullscreen and windowed mode.
 * <p/>/*from   w  w  w.  j av  a  2s .co  m*/
 * The first time the user touches the screen we save the X and Y coordinates.
 * If we receive a {@link MotionEvent#ACTION_DOWN} event we compare the previous
 * X and Y coordinates to the saved coordinates, if they are greater than {@link
 * #MOVE_THRESHOLD}
 * we prevent the toggle from windowed mode to fullscreen mode or vice versa, the idea
 * being that the user is either dragging the image or using pinch-to-zoom.
 * <p/>
 * TODO: Implement handling for double tap to zoom.
 *
 * @return The {@link OnTouchListener} for the {@link WebView} to use.
 */
public OnTouchListener getWebViewOnTouchListener() {
    return new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mCancelClick = false;
                mDownXPos = event.getX();
                mDownYPos = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                if (!mCancelClick) {
                    Intent intent = new Intent(Constants.Broadcast.BROADCAST_TOGGLE_FULLSCREEN);
                    intent.putExtra(Constants.Extra.EXTRA_IS_SYSTEM_UI_VISIBLE,
                            mSystemUiStateProvider.isSystemUiVisible());
                    LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent);
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (Math.abs(event.getX() - mDownXPos) > MOVE_THRESHOLD
                        || Math.abs(event.getY() - mDownYPos) > MOVE_THRESHOLD) {
                    mCancelClick = true;
                }
                break;
            }

            // Return false so that we still let the WebView consume the event
            return false;
        }
    };
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

/**
 * Returns whether the view itself will handle the touch event or not.
 *//*w  ww.ja  va  2 s .  com*/
public boolean shouldContainerScroll(MotionEvent ev) {
    int[] point = new int[2];
    point[0] = (int) ev.getX();
    point[1] = (int) ev.getY();
    Utilities.mapCoordInSelfToDescendent(mAppsRecyclerView, this, point);

    // IF the MotionEvent is inside the search box, and the container keeps on receiving
    // touch input, container should move down.
    if (mLauncher.getDragLayer().isEventOverView(mSearchContainer, ev)) {
        return true;
    }

    // IF the MotionEvent is inside the thumb, container should not be pulled down.
    if (mAppsRecyclerView.getScrollBar().isNearThumb(point[0], point[1])) {
        return false;
    }

    // IF a shortcuts container is open, container should not be pulled down.
    if (mLauncher.getOpenShortcutsContainer() != null) {
        return false;
    }

    // IF scroller is at the very top OR there is no scroll bar because there is probably not
    // enough items to scroll, THEN it's okay for the container to be pulled down.
    if (mAppsRecyclerView.getScrollBar().getThumbOffset().y <= 0) {
        return true;
    }
    return false;
}

From source file:com.aiga.events.android.views.NoScrollSwipeRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mCurrPercentage = 0;//w ww.  j av a 2  s  .c  om
        mDownEvent = MotionEvent.obtain(event);
        break;
    case MotionEvent.ACTION_MOVE:
        if (mDownEvent != null && !mReturningToStart && !mRefreshing && !mUserInteracting) {
            final float eventY = event.getY();
            float yDiff = eventY - mDownEvent.getY();
            if (yDiff > mTouchSlop) {
                // User velocity passed min velocity; trigger a refresh
                if (yDiff > mDistanceToTriggerSync) {
                    // User movement passed distance; trigger a refresh
                    mUserInteracting = true;
                    startRefresh();
                    handled = true;
                    break;
                }
                // Just track the user's movement
                setTriggerPercentage(mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync));
                updatePositionTimeout();
                handled = true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mUserInteracting = false;
        if (mDownEvent != null) {
            mDownEvent.recycle();
            mDownEvent = null;
        }
        break;
    }
    return handled;
}

From source file:com.androtex.viewpagerindicator.CirclePageIndicator.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        final int count = mViewPager.getAdapter().getCount();
        final int longSize = (mOrientation == HORIZONTAL) ? getWidth() : getHeight();
        final float halfLongSize = longSize / 2;
        final float halfCircleLongSize = (count * 3 * mRadius) / 2;
        final float pointerValue = (mOrientation == HORIZONTAL) ? event.getX() : event.getY();

        if ((mCurrentPage > 0) && (pointerValue < halfLongSize - halfCircleLongSize)) {
            setCurrentItem(mCurrentPage - 1);
            return true;
        } else if ((mCurrentPage < count - 1) && (pointerValue > halfLongSize + halfCircleLongSize)) {
            setCurrentItem(mCurrentPage + 1);
            return true;
        }//  ww  w .  j  a  v a 2 s . c om
    }

    return super.onTouchEvent(event);
}

From source file:com.example.appf.CS3570.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    // MotionEvent reports input details from the touch screen
    // and other input controls. In this case, you are only
    // interested in events where the touch position changed.

    float x = e.getX();
    float y = e.getY();

    switch (e.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (mother.out != null) {
            mother.out.println("{\"type\": \"DOWN\", \"x\": " + x + ", \"y\": " + y + "}\0");
        }/*from w w  w  .ja v  a 2s  .  c o  m*/
        break;
    case MotionEvent.ACTION_UP:
        if (mother.out != null) {
            mother.out.println("{\"type\": \"UP\", \"x\": " + x + ", \"y\": " + y + "}\0");
        }
        break;
    case MotionEvent.ACTION_MOVE:

        float dx = x - mPreviousX;
        float dy = y - mPreviousY;

        // reverse direction of rotation above the mid-line
        if (y > getHeight() / 2) {
            dx = dx * -1;
        }

        // reverse direction of rotation to left of the mid-line
        if (x < getWidth() / 2) {
            dy = dy * -1;
        }

        //mRenderer.mAngle += (dx + dy) * TOUCH_SCALE_FACTOR;  // = 180.0f / 320
        //mRenderer.mTetra.rotate(dx, 0, 1, 0);
        //mRenderer.mTetra.rotate(dy, 1, 0, 0);
        //mRenderer.mCamera.rotateY((double)(dx * TOUCH_SCALE_FACTOR));
        //mRenderer.mCamera.rotateX((double)(dy * TOUCH_SCALE_FACTOR));
        if (mother.out != null) {
            Log.e("eee", "{\"type\": \"MOVE\", \"x\": " + x + ", \"y\": " + y + "}");
            mother.out.println("{\"type\": \"MOVE\", \"x\": " + x + ",  \"y\": " + y + "}\0");
        }
        requestRender();
    }

    mPreviousX = x;
    mPreviousY = y;
    return true;
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

/**
 * Handles the touch events to dismiss all apps when clicking outside the bounds of the
 * recycler view.//  w  ww.j ava2 s  .co m
 */
private boolean handleTouchEvent(MotionEvent ev) {
    DeviceProfile grid = mLauncher.getDeviceProfile();
    int x = (int) ev.getX();
    int y = (int) ev.getY();

    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mContentBounds.isEmpty()) {
            // Outset the fixed bounds and check if the touch is outside all apps
            Rect tmpRect = new Rect(mContentBounds);
            tmpRect.inset(-grid.allAppsIconSizePx / 2, 0);
            if (ev.getX() < tmpRect.left || ev.getX() > tmpRect.right) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        } else {
            // Check if the touch is outside all apps
            if (ev.getX() < getPaddingLeft() || ev.getX() > (getWidth() - getPaddingRight())) {
                mBoundsCheckLastTouchDownPos.set(x, y);
                return true;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
        if (mBoundsCheckLastTouchDownPos.x > -1) {
            ViewConfiguration viewConfig = ViewConfiguration.get(getContext());
            float dx = ev.getX() - mBoundsCheckLastTouchDownPos.x;
            float dy = ev.getY() - mBoundsCheckLastTouchDownPos.y;
            float distance = (float) Math.hypot(dx, dy);
            if (distance < viewConfig.getScaledTouchSlop()) {
                // The background was clicked, so just go home
                Launcher launcher = Launcher.getLauncher(getContext());
                launcher.showWorkspace(true);
                return true;
            }
        }
        // Fall through
    case MotionEvent.ACTION_CANCEL:
        mBoundsCheckLastTouchDownPos.set(-1, -1);
        break;
    }
    return false;
}

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

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }//  w w w.j a v a  2s.  c  o  m

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        if (pointerIndex == -1) {
            break;
        }

        final int y = (int) MotionEventCompat.getY(ev, pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

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

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
    if (mTouchSlop < 0) {
        mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
    }// www  . j  a va  2 s  .c o  m

    final int action = ev.getAction();

    // Shortcut since we're being dragged
    if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
        return true;
    }

    switch (MotionEventCompat.getActionMasked(ev)) {
    case MotionEvent.ACTION_DOWN: {
        mIsBeingDragged = false;
        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
            mLastMotionY = y;
            mActivePointerId = ev.getPointerId(0);
            ensureVelocityTracker();
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }
        final int pointerIndex = ev.findPointerIndex(activePointerId);
        if (pointerIndex == -1) {
            break;
        }

        final int y = (int) ev.getY(pointerIndex);
        final int yDiff = Math.abs(y - mLastMotionY);
        if (yDiff > mTouchSlop) {
            mIsBeingDragged = true;
            mLastMotionY = y;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mIsBeingDragged = false;
        mActivePointerId = INVALID_POINTER;
        if (mVelocityTracker != null) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

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

    return mIsBeingDragged;
}

From source file:com.gizwits.framework.activity.BaseActivity.java

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