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:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public boolean onTouch(View v, final MotionEvent event) { mGestureDetector.onTouchEvent(event); if (event.getPointerCount() > 1) { return true; }//w w w . java 2 s .com switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mDownX = event.getX(); mDownY = event.getY(); isOnClick = true; break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (isOnClick) { swipe = false; } break; case MotionEvent.ACTION_MOVE: if (isOnClick && (Math.abs(mDownX - event.getX()) > 120 || Math.abs(mDownY - event.getY()) > 120)) { swipe = true; isOnClick = false; } break; default: break; } return false; }
From source file:com.borax12.materialdaterangepicker.single.time.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;/*from w w w . j av a 2s . c o m*/ Timepoint value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = null; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mIs24HourMode) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT // in case the user moves their finger quickly. mController.tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, TAP_TIMEOUT); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = mAccessibilityManager.isTouchExplorationEnabled(); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); Timepoint selectedTime = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false); if (mController.isOutOfRange(selectedTime, getCurrentItemShowing())) mDownDegrees = -1; if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // TAP_TIMEOUT in case the user moves their finger quickly. mController.tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; mLastValueSelected = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false); mLastValueSelected = roundToValidTime(mLastValueSelected, getCurrentItemShowing()); // Redraw reselectSelector(mLastValueSelected, true, getCurrentItemShowing()); mListener.onValueSelected(mLastValueSelected); } }, TAP_TIMEOUT); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = roundToValidTime(getTimeFromDegrees(degrees, isInnerCircle[0], false), getCurrentItemShowing()); reselectSelector(value, true, getCurrentItemShowing()); if (value != null && mLastValueSelected != null && !mLastValueSelected.equals(value)) { mController.tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(value); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.enablePicker(); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { Timepoint newSelection = new Timepoint(mCurrentTime); if (mIsTouchingAmOrPm == AM) newSelection.setAM(); else if (mIsTouchingAmOrPm == PM) newSelection.setPM(); newSelection = roundToValidTime(newSelection, HOUR_INDEX); reselectSelector(newSelection, false, HOUR_INDEX); mCurrentTime = newSelection; mListener.onValueSelected(newSelection); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = getTimeFromDegrees(degrees, isInnerCircle[0], !mDoingMove); value = roundToValidTime(value, getCurrentItemShowing()); reselectSelector(value, false, getCurrentItemShowing()); mCurrentTime = value; mListener.onValueSelected(value); mListener.advancePicker(getCurrentItemShowing()); } } mDoingMove = false; return true; default: break; } return false; }
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(); }//from w ww . j a v a 2s .c o 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.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // "|" used deliberately here; both methods should be invoked. final boolean interceptForDrag = mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev); boolean interceptForTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x;//from w w w .j a va 2s. com mInitialMotionY = y; if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) { interceptForTap = true; } mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; break; } case MotionEvent.ACTION_MOVE: { // If we cross the touch slop, don't perform the delayed peek for an edge touch. if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) { mLeftCallback.removeCallbacks(); mRightCallback.removeCallbacks(); } break; } case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { closeDrawers(true); mDisallowInterceptRequested = false; mChildrenCanceledTouch = false; } } return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch; }
From source file:com.callba.phone.widget.refreshlayout.RefreshLayout.java
private boolean headerInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_DOWN: setHeaderTargetOffsetTopAndBottom(mHeaderOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsHeaderBeingDragged = false;/*from w w w.j a va2s . c o m*/ final float initialDownY = getMotionEventY(ev, mActivePointerId); if (initialDownY == -1) { return false; } mInitialDownY = initialDownY; 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 float y = getMotionEventY(ev, mActivePointerId); if (y == -1) { return false; } final float yDiff = y - mInitialDownY; if (yDiff > mTouchSlop && !mIsHeaderBeingDragged) { mInitialMotionY = mInitialDownY + mTouchSlop; mIsHeaderBeingDragged = true; mProgress.setAlpha(STARTING_PROGRESS_ALPHA); } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsHeaderBeingDragged = false; mActivePointerId = INVALID_POINTER; break; } return mIsHeaderBeingDragged; }
From source file:bhav.swipeaction.SwipeAction.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex; if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;/*from w w w . ja v a 2 s . c o m*/ } if (!isEnabled() || mReturningToStart || 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 = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; break; case MotionEvent.ACTION_MOVE: { pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; if (mIsBeingDragged) { if (overscrollTop > 0) { moveSpinner(overscrollTop); } else { return false; } } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { pointerIndex = MotionEventCompat.getActionIndex(ev); if (pointerIndex < 0) { Log.e(TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index."); return false; } mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: { pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; mIsBeingDragged = false; finishSpinner(overscrollTop); mActivePointerId = INVALID_POINTER; return false; } case MotionEvent.ACTION_CANCEL: return false; } return true; }
From source file:com.example.SmartBoard.DrawingView.java
public void onTouchLineMode(MotionEvent event) { int eventaction = event.getAction(); int X = (int) event.getX(); int Y = (int) event.getY(); switch (eventaction) { case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on // a ball points = new Point[2]; startX = X;/*from www . jav a2 s. co m*/ startY = Y; linePath.from(X, Y); linePath.to(X, Y); finished = false; if (points[0] == null) { //initialize rectangle. points[0] = new Point(); points[0].x = X; points[0].y = Y; points[1] = new Point(); points[1].x = X; points[1].y = Y + 30; for (Point pt : points) { colorballs.add(new ColorBall(getContext(), R.drawable.dot_drag_handle, pt)); } invalidate(); } break; case MotionEvent.ACTION_MOVE: // touch drag with the ball linePath.to(X, Y); colorballs.get(1).setX(X); colorballs.get(1).setY(Y); invalidate(); break; case MotionEvent.ACTION_UP: // touch drop - just do things here after dropping linePath.to(X, Y); colorballs.get(1).setX(X); colorballs.get(1).setY(Y); finished = true; break; } // redraw the canvas invalidate(); return; }
From source file:com.bw.luzz.monkeyapplication.View.DateTimePicker.time.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;//from w ww .j av a 2 s. co m Timepoint value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = null; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mIs24HourMode) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT // in case the user moves their finger quickly. mController.tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, TAP_TIMEOUT); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = mAccessibilityManager.isTouchExplorationEnabled(); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); Timepoint selectedTime = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false); if (mController.isOutOfRange(selectedTime, getCurrentItemShowing())) mDownDegrees = -1; if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // TAP_TIMEOUT in case the user moves their finger quickly. mController.tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; mLastValueSelected = getTimeFromDegrees(mDownDegrees, isInnerCircle[0], false); mLastValueSelected = roundToValidTime(mLastValueSelected, getCurrentItemShowing()); // Redraw reselectSelector(mLastValueSelected, true, getCurrentItemShowing()); mListener.onValueSelected(mLastValueSelected); } }, TAP_TIMEOUT); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = roundToValidTime(getTimeFromDegrees(degrees, isInnerCircle[0], false), getCurrentItemShowing()); reselectSelector(value, true, getCurrentItemShowing()); if (value != null && (mLastValueSelected == null || !mLastValueSelected.equals(value))) { mController.tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(value); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.enablePicker(); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { Timepoint newSelection = new Timepoint(mCurrentTime); if (mIsTouchingAmOrPm == AM) newSelection.setAM(); else if (mIsTouchingAmOrPm == PM) newSelection.setPM(); newSelection = roundToValidTime(newSelection, HOUR_INDEX); reselectSelector(newSelection, false, HOUR_INDEX); mCurrentTime = newSelection; mListener.onValueSelected(newSelection); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = getTimeFromDegrees(degrees, isInnerCircle[0], !mDoingMove); value = roundToValidTime(value, getCurrentItemShowing()); reselectSelector(value, false, getCurrentItemShowing()); mCurrentTime = value; mListener.onValueSelected(value); mListener.advancePicker(getCurrentItemShowing()); } } mDoingMove = false; return true; default: break; } return false; }
From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); // Preserve the open state based on the last view that was touched. if (!mCanSlide && action == MotionEvent.ACTION_DOWN && getChildCount() > 1) { // After the first things will be slideable. final View secondChild = getChildAt(1); if (secondChild != null) { mPreservedOpenState = !mDragHelper.isViewUnder(secondChild, (int) ev.getX(), (int) ev.getY()); }//from ww w. j av a 2 s. c o m } // ======================== START ======================== if (!isSwipeBackEnable()) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } // ======================== END ======================== if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel(); return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } boolean interceptTap = false; switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; if (mDragHelper.isViewUnder(mSlideableView, (int) x, (int) y) && isDimmed(mSlideableView)) { interceptTap = true; } break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if (adx > slop && ady > adx) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag || interceptTap; }