private void setContext(android.view.MotionEvent curr) { if (mCurrEvent != null) { mCurrEvent.recycle(); } mCurrEvent = android.view.MotionEvent.obtain(curr); mCurrLen = -1; mPrevLen = -1; mScaleFactor = -1; android.view.MotionEvent prev = mPrevEvent; int prevIndex0 = prev.findPointerIndex(mActiveId0); int prevIndex1 = prev.findPointerIndex(mActiveId1); int currIndex0 = curr.findPointerIndex(mActiveId0); int currIndex1 = curr.findPointerIndex(mActiveId1); if (prevIndex0 < 0 || prevIndex1 < 0 || currIndex0 < 0 || currIndex1 < 0) { mInvalidGesture = true; android.util.Log.e(TAG, "Invalid MotionEvent stream detected.", new System.Exception ()); if (mGestureInProgress) { mListener.onScaleEnd(this); } return; } float px0 = prev.getX(prevIndex0); float py0 = prev.getY(prevIndex0); float px1 = prev.getX(prevIndex1); float py1 = prev.getY(prevIndex1); float cx0 = curr.getX(currIndex0); float cy0 = curr.getY(currIndex0); float cx1 = curr.getX(currIndex1); float cy1 = curr.getY(currIndex1); float pvx = px1 - px0; float pvy = py1 - py0; float cvx = cx1 - cx0; float cvy = cy1 - cy0; mPrevFingerDiffX = pvx; mPrevFingerDiffY = pvy; mCurrFingerDiffX = cvx; mCurrFingerDiffY = cvy; mFocusX = cx0 + cvx * 0.5f; mFocusY = cy0 + cvy * 0.5f; mTimeDelta = curr.getEventTime() - prev.getEventTime(); mCurrPressure = curr.getPressure(currIndex0) + curr.getPressure(currIndex1); mPrevPressure = prev.getPressure(prevIndex0) + prev.getPressure(prevIndex1); }
/// <summary>Checks a trackball event.</summary> /// <remarks>Checks a trackball event.</remarks> /// <param name="event">The event.</param> /// <param name="nestingLevel"> /// The nesting level: 0 if called from the base class, /// or 1 from a subclass. If the event was already checked by this consistency verifier /// at a higher nesting level, it will not be checked again. Used to handle the situation /// where a subclass dispatching method delegates to its superclass's dispatching method /// and both dispatching methods call into the consistency verifier. /// </param> public void onTrackballEvent(android.view.MotionEvent @event, int nestingLevel) { if (!startEvent(@event, nestingLevel, EVENT_TYPE_TRACKBALL)) { return; } try { ensureMetaStateIsNormalized(@event.getMetaState()); int action = @event.getAction(); int source = @event.getSource(); if ((source & android.view.InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { switch (action) { case android.view.MotionEvent.ACTION_DOWN: { if (mTrackballDown && !mTrackballUnhandled) { problem("ACTION_DOWN but trackball is already down."); } else { mTrackballDown = true; mTrackballUnhandled = false; } ensureHistorySizeIsZeroForThisAction(@event); ensurePointerCountIsOneForThisAction(@event); break; } case android.view.MotionEvent.ACTION_UP: { if (!mTrackballDown) { problem("ACTION_UP but trackball is not down."); } else { mTrackballDown = false; mTrackballUnhandled = false; } ensureHistorySizeIsZeroForThisAction(@event); ensurePointerCountIsOneForThisAction(@event); break; } case android.view.MotionEvent.ACTION_MOVE: { ensurePointerCountIsOneForThisAction(@event); break; } default: { problem("Invalid action " + android.view.MotionEvent.actionToString(action) + " for trackball event." ); break; } } if (mTrackballDown && @event.getPressure() <= 0) { problem("Trackball is down but pressure is not greater than 0."); } else { if (!mTrackballDown && @event.getPressure() != 0) { problem("Trackball is up but pressure is not equal to 0."); } } } else { problem("Source was not SOURCE_CLASS_TRACKBALL."); } } finally { finishEvent(); } }