Java Code Examples for org.andengine.input.touch.TouchEvent#ACTION_DOWN

The following examples show how to use org.andengine.input.touch.TouchEvent#ACTION_DOWN . 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: ClickDetector.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	switch (pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			this.prepareClick(pSceneTouchEvent);
			return true;
		case TouchEvent.ACTION_MOVE:
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				final long moveTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();
				if (moveTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					return true;
				}
			}
			return false;
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
			if (this.mPointerID == pSceneTouchEvent.getPointerID()) {
				final long upTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();

				boolean handled;
				if (upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					this.mDownTimeMilliseconds = Long.MIN_VALUE;
					this.mClickDetectorListener.onClick(this, this.mPointerID, pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
					handled = true;
				} else {
					handled = false;
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;

				return handled;
			} else {
				return false;
			}
		default:
			return false;
	}
}
 
Example 2
Source File: ClickDetector.java    From 30-android-libraries-in-30-days with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onManagedTouchEvent(final TouchEvent pSceneTouchEvent) {
	switch(pSceneTouchEvent.getAction()) {
		case TouchEvent.ACTION_DOWN:
			this.prepareClick(pSceneTouchEvent);
			return true;
		case TouchEvent.ACTION_UP:
		case TouchEvent.ACTION_CANCEL:
			if(this.mPointerID == pSceneTouchEvent.getPointerID()) {
				boolean handled = false;
				final long upTimeMilliseconds = pSceneTouchEvent.getMotionEvent().getEventTime();

				if(upTimeMilliseconds - this.mDownTimeMilliseconds <= this.mTriggerClickMaximumMilliseconds) {
					this.mDownTimeMilliseconds = Long.MIN_VALUE;
					this.mClickDetectorListener.onClick(this, pSceneTouchEvent.getPointerID(), pSceneTouchEvent.getX(), pSceneTouchEvent.getY());
					handled = true;
				}

				this.mPointerID = TouchEvent.INVALID_POINTER_ID;
				return handled;
			} else {
				return false;
			}
		default:
			return false;
	}
}
 
Example 3
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 4
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;
	}
}