List of usage examples for android.view MotionEvent ACTION_MOVE
int ACTION_MOVE
To view the source code for android.view MotionEvent ACTION_MOVE.
Click Source Link
From source file:com.android.BluetoothManager.UI.viewpager.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from w w w. ja va2 s .co m if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { if (!mViewPager.isFakeDragging()) { mViewPager.beginFakeDrag(); } mLastMotionX = x; mViewPager.fakeDragBy(deltaX); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.borqs.qiupu.fragment.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from www . j a v a2 s . c om if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; } final int action = ev.getAction(); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; case MotionEvent.ACTION_MOVE: { final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; if (!mIsDragging) { if (Math.abs(deltaX) > mTouchSlop) { mIsDragging = true; } } if (mIsDragging) { //TODO // if (!mViewPager.isFakeDragging()) { // mViewPager.beginFakeDrag(); // } mLastMotionX = x; //TODO // mViewPager.fakeDragBy(deltaX); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mIsDragging) { final int count = mViewPager.getAdapter().getCount(); final int width = getWidth(); final float halfWidth = width / 2f; final float sixthWidth = width / 6f; final float leftThird = halfWidth - sixthWidth; final float rightThird = halfWidth + sixthWidth; final float eventX = ev.getX(); if (eventX < leftThird) { if (mCurrentPage > 0) { mViewPager.setCurrentItem(mCurrentPage - 1); return true; } } else if (eventX > rightThird) { if (mCurrentPage < count - 1) { mViewPager.setCurrentItem(mCurrentPage + 1); return true; } } else { //Middle third if (mCenterItemClickListener != null) { mCenterItemClickListener.onCenterItemClick(mCurrentPage); } } } mIsDragging = false; mActivePointerId = INVALID_POINTER; //TODO // if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag(); break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); final float x = MotionEventCompat.getX(ev, index); mLastMotionX = x; mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } return true; }
From source file:com.app.afteryou.ui.staggered.StaggeredGridView.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 w w .j a v a2 s .c o m mVelocityTracker.addMovement(ev); final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { setTouchMode(TOUCH_MODE_DRAGGING); } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } updateSelectorState(); } break; case MotionEvent.ACTION_CANCEL: updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } setTouchMode(TOUCH_MODE_IDLE); break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO setTouchMode(TOUCH_MODE_FLINGING); mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; ViewCompat.postInvalidateOnAnimation(this); } else { setTouchMode(TOUCH_MODE_IDLE); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.bulletnoid.android.widget.StaggeredGridView.StaggeredGridView2.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { int action = ev.getAction(); View v;/* ww w . j av a 2 s . c om*/ /*if (mPositionScroller != null) { mPositionScroller.stop(); } if (!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 (mFastScroller != null && mFastScroller.onInterceptTouchEvent(ev)) { return true; }*/ switch (action & MotionEventCompat.ACTION_MASK) { 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_FLINGING && 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(); mLastTouchX = x; mLastTouchY = y; mMotionPosition = motionPosition; mTouchMode = TOUCH_MODE_DOWN; clearScrollingCache(); } mTouchRemainderY = Integer.MIN_VALUE; initOrResetVelocityTracker(); mVelocityTracker.addMovement(ev); if (touchMode == TOUCH_MODE_FLINGING) { return true; } break; } case MotionEvent.ACTION_MOVE: { switch (mTouchMode) { case TOUCH_MODE_DOWN: int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex == -1) { pointerIndex = 0; mActivePointerId = ev.getPointerId(pointerIndex); } final int y = (int) MotionEventCompat.getY(ev, pointerIndex); initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(ev); if (startScrollIfNeeded(y)) { 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); break; } case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); break; } } /*mVelocityTracker.addMovement(ev); final int action=ev.getAction()&MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); //mScroller.abortAnimation(); mLastTouchY=ev.getY(); mActivePointerId=MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY=0; if (mTouchMode==TOUCH_MODE_FLINGING) { // Catch! mTouchMode=TOUCH_MODE_DRAGGING; reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); return true; } break; case MotionEvent.ACTION_MOVE: { final int index=MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index<0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id "+ mActivePointerId+" - did StaggeredGridView receive an inconsistent "+ "event stream?"); return false; } final float y=MotionEventCompat.getY(ev, index); final float dy=y-mLastTouchY+mTouchRemainderY; final int deltaY=(int) dy; mTouchRemainderY=dy-deltaY; if (Math.abs(dy)>mTouchSlop) { mTouchMode=TOUCH_MODE_DRAGGING; return true; } } case MotionEvent.ACTION_UP: { mTouchMode=TOUCH_MODE_REST; mVelocityTracker.clear(); reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } }*/ return false; }
From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java
@Override public void onForwardedEvent(MotionEvent event, int activePointerId) { int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: // Track the velocity of movement, so we // can do swipe-to-dismiss. mVelocityTracker = VelocityTracker.obtain(); mTouchSticky = false;//from w ww . j a v a2 s .c o m case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_UP: populateStdMotion(event); if (action != MotionEvent.ACTION_UP) { return; // Don't fall down. } boolean dismissing = swipeToDismiss(); if (!dismissing) { if (mTouchSticky) { // Disable the default timeout mechanism and let // the selected widget to stay for a while. onWidgetStick(mSelectedWidget); } else if (mPressedIconView == null || !isPinnable()) { showHomeWidget(); } else { onWidgetPin(mSelectedWidget); } } case MotionEvent.ACTION_CANCEL: mTouchHandler.removeCallbacksAndMessages(null); mVelocityTracker.recycle(); mVelocityTracker = null; mTouchSticky = false; if (action == MotionEvent.ACTION_CANCEL) { showHomeWidget(); } break; } }
From source file:com.cmad.swipe.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();// w w w. ja va 2 s .c o 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; speedLimited = false; alreadyTestSpeed = false; mCurrPercentage = 0; mIsPulling = false; mCanRefreshing = false; if (vTracker == null) { vTracker = VelocityTracker.obtain(); } else { vTracker.clear(); } vTracker.addMovement(ev); 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; } if (!alreadyTestSpeed) { vTracker.addMovement(ev); vTracker.computeCurrentVelocity(1000); if (vTracker.getYVelocity() > 120) { speedLimited = true; return false; } alreadyTestSpeed = true; } else { if (speedLimited) 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.acious.android.paginationseekbar.PaginationSeekBar.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled()) { return false; }//from w ww .j a va 2 s .co m int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mDownX = event.getX(); startDragging(event, isInScrollingContainer()); break; case MotionEvent.ACTION_MOVE: if (isDragging()) { updateDragging(event); } else { final float x = event.getX(); if (Math.abs(x - mDownX) > mTouchSlop) { startDragging(event, false); } } break; case MotionEvent.ACTION_UP: notifyPageChange(mValue, true); case MotionEvent.ACTION_CANCEL: stopDragging(); break; } return true; }
From source file:com.bolaa.medical.view.pulltorefreshgrid.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);// w ww . ja va 2 s . c o m final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY()); switch (action) { case MotionEvent.ACTION_DOWN: LogUtil.d("----------onTouch ACTION_DOWN-------------"); isOnTouch = true; mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchY = ev.getY(); mLastTouchX = ev.getX(); motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderY = 0; if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0 && getAdapter().isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_DOWN; mBeginClick = true; if (mPendingCheckForTap == null) { mPendingCheckForTap = new CheckForTap(); } postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout()); } mMotionPosition = motionPosition; invalidate(); break; case MotionEvent.ACTION_MOVE: //LogUtil.d("----------onTouch ACTION_MOVE-------------"); float currentY = ev.getRawY(); if (mMoveTouchListener != null) { if (currentY - mFirstDownY >= 30) { mMoveTouchListener.onMoveDown(); } else if (mFirstDownY - currentY >= 30) { mMoveTouchListener.onMoveUp(); } } mFirstDownY = currentY; isOnTouch = true; final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (index < 0) { Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId + " - did StaggeredGridView receive an inconsistent " + "event stream?"); return false; } final float y = MotionEventCompat.getY(ev, index); final float dy = y - mLastTouchY + mTouchRemainderY; final int deltaY = (int) dy; mTouchRemainderY = dy - deltaY; if (Math.abs(dy) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL, getFirstVisiblePosition(), getLastPosition()); } updateSelectorState(); if (mFlingListener != null) { mFlingListener.onTouchFling(); } break; case MotionEvent.ACTION_CANCEL: // LogUtil.d("----------onTouch ACTION_CANCEL-------------"); isOnTouch = false; mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); updateSelectorState(); setPressed(false); View motionView = this.getChildAt(mMotionPosition - mFirstPosition); if (motionView != null) { motionView.setPressed(false); } final Handler handler = getHandler(); if (handler != null) { handler.removeCallbacks(mPendingCheckForLongPress); } if (mTopEdge != null) { mTopEdge.onRelease(); mBottomEdge.onRelease(); } mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); break; case MotionEvent.ACTION_UP: { //LogUtil.d("----------onTouch ACTION_UP-------------"); // LogUtil.d("TAG---------------onTouch ACTION_UP finish-----------" + mScroller.isFinished()); isOnTouch = false; mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); final int prevTouchMode = mTouchMode; if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mIsFling = true; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; reportScrollStateChange(OnScrollListener.SCROLL_STATE_FLING, getFirstVisiblePosition(), getLastPosition()); invalidate(); } else { mIsFling = true; mTouchMode = TOUCH_MODE_IDLE; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { // TODO : handle mTouchMode = TOUCH_MODE_TAP; } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } switch (prevTouchMode) { case TOUCH_MODE_DOWN: case TOUCH_MODE_TAP: case TOUCH_MODE_DONE_WAITING: final View child = getChildAt(motionPosition - mFirstPosition); final float x = ev.getX(); final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight(); if (child != null && !child.hasFocusable() && inList) { if (mTouchMode != TOUCH_MODE_DOWN) { child.setPressed(false); } if (mPerformClick == null) { invalidate(); mPerformClick = new PerformClick(); } final PerformClick performClick = mPerformClick; performClick.mClickMotionPosition = motionPosition; performClick.rememberWindowAttachCount(); if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) { final Handler handlerTouch = getHandler(); if (handlerTouch != null) { handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap : mPendingCheckForLongPress); } if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { mTouchMode = TOUCH_MODE_TAP; layoutChildren(mDataChanged); child.setPressed(true); positionSelector(mMotionPosition, child); setPressed(true); if (mSelector != null) { Drawable d = mSelector.getCurrent(); if (d != null && d instanceof TransitionDrawable) { ((TransitionDrawable) d).resetTransition(); } } if (mTouchModeReset != null) { removeCallbacks(mTouchModeReset); } mTouchModeReset = new Runnable() { @Override public void run() { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); child.setPressed(false); setPressed(false); if (!mDataChanged) { performClick.run(); } } }; postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration()); } else { mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } return true; } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) { performClick.run(); } } mTouchMode = TOUCH_MODE_REST; reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE, getFirstVisiblePosition(), getLastPosition()); } mBeginClick = false; updateSelectorState(); } break; } return true; }
From source file:com.base.view.slidemenu.SlideMenu.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int currentState = mCurrentState; if (STATE_DRAG == currentState || STATE_SCROLL == currentState) { return true; }/*from www . ja v a2 s. c o m*/ switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x; mPressedY = y; mIsTapInContent = isTapInContent(x, y); mIsTapInEdgeSlide = isTapInEdgeSlide(x, y); return isOpen() && mIsTapInContent; case MotionEvent.ACTION_MOVE: float dx = x - mPressedX; float dy = y - mPressedY; if (mIsEdgeSlideEnable && !mIsTapInEdgeSlide && mCurrentState == STATE_CLOSE) { return false; } // Detect the vertical scroll if (Math.abs(dy) >= mTouchSlop && mIsTapInContent && canScrollVertically(this, (int) dy, (int) x, (int) y)) { // if the child can response the vertical scroll, we will not to // steal the MotionEvent any more requestDisallowInterceptTouchEvent(true); return false; } if (Math.abs(dx) >= mTouchSlop && mIsTapInContent) { if (!canScrollHorizontally(this, (int) dx, (int) x, (int) y)) { setCurrentState(STATE_DRAG); return true; } } } return false; }
From source file:it.mb.whatshare.Utils.java
/** * Returns a string that represents the symbolic name of the specified * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent * numeric constant such as "35" if unknown. By Google. * // w w w .j a v a2 s . c om * @param action * The action. * @return The symbolic name of the specified action. */ public static String actionToString(int action) { switch (action) { case MotionEvent.ACTION_DOWN: return "ACTION_DOWN"; case MotionEvent.ACTION_UP: return "ACTION_UP"; case MotionEvent.ACTION_CANCEL: return "ACTION_CANCEL"; case MotionEvent.ACTION_OUTSIDE: return "ACTION_OUTSIDE"; case MotionEvent.ACTION_MOVE: return "ACTION_MOVE"; case MotionEvent.ACTION_HOVER_MOVE: return "ACTION_HOVER_MOVE"; case MotionEvent.ACTION_SCROLL: return "ACTION_SCROLL"; case MotionEvent.ACTION_HOVER_ENTER: return "ACTION_HOVER_ENTER"; case MotionEvent.ACTION_HOVER_EXIT: return "ACTION_HOVER_EXIT"; } int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: return "ACTION_POINTER_DOWN(" + index + ")"; case MotionEvent.ACTION_POINTER_UP: return "ACTION_POINTER_UP(" + index + ")"; default: return Integer.toString(action); } }