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