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


Java MotionEvent.getHistorySize方法代碼示例

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


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

示例1: process

import android.view.MotionEvent; //導入方法依賴的package包/類
public void process(final MotionEvent event)
{
	int ptr = 0; // Process only one touch event, because that's typically a pen/mouse
	for( ptr = 0; ptr < TOUCH_EVENTS_MAX; ptr++ )
	{
		if( touchEvents[ptr].down )
			break;
	}
	if( ptr >= TOUCH_EVENTS_MAX )
		ptr = 0;
	//Log.i("SDL", "Got motion event, getHistorySize " + (int)(event.getHistorySize()) + " ptr " + ptr);

	for( int i = 0; i < event.getHistorySize(); i++ )
	{
		DemoGLSurfaceView.nativeMotionEvent( (int)event.getHistoricalX(i), (int)event.getHistoricalY(i),
			Mouse.SDL_FINGER_MOVE, ptr, (int)( event.getHistoricalPressure(i) * Mouse.MAX_PRESSURE ), (int)( event.getHistoricalSize(i) * Mouse.MAX_PRESSURE ) );
	}
	super.process(event);
}
 
開發者ID:NeoTerm,項目名稱:NeoTerm,代碼行數:20,代碼來源:Video.java

示例2: 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

示例3: adjustHeaderPadding

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * adjust header padding according to motion event
 * 
 * @param ev
 */
private void adjustHeaderPadding(MotionEvent ev) {
    // adjust header padding according to motion event history
    int pointerCount = ev.getHistorySize();
    if (isVerticalFadingEdgeEnabled()) {
        setVerticalScrollBarEnabled(false);
    }
    for (int i = 0; i < pointerCount; i++) {
        if (currentHeaderStatus == HEADER_STATUS_DROP_DOWN_TO_LOAD
                || currentHeaderStatus == HEADER_STATUS_RELEASE_TO_LOAD) {
            headerLayout
                    .setPadding(
                            headerLayout.getPaddingLeft(),
                            (int) (((ev.getHistoricalY(i) - actionDownPointY) - headerOriginalHeight) / headerPaddingTopRate),
                            headerLayout.getPaddingRight(), headerLayout.getPaddingBottom());
        }
    }
}
 
開發者ID:Louis19910615,項目名稱:youkes_browser,代碼行數:23,代碼來源:SwipeListView.java

示例4: getMovedRect

import android.view.MotionEvent; //導入方法依賴的package包/類
private Rect getMovedRect(MotionEvent motionEvent) {
    if (cropRect == null) {
        return null;
    }

    PointF currentTouchPos = viewToSourceCoord(motionEvent.getX(),
            motionEvent.getY());

    int historySize = motionEvent.getHistorySize();
    if (historySize > 0) {
        PointF oldTouchPos = viewToSourceCoord(motionEvent.getHistoricalX(0),
                motionEvent.getHistoricalY(0));
        int deltaX = (int) (oldTouchPos.x - currentTouchPos.x);
        int deltaY = (int) (oldTouchPos.y - currentTouchPos.y);

        Rect newCropRect = new Rect(
                cropRect.left + deltaX,
                cropRect.top + deltaY,
                cropRect.right + deltaX,
                cropRect.bottom + deltaY);
        return checkRectBounds(newCropRect, false);
    } else {
        return cropRect;
    }
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:26,代碼來源:CropImageView.java

示例5: dispatchTrackballEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Process trackball events.  Used mainly for fine-tuned color adjustment, or alternatively to switch between slider controls.
 */
@Override
public boolean dispatchTrackballEvent(MotionEvent event) {
	float x = event.getX();
	float y = event.getY();

	//A longer event history implies faster trackball movement.
	//Use it to infer a larger jump and therefore faster palette/slider adjustment.
	int jump = event.getHistorySize() + 1;

	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN: {
			}
			break;
		case MotionEvent.ACTION_MOVE: {
				//NEW_METHOD_WORK_NEEDED_HERE
				//To add a new method, replicate and extend the appropriate entry in this list,
				//depending on whether you use 1D or 2D controllers
				switch (mMethod) {
					case METHOD_HS_V_PALETTE:
						if (mFocusedControl == 0) {
							changeHSPalette(x, y, jump);
						}
						else if (mFocusedControl == 1) {
							if (y < 0)
								changeSlider(mFocusedControl, true, jump);
							else if (y > 0)
								changeSlider(mFocusedControl, false, jump);
						}
						break;
				}
			}
			break;
		case MotionEvent.ACTION_UP: {
			}
			break;
	}

	return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:43,代碼來源:UberColorPickerDialog.java

示例6: addMovement

import android.view.MotionEvent; //導入方法依賴的package包/類
public void addMovement(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        mBuffer.clear();
        return;
    }
    long time = ev.getEventTime();
    final int count = ev.getHistorySize();
    for (int i = 0; i < count; i++) {
        addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i), ev.getHistoricalEventTime(i));
    }
    addPoint(ev.getX(), ev.getY(), time);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:13,代碼來源:SwipeTracker.java

示例7: getHistoricalEvents

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Get historical event. This is only applied to {@link MotionEvent#ACTION_MOVE}.
 * For other types of motionEvent, historical event is meaningless.
 * @param motionEvent motionEvent, which contains all pointers event in a period of time
 * @return If motionEvent.getActionMasked()!=MotionEvent.ACTION_MOVE,
 * this method will return an empty list.
 * Otherwise this method will return the historical motionEvent, which may also be empty.
 */
private List<Map<String, Object>> getHistoricalEvents(MotionEvent motionEvent) {
  List<Map<String, Object>> list = new ArrayList<>(motionEvent.getHistorySize());
  if (motionEvent.getActionMasked() == MotionEvent.ACTION_MOVE) {
    Map<String, Object> param;
    for (int i = 0; i < motionEvent.getHistorySize(); i++) {
      param = createFireEventParam(motionEvent, i,null);
      list.add(param);
    }
  }
  return list;
}
 
開發者ID:erguotou520,項目名稱:weex-uikit,代碼行數:20,代碼來源:WXGesture.java

示例8: createFireEventParam

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Create a list of event for {@link com.taobao.weex.WXSDKInstance#fireEvent(String, String, Map, Map)}.
 * As there is a batch mechanism in MotionEvent, so this method returns a list.
 * @param motionEvent motionEvent, which contains all pointers event in a period of time
 * @return List of Map, which contains touch object.
 */
private List<Map<String, Object>> createFireEventParam(MotionEvent motionEvent) {
  List<Map<String, Object>> list = new ArrayList<>(motionEvent.getHistorySize() + 1);
  list.addAll(getHistoricalEvents(motionEvent));
  list.add(createFireEventParam(motionEvent, CUR_EVENT));
  return list;
}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:13,代碼來源:WXGesture.java

示例9: createMultipleFireEventParam

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Create a list of event for {@link com.taobao.weex.WXSDKInstance#fireEvent(String, String, Map, Map)}.
 * As there is a batch mechanism in MotionEvent, so this method returns a list.
 * @param motionEvent motionEvent, which contains all pointers event in a period of time
 * @return List of Map, which contains touch object.
 */
private List<Map<String, Object>> createMultipleFireEventParam(MotionEvent motionEvent,String state) {
  List<Map<String, Object>> list = new ArrayList<>(motionEvent.getHistorySize() + 1);
  list.addAll(getHistoricalEvents(motionEvent));
  list.add(createFireEventParam(motionEvent, CUR_EVENT, state));
  return list;
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:13,代碼來源:WXGesture.java

示例10: addMovement

import android.view.MotionEvent; //導入方法依賴的package包/類
public void addMovement(MotionEvent ev) {
    long time = ev.getEventTime();
    final int N = ev.getHistorySize();
    for (int i = 0; i < N; i++) {
        addPoint(ev.getHistoricalX(i), ev.getHistoricalY(i),
                ev.getHistoricalEventTime(i));
    }
    addPoint(ev.getX(), ev.getY(), time);
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:10,代碼來源:MyKeyboardView.java

示例11: printSamples

import android.view.MotionEvent; //導入方法依賴的package包/類
void printSamples(MotionEvent ev) {
    final int historySize = ev.getHistorySize();
    final int pointerCount = ev.getPointerCount();
    for (int h = 0; h < historySize; h++) {
        System.out.printf("At time %d:", ev.getHistoricalEventTime(h));
        for (int p = 0; p < pointerCount; p++) {
            System.out.printf("  pointer %d: (%f,%f)", ev.getPointerId(p), ev.getHistoricalX(p, h),
                    ev.getHistoricalY(p, h));
        }
    }
    System.out.printf("At time %d:", ev.getEventTime());
    for (int p = 0; p < pointerCount; p++) {
        System.out.printf("  pointer %d: (%f,%f)", ev.getPointerId(p), ev.getX(p), ev.getY(p));
    }
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:16,代碼來源:TouchAreaView.java

示例12: 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

示例13: 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

示例14: touch_move

import android.view.MotionEvent; //導入方法依賴的package包/類
private void touch_move(float x, float y, MotionEvent event) {
    float dx = x - mfX;
    float dy = y - mfY;
    if (Math.abs(dx) >= TOUCH_TOLERANCE || Math.abs(dy) >= TOUCH_TOLERANCE) {
    	if (mnTouchingMode == 0 || mnTouchingMode == 1)	{	// draw mode
        	Canvas canvas = new Canvas(mbitmapActual);
    		Position3D pnt = mapView2Bitmap(new Position3D(x, y));
        	if (mfX == x && mfY == y)	{
        		canvas.drawPoint((float)pnt.getX(), (float)pnt.getY(), mpaint);
        	} else	{
        		Position3D pnt1 = mapView2Bitmap(new Position3D(mfX, mfY));
        		float xLast = (float)pnt1.getX(), yLast = (float)pnt1.getY();
        		for (int idx = 0; idx < event.getHistorySize(); idx ++) {
        			Position3D pntThis = mapView2Bitmap(new Position3D(event.getHistoricalX(idx), event.getHistoricalY(idx)));
        			float xThis = (float)pntThis.getX();
        			float yThis = (float)pntThis.getY();
        			canvas.drawLine(xLast, yLast, xThis, yThis, mpaint);
        			xLast = xThis;
        			yLast = yThis;
        		}
        		canvas.drawLine(xLast, yLast, (float)pnt.getX(), (float)pnt.getY(), mpaint);
        	}
	        ((ActivityFingerPaint)mcontext).mstrCurrentPnt = "(" + (int)(pnt.getX()) + "," + (int)(pnt.getY()) + ")";
	        ((ActivityFingerPaint)mcontext).mstrWidthHeight = "";
	        ((ActivityFingerPaint)mcontext).setImageInfoText();
    	} else if (mnTouchingMode == 2)	{	// select mode
    		calcCroppedArea(mfX0, mfY0, x, y);
	        ((ActivityFingerPaint)mcontext).mstrWidthHeight = (mnSelectedRight - mnSelectedLeft) + "×" + (mnSelectedBottom - mnSelectedTop);
	        ((ActivityFingerPaint)mcontext).setImageInfoText();
    	} else if (mnTouchingMode == 3)	{	// move mode
    		double dBmpActualLeft = mdBitmapX0, dBmpActualTop = mdBitmapY0;
    		double dBmpActualRight = mdBitmapX0 + mbitmapActual.getWidth() * mdZoomRatio;
    		double dBmpActualBottom  = mdBitmapY0 + mbitmapActual.getHeight() * mdZoomRatio;
    		double dMax2LeftMove = Math.max(0, dBmpActualRight - mnViewWidth);
    		double dMax2RightMove = Math.max(0, - dBmpActualLeft);
    		double dMaxUpMove = Math.max(0, dBmpActualBottom - mnViewHeight);
    		double dMaxDownMove = Math.max(0, - dBmpActualTop);
    		
    		if (dx < 0)	{	// move to left
    			dx = (float)Math.max(dx, - dMax2LeftMove);
    		} else if (dx > 0)	{	// move to right
    			dx = (float)Math.min(dx, dMax2RightMove);
    		}

    		if (dy < 0)	{	// move up
    			dy = (float)Math.max(dy, - dMaxUpMove);
    		} else if (dy > 0)	{	// move down
    			dy = (float)Math.min(dy, dMaxDownMove);
    		}
    		
    		mdBitmapX0 += dx / mdZoomRatio;
    		mdBitmapY0 += dy / mdZoomRatio;
    	}
        mfX = x;
        mfY = y;
    }
}
 
開發者ID:woshiwpa,項目名稱:SmartMath,代碼行數:58,代碼來源:PaintImageView.java

示例15: 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


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