當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.findPointerIndex方法代碼示例

本文整理匯總了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);
}
 
開發者ID:snowwolf10285,項目名稱:PicShow-zhaipin,代碼行數:34,代碼來源:EclairGestureDetector.java

示例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;
    }
}
 
開發者ID:leobert-lan,項目名稱:UiLib,代碼行數:34,代碼來源:EclairGestureDetector.java

示例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;
    }
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:39,代碼來源:EclairGestureDetector.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:DragDropTouchListener.java

示例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);
}
 
開發者ID:turoDog,項目名稱:KTalk,代碼行數:29,代碼來源:VersionedGestureDetector.java

示例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);
    }
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:28,代碼來源:PagedView.java

示例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);
}
 
開發者ID:martinwithaar,項目名稱:PinchToZoom,代碼行數:16,代碼來源:MultiTouchListener.java

示例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));
    }
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:10,代碼來源:GlowPadView.java

示例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);
}
 
開發者ID:Ilya-Gh,項目名稱:Typewriter,代碼行數:8,代碼來源:TypewriterRefreshLayout.java

示例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;
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:35,代碼來源:ListPopupWindow.java

示例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;
   }
}
 
開發者ID:yun2win,項目名稱:tvConnect_android,代碼行數:38,代碼來源:EclairGestureDetector.java

示例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;
}
 
開發者ID:eventtus,項目名稱:photo-editor-android,代碼行數:15,代碼來源:ScaleGestureDetector.java

示例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);
        }
    }
}
 
開發者ID:ibosong,項目名稱:CommentGallery,代碼行數:10,代碼來源:MultiPointerGestureDetector.java

示例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;
    }
 
開發者ID:yangjiantao,項目名稱:AndroidUiKit,代碼行數:59,代碼來源:ISwipeRefreshLayout.java

示例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);
    }
 
開發者ID:teisun,項目名稱:SunmiUI,代碼行數:64,代碼來源:FlexibleListView.java


注:本文中的android.view.MotionEvent.findPointerIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。