Java Code Examples for org.andengine.input.touch.TouchEvent#getMotionEvent()

The following examples show how to use org.andengine.input.touch.TouchEvent#getMotionEvent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HoldDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
protected void prepareHold(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
	this.mDownTimeMilliseconds = System.currentTimeMillis();
	this.mDownX = motionEvent.getX();
	this.mDownY = motionEvent.getY();
	this.mMaximumDistanceExceeded = false;
	this.mPointerID = pSceneTouchEvent.getPointerID();
	this.mHoldX = pSceneTouchEvent.getX();
	this.mHoldY = pSceneTouchEvent.getY();

	if (this.mTriggerHoldMinimumMilliseconds == 0) {
		this.triggerOnHoldStarted();
	}
}
 
Example 2
Source File: HoldDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
protected void prepareHold(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();
	this.mDownTimeMilliseconds = System.currentTimeMillis();
	this.mDownX = motionEvent.getX();
	this.mDownY = motionEvent.getY();
	this.mMaximumDistanceExceeded = false;
	this.mPointerID = pSceneTouchEvent.getPointerID();
	this.mHoldX = pSceneTouchEvent.getX();
	this.mHoldY = pSceneTouchEvent.getY();

	if(this.mTriggerHoldMinimumMilliseconds == 0) {
		this.triggerOnHoldStarted();
	}
}
 
Example 3
Source File: PinchZoomDetector.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	final int action = motionEvent.getAction() & MotionEvent.ACTION_MASK;

	switch (action) {
		case MotionEvent.ACTION_POINTER_DOWN:
			if (!this.mPinchZooming && PinchZoomDetector.hasTwoOrMorePointers(motionEvent)) {
				this.mInitialDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
				this.mCurrentDistance = this.mInitialDistance;
				if (this.mInitialDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
					this.mPinchZooming = true;
					this.mPinchZoomDetectorListener.onPinchZoomStarted(this, pSceneTouchEvent);
				}
			}
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_POINTER_UP:
			if (this.mPinchZooming) {
				this.mPinchZooming = false;
				this.mPinchZoomDetectorListener.onPinchZoomFinished(this, pSceneTouchEvent, this.getZoomFactor());
			}
			break;
		case MotionEvent.ACTION_MOVE:
			if (this.mPinchZooming) {
				if (PinchZoomDetector.hasTwoOrMorePointers(motionEvent)) {
					this.mCurrentDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
					if (this.mCurrentDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
						this.mPinchZoomDetectorListener.onPinchZoom(this, pSceneTouchEvent, this.getZoomFactor());
					}
				} else {
					this.mPinchZooming = false;
					this.mPinchZoomDetectorListener.onPinchZoomFinished(this, pSceneTouchEvent, this.getZoomFactor());
				}
			}
			break;
	}
	return true;
}
 
Example 4
Source File: ContinuousHoldDetector.java    From tilt-game-android with MIT License 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			if (this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
				this.prepareHold(pSceneTouchEvent);
				return true;
			} else {
				return false;
			}
		case TouchEvent.ACTION_MOVE:
		{
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > this.mTriggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > this.mTriggerHoldMaximumDistance;
				return true;
			} else {
				return false;
			}
		}
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
		{
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				if (this.mTriggering) {
					this.triggerOnHoldFinished(motionEvent.getEventTime() - this.mDownTimeMilliseconds);
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return true;
			} else {
				return false;
			}
		}
		default:
			return false;
	}
}
 
Example 5
Source File: PinchZoomDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	final int action = motionEvent.getAction() & MotionEvent.ACTION_MASK;

	switch(action) {
		case MotionEvent.ACTION_POINTER_DOWN:
			if(!this.mPinchZooming && PinchZoomDetector.hasTwoOrMorePointers(motionEvent))  {
				this.mInitialDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
				this.mCurrentDistance = this.mInitialDistance;
				if(this.mInitialDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
					this.mPinchZooming = true;
					this.mPinchZoomDetectorListener.onPinchZoomStarted(this, pSceneTouchEvent);
				}
			}
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_POINTER_UP:
			if(this.mPinchZooming) {
				this.mPinchZooming = false;
				this.mPinchZoomDetectorListener.onPinchZoomFinished(this, pSceneTouchEvent, this.getZoomFactor());
			}
			break;
		case MotionEvent.ACTION_MOVE:
			if(this.mPinchZooming) {
				if (PinchZoomDetector.hasTwoOrMorePointers(motionEvent)) {
					this.mCurrentDistance = PinchZoomDetector.calculatePointerDistance(motionEvent);
					if(this.mCurrentDistance > PinchZoomDetector.TRIGGER_PINCHZOOM_MINIMUM_DISTANCE_DEFAULT) {
						this.mPinchZoomDetectorListener.onPinchZoom(this, pSceneTouchEvent, this.getZoomFactor());
					}
				} else {
					this.mPinchZooming = false;
					this.mPinchZoomDetectorListener.onPinchZoomFinished(this, pSceneTouchEvent, this.getZoomFactor());
				}
			}
			break;
	}
	return true;
}
 
Example 6
Source File: ContinuousHoldDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	final MotionEvent motionEvent = pSceneTouchEvent.getMotionEvent();

	switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			if(this.mPointerID == TouchEvent.INVALID_POINTER_ID) {
				this.prepareHold(pSceneTouchEvent);
				return true;
			} else {
				return false;
			}
		case TouchEvent.ACTION_MOVE:
		{
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				this.mMaximumDistanceExceeded = this.mMaximumDistanceExceeded || Math.abs(this.mDownX - motionEvent.getX()) > this.mTriggerHoldMaximumDistance || Math.abs(this.mDownY - motionEvent.getY()) > this.mTriggerHoldMaximumDistance;
				return true;
			} else {
				return false;
			}
		}
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
		{
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				this.mHoldX = pSceneTouchEvent.getX();
				this.mHoldY = pSceneTouchEvent.getY();

				if(this.mTriggering) {
					this.triggerOnHoldFinished(motionEvent.getEventTime() - this.mDownTimeMilliseconds);
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return true;
			} else {
				return false;
			}
		}
		default:
			return false;
	}
}