Code example for Region

Methods: contains, translate

0
 
	@Override 
	public boolean onTouchEvent(MotionEvent event)
	{ 
		// Is the event inside of this view? 
		if (!mRegion.contains((int) event.getX(), (int) event.getY()))
		{ 
			return super.onTouchEvent(event);
		} 
 
		if (event.getAction() == MotionEvent.ACTION_DOWN)
		{ 
			mStartPosition.x = (int) event.getX();
			mStartPosition.y = (int) event.getY();
			bringToFront();
			// onSelected(); 
			return true; 
		} else if (event.getAction() == MotionEvent.ACTION_MOVE)
		{ 
			int x = 0, y = 0;
 
			x = (int) event.getX() - mStartPosition.x;
			/* 
			 * if (mLock == DirectionLock.FREE || mLock == 
			 * DirectionLock.HORIZONTAL_ONLY) { x = (int) event.getX() - 
			 * mStartPosition.x; } 
			 *  
			 * if (mLock == DirectionLock.FREE || mLock == 
			 * DirectionLock.VERTICAL_ONLY) { y = (int) event.getY() - 
			 * mStartPosition.y; } 
			 */ 
 
			mRegion.translate(x, y);
			mStartPosition.x = (int) event.getX();
			mStartPosition.y = (int) event.getY();
 
			invalidate();