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


Java MotionEvent.getHistoricalX方法代碼示例

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


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

示例1: pinchVelocity

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * <p>Calculates the pinch velocity for the last <code>timeWindow</code> milliseconds.</p>
 * @param event
 * @param pointerA id of pointer A
 * @param pointerB id of pointer B
 * @param timeWindow
 * @return spacing between both pointers
 */
public static final float pinchVelocity(MotionEvent event, int pointerA, int pointerB, long timeWindow) {
	int indexA = event.findPointerIndex(pointerA);
	int indexB = event.findPointerIndex(pointerB);
	long eventTime = event.getEventTime();
	long timeDelta = 0;
	float previousSpacing = spacingByIndex(event, indexA, indexB);
	float scale = 1;
	for(int i = 0, n = event.getHistorySize(); i < n && timeDelta < timeWindow; i++) {
		int index = (n - 1) - i;
		float x = event.getHistoricalX(indexA, index) - event.getHistoricalX(indexB, index);
		float y = event.getHistoricalY(indexA, index) - event.getHistoricalY(indexB, index);
		float spacing = (float) Math.sqrt(x * x + y * y);
		scale *= previousSpacing / spacing;
		previousSpacing = spacing;
		timeDelta = eventTime - event.getHistoricalEventTime(index);
	}
	return (float) Math.pow(Math.pow(scale, 1d / timeWindow), 1000d);
}
 
開發者ID:martinwithaar,項目名稱:PinchToZoom,代碼行數:27,代碼來源:MultiTouchListener.java

示例2: getEventLocInScreenCoordinate

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Get event location in Screen's coordinate, e.g. root(global) coordinate.
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Touch/screenX">screenX</a>
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Touch/screenY">screenY</a>
 * @param motionEvent the original motionEvent
 * @param pointerIndex pointerIndex
 * @param position if motionEvent.getHistoricalSize()!=0, the is the index of historical event,
 *                 otherwise this is {@link #CUR_EVENT} which indicates historicalSize is zero
 * @return the eventLocation in screen's coordinate
 */
private PointF getEventLocInScreenCoordinate(MotionEvent motionEvent, int pointerIndex, int position) {
  float eventX, eventY;
  if (position == CUR_EVENT) {
    eventX = motionEvent.getX(pointerIndex);
    eventY = motionEvent.getY(pointerIndex);
  } else {
    eventX = motionEvent.getHistoricalX(pointerIndex, position);
    eventY = motionEvent.getHistoricalY(pointerIndex, position);
  }
  return getEventLocInScreenCoordinate(eventX, eventY);
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:22,代碼來源:WXGesture.java

示例3: getEventLocInPageCoordinate

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Get event's location in Document's (Page) coordinate.
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Touch/pageX">pageX</a>
 * @see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Touch/pageY">pageY</a>
 * @param motionEvent the original motionEvent
 * @param pointerIndex pointerIndex
 * @param position if motionEvent.getHistoricalSize()!=0, the is the index of historical event,
 *                 otherwise this is {@link #CUR_EVENT} which indicates historicalSize is zero
 * @return the event location in page's coordinate.
 */
private PointF getEventLocInPageCoordinate(MotionEvent motionEvent, int pointerIndex, int position) {
  float eventX, eventY;
  if (position == CUR_EVENT) {
    eventX = motionEvent.getX(pointerIndex);
    eventY = motionEvent.getY(pointerIndex);
  } else {
    eventX = motionEvent.getHistoricalX(pointerIndex, position);
    eventY = motionEvent.getHistoricalY(pointerIndex, position);
  }
  return getEventLocInPageCoordinate(eventX, eventY);
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:22,代碼來源:WXGesture.java

示例4: onMoveEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
private void onMoveEvent(final int x, final int y, final long eventTime, final MotionEvent me) {
    if (DEBUG_MOVE_EVENT) {
        printTouchEvent("onMoveEvent:", x, y, eventTime);
    }
    if (mIsTrackingForActionDisabled) {
        return;
    }

    if (sGestureEnabler.shouldHandleGesture() && me != null) {
        // Add historical points to gesture path.
        final int pointerIndex = me.findPointerIndex(mPointerId);
        final int historicalSize = me.getHistorySize();
        for (int h = 0; h < historicalSize; h++) {
            final int historicalX = (int)me.getHistoricalX(pointerIndex, h);
            final int historicalY = (int)me.getHistoricalY(pointerIndex, h);
            final long historicalTime = me.getHistoricalEventTime(h);
            onGestureMoveEvent(historicalX, historicalY, historicalTime,
                    false /* isMajorEvent */, null);
        }
    }

    if (isShowingMoreKeysPanel()) {
        final int translatedX = mMoreKeysPanel.translateX(x);
        final int translatedY = mMoreKeysPanel.translateY(y);
        mMoreKeysPanel.onMoveEvent(translatedX, translatedY, mPointerId, eventTime);
        onMoveKey(x, y);
        if (mIsInSlidingKeyInput) {
            sDrawingProxy.showSlidingKeyInputPreview(this);
        }
        return;
    }
    onMoveEventInternal(x, y, eventTime);
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:34,代碼來源:PointerTracker.java

示例5: handleActionMove

import android.view.MotionEvent; //導入方法依賴的package包/類
private void handleActionMove(MotionEvent event) {
    float radius = mPathWidth;
    int historySize = event.getHistorySize();
    mTempInvalidateRect.setEmpty();
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        float x = i < historySize ? event.getHistoricalX(i) : event
                .getX();
        float y = i < historySize ? event.getHistoricalY(i) : event
                .getY();
        Dot hitDot = detectAndAddHit(x, y);
        int patternSize = mPattern.size();
        if (hitDot != null && patternSize == 1) {
            mPatternInProgress = true;
            notifyPatternStarted();
        }
        // Note current x and y for rubber banding of in progress patterns
        float dx = Math.abs(x - mInProgressX);
        float dy = Math.abs(y - mInProgressY);
        if (dx > DEFAULT_DRAG_THRESHOLD || dy > DEFAULT_DRAG_THRESHOLD) {
            invalidateNow = true;
        }

        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Dot> pattern = mPattern;
            final Dot lastDot = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastDot.mColumn);
            float lastCellCenterY = getCenterYForRow(lastDot.mRow);

            // Adjust for drawn segment from last cell to (x,y). Radius
            // accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;

            // Invalidate between the pattern's new cell and the pattern's
            // previous cell
            if (hitDot != null) {
                float width = mViewWidth * 0.5f;
                float height = mViewHeight * 0.5f;
                float hitCellCenterX = getCenterXForColumn(hitDot.mColumn);
                float hitCellCenterY = getCenterYForRow(hitDot.mRow);

                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }

            // Invalidate between the pattern's last cell and the previous
            // location
            mTempInvalidateRect.union(Math.round(left), Math.round(top),
                    Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();

    // To save updates, we only invalidate if the user moved beyond a
    // certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTempInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTempInvalidateRect);
    }
}
 
開發者ID:aritraroy,項目名稱:PatternLockView,代碼行數:68,代碼來源:PatternLockView.java

示例6: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
/** Process incoming touch events */
@SuppressWarnings("unused")
public boolean onTouchEvent(MotionEvent event) {
	try {
		int pointerCount = multiTouchSupported ? (Integer) m_getPointerCount.invoke(event) : 1;
		if (DEBUG)
			Log.i("MultiTouch", "Got here 1 - " + multiTouchSupported + " " + mMode + " " + handleSingleTouchEvents + " " + pointerCount);
		if (mMode == MODE_NOTHING && !handleSingleTouchEvents && pointerCount == 1)
			// Not handling initial single touch events, just pass them on
			return false;
		if (DEBUG)
			Log.i("MultiTouch", "Got here 2");

		// Handle history first (we sometimes get history with ACTION_MOVE events)
		int action = event.getAction();
		int histLen = event.getHistorySize() / pointerCount;
		for (int histIdx = 0; histIdx <= histLen; histIdx++) {
			// Read from history entries until histIdx == histLen, then read from current event
			boolean processingHist = histIdx < histLen;
			if (!multiTouchSupported || pointerCount == 1) {
				// Use single-pointer methods -- these are needed as a special case (for some weird reason) even if
				// multitouch is supported but there's only one touch point down currently -- event.getX(0) etc. throw
				// an exception if there's only one point down.
				if (DEBUG)
					Log.i("MultiTouch", "Got here 3");
				xVals[0] = processingHist ? event.getHistoricalX(histIdx) : event.getX();
				yVals[0] = processingHist ? event.getHistoricalY(histIdx) : event.getY();
				pressureVals[0] = processingHist ? event.getHistoricalPressure(histIdx) : event.getPressure();
			} else {
				// Read x, y and pressure of each pointer
				if (DEBUG)
					Log.i("MultiTouch", "Got here 4");
				int numPointers = Math.min(pointerCount, MAX_TOUCH_POINTS);
				if (DEBUG && pointerCount > MAX_TOUCH_POINTS)
					Log.i("MultiTouch", "Got more pointers than MAX_TOUCH_POINTS");
				for (int ptrIdx = 0; ptrIdx < numPointers; ptrIdx++) {
					int ptrId = (Integer) m_getPointerId.invoke(event, ptrIdx);
					pointerIds[ptrIdx] = ptrId;
					// N.B. if pointerCount == 1, then the following methods throw an array index out of range exception,
					// and the code above is therefore required not just for Android 1.5/1.6 but also for when there is
					// only one touch point on the screen -- pointlessly inconsistent :(
					xVals[ptrIdx] = (Float) (processingHist ? m_getHistoricalX.invoke(event, ptrIdx, histIdx) : m_getX.invoke(event, ptrIdx));
					yVals[ptrIdx] = (Float) (processingHist ? m_getHistoricalY.invoke(event, ptrIdx, histIdx) : m_getY.invoke(event, ptrIdx));
					pressureVals[ptrIdx] = (Float) (processingHist ? m_getHistoricalPressure.invoke(event, ptrIdx, histIdx) : m_getPressure
							.invoke(event, ptrIdx));
				}
			}
			// Decode event
			decodeTouchEvent(pointerCount, xVals, yVals, pressureVals, pointerIds, //
					/* action = */processingHist ? MotionEvent.ACTION_MOVE : action, //
					/* down = */processingHist ? true : action != MotionEvent.ACTION_UP //
							&& (action & ((1 << ACTION_POINTER_INDEX_SHIFT) - 1)) != ACTION_POINTER_UP //
							&& action != MotionEvent.ACTION_CANCEL, //
					processingHist ? event.getHistoricalEventTime(histIdx) : event.getEventTime());
		}

		return true;
	} catch (Exception e) {
		// In case any of the introspection stuff fails (it shouldn't)
		Log.e("MultiTouchController", "onTouchEvent() failed", e);
		return false;
	}
}
 
開發者ID:monthlypub,項目名稱:SmingZZick_App,代碼行數:64,代碼來源:MultiTouchController.java

示例7: handleActionMove

import android.view.MotionEvent; //導入方法依賴的package包/類
private void handleActionMove(MotionEvent event) {
    // Handle all recent motion events so we don't skip any cells even when
    // the device
    // is busy...
    final float radius = mPathWidth;
    final int historySize = event.getHistorySize();
    mTmpInvalidateRect.setEmpty();
    boolean invalidateNow = false;
    for (int i = 0; i < historySize + 1; i++) {
        final float x = i < historySize ? event.getHistoricalX(i) : event
                .getX();
        final float y = i < historySize ? event.getHistoricalY(i) : event
                .getY();
        Cell hitCell = detectAndAddHit(x, y);
        final int patternSize = mPattern.size();
        if (hitCell != null && patternSize == 1) {
            mPatternInProgress = true;
            notifyPatternStarted();
        }
        // note current x and y for rubber banding of in progress patterns
        final float dx = Math.abs(x - mInProgressX);
        final float dy = Math.abs(y - mInProgressY);
        if (dx > DRAG_THRESHHOLD || dy > DRAG_THRESHHOLD) {
            invalidateNow = true;
        }

        if (mPatternInProgress && patternSize > 0) {
            final ArrayList<Cell> pattern = mPattern;
            final Cell lastCell = pattern.get(patternSize - 1);
            float lastCellCenterX = getCenterXForColumn(lastCell.column);
            float lastCellCenterY = getCenterYForRow(lastCell.row);

            // Adjust for drawn segment from last cell to (x,y). Radius
            // accounts for line width.
            float left = Math.min(lastCellCenterX, x) - radius;
            float right = Math.max(lastCellCenterX, x) + radius;
            float top = Math.min(lastCellCenterY, y) - radius;
            float bottom = Math.max(lastCellCenterY, y) + radius;

            // Invalidate between the pattern's new cell and the pattern's
            // previous cell
            if (hitCell != null) {
                final float width = mSquareWidth * 0.5f;
                final float height = mSquareHeight * 0.5f;
                final float hitCellCenterX = getCenterXForColumn(hitCell.column);
                final float hitCellCenterY = getCenterYForRow(hitCell.row);

                left = Math.min(hitCellCenterX - width, left);
                right = Math.max(hitCellCenterX + width, right);
                top = Math.min(hitCellCenterY - height, top);
                bottom = Math.max(hitCellCenterY + height, bottom);
            }

            // Invalidate between the pattern's last cell and the previous
            // location
            mTmpInvalidateRect.union(Math.round(left), Math.round(top),
                    Math.round(right), Math.round(bottom));
        }
    }
    mInProgressX = event.getX();
    mInProgressY = event.getY();

    // To save updates, we only invalidate if the user moved beyond a
    // certain amount.
    if (invalidateNow) {
        mInvalidate.union(mTmpInvalidateRect);
        invalidate(mInvalidate);
        mInvalidate.set(mTmpInvalidateRect);
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:71,代碼來源:LockPatternViewEx.java


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