List of usage examples for android.view MotionEvent getPointerId
public final int getPointerId(int pointerIndex)
From source file:com.lovejjfg.powerrefresh.PowerRefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { ensureTarget();/*from w w w . j a v a2 s. com*/ final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex; if (!isEnabled() || isRefreshing || isLoading || !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 = ev.getPointerId(0); mIsBeingDragged = false; pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } mInitialDownY = ev.getY(pointerIndex); break; case MotionEvent.ACTION_MOVE: if (mActivePointerId == INVALID_POINTER) { return false; } pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } final float y = ev.getY(pointerIndex); startDragging(y); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mIsBeingDragged = false; mActivePointerId = INVALID_POINTER; break; } return mIsBeingDragged; }
From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = (ev.getAction() & ACTION_POINTER_INDEX_MASK) >> ACTION_POINTER_INDEX_SHIFT; final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose // a new active pointer and adjust accordingly. // TODO: Make this decision more intelligent. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mDownMotionX = ev.getX(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); }/*from w w w . j av a 2 s . c o m*/ }
From source file:com.ouyangzn.view.RefreshLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (mRefreshing) return false; boolean intercept = mDragHelper.shouldInterceptTouchEvent(ev); if (intercept) return true; switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: { mDownY = ev.getY();/*from www . ja v a 2s . com*/ break; } case MotionEvent.ACTION_MOVE: { if (isVerticalScrollView(mContentView)) { // if (ev.getY() - mDownY > 0) { intercept = !ViewCompat.canScrollVertically(mContentView, -1); Log.d(TAG, "----------intercept = " + intercept); } //else { // intercept = !ViewCompat.canScrollVertically(mContentView, 1); // Log.d(TAG, "----------intercept = " + intercept); //} } else { intercept = mDragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL); } break; } } if (intercept) mDragHelper.captureChildView(mContentView, ev.getPointerId(0)); return intercept; }
From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); if (canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return super.onTouchEvent(ev); }/*from ww w . j a va 2s . c o m*/ mVelocityTracker.addMovement(ev); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: { final float x = ev.getX(); final float y = ev.getY(); mInitialTouchX = x; mInitialTouchY = mLastTouchY = y; mActivePointerId = ev.getPointerId(0); if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) { mIsDragging = handled = true; } handled |= mCollapsibleHeight > 0; mScroller.abortAnimation(); } break; case MotionEvent.ACTION_MOVE: { int index = ev.findPointerIndex(mActivePointerId); if (index < 0) { Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting"); index = 0; mActivePointerId = ev.getPointerId(0); mInitialTouchX = ev.getX(); mInitialTouchY = mLastTouchY = ev.getY(); } final float x = ev.getX(index); final float y = ev.getY(index); if (!mIsDragging) { final float dy = y - mInitialTouchY; if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) { handled = mIsDragging = true; mLastTouchY = Math.max(mLastTouchY - mTouchSlop, Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop)); } } if (mIsDragging) { final float dy = y - mLastTouchY; performDrag(dy); } mLastTouchY = y; } break; case MotionEvent.ACTION_POINTER_DOWN: { final int pointerIndex = ev.getActionIndex(); final int pointerId = ev.getPointerId(pointerIndex); mActivePointerId = pointerId; mInitialTouchX = ev.getX(pointerIndex); mInitialTouchY = mLastTouchY = ev.getY(pointerIndex); } break; case MotionEvent.ACTION_POINTER_UP: { onSecondaryPointerUp(ev); } break; case MotionEvent.ACTION_UP: { mIsDragging = false; if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null && findChildUnder(ev.getX(), ev.getY()) == null) { if (mClickOutsideListener != null) { mClickOutsideListener.onClick(this); resetTouch(); return true; } } if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) { smoothScrollTo(0, 0); return true; } mVelocityTracker.computeCurrentVelocity(1000); final float yvel = mVelocityTracker.getYVelocity(mActivePointerId); if (Math.abs(yvel) > mMinFlingVelocity) { smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel); } else { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); } break; case MotionEvent.ACTION_CANCEL: { if (mIsDragging) { smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0); } resetTouch(); return true; } } return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0); }
From source file:com.shizhefei.view.coolrefreshview.CoolRefreshView.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex = -1; if (!isEnabled() || canChildScrollUp() || mRefreshing || mNestedScrollInProgress) { // Fail fast if we're not in a state where a swipe is possible return false; }/* w ww. j av a 2 s.c o m*/ switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = ev.getPointerId(0); mIsBeingDragged = false; mLastMotionY = getMotionEventY(ev, mActivePointerId); break; case MotionEvent.ACTION_MOVE: { pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = ev.getY(pointerIndex); startDragging(y); if (mIsBeingDragged) { float dy = mLastMotionY - y; touchMove((int) dy); mLastMotionY = y; } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { pointerIndex = MotionEventCompat.getActionIndex(ev); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index."); return false; } mActivePointerId = ev.getPointerId(pointerIndex); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: { pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id."); return false; } if (mIsBeingDragged) { // final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; mIsBeingDragged = false; finishSpinner(); } mActivePointerId = INVALID_POINTER; return false; } case MotionEvent.ACTION_CANCEL: return false; } return true; }
From source file:org.godotengine.godot.Godot.java
public boolean gotTouchEvent(final MotionEvent event) { final int evcount = event.getPointerCount(); if (evcount == 0) return true; if (mView != null) { final int[] arr = new int[event.getPointerCount() * 3]; for (int i = 0; i < event.getPointerCount(); i++) { arr[i * 3 + 0] = (int) event.getPointerId(i); arr[i * 3 + 1] = (int) event.getX(i); arr[i * 3 + 2] = (int) event.getY(i); }//from ww w . j a v a 2 s . c o m final int pointer_idx = event.getPointerId(event.getActionIndex()); //System.out.printf("gaction: %d\n",event.getAction()); final int action = event.getAction() & MotionEvent.ACTION_MASK; mView.queueEvent(new Runnable() { @Override public void run() { switch (action) { case MotionEvent.ACTION_DOWN: { GodotLib.touch(0, 0, evcount, arr); //System.out.printf("action down at: %f,%f\n", event.getX(),event.getY()); } break; case MotionEvent.ACTION_MOVE: { GodotLib.touch(1, 0, evcount, arr); /* for(int i=0;i<event.getPointerCount();i++) { System.out.printf("%d - moved to: %f,%f\n",i, event.getX(i),event.getY(i)); } */ } break; case MotionEvent.ACTION_POINTER_UP: { GodotLib.touch(4, pointer_idx, evcount, arr); //System.out.printf("%d - s.up at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_POINTER_DOWN: { GodotLib.touch(3, pointer_idx, evcount, arr); //System.out.printf("%d - s.down at: %f,%f\n",pointer_idx, event.getX(pointer_idx),event.getY(pointer_idx)); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: { GodotLib.touch(2, 0, evcount, arr); /* for(int i=0;i<event.getPointerCount();i++) { System.out.printf("%d - up! %f,%f\n",i, event.getX(i),event.getY(i)); } */ } break; } } }); } return true; }
From source file:jackson.com.slidingmenulib.MyViewDragHelper.java
private void saveLastMotion(MotionEvent ev) { final int pointerCount = ev.getPointerCount(); for (int i = 0; i < pointerCount; i++) { final int pointerId = ev.getPointerId(i); // If pointer is invalid then skip saving on ACTION_MOVE. if (!isValidPointerForActionMove(pointerId)) { continue; }//from w w w . j ava 2 s. c o m final float x = ev.getX(i); final float y = ev.getY(i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
From source file:com.shizhefei.view.coolrefreshview.CoolRefreshView.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); int pointerIndex; if (!isEnabled() || canChildScrollUp() || mRefreshing || mNestedScrollInProgress) { // Fail fast if we're not in a state where a swipe is possible return false; }//from ww w . j av a 2 s .co m switch (action) { case MotionEvent.ACTION_DOWN: // setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = ev.getPointerId(0); mIsBeingDragged = false; pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } mInitialDownY = ev.getY(pointerIndex); mLastMotionY = getMotionEventY(ev, pointerIndex); 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; } pointerIndex = ev.findPointerIndex(mActivePointerId); if (pointerIndex < 0) { return false; } final float y = ev.getY(pointerIndex); startDragging(y); 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.leeon.blank.widget.RangeBarNew.java
private void handleTouchDown(MotionEvent event) { final int actionIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int downX = (int) event.getX(actionIndex); final int downY = (int) event.getY(actionIndex); if (mLeftCursorRect.contains(downX, downY)) { if (mLeftHit) { return; }/*ww w .j a v a 2 s. co m*/ // If hit, change state of drawable, and record id of touch pointer. mLeftPointerLastX = downX; mLeftCursorBG.setState(mPressedEnableState); mLeftPointerID = event.getPointerId(actionIndex); mLeftHit = true; invalidate(); } else if (mRightCursorRect.contains(downX, downY)) { if (mRightHit) { return; } mRightPointerLastX = downX; mRightCursorBG.setState(mPressedEnableState); mRightPointerID = event.getPointerId(actionIndex); mRightHit = true; invalidate(); } }
From source file:com.wunderlist.slidinglayer.SlidingLayer.java
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = ev.getActionIndex(); final int pointerId = ev.getPointerId(pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mLastX = ev.getX(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear();//from ww w. ja v a 2s . co m } } }