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


Java MotionEvent.getPointerId方法代碼示例

本文整理匯總了Java中android.view.MotionEvent.getPointerId方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.getPointerId方法的具體用法?Java MotionEvent.getPointerId怎麽用?Java MotionEvent.getPointerId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getPointerId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onSecondaryPointerUp(MotionEvent ev) {
    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.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = mDownMotionX = ev.getX(newPointerIndex);
        mLastMotionY = ev.getY(newPointerIndex);
        mLastMotionXRemainder = 0;
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
開發者ID:TeamBrainStorm,項目名稱:SimpleUILauncher,代碼行數:19,代碼來源:PagedView.java

示例2: handleFling

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Handles a fling gesture.
 *
 * @param event
 *         The motion event, which triggered the fling gesture, as an instance of the class
 *         {@link MotionEvent}. The motion event may not be null
 * @param dragState
 *         The current drag state, which determines the fling direction, as a value of the enum
 *         {@link DragState}. The drag state may not be null
 */
private void handleFling(@NonNull final MotionEvent event, @NonNull final DragState dragState) {
    if (getVelocityTracker() != null) {
        int pointerId = event.getPointerId(0);
        getVelocityTracker().computeCurrentVelocity(1000, maxFlingVelocity);
        float flingVelocity = Math.abs(getVelocityTracker().getYVelocity(pointerId));

        if (flingVelocity > minFlingVelocity) {
            float flingDistance = 0.25f * flingVelocity;

            if (dragState == DragState.DRAG_TO_START) {
                flingDistance = -1 * flingDistance;
            }

            long duration = Math.round(Math.abs(flingDistance) / flingVelocity * 1000);
            notifyOnFling(flingDistance, duration);
        }
    }
}
 
開發者ID:michael-rapp,項目名稱:ChromeLikeTabSwitcher,代碼行數:29,代碼來源:AbstractDragTabsEventHandler.java

示例3: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private final 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);
    }
}
 
開發者ID:reyanshmishra,項目名稱:Rey-MusicPlayer,代碼行數:14,代碼來源:RangeSeekBar.java

示例4: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
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;
        mInitialTouchX = ev.getX(newPointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}
 
開發者ID:haruue,項目名稱:OpenWithX,代碼行數:13,代碼來源:ResolverDrawerLayout.java

示例5: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK)
            >> MotionEventCompat.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionY = (int) ev.getY(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
開發者ID:ccrama,項目名稱:Slide-RSS,代碼行數:14,代碼來源:NestedWebView.java

示例6: 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:Loofer,項目名稱:Watermark,代碼行數:39,代碼來源:EclairGestureDetector.java

示例7: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
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;
        mLastMotionX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}
 
開發者ID:thaihuynhxyz,項目名稱:recycler-view-pager,代碼行數:12,代碼來源:RecyclerViewPager.java

示例8: onInterceptTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
        case 0:
            this.mActivePointerId = event.getPointerId(0);
            this.mLastMotionY = event.getY();
            break;
        case 2:
            int activePointerIndex = event.findPointerIndex(this.mActivePointerId);
            if (activePointerIndex != -1) {
                int move = (int) (event.getY(activePointerIndex) - this.mLastMotionY);
                switch (this.mStatus) {
                    case one:
                        if (this.mChildHeader.isScrollBottom() && move < 0) {
                            return true;
                        }
                    case two:
                        if (this.mChildHeader.isScrollBottom() && this.mWebView.isScrollTop()
                                && move > 0) {
                            return true;
                        }
                    default:
                        break;
                }
            }
            break;
    }
    return super.onInterceptTouchEvent(event);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:29,代碼來源:HomeView.java

示例9: onPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onPointerUp(MotionEvent ev) {
    final int pointerIndex = ev.getActionIndex();
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mLastMotionX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
        if (mVelocityTracker != null) {
            mVelocityTracker.clear();
        }
    }
}
 
開發者ID:akashdeepsingh9988,項目名稱:Cybernet-VPN,代碼行數:13,代碼來源:FlowingDrawer.java

示例10: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    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);
    }
}
 
開發者ID:unixzii,項目名稱:android-source-codes,代碼行數:11,代碼來源:SwipeRefreshLayout.java

示例11: 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);
    return super.onTouchEvent(ev);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:30,代碼來源:VersionedGestureDetector.java

示例12: onScroll

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
  boolean result = false;
  if (containsPan() &&
      (e2.getPointerId(e1.getActionIndex()) == e1.getPointerId(e1.getActionIndex()))) {
    if (panDownTime != e1.getEventTime()) {
      panDownTime = e1.getEventTime();
      scrolling = true;
      component.getInstance().fireEvent(
                                           component.getDomObject().getRef(), HighLevelGesture.PAN_START.toString(),
                                           createFireEventParam(e1, CUR_EVENT));
    } else {
      component.getInstance().fireEvent(
                                           component.getDomObject().getRef(), HighLevelGesture.PAN_MOVE.toString(),
                                           createFireEventParam(e2, CUR_EVENT));
    }
    result = true;
  }
  if (component.containsGesture(HighLevelGesture.SWIPE)) {
    if (swipeDownTime != e1.getEventTime()) {
      swipeDownTime = e1.getEventTime();
      List<Map<String, Object>> list = createFireEventParam(e2);
      Map<String, Object> param = list.get(list.size() - 1);
      if (Math.abs(distanceX) > Math.abs(distanceY)) {
        param.put(GestureInfo.DIRECTION, distanceX > 0 ? "left" : "right");
      } else {
        param.put(GestureInfo.DIRECTION, distanceY > 0 ? "up" : "down");
      }
      component.getInstance().fireEvent( component.getDomObject().getRef(),
                                           HighLevelGesture.SWIPE.toString(), param);
      result = true;
    }
  }
  return result;
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:36,代碼來源:WXGesture.java

示例13: getSwipeDistance

import android.view.MotionEvent; //導入方法依賴的package包/類
private float getSwipeDistance(MotionEvent event) {
	for (int i = 0, l = event.getPointerCount(); i < l; ++i) {
		if (event.getPointerId(i) == pointerId) {
			return event.getX(i) - initialX;
		}
	}
	return 0;
}
 
開發者ID:markusfisch,項目名稱:SwipeImageView,代碼行數:9,代碼來源:SwipeImageView.java

示例14: onSecondaryPointerUp

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = MotionEventCompat.getActionIndex(ev);
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}
 
開發者ID:liuwei1993,項目名稱:Android-PullRefresh,代碼行數:9,代碼來源:PullRefreshLayout.java

示例15: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent ev) {
    final int action = ev.getActionMasked();
    final int actionIndex = ev.getActionIndex();

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action){
        case MotionEvent.ACTION_POINTER_DOWN:
            mActivePointerId = ev.getPointerId(actionIndex);

            mLastMotionX = ev.getX(actionIndex);
            mLastMotionY = ev.getY(actionIndex);
            break;

        case MotionEvent.ACTION_POINTER_UP:
            final int pointerId = ev.getPointerId(actionIndex);
            if(pointerId==mActivePointerId){
                final int newIndex = actionIndex == 0 ? 1 : 0;
                mActivePointerId = ev.getPointerId(newIndex);

                mLastMotionX = ev.getX(newIndex);
                mLastMotionY = ev.getY(newIndex);
            }
            break;

        //down時,已經將capture item定下來了。所以,後麵可以安心考慮event處理
        case MotionEvent.ACTION_MOVE: {
            final int activePointerIndex = ev.findPointerIndex(mActivePointerId);
            if (activePointerIndex == -1)
                break;

            final float x = ev.getX(activePointerIndex);
            final float y = (int) ev.getY(activePointerIndex);

            int deltaX = (int) (x - mLastMotionX);

            if(mCaptureItem!=null && mCaptureItem.getTouchMode()== Mode.DRAG){
                mLastMotionX = x;
                mLastMotionY = y;

                //對capture item進行拖拽
                mCaptureItem.trackMotionScroll(deltaX);
            }
            break;
        }

        case MotionEvent.ACTION_UP:
            if(mCaptureItem!=null){
                Mode touchMode = mCaptureItem.getTouchMode();
                if(touchMode== Mode.DRAG){
                    final VelocityTracker velocityTracker = mVelocityTracker;
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                    int xVel = (int) velocityTracker.getXVelocity(mActivePointerId);
                    mCaptureItem.fling(xVel);
                }
            }
            cancel();
            break;

        case MotionEvent.ACTION_CANCEL:
            if(mCaptureItem!=null)
                mCaptureItem.revise();

            cancel();
            break;

    }
}
 
開發者ID:AndroidBoySC,項目名稱:Mybilibili,代碼行數:73,代碼來源:SwipeItemLayout.java


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