Code example for GestureDetector

Methods: onTouchEvent

0
	// scroll to next page 
	@Override 
	public boolean onTouch(View v, MotionEvent event) {
		boolean actionUp = false;
		// If the user swipes 
		if (mGestureDetector.onTouchEvent(event))
			return true; 
		// else 
		switch (event.getAction()) {
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_POINTER_UP:
		case MotionEvent.ACTION_CANCEL:
			int scrollX = getScrollX();
			int featureWidth = getMeasuredWidth();
			// if scroll more than %25 of width, then go to next page 
			currentPage = ((scrollX + (featureWidth / 4 * 3)) / featureWidth);
			Log.d(TAG, "scrollX: " + scrollX + " featureWidth: "
					+ (featureWidth / 4 * 3) + " page: " + currentPage);
			int scrollTo = currentPage * featureWidth;
			smoothScrollTo(scrollTo, 0);
			// if you don't return true, a child view will interfere