本文整理汇总了Java中android.view.MotionEvent.findPointerIndex方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.findPointerIndex方法的具体用法?Java MotionEvent.findPointerIndex怎么用?Java MotionEvent.findPointerIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.findPointerIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
// Ignore deprecation, ACTION_POINTER_ID_MASK and
// ACTION_POINTER_ID_SHIFT has same value and are deprecated
// You can have either deprecation or lint target api warning
final int pointerIndex = Compat.getPointerIndex(ev.getAction());
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;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev
.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
: 0);
return super.onTouchEvent(ev);
}
示例2: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch(action & 255) {
case 0:
this.mActivePointerId = ev.getPointerId(0);
break;
case 1:
case 3:
this.mActivePointerId = -1;
case 2:
case 4:
case 5:
default:
break;
case 6:
int e = Compat.getPointerIndex(ev.getAction());
int pointerId = ev.getPointerId(e);
if(pointerId == this.mActivePointerId) {
int newPointerIndex = e == 0?1:0;
this.mActivePointerId = ev.getPointerId(newPointerIndex);
this.mLastTouchX = ev.getX(newPointerIndex);
this.mLastTouchY = ev.getY(newPointerIndex);
}
}
this.mActivePointerIndex = ev.findPointerIndex(this.mActivePointerId != -1?this.mActivePointerId:0);
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException var6) {
return true;
}
}
示例3: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
// Ignore deprecation, ACTION_POINTER_ID_MASK and
// ACTION_POINTER_ID_SHIFT has same value and are deprecated
// You can have either deprecation or lint target api warning
final int pointerIndex = Compat.getPointerIndex(ev.getAction());
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;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev
.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
: 0);
try {
return super.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
// Fix for support lib bug, happening when onDestroy is
return true;
}
}
示例4: move
import android.view.MotionEvent; //导入方法依赖的package包/类
private boolean move(MotionEvent event) {
if (activePointerId == -1) {
return false;
}
int pointerIndex = event.findPointerIndex(activePointerId);
int currentY = (int) event.getY(pointerIndex);
int deltaY = currentY - downY;
int mobileViewY = mobileViewStartY + deltaY;
mobileView.setY(mobileViewY);
switchViewsIfNeeded();
scrollIfNeeded();
return true;
}
示例5: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.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.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
return super.onTouchEvent(ev);
}
示例6: determineScrollingStart
import android.view.MotionEvent; //导入方法依赖的package包/类
protected void determineScrollingStart(MotionEvent ev, float touchSlopScale) {
// Disallow scrolling if we don't have a valid pointer index
final int pointerIndex = ev.findPointerIndex(mActivePointerId);
if (pointerIndex == -1) return;
// Disallow scrolling if we started the gesture from outside the viewport
final float x = ev.getX(pointerIndex);
final float y = ev.getY(pointerIndex);
if (!isTouchPointInViewportWithBuffer((int) x, (int) y)) return;
final int xDiff = (int) Math.abs(x - mLastMotionX);
final int touchSlop = Math.round(touchSlopScale * mTouchSlop);
boolean xMoved = xDiff > touchSlop;
if (xMoved) {
// Scroll if the user moved far enough along the X axis
mTouchState = TOUCH_STATE_SCROLLING;
mTotalMotionX += Math.abs(mLastMotionX - x);
mLastMotionX = x;
mLastMotionXRemainder = 0;
onScrollInteractionBegin();
pageBeginTransition();
// Stop listening for things like pinches.
requestDisallowInterceptTouchEvent(true);
}
}
示例7: midPoint
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* <p>Calculates the mid point between two pointers.</p>
* @param point
* @param event
* @param pointerA id of pointer A
* @param pointerB id of pointer B
*/
public static final void midPoint(PointF point, MotionEvent event, int pointerA, int pointerB) {
int indexA = event.findPointerIndex(pointerA);
int indexB = event.findPointerIndex(pointerB);
float x = event.getX(indexA) + event.getX(indexB);
float y = event.getY(indexA) + event.getY(indexB);
point.set(x / 2f, y / 2f);
}
示例8: handleCancel
import android.view.MotionEvent; //导入方法依赖的package包/类
private void handleCancel(MotionEvent event) {
// Drop the active target if canceled.
mActiveTarget = -1;
int actionIndex = event.findPointerIndex(mPointerId);
actionIndex = actionIndex == -1 ? 0 : actionIndex;
switchToState(STATE_FINISH, event.getX(actionIndex), event.getY(actionIndex));
}
示例9: getMotionEventY
import android.view.MotionEvent; //导入方法依赖的package包/类
private float getMotionEventY(MotionEvent motionEvent, int activePointerId) {
final int index = motionEvent.findPointerIndex(activePointerId);
if (index < 0) {
return -1f;
}
return motionEvent.getY(index);
}
示例10: onTouchObserved
import android.view.MotionEvent; //导入方法依赖的package包/类
private boolean onTouchObserved(MotionEvent srcEvent) {
View src = this.mSrc;
if (!src.isEnabled()) {
return false;
}
switch (MotionEventCompat.getActionMasked(srcEvent)) {
case 0:
this.mActivePointerId = srcEvent.getPointerId(0);
this.mWasLongPress = false;
if (this.mDisallowIntercept == null) {
this.mDisallowIntercept = new DisallowIntercept();
}
src.postDelayed(this.mDisallowIntercept, (long) this.mTapTimeout);
if (this.mTriggerLongPress == null) {
this.mTriggerLongPress = new TriggerLongPress();
}
src.postDelayed(this.mTriggerLongPress, (long) this.mLongPressTimeout);
return false;
case 1:
case 3:
clearCallbacks();
return false;
case 2:
int activePointerIndex = srcEvent.findPointerIndex(this.mActivePointerId);
if (activePointerIndex < 0 || pointInView(src, srcEvent.getX(activePointerIndex), srcEvent.getY(activePointerIndex), this.mScaledTouchSlop)) {
return false;
}
clearCallbacks();
src.getParent().requestDisallowInterceptTouchEvent(true);
return true;
default:
return false;
}
}
示例11: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
try {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
// Ignore deprecation, ACTION_POINTER_ID_MASK and
// ACTION_POINTER_ID_SHIFT has same value and are deprecated
// You can have either deprecation or lint target api warning
final int pointerIndex = Compat.getPointerIndex(ev.getAction());
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;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev
.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId
: 0);
return super.onTouchEvent(ev);
}catch (Exception e){
return false;
}
}
示例12: findNewActiveIndex
import android.view.MotionEvent; //导入方法依赖的package包/类
private int findNewActiveIndex(MotionEvent ev, int otherActiveId, int removedPointerIndex) {
final int pointerCount = ev.getPointerCount();
// It's ok if this isn't found and returns -1, it simply won't match.
final int otherActiveIndex = ev.findPointerIndex(otherActiveId);
// Pick a new id and update tracking state.
for (int i = 0; i < pointerCount; i++) {
if (i != removedPointerIndex && i != otherActiveIndex) {
return i;
}
}
return -1;
}
示例13: updatePointersOnMove
import android.view.MotionEvent; //导入方法依赖的package包/类
private void updatePointersOnMove(MotionEvent event) {
for (int i = 0; i < MAX_POINTERS; i++) {
int index = event.findPointerIndex(mId[i]);
if (index != -1) {
mCurrentX[i] = event.getX(index);
mCurrentY[i] = event.getY(index);
}
}
}
示例14: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
ensureTarget();
final int action = ev.getActionMasked();
int pointerIndex;
if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
mReturningToStart = false;
}
// System.out.println("isEnabled "+ isEnabled()+"; mReturningToStart "+mReturningToStart+"; canChildScrollUp() "+canChildScrollUp()+" " +
// " mRefreshing "+mRefreshing+"; mNestedScrollInProgress "+mNestedScrollInProgress+" ; mRefreshView "+mRefreshView);
if (canNotPullToRefresh()) {
// Fail fast if we're not in a state where a swipe is possible
return false;
}
switch (action) {
case MotionEvent.ACTION_DOWN:
translateContentViews(0f);
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) {
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 MotionEvent.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
break;
}
return mIsBeingDragged;
}
示例15: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
initVelocityTrackerIfNotExists();
mVelocityTracker.addMovement(ev);
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// LogUtil.d(TAG, "onTouchEvent ACTION_DOWN");
mIsBeingDragged = false;
mLastMotionY = (int) ev.getY();
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_MOVE:
// LogUtil.d(TAG, "onTouchEvent ACTION_MOVE");
final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
if (activePointerIndex == -1) {
// Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
break;
}
final int y = (int) ev.getY(activePointerIndex);
int deltaY = mLastMotionY - y;
if (!mIsBeingDragged && Math.abs(deltaY) > mTouchSlop) {
mIsBeingDragged = true;
if (deltaY > 0) {
deltaY -= mTouchSlop;
} else {
deltaY += mTouchSlop;
}
}
if (mIsBeingDragged) {
// Scroll to follow the motion event
mLastMotionY = y;
mFlexibleEffect.onPull((float) deltaY / getHeight());
if(!mFlexibleEffect.isFinished()){
return true;
}
}
break;
case MotionEvent.ACTION_UP:
// LogUtil.d(TAG, "onTouchEvent ACTION_UP");
if (mIsBeingDragged) {
mActivePointerId = INVALID_POINTER;
mIsBeingDragged = false;
if (mFlexibleEffect != null&&mFlexibleEffect.isPulling()) {
mFlexibleEffect.onAbsorb(-1);
}
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
currentVelocity = mVelocityTracker.getYVelocity(mActivePointerId);
Log.d(TAG, "currentVelocity:"+mVelocityTracker.getYVelocity(mActivePointerId) );
recycleVelocityTracker();
}
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return super.onTouchEvent(ev);
}