Code example for MotionEvent

Methods: getActiongetXgetYobtainoffsetLocation

0
			onTouchEvent(ev);
			 
			if(mMode != MODE_SLIDE) {
				super.dispatchTouchEvent(ev);
			} else { 
				MotionEvent cancelEvent = MotionEvent.obtain(ev);
				cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
				super.dispatchTouchEvent(cancelEvent);
			} 
			 
			return true; 
		} else { 
			Rect rect = new Rect();
			View menu = getChildAt(0);
			menu.getHitRect(rect);
			 
			if(!rect.contains((int) ev.getX(), (int) ev.getY())) {
				mClosing = true;
				onTouchEvent(ev);
				 
				return true; 
			} else { 
				onTouchEvent(ev);
				 
				ev.offsetLocation(-menu.getLeft(), -menu.getTop());
				menu.dispatchTouchEvent(ev);
				 
				return true; 
			} 
		} 
	} 
	 
	private boolean handleTouchEvent(MotionEvent ev) {
		if(!mEnabled) {
			return false; 
		} 
		 
		float x = ev.getX();
		 
		if(ev.getAction() == MotionEvent.ACTION_DOWN) {
			mHistoricalX = (int) x;
			 
			return mClosing;
		} 
		 
		if(ev.getAction() == MotionEvent.ACTION_MOVE) {
			float diff = x - mHistoricalX;
 
			if((diff > 50 && mMode == MODE_READY) || (diff < -50 && mMode == MODE_FINISHED)) {
				mHistoricalX = (int) x;
				 
				initSlideMode(); 
			} else if(mMode == MODE_SLIDE) {
				mOffset += (int) x - mHistoricalX;
				 
				mHistoricalX = (int) x;
				 
				if(!isSlideAllowed()) { 
					finishSlide(); 
				} 
			} else { 
				return false; 
			} 
		} 
		 
		if(ev.getAction() == MotionEvent.ACTION_UP) {
			if(mMode == MODE_SLIDE) {
				finishSlide(); 
			} 
			 
			return false;