List of usage examples for android.view MotionEvent getActionMasked
public final int getActionMasked()
From source file:org.uoyabause.android.PadButton.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getActionMasked(); int touchCount = event.getPointerCount(); int pointerIndex = event.getActionIndex(); int pointerId = event.getPointerId(pointerIndex); int posx = (int) event.getX(pointerIndex); int posy = (int) event.getY(pointerIndex); float hitsize = 15.0f * wscale * base_scale; RectF hittest = new RectF((int) (posx - hitsize), (int) (posy - hitsize), (int) (posx + hitsize), (int) (posy + hitsize)); switch (action) { case MotionEvent.ACTION_DOWN: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].On(pointerId); }/*from w w w .j a v a2 s . c o m*/ } if (_pad_mode == 1) { updatePad(hittest, posx, posy, pointerId); } break; case MotionEvent.ACTION_POINTER_DOWN: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].On(pointerId); } } if (_pad_mode == 1) { updatePad(hittest, posx, posy, pointerId); } break; case MotionEvent.ACTION_POINTER_UP: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].Off(); } } if (_pad_mode == 1) { releasePad(pointerId); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].intersects(hittest)) { buttons[btnindex].Off(); } } if (_pad_mode == 1) { releasePad(pointerId); } break; case MotionEvent.ACTION_MOVE: for (int index = 0; index < touchCount; index++) { int eventID2 = event.getPointerId(index); float x2 = event.getX(index); float y2 = event.getY(index); RectF hittest2 = new RectF((int) (x2 - hitsize), (int) (y2 - hitsize), (int) (x2 + hitsize), (int) (y2 + hitsize)); for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (eventID2 == buttons[btnindex].getPointId()) { if (buttons[btnindex].intersects(hittest2) == false) { buttons[btnindex].Off(); } } else if (buttons[btnindex].intersects(hittest2)) { buttons[btnindex].On(eventID2); } } if (_pad_mode == 1) { updatePad(hittest2, (int) x2, (int) y2, eventID2); } } break; } if (!testmode) { if (_pad_mode == 0) { for (int btnindex = 0; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].isOn()) { YabauseRunnable.press(btnindex, 0); } else { YabauseRunnable.release(btnindex, 0); } } } else { for (int btnindex = PadEvent.BUTTON_RIGHT_TRIGGER; btnindex < PadEvent.BUTTON_LAST; btnindex++) { if (buttons[btnindex].isOn()) { YabauseRunnable.press(btnindex, 0); } else { YabauseRunnable.release(btnindex, 0); } } } } if (testmode) { status = ""; status += "START:"; if (buttons[PadEvent.BUTTON_START].isOn()) status += "ON "; else status += "OFF "; status += "\nUP:"; if (buttons[PadEvent.BUTTON_UP].isOn()) status += "ON "; else status += "OFF "; status += "DOWN:"; if (buttons[PadEvent.BUTTON_DOWN].isOn()) status += "ON "; else status += "OFF "; status += "LEFT:"; if (buttons[PadEvent.BUTTON_LEFT].isOn()) status += "ON "; else status += "OFF "; status += "RIGHT:"; if (buttons[PadEvent.BUTTON_RIGHT].isOn()) status += "ON "; else status += "OFF "; status += "\nA:"; if (buttons[PadEvent.BUTTON_A].isOn()) status += "ON "; else status += "OFF "; status += "B:"; if (buttons[PadEvent.BUTTON_B].isOn()) status += "ON "; else status += "OFF "; status += "C:"; if (buttons[PadEvent.BUTTON_C].isOn()) status += "ON "; else status += "OFF "; status += "\nX:"; if (buttons[PadEvent.BUTTON_X].isOn()) status += "ON "; else status += "OFF "; status += "Y:"; if (buttons[PadEvent.BUTTON_Y].isOn()) status += "ON "; else status += "OFF "; status += "Z:"; if (buttons[PadEvent.BUTTON_Z].isOn()) status += "ON "; else status += "OFF "; status += "\nLT:"; if (buttons[PadEvent.BUTTON_LEFT_TRIGGER].isOn()) status += "ON "; else status += "OFF "; status += "RT:"; if (buttons[PadEvent.BUTTON_RIGHT_TRIGGER].isOn()) status += "ON "; else status += "OFF "; status += "\nAX:"; if (_analog_pad.isOn()) status += "ON " + _axi_x; else status += "OFF " + _axi_x; status += "AY:"; if (_analog_pad.isOn()) status += "ON " + _axi_y; else status += "OFF " + _axi_y; } if ((listener != null)) { listener.onPad(null); } return true; }
From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }/*ww w . j a v a 2 s . c o m*/ int action = event.getActionMasked(); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } if (mViewDragHelper != null) { mViewDragHelper.processTouchEvent(event); } // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
From source file:net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; }/*from w ww.ja v a 2 s . c o m*/ int action = event.getActionMasked(); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } mViewDragHelper.processTouchEvent(event); // Record the velocity if (action == MotionEvent.ACTION_DOWN) { reset(); } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(event); // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
From source file:com.emmasuzuki.quickreturnlistview.view.QuickReturnListView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { // If items are all visible or first item is visible, do nothing for quick return view if (mAllItemsVisible || !mQuickReturnEnabled) { return super.dispatchTouchEvent(ev); }// ww w . j a va 2 s.c om mGestureListener.onTouchEvent(ev); if (mAbsListView.getFirstVisiblePosition() == 0) { mState = STATE_ONSCREEN; animateQuickReturnViewToDest(0); } else { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mSettleEnabled = false; mPrevY = (int) ev.getY(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: // Settle quick return view with animation mSettleEnabled = true; mScrollSettleHandler.onScroll(); break; case MotionEvent.ACTION_MOVE: // Move quick return view according to touch move mDeltaY = (int) ev.getY() - mPrevY; handleMove(); mPrevY = (int) ev.getY(); break; } } return super.dispatchTouchEvent(ev); }
From source file:study.com.s_sxl.carelib.pullRefreshView.layout.FlingLayout.java
/******************************************************************/ @Override//from www. j a va 2 s .c o m public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tempY = downY = y; tempX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tempX = ev.getX(pointerIndex); tempY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tempX); int dataY = (int) (my - tempY); tempX = mx; tempY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tempY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.leap.mini.widget.pullrefresh.base.layout.FlingLayout.java
/******************************************************************/ @Override/*from www. java 2 s. c om*/ public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } // ????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 // ?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { // ?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);// ? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { // 0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { // ?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.ybao.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override//from ww w .j a v a 2 s .c o m public boolean dispatchTouchEvent(MotionEvent ev) { if (mPullView != null && !ViewCompat.isNestedScrollingEnabled(mPullView)) { float moveY = getMoveY(); int pointerCount = ev.getPointerCount(); int pointerIndex = ev.getActionIndex(); if (!mScroller.isFinished()) { mScroller.abortAnimation(); } switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: mPointerId = ev.getPointerId(pointerIndex); float x = ev.getX(pointerIndex); float y = ev.getY(pointerIndex); tepmY = downY = y; tepmX = downX = x; tempStateType = SCROLL_STATE_TOUCH_SCROLL; if (moveY != 0) { return true; } break; case MotionEvent.ACTION_POINTER_DOWN: mPointerId = ev.getPointerId(pointerIndex); tepmX = ev.getX(pointerIndex); tepmY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: pointerIndex = ev.findPointerIndex(mPointerId); float mx; float my; if (pointerCount > pointerIndex && pointerIndex >= 0) { mx = ev.getX(pointerIndex); my = ev.getY(pointerIndex); } else { mx = ev.getX(); my = ev.getY(); } //????? int dataX = (int) (mx - tepmX); int dataY = (int) (my - tepmY); tepmX = mx; tepmY = my; if (isScrolling || (Math.abs(dataY) > Math.abs(dataX))) { isScrolling = true; if (moveY == 0) { // 0,0 //?? if ((dataY < 0 && canPullUp()) || (dataY > 0 && canPullDown())) { moveBy(dataY); return true; } } else { //?0,0 ev.setAction(MotionEvent.ACTION_CANCEL);//? if ((moveY < 0 && moveY + dataY >= 0) || (moveY > 0 && moveY + dataY <= 0)) { //0,0 ev.setAction(MotionEvent.ACTION_DOWN); moveTo(0); } else if ((moveY > 0 && dataY > 0) || (moveY < 0 && dataY < 0)) { //?? if (maxDistance == 0 || Math.abs(moveY) < maxDistance) { int ps = 0; int hDataY = dataY / 2; if (maxDistance == 0) { ps = (int) (-hDataY * Math.abs(moveY) / (float) MAXDISTANCE) - hDataY; } else { ps = (int) (-hDataY * Math.abs(moveY) / (float) maxDistance) - hDataY; } moveBy(ps + dataY); } else if (moveY > maxDistance) { moveTo(maxDistance); } else if (moveY < -maxDistance) { moveTo(-maxDistance); } } else { moveBy(dataY); } } } else { ev.setLocation(mx, downY); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: startFling(); isScrolling = false; break; case MotionEvent.ACTION_POINTER_UP: // ?? int pointerIdLeave = ev.getPointerId(pointerIndex); if (mPointerId == pointerIdLeave) { // ??????VelocityTracker int reIndex = pointerIndex == 0 ? 1 : 0; mPointerId = ev.getPointerId(reIndex); // ? tepmY = ev.getY(reIndex); } } return super.dispatchTouchEvent(ev) || isScrolling; } else { return super.dispatchTouchEvent(ev); } }
From source file:com.me.harris.androidanimations._06_touch.swipelistview.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(View, MotionEvent) *///from ww w . j a v a2s . c o m @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (paused) { return false; } swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; int childCount = swipeListView.getChildCount(); int[] listViewCoords = new int[2]; swipeListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View child; for (int i = 0; i < childCount; i++) { child = swipeListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView)); downX = motionEvent.getRawX(); downPosition = swipeListView.getPositionForView(child); frontView.setClickable(!opened.get(downPosition)); frontView.setLongClickable(!opened.get(downPosition)); velocityTracker = VelocityTracker.obtain(); velocityTracker.addMovement(motionEvent); if (swipeBackView > 0) { setBackView(child.findViewById(swipeBackView)); } break; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (velocityTracker == null || !swiping) { break; } float deltaX = motionEvent.getRawX() - downX; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); if (!opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) { velocityX = 0; } if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(velocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) { swap = false; } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) { swap = false; } else { swap = true; } } else if (Math.abs(deltaX) > viewWidth / 2) { swap = true; swapRight = deltaX > 0; } generateAnimate(frontView, swap, swapRight, downPosition); velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view if (swap) { frontView.setClickable(opened.get(downPosition)); frontView.setLongClickable(opened.get(downPosition)); } frontView = null; backView = null; this.downPosition = ListView.INVALID_POSITION; swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused) { break; } velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); float velocityY = Math.abs(velocityTracker.getYVelocity()); float deltaX = motionEvent.getRawX() - downX; float deltaMode = Math.abs(deltaX); if (swipeMode == SwipeListView.SWIPE_MODE_NONE) { deltaMode = 0; } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) { if (opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) { deltaMode = 0; } } else { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) { deltaMode = 0; } } } if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) { swiping = true; boolean swipingRight = (deltaX > 0); if (opened.get(downPosition)) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } else { if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHECK) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHECK; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHECK) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHECK; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); } if (swiping) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } return false; }
From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;//from ww w . jav a 2 s.co m return false; } int action = event.getActionMasked(); // 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(); View scroll = mNestedScrollingChildRef != null ? mNestedScrollingChildRef.get() : null; if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) { mActivePointerId = event.getPointerId(event.getActionIndex()); mTouchingScrollingChild = true; } 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. View scroll = mNestedScrollingChildRef.get(); return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
/** * {@inheritDoc}//from w ww . j a v a2 s .c om */ @Override public boolean onTouchEvent(final MotionEvent event) { final int action = event.getActionMasked(); final int index = event.getActionIndex(); final int pointerId = event.getPointerId(index); switch (action) { case MotionEvent.ACTION_DOWN: // Initialize velocity tracker if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } mVelocityTracker.addMovement(event); mScroller.forceFinished(true); mState = STATE_INITIALIZE; mInitialTouchOffset = mCurrentOffset; mInitialTouchX = event.getX(); mInitialTouchY = event.getY(); return true; case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(event); float diffX = event.getX() - mInitialTouchX; float diffY = event.getY() - mInitialTouchY; if (Math.abs(diffX) > mTouchSlop || mState >= STATE_MOVING) { mCurrentOffset = mInitialTouchOffset + diffX; if (mCurrentOffset < 0) { onOverScroll(); mCurrentOffset = 0; } else if (mCurrentOffset > mMaxOffset) { onOverScroll(); mCurrentOffset = mMaxOffset; } mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity); mState = STATE_MOVING; ViewCompat.postInvalidateOnAnimation(this); } else if (Math.abs(diffY) > mTouchSlop && mState < STATE_MOVING) { return false; } return true; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mState >= STATE_MOVING) { final int velocity = (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId); mScroller.forceFinished(true); mState = STATE_FLINGING; mScroller.fling((int) mCurrentOffset, 0, velocity, 0, 0, (int) mMaxOffset, 0, 0); ViewCompat.postInvalidateOnAnimation(this); } else { // Reset scrolling state mState = STATE_IDLE; } return true; } return false; }