List of usage examples for android.view MotionEvent ACTION_DOWN
int ACTION_DOWN
To view the source code for android.view MotionEvent ACTION_DOWN.
Click Source Link
From source file:com.android.screenspeak.contextmenu.RadialMenuView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_HOVER_ENTER: // Fall-through to movement events. onEnter(event.getX(), event.getY()); case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_HOVER_MOVE: onMove(event.getX(), event.getY()); break;//from www . j av a 2 s.co m case MotionEvent.ACTION_UP: case MotionEvent.ACTION_HOVER_EXIT: onUp(event.getX(), event.getY()); break; default: // Don't handle other types of events. return false; } mHandler.onTouch(this, event); return true; }
From source file:com.adhere.view.swipe.SwipeRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();/* ww w .j a va2 s. 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(mOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; 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 && !mIsBeingDragged) { mInitialMotionY = mInitialDownY + mTouchSlop; mIsBeingDragged = true; mProgress.setAlpha(STARTING_PROGRESS_ALPHA); } 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:cn.fantasee.swipwmenulistview.swipelistview.SwipeListViewTouchListener.java
/** * @see View.OnTouchListener#onTouch(View, MotionEvent) *//* w ww .ja v a 2 s. co m*/ @Override public boolean onTouch(View view, MotionEvent motionEvent) { if (!isSwipeEnabled()) { return false; } if (viewWidth < 2) { viewWidth = swipeListView.getWidth(); } switch (MotionEventCompat.getActionMasked(motionEvent)) { case MotionEvent.ACTION_DOWN: { if (paused && downPosition != ListView.INVALID_POSITION) { return false; } swipeCurrentAction = SwipeListView.SWIPE_ACTION_NONE; int childCount = swipeListView.getChildCount(); int[] listViewCoords = new int[2]; swipeListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View child; for (int i = 0; i < childCount; i++) { child = swipeListView.getChildAt(i); child.getHitRect(rect); int childPosition = swipeListView.getPositionForView(child); // dont allow swiping if this is on the header or footer or IGNORE_ITEM_VIEW_TYPE or enabled is false on the adapter boolean allowSwipe = swipeListView.getAdapter().isEnabled(childPosition) && swipeListView.getAdapter().getItemViewType(childPosition) >= 0; if (allowSwipe && rect.contains(x, y)) { setParentView(child); setFrontView(child.findViewById(swipeFrontView), childPosition); downX = motionEvent.getRawX(); downPosition = childPosition; frontView.setClickable(!opened.get(downPosition)); frontView.setLongClickable(!opened.get(downPosition)); velocityTracker = VelocityTracker.obtain(); velocityTracker.addMovement(motionEvent); if (swipeBackView > 0) { setBackView(child.findViewById(swipeBackView)); } break; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (velocityTracker == null || !swiping || downPosition == ListView.INVALID_POSITION) { break; } float deltaX = motionEvent.getRawX() - downX; velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); if (!opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && velocityTracker.getXVelocity() > 0) { velocityX = 0; } if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && velocityTracker.getXVelocity() < 0) { velocityX = 0; } } float velocityY = Math.abs(velocityTracker.getYVelocity()); boolean swap = false; boolean swapRight = false; if (minFlingVelocity <= velocityX && velocityX <= maxFlingVelocity && velocityY * 2 < velocityX) { swapRight = velocityTracker.getXVelocity() > 0; if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "swapRight: " + swapRight + " - swipingRight: " + swipingRight); } if (swapRight != swipingRight && swipeActionLeft != swipeActionRight) { swap = false; } else if (opened.get(downPosition) && openedRight.get(downPosition) && swapRight) { swap = false; } else if (opened.get(downPosition) && !openedRight.get(downPosition) && !swapRight) { swap = false; } else { swap = true; } } else if (Math.abs(deltaX) > viewWidth / 2) { swap = true; swapRight = deltaX > 0; } generateAnimate(frontView, swap, swapRight, downPosition); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { swapChoiceState(downPosition); } velocityTracker.recycle(); velocityTracker = null; downX = 0; // change clickable front view // if (swap) { // frontView.setClickable(opened.get(downPosition)); // frontView.setLongClickable(opened.get(downPosition)); // } swiping = false; break; } case MotionEvent.ACTION_MOVE: { if (velocityTracker == null || paused || downPosition == ListView.INVALID_POSITION) { break; } velocityTracker.addMovement(motionEvent); velocityTracker.computeCurrentVelocity(1000); float velocityX = Math.abs(velocityTracker.getXVelocity()); float velocityY = Math.abs(velocityTracker.getYVelocity()); float deltaX = motionEvent.getRawX() - downX; float deltaMode = Math.abs(deltaX); int swipeMode = this.swipeMode; int changeSwipeMode = swipeListView.changeSwipeMode(downPosition); if (changeSwipeMode >= 0) { swipeMode = changeSwipeMode; } if (swipeMode == SwipeListView.SWIPE_MODE_NONE) { deltaMode = 0; } else if (swipeMode != SwipeListView.SWIPE_MODE_BOTH) { if (opened.get(downPosition)) { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX < 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX > 0) { deltaMode = 0; } } else { if (swipeMode == SwipeListView.SWIPE_MODE_LEFT && deltaX > 0) { deltaMode = 0; } else if (swipeMode == SwipeListView.SWIPE_MODE_RIGHT && deltaX < 0) { deltaMode = 0; } } } if (deltaMode > slop && swipeCurrentAction == SwipeListView.SWIPE_ACTION_NONE && velocityY < velocityX) { swiping = true; swipingRight = (deltaX > 0); if (SwipeListView.DEBUG) { Log.d(SwipeListView.TAG, "deltaX: " + deltaX + " - swipingRight: " + swipingRight); } if (opened.get(downPosition)) { swipeListView.onStartClose(downPosition, swipingRight); swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } else { if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_DISMISS) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_DISMISS; } else if (swipingRight && swipeActionRight == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else if (!swipingRight && swipeActionLeft == SwipeListView.SWIPE_ACTION_CHOICE) { swipeCurrentAction = SwipeListView.SWIPE_ACTION_CHOICE; } else { swipeCurrentAction = SwipeListView.SWIPE_ACTION_REVEAL; } swipeListView.onStartOpen(downPosition, swipeCurrentAction, swipingRight); } swipeListView.requestDisallowInterceptTouchEvent(true); MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT)); swipeListView.onTouchEvent(cancelEvent); if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) { backView.setVisibility(View.GONE); } } if (swiping && downPosition != ListView.INVALID_POSITION) { if (opened.get(downPosition)) { deltaX += openedRight.get(downPosition) ? viewWidth - rightOffset : -viewWidth + leftOffset; } move(deltaX); return true; } break; } } return false; }
From source file:com.a.mirko.android.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 ww w. j a v a 2 s .co m*/ int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { 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. 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 = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); 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. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, 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 = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } 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.onValueSelected(ENABLE_PICKER_INDEX, 1, false); 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) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } 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 = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); int action = event.getAction(); action = action & MotionEvent.ACTION_MASK; mGestureDetector.onTouchEvent(event); boolean scaleInProgress = scaleInProgress(); mScaleGestureDetector.onTouchEvent(event); if (mInteractionMode == InteractionMode.SCALE) { return true; }//from www.j ava2 s. c o m if (!scaleInProgress() && scaleInProgress) { // If we were scaling, the scale will stop but we will // still issue an ACTION_UP. Let the subclasses know. mFinishedScalingOperation = true; } int ex = (int) event.getX(); int ey = (int) event.getY(); if (action == MotionEvent.ACTION_DOWN) { mInteractionMode = InteractionMode.MOVE; mTouchDown.x = ex; mTouchDown.y = ey; mTouchShowOriginalDate = System.currentTimeMillis(); mShowOriginalDirection = 0; MasterImage.getImage().setOriginalTranslation(MasterImage.getImage().getTranslation()); } if (action == MotionEvent.ACTION_MOVE && mInteractionMode == InteractionMode.MOVE) { mTouch.x = ex; mTouch.y = ey; float scaleFactor = MasterImage.getImage().getScaleFactor(); if (scaleFactor > 1 && (!ENABLE_ZOOMED_COMPARISON || event.getPointerCount() == 2)) { float translateX = (mTouch.x - mTouchDown.x) / scaleFactor; float translateY = (mTouch.y - mTouchDown.y) / scaleFactor; Point originalTranslation = MasterImage.getImage().getOriginalTranslation(); Point translation = MasterImage.getImage().getTranslation(); translation.x = (int) (originalTranslation.x + translateX); translation.y = (int) (originalTranslation.y + translateY); MasterImage.getImage().setTranslation(translation); mTouchShowOriginal = false; } else if (enableComparison() && !mOriginalDisabled && (System.currentTimeMillis() - mTouchShowOriginalDate > mTouchShowOriginalDelayMin) && event.getPointerCount() == 1) { mTouchShowOriginal = true; } } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mInteractionMode = InteractionMode.NONE; mTouchShowOriginal = false; mTouchDown.x = 0; mTouchDown.y = 0; mTouch.x = 0; mTouch.y = 0; if (MasterImage.getImage().getScaleFactor() <= 1) { MasterImage.getImage().setScaleFactor(1); MasterImage.getImage().resetTranslation(); } } float scaleFactor = MasterImage.getImage().getScaleFactor(); Point translation = MasterImage.getImage().getTranslation(); constrainTranslation(translation, scaleFactor); MasterImage.getImage().setTranslation(translation); invalidate(); return true; }
From source file:com.android.dialer.widget.OverlappingPaneLayout.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 w w w . ja va 2s . co m } if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } return false; } switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; final float x = ev.getX(); final float y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; 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 (ady > slop && adx > ady || !isCapturableViewUnder((int) x, (int) y)) { if (!mIsInNestedScroll) { mDragHelper.cancel(); } mIsUnableToDrag = true; return false; } } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev); return interceptForDrag; }
From source file:com.android.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 w w . j av a2s .c o m int 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 = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { 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. mHapticFeedbackController.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 = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); 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. mHapticFeedbackController.tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, 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 = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { mHapticFeedbackController.tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } 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.onValueSelected(ENABLE_PICKER_INDEX, 1, false); 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) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } 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 = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:cn.edu.bit.bookstore.bookstore_android.widget.PullToRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();// w w w . j av a 2 s. c o m final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (!isEnabled() || mReturningToStart || canChildScrollUp() || mRefreshing || mNestedScrollInProgress) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; 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 && !mIsBeingDragged) { mInitialMotionY = mInitialDownY + mTouchSlop; mIsBeingDragged = true; mProgress.setAlpha(STARTING_PROGRESS_ALPHA); } 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.akshay.protocol10.asplayer.widget.SlidingUpPanelLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (!isEnabled() || !mIsSlidingEnabled || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel();/* ww w . ja va 2 s . c o m*/ return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } final float x = ev.getX(); final float y = ev.getY(); switch (action) { case MotionEvent.ACTION_DOWN: { mIsUnableToDrag = false; mInitialMotionX = x; mInitialMotionY = y; break; } case MotionEvent.ACTION_MOVE: { final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int dragSlop = mDragHelper.getTouchSlop(); // Handle any horizontal scrolling on the drag view. if (mIsUsingDragViewTouchEvents && adx > dragSlop && ady < dragSlop) { return super.onInterceptTouchEvent(ev); } if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) mInitialMotionX, (int) mInitialMotionY)) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } break; } } return mDragHelper.shouldInterceptTouchEvent(ev); }
From source file:caesar.feng.framework.widget.StaggeredGrid.ExtendableListView.java
/** * {@inheritDoc}// ww w . j av a 2 s . co m */ @Override public boolean onTouchEvent(MotionEvent event) { // we're not passing this down as // all the touch handling is right here // super.onTouchEvent(event); if (!isEnabled()) { // A disabled view that is clickable still consumes the touch // events, it just doesn't respond to them. return isClickable() || isLongClickable(); } initVelocityTrackerIfNotExists(); mVelocityTracker.addMovement(event); if (!hasChildren()) return false; boolean handled; final int action = event.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: handled = onTouchDown(event); break; case MotionEvent.ACTION_MOVE: handled = onTouchMove(event); break; case MotionEvent.ACTION_CANCEL: handled = onTouchCancel(event); break; case MotionEvent.ACTION_POINTER_UP: handled = onTouchPointerUp(event); break; case MotionEvent.ACTION_UP: handled = onTouchUp(event); break; default: handled = false; break; } notifyTouchMode(); return handled; }