List of usage examples for android.support.v4.view MotionEventCompat getActionMasked
public static int getActionMasked(MotionEvent event)
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled() || (canChildScrollUp() && canChildScrollDown()) || footerView.getSwipeStatus() == SwipeStatus.REFRESHING || headerView.getSwipeStatus() == SwipeStatus.REFRESHING || (swipeDownRefreshListener == null && swipeUpRefreshListener == null) || isAnimating()) { return false; }/*from ww w . ja v a2 s.c om*/ final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: isDragging = false; //reset currentContentOffset = 0; headerView.setCurrentOffset(0); footerView.setCurrentOffset(0); headerView.updateStatus(SwipeStatus.NORMAL); footerView.updateStatus(SwipeStatus.NORMAL); activePointerId = MotionEventCompat.getPointerId(ev, ev.getActionIndex()); initialMotionY = getMotionEventY(ev, activePointerId); break; case MotionEvent.ACTION_MOVE: if (activePointerId == INVALID_POINTER) { return false; } final float diffY = getMotionEventY(ev, activePointerId) - initialMotionY; //deal border if ((diffY > 0 && !canChildScrollUp() || (diffY < 0 && !canChildScrollDown()))) { if (Math.abs(diffY) > touchSlop && !isDragging) { isDragging = true; } } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: isDragging = false; activePointerId = INVALID_POINTER; break; } return isDragging; }
From source file:com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior.java
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown() || !mAllowUserDragging) { return false; }//from w w w . j a v a 2s . c om int action = MotionEventCompat.getActionMasked(event); 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:com.linsq.androiddemo.refresh2.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();/* w w w . ja v a 2 s . c o m*/ final int action = MotionEventCompat.getActionMasked(ev);// if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { // ???? mReturningToStart = false; } if (!isEnabled() || mReturningToStart || canChildScrollUp()) { // viewGroup????view??? // ?view return false; } // switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0);// Action_DOWND mIsBeingDragged = false; mCurrPercentage = 0; break; // ---------------------------------------------------- case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { // Logger.e("Got ACTION_MOVE event but don't have an active pointer id."); return false; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { // ??? Logger.e("Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = y - mInitialMotionY;// y? if (yDiff > mTouchSlop) {// mLastMotionY = y; mIsBeingDragged = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev);// ? break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mCurrPercentage = 0; mActivePointerId = INVALID_POINTER; break; } // true?onTouchEventmoveup? // false?view?moveup? return mIsBeingDragged; }
From source file:com.sohu.xzd.widget.SwipeRefresh.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();//from w w w . j a va 2s. c om final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: setTargetOffsetTopAndBottom(mOriginalTargetOffsetTop - mTarget.getTop(), true); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; final float initialMotionY = getMotionEventY(ev, mActivePointerId); if (initialMotionY == -1) { return false; } mInitialMotionY = initialMotionY; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); return false; } final float y = getMotionEventY(ev, mActivePointerId); if (y == -1) { return false; } final float yDiff = y - mInitialMotionY; if (yDiff > mTouchSlop && !mIsBeingDragged) { mIsBeingDragged = true; mIsSuccess = false; mRefreshHeader.onReset(); } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; break; } return mIsBeingDragged; }
From source file:com.taobao.luaview.view.widget.SuperSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;// w ww.ja v a 2s .c om } if (!isEnabled() || mReturningToStart || !isChildScrollToTop()) { // ?View???View? return false; } return handlerPullTouchEvent(ev, action); }
From source file:com.lovejjfg.powerrefresh.PowerRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();//from www .java2s. co m final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex; if (!isEnabled() || isRefreshing || isLoading || !canChildScrollUp() || mNestedScrollInProgress) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getPointerId(0); mIsBeingDragged = false; pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } mInitialDownY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { return false; } pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } final float y = ev.getY(pointerIndex); startDragging(y); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; break; } return mIsBeingDragged; }
From source file:com.cyj.ui.component.listview.CusSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;// w w w .j av a2 s . c o m } if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; mIsPulling = false; mCanRefreshing = false; break; case MotionEvent.ACTION_MOVE: final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = y - mInitialMotionY; if (!mIsBeingDragged && yDiff > mTouchSlop) { mIsBeingDragged = true; } if (mIsBeingDragged) { if (yDiff / 2 > mDistanceToTriggerSync) { mCanStartRefresh = true; } else { mCanStartRefresh = false; } updateContentOffsetTop((int) (yDiff / 2)); if (mLastMotionY > y && mTarget.getTop() == getPaddingTop()) { removeCallbacks(mCancel); } mLastMotionY = y; } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastMotionY = MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mCanStartRefresh) { startRefresh(); } else { removeCallbacks(mCancel); post(mCancel); } mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; return false; } return true; }
From source file:com.example.alyshia.customsimplelauncher.launcher.GridFragment.java
private void ensureGrid() { if (mGrid != null) { return;// w ww. j ava 2s . c o m } View root = getView(); if (root == null) { throw new IllegalStateException("Content view not yet created"); } if (root instanceof GridView) { mGrid = (GridView) root; } else { mStandardEmptyView = (TextView) root.findViewById(INTERNAL_EMPTY_ID); if (mStandardEmptyView == null) { mEmptyView = root.findViewById(android.R.id.empty); } else { mStandardEmptyView.setVisibility(View.GONE); } mProgressContainer = root.findViewById(INTERNAL_PROGRESS_CONTAINER_ID); mGridContainer = root.findViewById(INTERNAL_LIST_CONTAINER_ID); View rawGridView = root.findViewById(android.R.id.list); if (!(rawGridView instanceof GridView)) { if (rawGridView == null) { throw new RuntimeException( "Your content must have a GridView whose id attribute is " + "'android.R.id.list'"); } throw new RuntimeException( "Content has view with id attribute 'android.R.id.list' " + "that is not a GridView class"); } mGrid = (GridView) rawGridView; if (mEmptyView != null) { mGrid.setEmptyView(mEmptyView); } else if (mEmptyText != null) { mStandardEmptyView.setText(mEmptyText); mGrid.setEmptyView(mStandardEmptyView); } } mGridShown = true; mGrid.setOnItemClickListener(mOnClickListener); mGrid.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int action = MotionEventCompat.getActionMasked(event); Log.d("ME", "action is " + action); switch (action) { case MotionEvent.ACTION_DOWN: Log.d("CLICK", "ACTION_DOWN"); mLastMotionX = event.getX(); mLastMotionY = event.getY(); // int _x = Math.round(mLastMotionX); int _y = Math.round(mLastMotionY); postCheckForLongClick(600); // Long click message if (mGrid.pointToPosition(_x, _y) == AdapterView.INVALID_POSITION) { //empty spot. Log.d("grid", "emtpdyspot " + mGrid.pointToPosition(_x, _y)); } else { Log.d("grid", "reomo" + +mGrid.pointToPosition(_x, _y)); removeLongPressCallback(); } break; case MotionEvent.ACTION_SCROLL: Log.d("CLICK", "action scroll"); removeLongPressCallback(); break; case MotionEvent.ACTION_MOVE: Log.d("CLICK", "ACTION_MOVE"); final float x = event.getX(); final float y = event.getY(); final int deltaX = Math.abs((int) (mLastMotionX - x)); final int deltaY = Math.abs((int) (mLastMotionY - y)); if (deltaX >= mTouchSlop || deltaY >= mTouchSlop) { if (!mHasPerformedLongPress) { removeLongPressCallback(); } } break; case MotionEvent.ACTION_CANCEL: if (!mHasPerformedLongPress) { removeLongPressCallback(); } break; case MotionEvent.ACTION_OUTSIDE: if (!mHasPerformedLongPress) { removeLongPressCallback(); } break; case MotionEvent.ACTION_UP: Log.d("CLICK", "ACTION_UP"); if (!mHasPerformedLongPress) { removeLongPressCallback(); if (timeout) { Log.d("CLICK", "timeout"); return true; } else { Log.d("CLICK", " no time out"); } } break; default: break; } return false; } }); if (mAdapter != null) { ListAdapter adapter = mAdapter; mAdapter = null; setGridAdapter(adapter); } else { // We are starting without an adapter, so assume we won't // have our data right away and start with the progress indicator. if (mProgressContainer != null) { setGridShown(false, false); } } mHandler.post(mRequestFocus); }
From source file:com.bluepixel.android.sgpool.ui.widget.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();// ww w.j ava 2s.co m final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (!isEnabled() || mReturningToStart || canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mLastMotionY = mInitialMotionY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; mCurrPercentage = 0; break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); return false; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = y - mInitialMotionY; if (yDiff > mTouchSlop) { mLastMotionY = y; mIsBeingDragged = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mCurrPercentage = 0; mActivePointerId = INVALID_POINTER; break; } return mIsBeingDragged; }
From source file:com.shizhefei.view.coolrefreshview.CoolRefreshView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex; if (!isEnabled() || canChildScrollUp() || mRefreshing || mNestedScrollInProgress) { // Fail fast if we're not in a state where a swipe is possible return false; }// w w w. ja v a 2 s .c o m switch (action) { case MotionEvent.ACTION_DOWN: // setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = ev.getPointerId(0); mIsBeingDragged = false; pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } mInitialDownY = ev.getY(pointerIndex); mLastMotionY = getMotionEventY(ev, pointerIndex); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { Log.e(LOG_TAG, "Got ACTION_MOVE event but don't have an active pointer id."); return false; } pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } final float y = ev.getY(pointerIndex); startDragging(y); break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; break; } return mIsBeingDragged; }