本文整理汇总了Java中android.support.v4.view.MotionEventCompat.findPointerIndex方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat.findPointerIndex方法的具体用法?Java MotionEventCompat.findPointerIndex怎么用?Java MotionEventCompat.findPointerIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.MotionEventCompat
的用法示例。
在下文中一共展示了MotionEventCompat.findPointerIndex方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSwipedView
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private ViewHolder findSwipedView(MotionEvent motionEvent) {
final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
return null;
}
final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, mActivePointerId);
final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - mInitialTouchX;
final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - mInitialTouchY;
final float absDx = Math.abs(dx);
final float absDy = Math.abs(dy);
if (absDx < mSlop && absDy < mSlop) {
return null;
}
if (absDx > absDy && lm.canScrollHorizontally()) {
return null;
} else if (absDy > absDx && lm.canScrollVertically()) {
return null;
}
View child = findChildView(motionEvent);
if (child == null) {
return null;
}
return mRecyclerView.getChildViewHolder(child);
}
示例2: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
//Check pointer index to avoid -1 (error)
if (MotionEventCompat.findPointerIndex(event, 0) == -1) {
return super.onTouchEvent(event);
}
if (event.getPointerCount() >= 1) {
requestDisallowInterceptTouchEvent(true);
} else {
requestDisallowInterceptTouchEvent(false);
}
return super.onTouchEvent(event);
}
示例3: getPointerIndex
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
/**
* 得到指针的索引值
*/
private int getPointerIndex(MotionEvent ev, int id) {
int activePointerIndex = MotionEventCompat.findPointerIndex(ev, id);
if (activePointerIndex == -1)
mActivePointerId = INVALID_POINTER;
return activePointerIndex;
}
示例4: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (index < 0) {
return -1;
}
return MotionEventCompat.getY(ev, index);
}
示例5: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
final int index = MotionEventCompat.findPointerIndex(ev,
activePointerId);
if (index < 0) {
return -1;
}
return MotionEventCompat.getY(ev, index);
}
示例6: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
ItemTouchHelper.this.mGestureDetector.onTouchEvent(event);
int action = MotionEventCompat.getActionMasked(event);
if (action == 0) {
ItemTouchHelper.this.mActivePointerId = MotionEventCompat.getPointerId(event, 0);
ItemTouchHelper.this.mInitialTouchX = event.getX();
ItemTouchHelper.this.mInitialTouchY = event.getY();
ItemTouchHelper.this.obtainVelocityTracker();
if (ItemTouchHelper.this.mSelected == null) {
RecoverAnimation animation = ItemTouchHelper.this.findAnimation(event);
if (animation != null) {
ItemTouchHelper itemTouchHelper = ItemTouchHelper.this;
itemTouchHelper.mInitialTouchX -= animation.mX;
itemTouchHelper = ItemTouchHelper.this;
itemTouchHelper.mInitialTouchY -= animation.mY;
ItemTouchHelper.this.endRecoverAnimation(animation.mViewHolder, true);
if (ItemTouchHelper.this.mPendingCleanup.remove(animation.mViewHolder.itemView)) {
ItemTouchHelper.this.mCallback.clearView(ItemTouchHelper.this.mRecyclerView, animation.mViewHolder);
}
ItemTouchHelper.this.select(animation.mViewHolder, animation.mActionState);
ItemTouchHelper.this.updateDxDy(event, ItemTouchHelper.this.mSelectedFlags, 0);
}
}
} else if (action == 3 || action == 1) {
ItemTouchHelper.this.mActivePointerId = -1;
ItemTouchHelper.this.select(null, 0);
} else if (ItemTouchHelper.this.mActivePointerId != -1) {
int index = MotionEventCompat.findPointerIndex(event, ItemTouchHelper.this.mActivePointerId);
if (index >= 0) {
ItemTouchHelper.this.checkSelectForSwipe(action, event, index);
}
}
if (ItemTouchHelper.this.mVelocityTracker != null) {
ItemTouchHelper.this.mVelocityTracker.addMovement(event);
}
if (ItemTouchHelper.this.mSelected != null) {
return true;
}
return false;
}
示例7: getMotionEventY
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent ev, int activePointerId) {
int index = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (index < 0) {
return -1.0f;
}
return MotionEventCompat.getY(ev, index);
}
示例8: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
final int action = MotionEventCompat.getActionMasked(e);
final int actionIndex = MotionEventCompat.getActionIndex(e);
switch (action) {
case MotionEvent.ACTION_DOWN:
mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
mInitialTouchX = (int) (e.getX() + 0.5f);
mInitialTouchY = (int) (e.getY() + 0.5f);
return super.onInterceptTouchEvent(e);
case MotionEventCompat.ACTION_POINTER_DOWN:
mScrollPointerId = MotionEventCompat.getPointerId(e, actionIndex);
mInitialTouchX = (int) (MotionEventCompat.getX(e, actionIndex) + 0.5f);
mInitialTouchY = (int) (MotionEventCompat.getY(e, actionIndex) + 0.5f);
return super.onInterceptTouchEvent(e);
case MotionEvent.ACTION_MOVE: {
final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
if (index < 0) {
return false;
}
final int x = (int) (MotionEventCompat.getX(e, index) + 0.5f);
final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
if (getScrollState() != SCROLL_STATE_DRAGGING) {
final int dx = x - mInitialTouchX;
final int dy = y - mInitialTouchY;
final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally();
final boolean canScrollVertically = getLayoutManager().canScrollVertically();
boolean startScroll = false;
if (canScrollHorizontally && Math.abs(dx) > mTouchSlop && (Math.abs(dx) >= Math.abs(dy) || canScrollVertically)) {
startScroll = true;
}
if (canScrollVertically && Math.abs(dy) > mTouchSlop && (Math.abs(dy) >= Math.abs(dx) || canScrollHorizontally)) {
startScroll = true;
}
return startScroll && super.onInterceptTouchEvent(e);
}
return super.onInterceptTouchEvent(e);
}
default:
return super.onInterceptTouchEvent(e);
}
}
示例9: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onTouchEvent(MotionEvent ev) {
int action = MotionEventCompat.getActionMasked(ev);
if (this.mReturningToStart && action == 0) {
this.mReturningToStart = false;
}
if (!isEnabled() || this.mReturningToStart || canChildScrollUp() || this.mNestedScrollInProgress) {
return false;
}
int pointerIndex;
float overscrollTop;
switch (action) {
case 0:
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
this.mIsBeingDragged = false;
break;
case 1:
pointerIndex = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId);
if (pointerIndex < 0) {
Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id.");
return false;
}
overscrollTop = (MotionEventCompat.getY(ev, pointerIndex) - this.mInitialMotionY) * DRAG_RATE;
this.mIsBeingDragged = false;
finishSpinner(overscrollTop);
this.mActivePointerId = -1;
return false;
case 2:
pointerIndex = MotionEventCompat.findPointerIndex(ev, this.mActivePointerId);
if (pointerIndex < 0) {
Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id.");
return false;
}
overscrollTop = (MotionEventCompat.getY(ev, pointerIndex) - this.mInitialMotionY) * DRAG_RATE;
if (this.mIsBeingDragged) {
if (overscrollTop > 0.0f) {
moveSpinner(overscrollTop);
break;
}
return false;
}
break;
case 3:
return false;
case 5:
pointerIndex = MotionEventCompat.getActionIndex(ev);
if (pointerIndex >= 0) {
this.mActivePointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
break;
}
Log.e(LOG_TAG, "Got ACTION_POINTER_DOWN event but have an invalid action index.");
return false;
case 6:
onSecondaryPointerUp(ev);
break;
}
return true;
}
示例10: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
mGestureDetector.onTouchEvent(event);
if (DEBUG) {
Log.d(TAG, "intercept: x:" + event.getX() + ",y:" + event.getY() + ", " + event);
}
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mActivePointerId = MotionEventCompat.getPointerId(event, 0);
mInitialTouchX = event.getX();
mInitialTouchY = event.getY();
obtainVelocityTracker();
if (mSelected == null) {
final RecoverAnimation animation = findAnimation(event);
if (animation != null) {
mInitialTouchX -= animation.mX;
mInitialTouchY -= animation.mY;
endRecoverAnimation(animation.mViewHolder, true);
if (mPendingCleanup.remove(animation.mViewHolder.itemView)) {
mCallback.clearView(mRecyclerView, animation.mViewHolder);
}
select(animation.mViewHolder, animation.mActionState);
updateDxDy(event, mSelectedFlags, 0);
}
}
} else if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
mActivePointerId = ACTIVE_POINTER_ID_NONE;
select(null, ACTION_STATE_IDLE);
} else if (mActivePointerId != ACTIVE_POINTER_ID_NONE) {
// in a non scroll orientation, if distance change is above threshold, we
// can select the item
final int index = MotionEventCompat.findPointerIndex(event, mActivePointerId);
if (DEBUG) {
Log.d(TAG, "pointer index " + index);
}
if (index >= 0) {
checkSelectForSwipe(action, event, index);
}
}
if (mVelocityTracker != null) {
mVelocityTracker.addMovement(event);
}
return mSelected != null;
}
示例11: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
if (this.mTouchSlop < 0) {
this.mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
}
if (ev.getAction() == 2 && this.mIsBeingDragged) {
return true;
}
int y;
switch (MotionEventCompat.getActionMasked(ev)) {
case 0:
this.mIsBeingDragged = false;
int x = (int) ev.getX();
y = (int) ev.getY();
if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
this.mLastMotionY = y;
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
ensureVelocityTracker();
break;
}
case 1:
case 3:
this.mIsBeingDragged = false;
this.mActivePointerId = -1;
if (this.mVelocityTracker != null) {
this.mVelocityTracker.recycle();
this.mVelocityTracker = null;
break;
}
break;
case 2:
int activePointerId = this.mActivePointerId;
if (activePointerId != -1) {
int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (pointerIndex != -1) {
y = (int) MotionEventCompat.getY(ev, pointerIndex);
if (Math.abs(y - this.mLastMotionY) > this.mTouchSlop) {
this.mIsBeingDragged = true;
this.mLastMotionY = y;
break;
}
}
}
break;
}
if (this.mVelocityTracker != null) {
this.mVelocityTracker.addMovement(ev);
}
return this.mIsBeingDragged;
}
示例12: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public void onTouchEvent(RecyclerView recyclerView, MotionEvent event) {
int newPointerIndex = 0;
ItemTouchHelper.this.mGestureDetector.onTouchEvent(event);
if (ItemTouchHelper.this.mVelocityTracker != null) {
ItemTouchHelper.this.mVelocityTracker.addMovement(event);
}
if (ItemTouchHelper.this.mActivePointerId != -1) {
int action = MotionEventCompat.getActionMasked(event);
int activePointerIndex = MotionEventCompat.findPointerIndex(event, ItemTouchHelper.this.mActivePointerId);
if (activePointerIndex >= 0) {
ItemTouchHelper.this.checkSelectForSwipe(action, event, activePointerIndex);
}
ViewHolder viewHolder = ItemTouchHelper.this.mSelected;
if (viewHolder != null) {
switch (action) {
case 1:
break;
case 2:
if (activePointerIndex >= 0) {
ItemTouchHelper.this.updateDxDy(event, ItemTouchHelper.this.mSelectedFlags, activePointerIndex);
ItemTouchHelper.this.moveIfNecessary(viewHolder);
ItemTouchHelper.this.mRecyclerView.removeCallbacks(ItemTouchHelper.this.mScrollRunnable);
ItemTouchHelper.this.mScrollRunnable.run();
ItemTouchHelper.this.mRecyclerView.invalidate();
return;
}
return;
case 3:
if (ItemTouchHelper.this.mVelocityTracker != null) {
ItemTouchHelper.this.mVelocityTracker.clear();
break;
}
break;
case 6:
int pointerIndex = MotionEventCompat.getActionIndex(event);
if (MotionEventCompat.getPointerId(event, pointerIndex) == ItemTouchHelper.this.mActivePointerId) {
if (pointerIndex == 0) {
newPointerIndex = 1;
}
ItemTouchHelper.this.mActivePointerId = MotionEventCompat.getPointerId(event, newPointerIndex);
ItemTouchHelper.this.updateDxDy(event, ItemTouchHelper.this.mSelectedFlags, pointerIndex);
return;
}
return;
default:
return;
}
ItemTouchHelper.this.select(null, 0);
ItemTouchHelper.this.mActivePointerId = -1;
}
}
}
示例13: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onInterceptTouchEvent(MotionEvent ev) {
boolean z = false;
int action = ev.getAction();
if (action == 2 && this.mIsBeingDragged) {
return true;
}
int y;
switch (action & 255) {
case 0:
y = (int) ev.getY();
if (!inChild((int) ev.getX(), y)) {
this.mIsBeingDragged = false;
recycleVelocityTracker();
break;
}
this.mLastMotionY = y;
this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
initOrResetVelocityTracker();
this.mVelocityTracker.addMovement(ev);
this.mScroller.computeScrollOffset();
if (!this.mScroller.isFinished()) {
z = true;
}
this.mIsBeingDragged = z;
startNestedScroll(2);
break;
case 1:
case 3:
this.mIsBeingDragged = false;
this.mActivePointerId = -1;
recycleVelocityTracker();
if (this.mScroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) {
ViewCompat.postInvalidateOnAnimation(this);
}
stopNestedScroll();
break;
case 2:
int activePointerId = this.mActivePointerId;
if (activePointerId != -1) {
int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
if (pointerIndex != -1) {
y = (int) MotionEventCompat.getY(ev, pointerIndex);
if (Math.abs(y - this.mLastMotionY) > this.mTouchSlop && (getNestedScrollAxes() & 2) == 0) {
this.mIsBeingDragged = true;
this.mLastMotionY = y;
initVelocityTrackerIfNotExists();
this.mVelocityTracker.addMovement(ev);
this.mNestedYOffset = 0;
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
break;
}
}
}
Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent");
break;
}
break;
case 6:
onSecondaryPointerUp(ev);
break;
}
return this.mIsBeingDragged;
}