Code example for MotionEvent

Methods: getActionoffsetLocation

0
		int initX; 
		int initY; 
		boolean setInitialPosition; 
		public boolean onTouch(View v, MotionEvent event) { 
//			Log.d(TAG, "state: " + mState + " x: " + event.getX() + " y: " + event.getY()); 
			int action = event.getAction(); 
			if (action == MotionEvent.ACTION_DOWN) { 
				initX = 0; 
				initY = 0; 
				if (mContent.getVisibility() == GONE) { 
					// since we may not know content dimensions we use factors here 
					if (mOrientation == VERTICAL) { 
						initY = mPosition == TOP? -1 : 1; 
					} else { 
						initX = mPosition == LEFT? -1 : 1; 
					} 
				} 
				setInitialPosition = true; 
			} else { 
				if (setInitialPosition) { 
					// now we know content dimensions, so we multiply factors... 
					initX *= mContentWidth; 
					initY *= mContentHeight; 
					// ... and set initial panel's position 
					mGestureListener.setScroll(initX, initY); 
					setInitialPosition = false; 
					// for offsetLocation we have to invert values 
					initX = -initX; 
					initY = -initY; 
				} 
				// offset every ACTION_MOVE & ACTION_UP event  
				event.offsetLocation(initX, initY); 
			} 
			if (!mGestureDetector.onTouchEvent(event)) { 
				if (action == MotionEvent.ACTION_UP) { 
					// tup up after scrolling 
					post(startAnimation);