当前位置: 首页>>代码示例>>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;未经允许,请勿转载。