List of usage examples for android.view MotionEvent getActionMasked
public final int getActionMasked()
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
private boolean isOpenQsEvent(MotionEvent event) { final int pointerCount = event.getPointerCount(); final int action = event.getActionMasked(); final boolean twoFingerDrag = action == MotionEvent.ACTION_POINTER_DOWN && pointerCount == 2; final boolean stylusButtonClickDrag = action == MotionEvent.ACTION_DOWN && (event.isButtonPressed(MotionEvent.BUTTON_STYLUS_PRIMARY) || event.isButtonPressed(MotionEvent.BUTTON_STYLUS_SECONDARY)); final boolean mouseButtonClickDrag = action == MotionEvent.ACTION_DOWN && (event.isButtonPressed(MotionEvent.BUTTON_SECONDARY) || event.isButtonPressed(MotionEvent.BUTTON_TERTIARY)); boolean isOverride = true; return twoFingerDrag || isOverride || stylusButtonClickDrag || mouseButtonClickDrag; }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
@Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getAction(); if ((ev.getActionMasked() == MotionEvent.ACTION_DOWN) || (ev.getActionMasked() == MotionEvent.ACTION_UP) || (ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) || (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN)) { mRecalCenterHour = true;//from w w w. j a v a2 s . c om } if ((mTouchMode & TOUCH_MODE_HSCROLL) == 0) { mScaleGestureDetector.onTouchEvent(ev); } switch (action) { case MotionEvent.ACTION_DOWN: mStartingScroll = true; mHandleActionUp = true; mGestureDetector.onTouchEvent(ev); return true; case MotionEvent.ACTION_MOVE: mGestureDetector.onTouchEvent(ev); return true; case MotionEvent.ACTION_UP: mEdgeEffectTop.onRelease(); mEdgeEffectBottom.onRelease(); mStartingScroll = false; mGestureDetector.onTouchEvent(ev); if (!mHandleActionUp) { mHandleActionUp = true; mViewStartX = 0; invalidate(); return true; } if (mOnFlingCalled) { return true; } // If we were scrolling, then reset the selected hour so that it is visible. if (mScrolling) { mScrolling = false; resetSelectedHour(); invalidate(); } if ((mTouchMode & TOUCH_MODE_HSCROLL) != 0) { mTouchMode = TOUCH_MODE_INITIAL_STATE; if (Math.abs(mViewStartX) > mHorizontalSnapBackThreshold) { // The user has gone beyond the threshold so switch views switchViews(mViewStartX > 0, mViewStartX, mViewWidth, 0); mViewStartX = 0; return true; } else { // Not beyond the threshold so invalidate which will cause // the view to snap back. Also call recalc() to ensure // that we have the correct starting date and title. recalc(); invalidate(); mViewStartX = 0; } } return true; // This case isn't expected to happen. case MotionEvent.ACTION_CANCEL: mGestureDetector.onTouchEvent(ev); mScrolling = false; resetSelectedHour(); return true; default: if (mGestureDetector.onTouchEvent(ev)) { return true; } return super.onTouchEvent(ev); } }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
private boolean onQsIntercept(MotionEvent event) { int pointerIndex = event.findPointerIndex(mTrackingPointer); if (pointerIndex < 0) { pointerIndex = 0;//from ww w. j a v a 2 s. c om mTrackingPointer = event.getPointerId(pointerIndex); } final float x = event.getX(pointerIndex); final float y = event.getY(pointerIndex); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: mIntercepting = true; mInitialTouchY = y; mInitialTouchX = x; initVelocityTracker(); trackMovement(event); if (shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, 0)) { getParent().requestDisallowInterceptTouchEvent(true); } if (mQsExpansionAnimator != null) { onQsExpansionStarted(); mInitialHeightOnTouch = mQsExpansionHeight; mQsTracking = true; mIntercepting = false; mNotificationStackScroller.removeLongPressCallback(); } break; case MotionEvent.ACTION_POINTER_UP: final int upPointer = event.getPointerId(event.getActionIndex()); if (mTrackingPointer == upPointer) { // gesture is ongoing, find a new pointer to track final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; mTrackingPointer = event.getPointerId(newIndex); mInitialTouchX = event.getX(newIndex); mInitialTouchY = event.getY(newIndex); } break; case MotionEvent.ACTION_MOVE: final float h = y - mInitialTouchY; trackMovement(event); if (mQsTracking) { // Already tracking because onOverscrolled was called. We need to update here // so we don't stop for a frame until the next touch event gets handled in // onTouchEvent. setQsExpansion(h + mInitialHeightOnTouch); trackMovement(event); mIntercepting = false; return true; } if (Math.abs(h) > mTouchSlop && Math.abs(h) > Math.abs(x - mInitialTouchX) && shouldQuickSettingsIntercept(mInitialTouchX, mInitialTouchY, h)) { mQsTracking = true; onQsExpansionStarted(); notifyExpandingFinished(); mInitialHeightOnTouch = mQsExpansionHeight; mInitialTouchY = y; mInitialTouchX = x; mIntercepting = false; mNotificationStackScroller.removeLongPressCallback(); return true; } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: trackMovement(event); if (mQsTracking) { flingQsWithCurrentVelocity(y, event.getActionMasked() == MotionEvent.ACTION_CANCEL); mQsTracking = false; } mIntercepting = false; break; } return false; }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
private void onQsTouch(MotionEvent event) { int pointerIndex = event.findPointerIndex(mTrackingPointer); if (pointerIndex < 0) { pointerIndex = 0;/*from w ww. jav a 2 s . co m*/ mTrackingPointer = event.getPointerId(pointerIndex); } final float y = event.getY(pointerIndex); final float x = event.getX(pointerIndex); final float h = y - mInitialTouchY; logf("onQsTouch() touch event = " + event.getActionMasked()); switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: logf("onQsTouch() touch event = MotionEvent.ACTION_DOWN "); mQsTracking = true; mInitialTouchY = y; mInitialTouchX = x; onQsExpansionStarted(); mInitialHeightOnTouch = mQsExpansionHeight; initVelocityTracker(); trackMovement(event); break; case MotionEvent.ACTION_POINTER_UP: logf("onQsTouch() touch event = MotionEvent.ACTION_POINTER_UP "); final int upPointer = event.getPointerId(event.getActionIndex()); if (mTrackingPointer == upPointer) { // gesture is ongoing, find a new pointer to track final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1; final float newY = event.getY(newIndex); final float newX = event.getX(newIndex); mTrackingPointer = event.getPointerId(newIndex); mInitialHeightOnTouch = mQsExpansionHeight; mInitialTouchY = newY; mInitialTouchX = newX; } break; case MotionEvent.ACTION_MOVE: logf("onQsTouch() touch event = MotionEvent.ACTION_MOVE "); setQsExpansion(h + mInitialHeightOnTouch); if (h >= getFalsingThreshold()) { mQsTouchAboveFalsingThreshold = true; } trackMovement(event); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: logf("onQsTouch() touch event = MotionEvent.ACTION_UP/ACTION_CANCEL"); mQsTracking = false; mTrackingPointer = -1; trackMovement(event); float fraction = getQsExpansionFraction(); if ((fraction != 0f || y >= mInitialTouchY) && (fraction != 1f || y <= mInitialTouchY)) { flingQsWithCurrentVelocity(y, event.getActionMasked() == MotionEvent.ACTION_CANCEL); } else { logQsSwipeDown(y); mScrollYOverride = -1; } if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } break; } }
From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java
@Override public boolean onTouchEvent(MotionEvent event) { // Log.e("=====onTouchEvent======", "event:"+event.getActionMasked()); if (mBlockTouches) { return false; }//from w ww. ja v a 2s.c o m initDownStates(event); if (mListenForHeadsUp && !mHeadsUpTouchHelper.isTrackingHeadsUp() && mHeadsUpTouchHelper.onInterceptTouchEvent(event)) { mIsExpansionFromHeadsUp = true; MetricsLogger.count(mContext, COUNTER_PANEL_OPEN_PEEK, 1); } if ((!mIsExpanding || mHintAnimationRunning) && !mQsExpanded && mStatusBar.getBarState() != StatusBarState.SHADE) { mAfforanceHelper.onTouchEvent(event); } if (mOnlyAffordanceInThisMotion) { return true; } mHeadsUpTouchHelper.onTouchEvent(event); //??????event if (!mHeadsUpTouchHelper.isTrackingHeadsUp() && handleQsTouch(event)) { return true; } if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) { MetricsLogger.count(mContext, COUNTER_PANEL_OPEN, 1); updateVerticalPanelPosition(event.getX()); } super.onTouchEvent(event); return true; }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); }/* w ww . ja v a2s .co m*/ initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); final int actionMasked = ev.getActionMasked(); switch (actionMasked) { case MotionEvent.ACTION_DOWN: { onTouchDown(ev); break; } case MotionEvent.ACTION_MOVE: { onTouchMove(ev); break; } case MotionEvent.ACTION_UP: { onTouchUp(ev); break; } case MotionEvent.ACTION_CANCEL: { onTouchCancel(); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); final int x = (int) mLastTouchX; final int y = (int) mLastTouchY; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started final View child = getChildAt(motionPosition - mFirstPosition); //mMotionViewOriginalTop = child.getTop(); mMotionPosition = motionPosition; } mTouchRemainderY = y; break; } case MotionEvent.ACTION_POINTER_DOWN: { // New pointers take over dragging duties final int index = ev.getActionIndex(); final int id = ev.getPointerId(index); final int x = (int) ev.getX(index); final int y = (int) ev.getY(index); mMotionCorrection = 0; mActivePointerId = id; mLastTouchX = x; mLastTouchY = y; final int motionPosition = pointToPosition(x, y); if (motionPosition >= 0) { // Remember where the motion event started final View child = getChildAt(motionPosition - mFirstPosition); //mMotionViewOriginalTop = child.getTop(); mMotionPosition = motionPosition; } mTouchRemainderY = y; break; } } return true; }
From source file:com.lovely3x.eavlibrary.EasyAdapterView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { boolean beginScroll = false; float x = ev.getX(); float y = ev.getY(); mVelocity.addMovement(ev);//from w w w . j a v a 2 s.c o m switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { mLastMotionX = x; mLastMotionY = y; mDownX = (int) ev.getX(); mDownY = (int) ev.getY(); switch (mTouchState) { case FLING: case SCROLL: case SPRING_BACK: // beginScroll = true; mTouchState = REST; break; default: mFlingRunnable.endScrollerAnimation(false, true); mTouchState = TAP; break; } if (mMaxAmountScrollPage != -1) {//,? final int first = getSelectedItemPosition(); mMaxPosition = first + mMaxAmountScrollPage; mMinPosition = first - mMaxAmountScrollPage; } mScrollTrigger = SCROLL_TRIGGER_USER; break; } case MotionEvent.ACTION_MOVE: { switch (mLayoutDirectly) { case LAYOUT_DIRECTLY_HORIZONTAL: if (mLastMotionX != Integer.MIN_VALUE) { float xDelta = x - mLastMotionX; float absDelta = Math.abs(xDelta); if (absDelta >= mTouchSlop) { beginScroll = true; mTouchState = SCROLL; if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(xDelta, 0); } else { mTouchState = TAP; } mLastMotionX = x; mLastMotionY = y; } break; case LAYOUT_DIRECTLY_VERTICAL: { if (mLastMotionY != Integer.MIN_VALUE) { float yDelta = y - mLastMotionY; float absDelta = Math.abs(yDelta); if (absDelta >= mTouchSlop) { if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } mTouchState = SCROLL; beginScroll = true; reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(0, yDelta); } else { mTouchState = TAP; } mLastMotionX = x/*Integer.MIN_VALUE*/; mLastMotionY = y; } } break; } break; } } return beginScroll; }
From source file:com.lovely3x.eavlibrary.EasyAdapterView.java
@Override public boolean onTouchEvent(MotionEvent event) { final float x = event.getX(); final float y = event.getY(); mVelocity.addMovement(event);/*from w ww. j a va2 s. co m*/ switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: { // switch (mTouchState) { // case FLING: // case SCROLL: // case SPRING_BACK: // mTouchState = REST; // break; // default: // mTouchState = TAP; // mFlingRunnable.endScrollerAnimation(false); // break; // } mLastMotionX = event.getX(); mLastMotionY = event.getY(); mDownX = (int) event.getX(); mDownY = (int) event.getY(); switch (mTouchState) { case FLING: case SCROLL: case SPRING_BACK: // beginScroll = true; mTouchState = REST; break; default: mFlingRunnable.endScrollerAnimation(false, true); mTouchState = TAP; break; } if (mMaxAmountScrollPage != -1) {//,? final int first = getSelectedItemPosition(); // mMaxPosition = (first + mMaxAmountScrollPage) % (mItemCount - 1); // mMinPosition = (first - mMaxAmountScrollPage) % (mItemCount - 1); // mMaxPosition = (first + mMaxAmountScrollPage); mMinPosition = (first - mMaxAmountScrollPage); } mScrollTrigger = SCROLL_TRIGGER_USER; break; } case MotionEvent.ACTION_MOVE: { switch (mLayoutDirectly) { case LAYOUT_DIRECTLY_HORIZONTAL: if (mLastMotionX != Integer.MIN_VALUE) { float xDelta = x - mLastMotionX; float absDelta = Math.abs(xDelta); if (isBeginDrag) { mTouchState = SCROLL; reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(xDelta, 0); } else { if (absDelta >= mTouchSlop) { isBeginDrag = true; mTouchState = SCROLL; if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(xDelta, 0); } else { mTouchState = TAP; } } mLastMotionX = x; mLastMotionY = y/*Integer.MIN_VALUE*/; } break; case LAYOUT_DIRECTLY_VERTICAL: { if (mLastMotionY != Integer.MIN_VALUE) { float yDelta = y - mLastMotionY; float absDelta = Math.abs(yDelta); if (isBeginDrag) { mTouchState = SCROLL; reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(0, yDelta); } else { if (absDelta >= mTouchSlop) { isBeginDrag = true; mTouchState = SCROLL; if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } reportScrollStateChanged(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); startScrollIfNeed(0, yDelta); } else { mTouchState = TAP; } } mLastMotionX = x/*Integer.MIN_VALUE*/; mLastMotionY = y; } } break; } break; } case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { isBeginDrag = false; mVelocity.computeCurrentVelocity(1000, mMaximumVelocity); float yVelocity = mVelocity.getYVelocity(); float xVelocity = mVelocity.getXVelocity(); int xDelta = 0; if (mDownX != Integer.MIN_VALUE) xDelta = (int) (event.getX() - mDownX); int yDelta = 0; if (mDownY != Integer.MIN_VALUE) yDelta = (int) (event.getY() - mDownY); final int maxDelta = Math.max(Math.abs(xDelta), Math.abs(yDelta)); boolean needAdjust = true; boolean isUpEvent = event.getActionMasked() == MotionEvent.ACTION_UP; switch (mLayoutDirectly) { case LAYOUT_DIRECTLY_HORIZONTAL: { if (Math.abs(xVelocity) > mMinimumVelocity && isUpEvent && maxDelta >= mTouchSlop) { needAdjust = false; mTouchState = FLING; flingInner(xVelocity, 0); } else { mFlingRunnable.endScrollerAnimation(false); mScrollTrigger = SCROLL_TRIGGER_SYSTEM; if (mTouchState == TAP && isUpEvent) { tryToClickItem((int) x, (int) y); adjustSelView(); } else { adjustSelView(); } } break; } case LAYOUT_DIRECTLY_VERTICAL: { if (Math.abs(yVelocity) > mMinimumVelocity && isUpEvent && maxDelta >= mTouchSlop) { needAdjust = false; mTouchState = FLING; flingInner(0, yVelocity); } else { mFlingRunnable.endScrollerAnimation(false); mScrollTrigger = SCROLL_TRIGGER_SYSTEM; if (mTouchState == TAP && isUpEvent) { tryToClickItem((int) x, (int) y); adjustSelView(); } else { adjustSelView(); } } break; } } if (needAdjust) mVelocity.clear(); mLastMotionY = Integer.MIN_VALUE; mLastMotionX = Integer.MIN_VALUE; mDownX = Integer.MIN_VALUE; mDownY = Integer.MIN_VALUE; mYOverScrollDistance = -1; mXOverScrollDistance = -1; mActiveEffect = null; break; } } return true; }
From source file:com.glview.widget.AbsListView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int actionMasked = ev.getActionMasked(); View v;//from w w w.j a va 2 s .com if (mPositionScroller != null) { mPositionScroller.stop(); } if (mIsDetaching || !isAttachedToWindow()) { // Something isn't right. // Since we rely on being attached to get data set change notifications, // don't risk doing anything where we might try to resync and find things // in a bogus state. return false; } if (mFastScroll != null && mFastScroll.onInterceptTouchEvent(ev)) { return true; } switch (actionMasked) { case MotionEvent.ACTION_DOWN: { int touchMode = mTouchMode; if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) { mMotionCorrection = 0; return true; } final int x = (int) ev.getX(); final int y = (int) ev.getY(); mActivePointerId = ev.getPointerId(0); int motionPosition = findMotionRow(y); if (touchMode != TOUCH_MODE_FLING && motionPosition >= 0) { // User clicked on an actual view (and was not stopping a fling). // Remember where the motion event started v = getChildAt(motionPosition - mFirstPosition); mMotionViewOriginalTop = v.getTop(); mMotionX = x; mMotionY = y; mMotionPosition = motionPosition; mTouchMode = TOUCH_MODE_DOWN; clearScrollingCache(); } mLastY = Integer.MIN_VALUE; initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); mNestedYOffset = 0; startNestedScroll(SCROLL_AXIS_VERTICAL); if (touchMode == TOUCH_MODE_FLING) { return true; } break; } case MotionEvent.ACTION_MOVE: { switch (mTouchMode) { case TOUCH_MODE_DOWN: int pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex == -1) { pointerIndex = 0; mActivePointerId = ev.getPointerId(pointerIndex); } final int y = (int) ev.getY(pointerIndex); initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); if (startScrollIfNeeded((int) ev.getX(pointerIndex), y, null)) { return true; } break; } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { mTouchMode = TOUCH_MODE_REST; mActivePointerId = INVALID_POINTER; recycleVelocityTracker(); reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); stopNestedScroll(); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); break; } } return false; }