List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_DOWN: mDownX = event.getX();/*w ww . j a v a 2 s . co m*/ mDisallowedParentIntercept = false; case MotionEvent.ACTION_MOVE: int x = (int) event.getX(); if (!mDisallowedParentIntercept && Math.abs(x - mDownX) > mScaledTouchSlop) { getParent().requestDisallowInterceptTouchEvent(true); mDisallowedParentIntercept = true; } Item item = findItemByPoint(x, (int) event.getY()); if (mTargetItem != item) { mTargetItem = item; if (item != null) { item.setSelected(!item.isSelected()); ItemState state = new ItemState(); state.item = item; state.isSelected = item.isSelected(); if (mItemState == null) { mItemState = state; } else { state.next = mItemState; mItemState = state; } } } break; case MotionEvent.ACTION_CANCEL: if (mItemState != null) { ItemState state = mItemState; while (state != null) { state.item.setSelected(!state.isSelected); state = state.next; } } case MotionEvent.ACTION_UP: requestLayout(); invalidate(); mTargetItem = null; if (mDisallowedParentIntercept) { getParent().requestDisallowInterceptTouchEvent(false); } mItemState = null; break; } return true; }
From source file:co.vn.e_alarm.customwiget.SlidingLayer.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mEnabled) { return false; }//from ww w .jav a 2 s .c o m final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { /* * Return event touch to children view. */ mIsDragging = false; mIsUnableToDrag = false; mActivePointerId = INVALID_POINTER; if (mVelocityTracker != null) { mVelocityTracker.recycle(); mVelocityTracker = null; } return false; } if (action != MotionEvent.ACTION_DOWN) { if (mIsDragging) { return true; } else if (mIsUnableToDrag) { return false; } } switch (action) { case MotionEvent.ACTION_MOVE: final int activePointerId = mActivePointerId; if (activePointerId == INVALID_POINTER) { break; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastY; final float yDiff = Math.abs(y - mLastY); if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) { // mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); } else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) { // mIsDragging = true; mLastY = y; setDrawingCacheEnabled(true); } float matY = (float) Math.abs(corY - ev.getRawY()); float matX = (float) Math.abs(corX - ev.getRawX()); if (matY - 100 > 0) { mIsDragging = true; setDrawingCacheEnabled(true); // Dang di chuyen len } else if (matX - 100 > 0) { mIsDragging = false; } if (matY == 0) { setDrawingCacheEnabled(false); } /* }else{ mIsDragging = false; setDrawingCacheEnabled(true); }*/ /* }else if(corX +150 > ev.getRawX()){ mIsDragging = false; setDrawingCacheEnabled(true); }else if(corX +150 < ev.getRawX()){ mIsDragging = false; setDrawingCacheEnabled(true); }*/ // double corY = ev.getY(); break; case MotionEvent.ACTION_DOWN: corX = ev.getRawX(); corY = ev.getRawY(); mActivePointerId = ev.getAction() & (Build.VERSION.SDK_INT >= 8 ? MotionEvent.ACTION_POINTER_INDEX_MASK : MotionEventCompat.ACTION_POINTER_INDEX_MASK); mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId); mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId); if (allowSlidingFromHereX(ev, mInitialX)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else if (allowSlidingFromHereY(ev, mInitialY)) { mIsDragging = false; mIsUnableToDrag = false; // If nobody else got the focus we use it to close the layer return super.onInterceptTouchEvent(ev); } else { mIsUnableToDrag = true; } break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; } if (!mIsDragging) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); } return mIsDragging; }
From source file:org.cocos2dx.lib.TextInputWraper.java
public boolean onTouchEvent(final MotionEvent event) { // these data are used in ACTION_MOVE and ACTION_CANCEL final int pointerNumber = event.getPointerCount(); final int[] ids = new int[pointerNumber]; final float[] xs = new float[pointerNumber]; final float[] ys = new float[pointerNumber]; for (int i = 0; i < pointerNumber; i++) { ids[i] = event.getPointerId(i);/*from ww w.j a v a 2 s. co m*/ xs[i] = event.getX(i); ys[i] = event.getY(i); } switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerDown = event.getPointerId(indexPointerDown); final float xPointerDown = event.getX(indexPointerDown); final float yPointerDown = event.getY(indexPointerDown); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown); } }); break; case MotionEvent.ACTION_DOWN: // there are only one finger on the screen final int idDown = event.getPointerId(0); final float xDown = xs[0]; final float yDown = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idDown, xDown, yDown); } }); break; case MotionEvent.ACTION_MOVE: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionMove(ids, xs, ys); } }); break; case MotionEvent.ACTION_POINTER_UP: final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerUp = event.getPointerId(indexPointUp); final float xPointerUp = event.getX(indexPointUp); final float yPointerUp = event.getY(indexPointUp); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp); } }); break; case MotionEvent.ACTION_UP: // there are only one finger on the screen final int idUp = event.getPointerId(0); final float xUp = xs[0]; final float yUp = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idUp, xUp, yUp); } }); break; case MotionEvent.ACTION_CANCEL: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionCancel(ids, xs, ys); } }); break; } if (debug) { dumpEvent(event); } return true; }
From source file:cc.solart.turbo.TurboRecyclerView.java
@Override public boolean onTouchEvent(MotionEvent e) { if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) { return super.onTouchEvent(e); }/*from www . j a va2 s .c o m*/ if (dispatchOnItemTouch(e)) { return true; } if (getLayoutManager() == null) { return false; } final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally(); final boolean canScrollVertically = getLayoutManager().canScrollVertically(); final int action = MotionEventCompat.getActionMasked(e); switch (action) { case MotionEvent.ACTION_DOWN: { final int index = MotionEventCompat.getActionIndex(e); mActivePointerId = MotionEventCompat.getPointerId(e, 0); mInitialMotionX = getMotionEventX(e, index); mInitialMotionY = getMotionEventY(e, index); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(e); mActivePointerId = MotionEventCompat.getPointerId(e, index); mInitialMotionX = getMotionEventX(e, index); mInitialMotionY = getMotionEventY(e, index); } break; case MotionEvent.ACTION_MOVE: { final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId); if (index < 0) { Log.w(TAG, "pointer index for id " + index + " not found. return super"); return super.onTouchEvent(e); } final int x = getMotionEventX(e, index); final int y = getMotionEventY(e, index); int deltaY = y - mInitialMotionY; if (canScrollVertically && Math.abs(deltaY) > mTouchSlop && deltaY < 0) { float targetEnd = -dampAxis(deltaY); setTranslationY(targetEnd); return true; } int deltaX = x - mInitialMotionX; if (canScrollHorizontally && Math.abs(deltaX) > mTouchSlop && deltaX < 0) { float targetEnd = -dampAxis(deltaX); setTranslationX(targetEnd); return true; } } break; case MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { if (canScrollHorizontally) animateOffsetToEnd("translationX", mInterpolator, 0f); if (canScrollVertically) animateOffsetToEnd("translationY", mInterpolator, 0f); final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId); if (index < 0) { Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id."); return super.onTouchEvent(e); } final int y = getMotionEventY(e, index); final int x = getMotionEventX(e, index); final float overScrollBottom = (mInitialMotionY - y) * DRAG_RATE; final float overScrollRight = (mInitialMotionX - x) * DRAG_RATE; if ((canScrollVertically && overScrollBottom > mTotalDragDistance) || (canScrollHorizontally && overScrollRight > mTotalDragDistance)) { Log.i(TAG, "refreshing..."); mIsLoading = true; dispatchOnLoadingMoreListeners(); smoothScrollToPosition(mLastVisibleItemPosition + 1); mActivePointerId = INVALID_POINTER; return true; } else { mIsLoading = false; mActivePointerId = INVALID_POINTER; } } break; } return super.onTouchEvent(e); }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterListView.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final float x = ev.getX(); final float y = ev.getY(); final int action = ev.getAction(); if (action == MotionEvent.ACTION_DOWN && touchTarget == null && stickyWrapper != null && isStickyViewTouched(stickyWrapper.view, x, y)) { touchTarget = stickyWrapper.view; touchPt.x = x;// w w w.j av a 2s. co m touchPt.y = y; downEvent = MotionEvent.obtain(ev); } if (touchTarget != null) { if (isStickyViewTouched(touchTarget, x, y)) { // forward event to header view touchTarget.dispatchTouchEvent(ev); } if (action == MotionEvent.ACTION_UP) { super.dispatchTouchEvent(ev); clearTouchTarget(); } else if (action == MotionEvent.ACTION_CANCEL) { clearTouchTarget(); } else if (action == MotionEvent.ACTION_MOVE) { if (Math.abs(y - touchPt.y) > touchSlop) { MotionEvent event = MotionEvent.obtain(ev); event.setAction(MotionEvent.ACTION_CANCEL); touchTarget.dispatchTouchEvent(event); event.recycle(); super.dispatchTouchEvent(downEvent); super.dispatchTouchEvent(ev); clearTouchTarget(); } } return true; } return super.dispatchTouchEvent(ev); }
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
/** * This is why you don't implement your own TextView kids; you have to handle everything! *///from ww w. j ava2 s .c o m @Override public boolean onTouchEvent(MotionEvent event) { if (!(text instanceof Spanned)) return super.onTouchEvent(event); Spannable spannedText = (Spannable) text; boolean handled = false; if (event.getAction() == MotionEvent.ACTION_DOWN) { pressedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null) { pressedSpan.setPressed(true); Selection.setSelection(spannedText, spannedText.getSpanStart(pressedSpan), spannedText.getSpanEnd(pressedSpan)); handled = true; postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_MOVE) { TouchableUrlSpan touchedSpan = getPressedSpan(spannedText, event); if (pressedSpan != null && touchedSpan != pressedSpan) { pressedSpan.setPressed(false); pressedSpan = null; Selection.removeSelection(spannedText); postInvalidateOnAnimation(); } } else if (event.getAction() == MotionEvent.ACTION_UP) { if (pressedSpan != null) { pressedSpan.setPressed(false); pressedSpan.onClick(this); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } else { if (pressedSpan != null) { pressedSpan.setPressed(false); handled = true; postInvalidateOnAnimation(); } pressedSpan = null; Selection.removeSelection(spannedText); } return handled; }
From source file:chinanurse.cn.nurse.list.WaveSwipeRefreshLayout.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (!isEnabled() || canChildScrollUp()) { return false; }/*www.jav a2s . c o m*/ mIsBeingDropped = mWaveView.isDisappearCircleAnimatorRunning(); final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: // Here is not called from anywhere break; case MotionEvent.ACTION_MOVE: final int pointerIndex = MotionEventCompat.findPointerIndex(event, mActivePointerId); return pointerIndex >= 0 && onMoveTouchEvent(event, pointerIndex); case MotionEvent.ACTION_UP: if (mIsBeingDropped) { mIsBeingDropped = false; return false; } final float diffY = event.getY() - mFirstTouchDownPointY; final float waveHeightThreshold = diffY * (5f - 2 * diffY / Math.min(getMeasuredWidth(), getMeasuredHeight())) / 1000f; mWaveView.startWaveAnimation(waveHeightThreshold); case MotionEvent.ACTION_CANCEL: if (mActivePointerId == INVALID_POINTER) { return false; } if (!isRefreshing()) { mCircleView.setProgressStartEndTrim(0f, 0f); mCircleView.showArrow(false); mCircleView.setVisibility(GONE); } mActivePointerId = INVALID_POINTER; return false; } return true; }
From source file:com.achep.acdisplay.ui.widgets.CircleView.java
public boolean sendTouchEvent(@NonNull MotionEvent event) { final int action = event.getActionMasked(); // If current circle is canceled then // ignore all actions except of touch down (to reset state.) if (mCanceled && action != MotionEvent.ACTION_DOWN) return false; // Cancel the current circle on two-or-more-fingers touch. if (event.getPointerCount() > 1) { cancelCircle();/*from w w w. j av a 2 s . c o m*/ return false; } final float x = event.getX(); final float y = event.getY(); switch (action) { case MotionEvent.ACTION_DOWN: clearAnimation(); Config config = Config.getInstance(); // Corner actions int width = getWidth(); int height = getHeight(); int radius = Math.min(width, height) / 3; if (MathUtils.isInCircle(x, y, 0, 0, radius)) { // Top left mCornerActionId = config.getCornerActionLeftTop(); } else if (MathUtils.isInCircle(x, y, -width, 0, radius)) { // Top right mCornerActionId = config.getCornerActionRightTop(); } else if (MathUtils.isInCircle(x, y, 0, -height, radius)) { // Bottom left mCornerActionId = config.getCornerActionLeftBottom(); } else if (MathUtils.isInCircle(x, y, -width, -height, radius)) { // Bottom right mCornerActionId = config.getCornerActionRightBottom(); } else { // The default action is unlocking. mCornerActionId = Config.CORNER_UNLOCK; } // Update colors and icon drawable. boolean needsColorReset = updateIcon(); setInnerColor(getColor(config.getCircleInnerColor()), needsColorReset); setOuterColor(getColor(config.getCircleOuterColor())); // Initialize circle mRadiusTargetAimed = false; mRadiusMaxPeak = 0; mPoint[0] = x; mPoint[1] = y; mCanceled = false; if (mHandler.hasMessages(ACTION_UNLOCK)) { // Cancel unlocking process. mHandler.sendEmptyMessage(ACTION_UNLOCK_CANCEL); } mHandler.removeCallbacksAndMessages(null); mHandler.sendEmptyMessageDelayed(MSG_CANCEL, 1000); mHandler.sendEmptyMessage(ACTION_START); break; case MotionEvent.ACTION_MOVE: setRadius(x, y); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: if (!mRadiusTargetAimed || action == MotionEvent.ACTION_CANCEL) { cancelCircle(); break; } startUnlock(); break; } return true; }
From source file:cn.ieclipse.af.view.StaggeredGridView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//from w ww .j a v a 2s . co m 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; 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; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchY = y; if (!trackMotionScroll(deltaY, true)) { // Break fling velocity if we impacted an edge. mVelocityTracker.clear(); } } } break; case MotionEvent.ACTION_CANCEL: mTouchMode = TOUCH_MODE_IDLE; break; case MotionEvent.ACTION_UP: { mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId); if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); mLastTouchY = 0; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } break; } return true; }