Java Code Examples for android.support.v4.view.MotionEventCompat#getY()
The following examples show how to use
android.support.v4.view.MotionEventCompat#getY() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomViewAbove.java From BigApp_Discuz_Android with Apache License 2.0 | 6 votes |
private void determineDrag(MotionEvent ev) { final int activePointerId = mActivePointerId; final int pointerIndex = getPointerIndex(ev, activePointerId); if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER) return; final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastMotionX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastMotionY; final float yDiff = Math.abs(dy); if (xDiff > (isMenuOpen()?mTouchSlop/2:mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { startDrag(); mLastMotionX = x; mLastMotionY = y; setScrollingCacheEnabled(true); // TODO add back in touch slop check } else if (xDiff > mTouchSlop) { mIsUnableToDrag = true; } }
Example 2
Source File: ViewDragHelper.java From ChipHellClient with Apache License 2.0 | 5 votes |
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
Example 3
Source File: ViewDragHelper.java From android-recipes-app with Apache License 2.0 | 5 votes |
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
Example 4
Source File: ViewDragHelper.java From Nimingban with Apache License 2.0 | 5 votes |
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
Example 5
Source File: MySwipeRefreshLayout.java From Cotable with Apache License 2.0 | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
Example 6
Source File: ViewDragHelper.java From SwipeAdapterView with Apache License 2.0 | 5 votes |
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
Example 7
Source File: PullRefreshLayout.java From android-PullRefreshLayout with MIT License | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
Example 8
Source File: VerticalViewPager.java From VerticalViewPager with MIT License | 5 votes |
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex); mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }
Example 9
Source File: SwipeRefreshLayout.java From letv with Apache License 2.0 | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1.0f; } return MotionEventCompat.getY(ev, index); }
Example 10
Source File: SlidingLayout.java From stynico with MIT License | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
Example 11
Source File: ViewDragHelper.java From MiBandDecompiled with Apache License 2.0 | 5 votes |
private void a(MotionEvent motionevent) { int i1 = MotionEventCompat.getPointerCount(motionevent); for (int j1 = 0; j1 < i1; j1++) { int k1 = MotionEventCompat.getPointerId(motionevent, j1); float f1 = MotionEventCompat.getX(motionevent, j1); float f2 = MotionEventCompat.getY(motionevent, j1); j[k1] = f1; k[k1] = f2; } }
Example 12
Source File: PigeonholeView.java From PigeonholeView with Apache License 2.0 | 5 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: { try { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, pointerIndex); final float y = MotionEventCompat.getY(ev, pointerIndex); // Remember where we started (for dragging) lastTouchX = x; lastTouchY = y; // Save the ID of this pointer (for dragging) activePointerId = MotionEventCompat.getPointerId(ev, 0); } catch (IllegalArgumentException ex) { // pointerIndex out of range Log.e(TAG, "IllegalArgumentException: " + ex.getMessage()); return false; } break; } case MotionEvent.ACTION_UP: { onMouseActionUp(ev); break; } case MotionEvent.ACTION_CANCEL: { cancelDrag(); break; } } return isDragging; }
Example 13
Source File: ScaleDragDetector.java From CanPhotos with Apache License 2.0 | 5 votes |
private float getActiveY(MotionEvent ev) { try { return MotionEventCompat.getY(ev, mActivePointerIndex); } catch (Exception e) { return ev.getY(); } }
Example 14
Source File: PullToRefreshView.java From Phoenix with Apache License 2.0 | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
Example 15
Source File: SwipeRefreshLayout.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
Example 16
Source File: ViewDragHelper.java From photo-editor-android with MIT License | 5 votes |
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); // Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it. if (mLastMotionX != null && mLastMotionY != null && mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) { mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } } }
Example 17
Source File: FlipView.java From android-FlipView with Apache License 2.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mIsFlippingEnabled) { return false; } if (mPageCount < 1) { return false; } final int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mIsFlipping = false; mIsUnableToFlip = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsFlipping) { return true; } else if (mIsUnableToFlip) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastY; final float yDiff = Math.abs(dy); if ((mIsFlippingVertically && yDiff > mTouchSlop && yDiff > xDiff) || (!mIsFlippingVertically && xDiff > mTouchSlop && xDiff > yDiff)) { mIsFlipping = true; mLastX = x; mLastY = y; } else if ((mIsFlippingVertically && xDiff > mTouchSlop) || (!mIsFlippingVertically && yDiff > mTouchSlop)) { mIsUnableToFlip = true; } break; case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK; mLastX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = MotionEventCompat.getY(ev, mActivePointerId); mIsFlipping = !mScroller.isFinished() | mPeakAnim != null; mIsUnableToFlip = false; mLastTouchAllowed = true; break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsFlipping) { trackVelocity(ev); } return mIsFlipping; }
Example 18
Source File: CustomViewAbove.java From BigApp_WordPress_Android with Apache License 2.0 | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) return false; final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (DEBUG) if (action == MotionEvent.ACTION_DOWN) Log.v(TAG, "Received ACTION_DOWN"); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) { endDrag(); return false; } switch (action) { case MotionEvent.ACTION_MOVE: determineDrag(ev); break; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); if (mActivePointerId == INVALID_POINTER) break; mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); mLastMotionY = MotionEventCompat.getY(ev, index); if (thisTouchAllowed(ev)) { mIsBeingDragged = false; mIsUnableToDrag = false; if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { mQuickReturn = true; } } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsBeingDragged) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsBeingDragged || mQuickReturn; }
Example 19
Source File: CustomViewAbove.java From LiuAGeAndroid with MIT License | 4 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) return false; final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (DEBUG) if (action == MotionEvent.ACTION_DOWN) Log.v(TAG, "Received ACTION_DOWN"); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP || (action != MotionEvent.ACTION_DOWN && mIsUnableToDrag)) { endDrag(); return false; } switch (action) { case MotionEvent.ACTION_MOVE: determineDrag(ev); break; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); if (mActivePointerId == INVALID_POINTER) break; mLastMotionX = mInitialMotionX = MotionEventCompat.getX(ev, index); mLastMotionY = MotionEventCompat.getY(ev, index); if (thisTouchAllowed(ev)) { mIsBeingDragged = false; mIsUnableToDrag = false; if (isMenuOpen() && mViewBehind.menuTouchInQuickReturn(mContent, mCurItem, ev.getX() + mScrollX)) { mQuickReturn = true; } } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsBeingDragged) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsBeingDragged || mQuickReturn; }
Example 20
Source File: ItemTouchHelper.java From letv with Apache License 2.0 | 4 votes |
private boolean checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) { if (this.mSelected != null || action != 2 || this.mActionState == 2 || !this.mCallback.isItemViewSwipeEnabled()) { return false; } if (this.mRecyclerView.getScrollState() == 1) { return false; } ViewHolder vh = findSwipedView(motionEvent); if (vh == null) { return false; } int swipeFlags = (65280 & this.mCallback.getAbsoluteMovementFlags(this.mRecyclerView, vh)) >> 8; if (swipeFlags == 0) { return false; } float x = MotionEventCompat.getX(motionEvent, pointerIndex); float dx = x - this.mInitialTouchX; float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY; float absDx = Math.abs(dx); float absDy = Math.abs(dy); if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) { return false; } if (absDx > absDy) { if (dx < 0.0f && (swipeFlags & 4) == 0) { return false; } if (dx > 0.0f && (swipeFlags & 8) == 0) { return false; } } else if (dy < 0.0f && (swipeFlags & 1) == 0) { return false; } else { if (dy > 0.0f && (swipeFlags & 2) == 0) { return false; } } this.mDy = 0.0f; this.mDx = 0.0f; this.mActivePointerId = MotionEventCompat.getPointerId(motionEvent, 0); select(vh, 1); return true; }