當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。