List of usage examples for android.view MotionEvent getActionMasked
public final int getActionMasked()
From source file:com.cw.litenote.note.Note.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { int maskedAction = event.getActionMasked(); switch (maskedAction) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: System.out.println("Note / _dispatchTouchEvent / MotionEvent.ACTION_UP / viewPager.getCurrentItem() =" + viewPager.getCurrentItem()); //1st touch to turn on UI if (picUI_touch == null) { picUI_touch = new NoteUi(act, viewPager, viewPager.getCurrentItem()); picUI_touch.tempShow_picViewUI(5000, getCurrentPictureString()); }/* ww w.j av a 2 s .com*/ //2nd touch to turn off UI else setTransientPicViewUI(); //1st touch to turn off UI (primary) if (Note_adapter.picUI_primary != null) setTransientPicViewUI(); break; case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_CANCEL: break; } return super.dispatchTouchEvent(event); }
From source file:com.cocarechina.pullrefreshview.layout.FlingLayout.java
/******************************************************************/ @Override//from w w 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; } lastY = ev.getY(); Log.v("lastY", moveY + ""); 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); } Log.v("flingLayout", "ev.getY()" + ev.getY() + " --- lastY " + lastY); if (ev.getY() - lastY > 5) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollBottom(); } } else if (ev.getY() - lastY < -10) { if (monScrollHeadListener != null) { monScrollHeadListener.onScrollTop(); } } 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.matcontrol.control.BottomSheetBehavior_v27.java
@Override public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { mIgnoreEvents = true;//from w w w.ja v a 2 s .com 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(); if (mNestedScrollingChildRefList != null) { for (View childView : mNestedScrollingChildRefList) { if (childView != null && parent.isPointInChildBounds(childView, 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. return action == MotionEvent.ACTION_MOVE && !mIgnoreEvents && mState != STATE_DRAGGING && !isPointInsideChildScrollView(parent, (int) event.getX(), (int) event.getY()) && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop(); }
From source file:com.leeon.blank.widget.RangeBarNew.java
@Override public boolean onTouchEvent(MotionEvent event) { getParent().requestDisallowInterceptTouchEvent(false); // For multiple touch final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: downY = event.getY();//from w ww . j a va 2s . co m handleTouchDown(event); break; case MotionEvent.ACTION_POINTER_DOWN: handleTouchDown(event); break; case MotionEvent.ACTION_MOVE: final float yDiff = Math.abs(event.getY() - downY); if (yDiff > mTouchSlop) { return false; } else { getParent().requestDisallowInterceptTouchEvent(true); handleTouchMove(event); } break; case MotionEvent.ACTION_POINTER_UP: handleTouchUp(event); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: handleTouchUp(event); break; } return super.onTouchEvent(event); }
From source file:com.android.mail.browse.ConversationContainer.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { mTouchIsDown = false;//from w w w .j av a 2 s . c o m } else if (!mTouchIsDown && (action == MotionEvent.ACTION_MOVE || action == MotionEvent.ACTION_POINTER_DOWN)) { forwardFakeMotionEvent(ev, MotionEvent.ACTION_DOWN); if (mMissedPointerDown) { forwardFakeMotionEvent(ev, MotionEvent.ACTION_POINTER_DOWN); mMissedPointerDown = false; } mTouchIsDown = true; } final boolean webViewResult = mWebView.onTouchEvent(ev); // LogUtils.v(TAG, "in Container.OnTouch. action=%d x/y=%f/%f pointers=%d", // ev.getActionMasked(), ev.getX(), ev.getY(), ev.getPointerCount()); return webViewResult; }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean dispatchTouchEvent(MotionEvent event) { final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: removeAllCallbacks();/*from ww w . ja v a 2 s . c o m*/ break; } return super.dispatchTouchEvent(event); }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean dispatchTrackballEvent(MotionEvent event) { final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: removeAllCallbacks();/*from w ww .j a v a2 s . c o m*/ break; } return super.dispatchTrackballEvent(event); }
From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java
@Override public boolean onTouch(View view, MotionEvent ev) { if (mViewWidth < 2) { mViewWidth = mListView.getWidth(); }//from ww w .j a v a 2 s . c om switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { if (mSwipePaused) { return false; } // Find the child view that was touched (perform a hit test) Rect rect = new Rect(); int childCount = mListView.getChildCount(); int[] listViewCoords = new int[2]; mListView.getLocationOnScreen(listViewCoords); int x = (int) ev.getRawX() - listViewCoords[0]; int y = (int) ev.getRawY() - listViewCoords[1]; View child; for (int i = mListView.getHeaderViewsCount(); i < childCount; i++) { child = mListView.getChildAt(i); if (child != null) { child.getHitRect(rect); if (rect.contains(x, y)) { // if a specific swiping layout has been giving, use this to swipe. if (mSwipingLayout > 0) { View swipingView = child.findViewById(mSwipingLayout); if (swipingView != null) { mSwipeDownView = swipingView; mSwipeDownChild = child; break; } } // If no swiping layout has been found, swipe the whole child mSwipeDownView = mSwipeDownChild = child; break; } } } if (mSwipeDownView != null) { // test if the item should be swiped int position = mListView.getPositionForView(mSwipeDownView) - mListView.getHeaderViewsCount(); if (mCallbacks == null || mCallbacks.canDismiss(position)) { mDownX = ev.getRawX(); mDownY = ev.getRawY(); mDownPosition = position; mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(ev); } else { // set back to null to revert swiping mSwipeDownView = mSwipeDownChild = null; } } return false; } case MotionEvent.ACTION_CANCEL: { if (mVelocityTracker == null) { break; } if (mSwipeDownView != null && mSwiping) { // cancel ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime) .setListener(null); } mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; mDownY = 0; mSwipeDownView = mSwipeDownChild = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; } case MotionEvent.ACTION_UP: { if (mVelocityTracker == null) { break; } float deltaX = ev.getRawX() - mDownX; mVelocityTracker.addMovement(ev); mVelocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(mVelocityTracker.getXVelocity()); float velocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean dismiss = false; boolean dismissRight = false; if (Math.abs(deltaX) > mViewWidth / 2 && mSwiping) { dismiss = true; dismissRight = deltaX > 0; } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX && mSwiping && isSwipeDirectionValid(mVelocityTracker.getXVelocity()) && deltaX >= mViewWidth * 0.2f) { dismiss = true; dismissRight = mVelocityTracker.getXVelocity() > 0; } if (dismiss) { // dismiss slideOutView(mSwipeDownView, mSwipeDownChild, mDownPosition, dismissRight); } else if (mSwiping) { // Swipe back to regular position ViewCompat.animate(mSwipeDownView).translationX(0).alpha(1).setDuration(mAnimationTime) .setListener(null); } mVelocityTracker = null; mDownX = 0; mDownY = 0; mSwipeDownView = null; mSwipeDownChild = null; mDownPosition = AbsListView.INVALID_POSITION; mSwiping = false; break; } case MotionEvent.ACTION_MOVE: { if (mVelocityTracker == null || mSwipePaused) { break; } mVelocityTracker.addMovement(ev); float deltaX = ev.getRawX() - mDownX; float deltaY = ev.getRawY() - mDownY; // Only start swipe in correct direction if (isSwipeDirectionValid(deltaX)) { ViewParent parent = mListView.getParent(); if (parent != null) { // If we swipe don't allow parent to intercept touch (e.g. like NavigationDrawer does) // otherwise swipe would not be working. parent.requestDisallowInterceptTouchEvent(true); } if (Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true); // Cancel ListView's touch (un-highlighting the item) MotionEvent cancelEvent = MotionEvent.obtain(ev); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (ev.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mListView.onTouchEvent(cancelEvent); } } else { // If we swiped into wrong direction, act like this was the new // touch down point mDownX = ev.getRawX(); deltaX = 0; } if (mSwiping) { ViewCompat.setTranslationX(mSwipeDownView, deltaX); ViewCompat.setAlpha(mSwipeDownView, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth))); return true; } break; } } return false; }
From source file:com.google.android.apps.forscience.whistlepunk.RunReviewOverlay.java
public void setOnLabelClickListener(OnLabelClickListener onLabelClickListener) { mOnLabelClickListener = onLabelClickListener; this.setOnTouchListener(new OnTouchListener() { private PointF downPoint = new PointF(); @Override// w w w . j a v a2 s. c o m public boolean onTouch(View v, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if ((!mIsCropping && eventOnFlag(event, mPointData)) || mIsCropping && (eventOnFlag(event, mCropStartData) || eventOnFlag(event, mCropEndData))) { downPoint.set(event.getX(), event.getY()); return true; } } else if (event.getActionMasked() == MotionEvent.ACTION_UP) { // See if the click is ending in any of the label boxes if (!mIsCropping && eventOnFlag(event, mPointData) && mPointData.labelRect.contains(downPoint.x, downPoint.y)) { mOnLabelClickListener.onValueLabelClicked(); return true; } else if (mIsCropping && eventOnFlag(event, mCropStartData) && mCropStartData.labelRect.contains(downPoint.x, downPoint.y)) { mOnLabelClickListener.onCropStartLabelClicked(); return true; } else if (mIsCropping && eventOnFlag(event, mCropEndData) && mCropEndData.labelRect.contains(downPoint.x, downPoint.y)) { mOnLabelClickListener.onCropEndLabelClicked(); return true; } } return false; } private boolean eventOnFlag(MotionEvent event, OverlayPointData pointData) { return pointData.labelRect.contains(event.getX(), event.getY()); } }); // TODO: P3: Could add an ExploreByTouchHelper to make these discoverable for a11y users. // Since the same functionality is accessible from the menu options, this is not high // priority. // https://developer.android.com/reference/android/support/v4/widget/ExploreByTouchHelper.html }
From source file:org.telegram.ui.Components.NumberPicker.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; }// ww w. ja va2 s . c o m final int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: { removeAllCallbacks(); mInputText.setVisibility(View.INVISIBLE); mLastDownOrMoveEventY = mLastDownEventY = event.getY(); mLastDownEventTime = event.getEventTime(); mIngonreMoveEvents = false; if (mLastDownEventY < mTopSelectionDividerTop) { if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_DECREMENT); } } else if (mLastDownEventY > mBottomSelectionDividerBottom) { if (mScrollState == OnScrollListener.SCROLL_STATE_IDLE) { mPressedStateHelper.buttonPressDelayed(PressedStateHelper.BUTTON_INCREMENT); } } getParent().requestDisallowInterceptTouchEvent(true); if (!mFlingScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } else if (!mAdjustScroller.isFinished()) { mFlingScroller.forceFinished(true); mAdjustScroller.forceFinished(true); } else if (mLastDownEventY < mTopSelectionDividerTop) { postChangeCurrentByOneFromLongPress(false, ViewConfiguration.getLongPressTimeout()); } else if (mLastDownEventY > mBottomSelectionDividerBottom) { postChangeCurrentByOneFromLongPress(true, ViewConfiguration.getLongPressTimeout()); } return true; } } return false; }