当前位置: 首页>>代码示例>>Java>>正文


Java MotionEvent.getActionIndex方法代码示例

本文整理汇总了Java中android.view.MotionEvent.getActionIndex方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getActionIndex方法的具体用法?Java MotionEvent.getActionIndex怎么用?Java MotionEvent.getActionIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.getActionIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: velocityTrackerPointerUpCleanUpIfNecessary

import android.view.MotionEvent; //导入方法依赖的package包/类
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
                                                              VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();
            break;
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:Utils.java

示例2: createFireEventParam

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * Create a map represented touch event at a certain moment.
 * @param motionEvent motionEvent, which contains all pointers event in a period of time
 * @param pos index used to retrieve a certain moment in a period of time.
 * @return touchEvent
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent">touchEvent</a>
 */
private Map<String, Object> createFireEventParam(MotionEvent motionEvent, int pos, String state) {
  JSONArray jsonArray = new JSONArray(motionEvent.getPointerCount());
  if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
    for (int i = 0; i < motionEvent.getPointerCount(); i++) {
      jsonArray.add(createJSONObject(motionEvent, pos, i));
    }
  } else if (isPointerNumChanged(motionEvent)) {
    int pointerIndex = motionEvent.getActionIndex();
    jsonArray.add(createJSONObject(motionEvent, CUR_EVENT, pointerIndex));
  }
  Map<String, Object> map = new HashMap<>();
  map.put(GestureInfo.HISTORICAL_XY, jsonArray);
  if (state != null) {
    map.put(GestureInfo.STATE, state);
  }
  return map;
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:25,代码来源:WXGesture.java

示例3: getPressedPointerIndex

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * Gets the index of the i-th pressed pointer.
 * Normally, the index will be equal to i, except in the case when the pointer is released.
 *
 * @return index of the specified pointer or -1 if not found (i.e. not enough pointers are down)
 */
private int getPressedPointerIndex(MotionEvent event, int i) {
    final int count = event.getPointerCount();
    final int action = event.getActionMasked();
    final int index = event.getActionIndex();
    if (action == MotionEvent.ACTION_UP ||
            action == MotionEvent.ACTION_POINTER_UP) {
        if (i >= index) {
            i++;
        }
    }
    return (i < count) ? i : -1;
}
 
开发者ID:ibosong,项目名称:CommentGallery,代码行数:19,代码来源:MultiPointerGestureDetector.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;
        mLastMotionX = ev.getX(newPointerIndex);
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}
 
开发者ID:thaihuynhxyz,项目名称:recycler-view-pager,代码行数:12,代码来源:RecyclerViewPager.java

示例5: 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:ultrasonic,项目名称:ultrasonic,代码行数:13,代码来源:SlidingDrawer.java

示例6: 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;
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}
 
开发者ID:yangjiantao,项目名称:AndroidUiKit,代码行数:11,代码来源:ISwipeRefreshLayout.java

示例7: onHoverExit

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
protected void onHoverExit(final MotionEvent event) {
    final Key lastKey = getLastHoverKey();
    if (DEBUG_HOVER) {
        Log.d(TAG, "onHoverExit: key=" + getHoverKeyOf(event) + " last=" + lastKey);
    }
    if (lastKey != null) {
        super.onHoverExitFrom(lastKey);
    }
    setLastHoverKey(null);
    final int actionIndex = event.getActionIndex();
    final int x = (int)event.getX(actionIndex);
    final int y = (int)event.getY(actionIndex);
    final int pointerId = event.getPointerId(actionIndex);
    final long eventTime = event.getEventTime();
    // A hover exit event at one pixel width or height area on the edges of more keys keyboard
    // are treated as closing.
    mMoreKeysKeyboardValidBounds.set(0, 0, mKeyboardView.getWidth(), mKeyboardView.getHeight());
    mMoreKeysKeyboardValidBounds.inset(CLOSING_INSET_IN_PIXEL, CLOSING_INSET_IN_PIXEL);
    if (mMoreKeysKeyboardValidBounds.contains(x, y)) {
        // Invoke {@link MoreKeysKeyboardView#onUpEvent(int,int,int,long)} as if this hover
        // exit event selects a key.
        mKeyboardView.onUpEvent(x, y, pointerId, eventTime);
        // TODO: Should fix this reference. This is a hack to clear the state of
        // {@link PointerTracker}.
        PointerTracker.dismissAllMoreKeysPanels();
        return;
    }
    // Close the more keys keyboard.
    // TODO: Should fix this reference. This is a hack to clear the state of
    // {@link PointerTracker}.
    PointerTracker.dismissAllMoreKeysPanels();
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:34,代码来源:MoreKeysKeyboardAccessibilityDelegate.java

示例8: getPressedPointerIndex

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * Gets the index of the i-th pressed pointer.
 * Normally, the index will be equal to i, except in the case when the pointer is released.
 * @return index of the specified pointer or -1 if not found (i.e. not enough pointers are down)
 */
private int getPressedPointerIndex(MotionEvent event, int i) {
  final int count = event.getPointerCount();
  final int action = event.getActionMasked();
  final int index = event.getActionIndex();
  if (action == MotionEvent.ACTION_UP ||
      action == MotionEvent.ACTION_POINTER_UP) {
    if (i >= index) {
      i++;
    }
  }
  return (i < count) ? i : -1;
}
 
开发者ID:idisfkj,项目名称:Zoomable,代码行数:18,代码来源:MultiPointerGestureDetector.java

示例9: createFireEventParam

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * Create a map represented touch event at a certain moment.
 * @param motionEvent motionEvent, which contains all pointers event in a period of time
 * @param pos index used to retrieve a certain moment in a period of time.
 * @return touchEvent
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent">touchEvent</a>
 */
private Map<String, Object> createFireEventParam(MotionEvent motionEvent, int pos) {
  JSONArray jsonArray = new JSONArray(motionEvent.getPointerCount());
  if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
    for (int i = 0; i < motionEvent.getPointerCount(); i++) {
      jsonArray.add(createJSONObject(motionEvent, pos, i));
    }
  } else if (isPointerNumChanged(motionEvent)) {
    int pointerIndex = motionEvent.getActionIndex();
    jsonArray.add(createJSONObject(motionEvent, CUR_EVENT, pointerIndex));
  }
  Map<String, Object> map = new HashMap<>();
  map.put(GestureInfo.HISTORICAL_XY, jsonArray);
  return map;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:WXGesture.java

示例10: onTouchEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(final MotionEvent me) {
    if (mActiveForwarder == null) {
        return super.onTouchEvent(me);
    }

    final Rect rect = mInputViewRect;
    getGlobalVisibleRect(rect);
    final int index = me.getActionIndex();
    final int x = (int)me.getX(index) + rect.left;
    final int y = (int)me.getY(index) + rect.top;
    return mActiveForwarder.onTouchEvent(x, y, me);
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:14,代码来源:InputView.java

示例11: getHoverKeyOf

import android.view.MotionEvent; //导入方法依赖的package包/类
/**
 * Get a key that a hover event is on.
 *
 * @param event The hover event.
 * @return key The key that the <code>event</code> is on.
 */
protected final Key getHoverKeyOf(final MotionEvent event) {
    final int actionIndex = event.getActionIndex();
    final int x = (int)event.getX(actionIndex);
    final int y = (int)event.getY(actionIndex);
    return mKeyDetector.detectHitKey(x, y);
}
 
开发者ID:sergeychilingaryan,项目名称:AOSP-Kayboard-7.1.2,代码行数:13,代码来源:KeyboardAccessibilityDelegate.java

示例12: calculateCurrFocusAndSpan

import android.view.MotionEvent; //导入方法依赖的package包/类
private void calculateCurrFocusAndSpan(MotionEvent ev) {
    final float action = ev.getActionMasked();
    final boolean pointerUp = (action == MotionEvent.ACTION_POINTER_UP);
    final int skipIndex = pointerUp ? ev.getActionIndex() : -1;

    // Determine focal point
    float sumX = 0, sumY = 0;
    final int count = ev.getPointerCount();
    for (int i = 0; i < count; i++) {
        if (skipIndex == i) continue;
        sumX += ev.getX(i);
        sumY += ev.getY(i);
    }
    final int div = pointerUp ? count - 1 : count;
    final float focusX = sumX / div;
    final float focusY = sumY / div;
    currFocusX = sumX / div;
    currFocusY = sumY / div;

    // Determine average deviation from focal point
    float devSumX = 0, devSumY = 0;
    for (int i = 0; i < count; i++) {
        if (skipIndex == i) continue;

        // Convert the resulting diameter into a radius.
        devSumX += Math.abs(ev.getX(i) - focusX);
        devSumY += Math.abs(ev.getY(i) - focusY);
    }
    final float devX = devSumX / div;
    final float devY = devSumY / div;

    // Span is the average distance between touch points through the focal point;
    // i.e. the diameter of the circle with a radius of the average deviation from
    // the focal point.
    final float spanX = devX * 2;
    final float spanY = devY * 2;
    currSpan = (float) Math.hypot(spanX, spanY);
}
 
开发者ID:xyzxqs,项目名称:XphotoView,代码行数:39,代码来源:GooglePhotosGestureDetector.java

示例13: handlerInterceptTouchEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
private boolean handlerInterceptTouchEvent(MotionEvent ev, boolean isHead) {
    final int action = ev.getActionMasked();
    boolean mIsBeingDragged = false;
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = ev.getPointerId(0);
            mIsBeingDragged = false;
            final float initialMotionY = ev.getY(mActivePointerId);
            if (initialMotionY == -1) {
                return false;
            }
            mInitialMotionX = ev.getX(mActivePointerId);
            mInitialMotionY = initialMotionY;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mActivePointerId == MotionEvent.INVALID_POINTER_ID) {
                return false;
            }
            final int index = ev.findPointerIndex(mActivePointerId);
            if (index < 0) {
                return false;
            }
            final float y = ev.getY(mActivePointerId);
            final float x = ev.getX(mActivePointerId);

            if (y == -1) {
                return false;
            }
            float yDiff = y - mInitialMotionY;
            float xDiff = x - mInitialMotionX;
            if (!isHead)
                yDiff = -yDiff;
            if (yDiff > touchSlop && Math.abs(yDiff) > Math.abs(xDiff)) {
                mInitialMotionY = y;//触发拖曳 刷新下Y值
                mIsBeingDragged = true;
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mIsBeingDragged = false;
            mActivePointerId = MotionEvent.INVALID_POINTER_ID;
            break;
        case MotionEvent.ACTION_POINTER_UP://兼容多个手指
            final int pointerIndex = ev.getActionIndex();
            final int pointerId = ev.getPointerId(pointerIndex);
            if (pointerId == mActivePointerId) {
                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
                mActivePointerId = ev.getPointerId(newPointerIndex);
            }
            break;
    }
    return mIsBeingDragged;
}
 
开发者ID:tohodog,项目名称:QSRefreshLayout,代码行数:54,代码来源:QSBaseRefreshLayout.java

示例14: onTouchEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@UiThread
 public boolean onTouchEvent(MotionEvent e) {
     //we need to convert multi-touch event handling into struct of arrays for many pointers to send over JNI

     //C++ event representation is like;
     /*
float x, y;
int pointerIdentity;
int pointerIndex;
*/

     final int pointerCount = e.getPointerCount();
     final int primaryActionIndex = e.getActionIndex();
     final int primaryActionIdentifier = e.getPointerId(primaryActionIndex);

     final float[] xArray = new float[pointerCount];
     final float[] yArray = new float[pointerCount];
     final int[] pointerIdentityArray = new int[pointerCount];
     final int[] pointerIndexArray = new int[pointerCount];

     for (int pointerIndex = 0; pointerIndex < pointerCount; ++pointerIndex) {
         xArray[pointerIndex] = e.getX(pointerIndex);
         yArray[pointerIndex] = e.getY(pointerIndex);
         pointerIdentityArray[pointerIndex] = e.getPointerId(pointerIndex);
         pointerIndexArray[pointerIndex] = pointerIndex;
     }

     boolean handled = true;

     switch (e.getActionMasked()) {
         case MotionEvent.ACTION_DOWN:
         case MotionEvent.ACTION_POINTER_DOWN:
             m_eegeoNativeMapView.onPointerDown(primaryActionIndex, primaryActionIdentifier, pointerCount, xArray, yArray, pointerIdentityArray, pointerIndexArray);
             break;

         case MotionEvent.ACTION_POINTER_UP:
         case MotionEvent.ACTION_UP:
             m_eegeoNativeMapView.onPointerUp(primaryActionIndex, primaryActionIdentifier, pointerCount, xArray, yArray, pointerIdentityArray, pointerIndexArray);
             break;

         case MotionEvent.ACTION_MOVE:
             m_eegeoNativeMapView.onPointerMove(primaryActionIndex, primaryActionIdentifier, pointerCount, xArray, yArray, pointerIdentityArray, pointerIndexArray);
             break;
         default:
             handled = false;
     }

     return handled;
 }
 
开发者ID:wrld3d,项目名称:android-api,代码行数:50,代码来源:MapViewTouchHandler.java

示例15: onTouchEvent

import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    float y = event.getY();
    float dx = x - mPrevX;
    float dy = y - mPrevY;
    int index = event.getActionIndex();
    int pointerId = event.getPointerId(index);

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:

            if (!mScroller.isFinished()) {
                mScroller.abortAnimation();
            }

            mMode = MODE_RULER_DRAG;
            if (mIsVertical) {
                if (y - mViewportStart >= mHighlightStart &&
                        y - mViewportStart <= mHighlightStart + mHighlightSize) {
                    mMode = MODE_HIGHLIGHT_DRAG;
                }
            } else {
                if (x - mViewportStart >= mHighlightStart &&
                        x - mViewportStart <= mHighlightStart + mHighlightSize) {
                    mMode = MODE_HIGHLIGHT_DRAG;
                }
            }

            if (mVelocityTracker == null) {
                mVelocityTracker = VelocityTracker.obtain();
            } else {
                mVelocityTracker.clear();
            }
            mVelocityTracker.addMovement(event);

            break;
        case MotionEvent.ACTION_MOVE:
            mVelocityTracker.addMovement(event);

            if (mMode == MODE_RULER_DRAG) {
                if (mIsVertical) {
                    setViewportStart(getViewportStart() + dy);
                } else {
                    setViewportStart(getViewportStart() + dx);
                }
            } else if (mMode == MODE_HIGHLIGHT_DRAG) {
                if (mIsVertical) {
                    // Drag highlight by whole pixels for now
                    setHighlightStart(getHighlightStart() + Math.round(dy));
                } else {
                    setHighlightStart(getHighlightStart() + Math.round(dx));
                }
            }

            break;

        case MotionEvent.ACTION_UP:
            if (mMode == MODE_RULER_DRAG) {
                mVelocityTracker.computeCurrentVelocity(1000);
                int vx = (int) (VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId));
                int vy = (int) (VelocityTrackerCompat.getYVelocity(mVelocityTracker, pointerId));
                mScroller.fling((int) getViewportStart(), (int) getViewportStart(), vx, vy,
                        -10000, 10000, -10000, 10000);
                this.invalidate();
            }

            break;
    }

    mPrevX = x;
    mPrevY = y;

    return true;
}
 
开发者ID:google,项目名称:spline,代码行数:76,代码来源:RulerView.java


注:本文中的android.view.MotionEvent.getActionIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。