List of usage examples for android.view MotionEvent getAction
public final int getAction()
From source file:com.android.photos.views.GalleryThumbnailView.java
@Override public boolean onTouchEvent(MotionEvent ev) { mVelocityTracker.addMovement(ev);//www .j ava2s . com final int action = ev.getAction() & MotionEventCompat.ACTION_MASK; switch (action) { case MotionEvent.ACTION_DOWN: mVelocityTracker.clear(); mScroller.abortAnimation(); mLastTouchX = ev.getX(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mTouchRemainderX = 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 x = MotionEventCompat.getX(ev, index); final float dx = x - mLastTouchX + mTouchRemainderX; final int deltaX = (int) dx; mTouchRemainderX = dx - deltaX; if (Math.abs(dx) > mTouchSlop) { mTouchMode = TOUCH_MODE_DRAGGING; } if (mTouchMode == TOUCH_MODE_DRAGGING) { mLastTouchX = x; if (!trackMotionScroll(deltaX, 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.getXVelocity(mVelocityTracker, mActivePointerId); if (Math.abs(velocity) > mFlingVelocity) { // TODO mTouchMode = TOUCH_MODE_FLINGING; mScroller.fling(0, 0, (int) velocity, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0); mLastTouchX = 0; ViewCompat.postInvalidateOnAnimation(this); } else { mTouchMode = TOUCH_MODE_IDLE; } } break; } return true; }
From source file:com.ssn.currency.convertor.WheelView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled() || getViewAdapter() == null) { return true; }//from w w w. j a v a 2s . co m switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: if (!isScrollingPerformed) { int distance = (int) event.getY() - getHeight() / 2; if (distance > 0) { distance += getItemHeight() / 2; } else { distance -= getItemHeight() / 2; } int items = distance / getItemHeight(); if (items != 0 && isValidItemIndex(currentItem + items)) { notifyClickListenersAboutClick(currentItem + items); } } break; } return scroller.onTouchEvent(event); }
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 w w w.j a v a 2 s . c o 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:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
@Override public boolean onInterceptTouchEvent(final MotionEvent me) { if (mStripVisibilityGroup.isShowingImportantNoticeStrip()) { return false; }/*w ww .jav a 2s . c o m*/ // Detecting sliding up finger to show {@link MoreSuggestionsView}. if (!mMoreSuggestionsView.isShowingInParent()) { mLastX = (int) me.getX(); mLastY = (int) me.getY(); return mMoreSuggestionsSlidingDetector.onTouchEvent(me); } if (mMoreSuggestionsView.isInModalMode()) { return false; } final int action = me.getAction(); final int index = me.getActionIndex(); final int x = (int) me.getX(index); final int y = (int) me.getY(index); if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance || mOriginY - y >= mMoreSuggestionsModalTolerance) { // Decided to be in the sliding suggestion mode only when the touch point has been moved // upward. Further {@link MotionEvent}s will be delivered to // {@link #onTouchEvent(MotionEvent)}. mNeedsToTransformTouchEventToHoverEvent = AccessibilityUtils.getInstance().isTouchExplorationEnabled(); mIsDispatchingHoverEventToMoreSuggestions = false; return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { // Decided to be in the modal input mode. mMoreSuggestionsView.setModalMode(); } return false; }
From source file:com.spoiledmilk.ibikecph.map.MapActivity.java
protected boolean onImgSwiperTouch(View view, MotionEvent event) { if (leftContainer.getVisibility() != View.VISIBLE) { leftContainer.setVisibility(View.VISIBLE); }//from ww w. j a v a 2 s .c o m if (mapDisabledView.getVisibility() != View.VISIBLE) { mapDisabledView.setVisibility(View.VISIBLE); } switch (event.getAction()) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: view.setPressed(false); if (moveCount <= 3) translate(slidden ? -maxSlide : maxSlide, true); else translate(0, true); break; case MotionEvent.ACTION_DOWN: moveCount = 0; view.setPressed(true); touchX = event.getX(); break; case MotionEvent.ACTION_MOVE: if (moveCount++ < 3) break; newTouchX = event.getX(); delta = newTouchX - touchX; translate(delta, false); touchX = newTouchX; break; } if (slidden && mapDisabledView.getVisibility() != View.GONE) { mapDisabledView.setVisibility(View.GONE); } return true; }
From source file:com.aincc.libtest.activity.flip.FlipViewGroup.java
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { int tempCurrentViewId = currentItem; if (event.getY() < getHeight() / 2) { if (tempCurrentViewId > 0) { tempCurrentViewId--;/*from w w w .j av a2 s .co m*/ } renderer.getCards().handleTouchEventDown(true, tempCurrentViewId, getPrevPrevView()); } else { if (tempCurrentViewId < adapter.getCount() - 1) { tempCurrentViewId++; } renderer.getCards().handleTouchEventDown(false, tempCurrentViewId, getNextNextView()); } } return renderer.getCards().handleTouchEvent(event); }
From source file:am.widget.scalerecyclerview.ScaleRecyclerView.java
@SuppressLint("ClickableViewAccessibility") @Override/*from w ww .j a v a2 s .c om*/ public boolean onTouchEvent(MotionEvent e) { if (!mScaleEnable) return super.onTouchEvent(e); boolean superResult = false; // if (e.getPointerCount() >= 2) { // if (!mScaleBegin) { // ACTION_UP final int action = e.getAction(); e.setAction(MotionEvent.ACTION_UP); setForceInterceptDispatchOnScrollStateChanged(true); superResult = super.onTouchEvent(e); setForceInterceptDispatchOnScrollStateChanged(false); e.setAction(action); mScaleBegin = true; } superResult = mScaleGestureDetector.onTouchEvent(e) || superResult; } else { // ? final int action = e.getAction(); boolean dispatch = false; if (action == MotionEvent.ACTION_UP && getScrollState() == SCROLL_STATE_IDLE) { dispatch = true; } if (mScaleBegin) { mScaleBegin = false; // ?ACTION_DOWN e.setAction(MotionEvent.ACTION_DOWN); super.onInterceptTouchEvent(e); e.setAction(action); } superResult = super.onTouchEvent(e); if (dispatch) { dispatchOnScrollStateChanged(SCROLL_STATE_IDLE); } } return superResult; }
From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) { return false; }/*from w ww . j a v a 2 s . c o m*/ 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.appunite.list.FastScroller.java
boolean onTouchEvent(MotionEvent me) { if (mState == STATE_NONE) { return false; }//from w w w . ja v a 2 s.c om final int action = me.getAction(); if (action == MotionEvent.ACTION_DOWN) { if (isPointInside(me.getX(), me.getY())) { if (!mList.isInScrollingContainerUnhide()) { beginDrag(); return true; } mInitialTouchY = me.getY(); startPendingDrag(); } } else if (action == MotionEvent.ACTION_UP) { // don't add ACTION_CANCEL here if (mPendingDrag) { // Allow a tap to scroll. beginDrag(); final int viewHeight = mList.getHeight(); // Jitter int newThumbY = (int) me.getY() - mThumbH + 10; if (newThumbY < 0) { newThumbY = 0; } else if (newThumbY + mThumbH > viewHeight) { newThumbY = viewHeight - mThumbH; } mThumbY = newThumbY; scrollTo((float) mThumbY / (viewHeight - mThumbH)); cancelPendingDrag(); // Will hit the STATE_DRAGGING check below } if (mState == STATE_DRAGGING) { if (mList != null) { // ViewGroup does the right thing already, but there might // be other classes that don't properly reset on touch-up, // so do this explicitly just in case. mList.requestDisallowInterceptTouchEvent(false); mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE); } setState(STATE_VISIBLE); final Handler handler = mHandler; handler.removeCallbacks(mScrollFade); if (!mAlwaysShow) { handler.postDelayed(mScrollFade, 1000); } mList.invalidate(); return true; } } else if (action == MotionEvent.ACTION_MOVE) { if (mPendingDrag) { final float y = me.getY(); if (Math.abs(y - mInitialTouchY) > mScaledTouchSlop) { setState(STATE_DRAGGING); if (mListAdapter == null && mList != null) { getSectionsFromIndexer(); } if (mList != null) { mList.requestDisallowInterceptTouchEvent(true); mList.reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL); } cancelFling(); cancelPendingDrag(); // Will hit the STATE_DRAGGING check below } } if (mState == STATE_DRAGGING) { final int viewHeight = mList.getHeight(); // Jitter int newThumbY = (int) me.getY() - mThumbH + 10; if (newThumbY < 0) { newThumbY = 0; } else if (newThumbY + mThumbH > viewHeight) { newThumbY = viewHeight - mThumbH; } if (Math.abs(mThumbY - newThumbY) < 2) { return true; } mThumbY = newThumbY; // If the previous scrollTo is still pending if (mScrollCompleted) { scrollTo((float) mThumbY / (viewHeight - mThumbH)); } return true; } } else if (action == MotionEvent.ACTION_CANCEL) { cancelPendingDrag(); } 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; }// w w w .j av a2s .c om 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; }