Code example for MotionEvent

Methods: getEventTimegetPressuregetXgetYobtain

0
 
	private void setContext(final MotionEvent curr) {
		if (mCurrEvent != null) {
			mCurrEvent.recycle();
		} 
		mCurrEvent = MotionEvent.obtain(curr);
 
		mCurrLen = -1;
		mPrevLen = -1;
		mScaleFactor = -1;
 
		final MotionEvent prev = mPrevEvent;
 
		final float px0 = prev.getX(0);
		final float py0 = prev.getY(0);
		final float px1 = prev.getX(1);
		final float py1 = prev.getY(1);
		final float cx0 = curr.getX(0);
		final float cy0 = curr.getY(0);
		final float cx1 = curr.getX(1);
		final float cy1 = curr.getY(1);
 
		final float pvx = px1 - px0;
		final float pvy = py1 - py0;
		final float cvx = cx1 - cx0;
		final 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(0) + curr.getPressure(1);
		mPrevPressure = prev.getPressure(0) + prev.getPressure(1);
	} 
 
	/** 
	 * MotionEvent has no getRawX(int) method; simulate it pending future API