Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

In this page you can find the example usage for android.view MotionEvent ACTION_DOWN.

Prototype

int ACTION_DOWN

To view the source code for android.view MotionEvent ACTION_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

Usage

From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (!mCanSlide || !mIsSlidingEnabled || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
        mDragHelper.cancel();//from  www.j  a va  2s .c om
        return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        mDragHelper.cancel();
        return false;
    }

    final float x = ev.getX();
    final float y = ev.getY();
    boolean interceptTap = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mIsUnableToDrag = false;
        mInitialMotionX = x;
        mInitialMotionY = y;
        if (isDragViewUnder((int) x, (int) y) && !mIsUsingDragViewTouchEvents) {
            interceptTap = true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int dragSlop = mDragHelper.getTouchSlop();

        // Handle any horizontal scrolling on the drag view.
        if (mIsUsingDragViewTouchEvents) {
            if (adx > mScrollTouchSlop && ady < mScrollTouchSlop) {
                return super.onInterceptTouchEvent(ev);
            }
            // Intercept the touch if the drag view has any vertical scroll.
            // onTouchEvent will determine if the view should drag vertically.
            else if (ady > mScrollTouchSlop) {
                interceptTap = isDragViewUnder((int) x, (int) y);
            }
        }

        if ((ady > dragSlop && adx > ady) || !isDragViewUnder((int) x, (int) y)) {
            mDragHelper.cancel();
            mIsUnableToDrag = true;
            return false;
        }
        break;
    }
    }

    final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev);

    return interceptForDrag || interceptTap;
}

From source file:com.android.leanlauncher.Workspace.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        break;/*from  w ww  .  ja v  a 2 s  .c  o m*/
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
        if (mTouchState == PagedView.TOUCH_STATE_REST) {
            final CellLayout currentPage = mWorkspace;
            if (currentPage != null) {
                onWallpaperTap(ev);
            }
        }
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:android.support.design.widget.CoordinatorLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    MotionEvent cancelEvent = null;//from  w w  w.jav a2 s.  co  m

    final int action = MotionEventCompat.getActionMasked(ev);

    // Make sure we reset in case we had missed a previous important event.
    if (action == MotionEvent.ACTION_DOWN) {
        resetTouchBehaviors();
    }

    final boolean intercepted = performIntercept(ev, TYPE_ON_INTERCEPT);

    if (cancelEvent != null) {
        cancelEvent.recycle();
    }

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
        resetTouchBehaviors();
    }

    return intercepted;
}

From source file:com.example.SmartBoard.DrawingView.java

public void onTouchRectangleMode(MotionEvent event) {
    int eventaction = event.getAction();

    int X = (int) event.getX();
    int Y = (int) event.getY();

    switch (eventaction) {

    case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on
        // a ball
        finished = false;// ww w.ja va 2  s . com
        if (points[0] == null) {
            //initialize rectangle.
            points[0] = new Point();
            points[0].x = X;
            points[0].y = Y;

            points[1] = new Point();
            points[1].x = X;
            points[1].y = Y + 30;

            points[2] = new Point();
            points[2].x = X + 30;
            points[2].y = Y + 30;

            points[3] = new Point();
            points[3].x = X + 30;
            points[3].y = Y;

            balID = 2;
            groupId = 1;
            // declare each ball with the ColorBall class
            for (Point pt : points) {
                colorballs.add(new ColorBall(getContext(), R.drawable.dot_drag_handle, pt));
            }
        } else {
            //resize rectangle
            balID = -1;
            groupId = -1;
            for (int i = colorballs.size() - 1; i >= 0; i--) {
                ColorBall ball = colorballs.get(i);
                // check if inside the bounds of the ball (circle)
                // get the center for the ball
                int centerX = ball.getX() + ball.getWidthOfBall();
                int centerY = ball.getY() + ball.getHeightOfBall();

                // calculate the radius from the touch to the center of the
                // ball
                double radCircle = Math
                        .sqrt((double) (((centerX - X) * (centerX - X)) + (centerY - Y) * (centerY - Y)));

                if (radCircle < ball.getWidthOfBall()) {

                    balID = ball.getID();
                    if (balID == 1 || balID == 3) {
                        groupId = 2;
                    } else {
                        groupId = 1;
                    }
                    invalidate();
                    break;
                }
                invalidate();
            }
        }
        break;

    case MotionEvent.ACTION_MOVE: // touch drag with the ball

        if (balID > -1) {
            // move the balls the same as the finger
            colorballs.get(balID).setX(X);
            colorballs.get(balID).setY(Y);

            if (groupId == 1) {
                colorballs.get(1).setX(colorballs.get(0).getX());
                colorballs.get(1).setY(colorballs.get(2).getY());
                colorballs.get(3).setX(colorballs.get(2).getX());
                colorballs.get(3).setY(colorballs.get(0).getY());
            } else {
                colorballs.get(0).setX(colorballs.get(1).getX());
                colorballs.get(0).setY(colorballs.get(3).getY());
                colorballs.get(2).setX(colorballs.get(3).getX());
                colorballs.get(2).setY(colorballs.get(1).getY());
            }

            invalidate();
        }

        break;

    case MotionEvent.ACTION_UP:
        // touch drop - just do things here after dropping
        finished = true;

        break;
    }
    // redraw the canvas
    invalidate();
    return;

}

From source file:com.timemachine.controller.ControllerActivity.java

private void setupUI() {
    // Set layout listener
    View controllerView = findViewById(R.id.controllerView);
    ViewTreeObserver vto = controllerView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override/*  w  ww .  j  av a 2 s .  c  o m*/
        public void onGlobalLayout() {
            runOnUiThread(new Runnable() {
                public void run() {
                    locationSliderHeight = locationSlider.getHeight();
                    originLocationSliderContainerY = locationSliderContainer.getY();
                    originPlayPauseButtonY = playPause.getY();
                    minLocationSliderContainerY = originLocationSliderContainerY;
                    maxLocationSliderContainerY = originLocationSliderContainerY + locationSliderHeight;
                    midLocationSliderContainerY = (minLocationSliderContainerY + maxLocationSliderContainerY)
                            / 2;
                }
            });
            System.out.println("locationSliderHeight: " + locationSliderHeight);
            System.out.println("locationSliderContainerY: " + originLocationSliderContainerY);
            locationSlider.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });

    // Connect to controller.html
    controllerURL = "http://" + ipText + ":8080/controller.html";
    locationSlider = (WebView) findViewById(R.id.webview);
    locationSliderContainer = (FrameLayout) findViewById(R.id.sliderContainer);
    locationSlider.setBackgroundColor(Color.TRANSPARENT);
    locationSlider.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
    locationSlider.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            System.out.println("onReceivedError");
            showConnectDialog("Error while connecting to controller. Connect again.");
        }

        @Override
        public void onLoadResource(WebView view, String url) {
            if (url.contains("thumbnail"))
                isMasterConnected = true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            isMasterConnectedTimerTask = null;
            isMasterConnectedTimerTask = new TimerTask() {
                @Override
                public void run() {
                    if (isMasterConnected == false)
                        showConnectDialog("Master is not loaded in the browser. Connect again.");
                }
            };
            isMasterConnectedTimer.schedule(isMasterConnectedTimerTask, 6000);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (url.contains(controllerURL)) {
                drag.setVisibility(View.VISIBLE);
                playPause.setVisibility(View.VISIBLE);
                loadPreferences();
            }
            super.onPageFinished(view, url);
        }
    });
    try {
        locationSlider.loadUrl(controllerURL);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Set JavaScript Interface
    locationSlider.addJavascriptInterface(this, "androidObject");
    WebSettings webSettings = locationSlider.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Set the play-pause button
    playPause = (ImageButton) findViewById(R.id.playPauseButton);
    playPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            socket.emit("handlePlayPauseServer");
        }
    });
    socket.emit("setControllerPlayButton");

    // Set the drag button
    drag = (ImageButton) findViewById(R.id.drag);
    drag.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                dragYDiffBetweenFingerAndSliderTop = locationSliderContainer.getY() - event.getRawY();
                dragYDiffBetweenFingerAndPlayPauseTop = playPause.getY() - event.getRawY();
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                // Move the slider based on current finger location
                float newSliderY = event.getRawY() + dragYDiffBetweenFingerAndSliderTop;
                float newPlayPauseY = event.getRawY() + dragYDiffBetweenFingerAndPlayPauseTop;
                if (newSliderY > minLocationSliderContainerY && newSliderY < maxLocationSliderContainerY) {
                    locationSliderContainer.setY(newSliderY);
                    playPause.setY(newPlayPauseY);
                }
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getEventTime() - event.getDownTime() <= tapTimeout) {
                    // Tap is detected, toggle the slider
                    System.out.println("onTap");
                    runOnUiThread(new Runnable() {
                        public void run() {
                            toggleSlider();
                        }
                    });
                } else {
                    // Not a tap gesture, slide up or down based on the slider's current position
                    if (locationSliderContainer.getY() > midLocationSliderContainerY)
                        slideDown();
                    else
                        slideUp();
                }
            }
            return true;
        }
    });

    // Set the Google map
    setUpMapIfNeeded();
}

From source file:cn.edu.zafu.easemob.imagecoverflow.CoverFlowView.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (getParent() != null) {
        getParent().requestDisallowInterceptTouchEvent(true);
    }/*from   w  w w .j  a  v a2 s. c  o  m*/

    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mScroller.computeScrollOffset()) {
            mScroller.abortAnimation();
            invalidate();
        }
        stopLongClick();
        triggleLongClick(event.getX(), event.getY());
        touchBegan(event);
        return true;
    case MotionEvent.ACTION_MOVE:
        touchMoved(event);
        return true;
    case MotionEvent.ACTION_UP:
        touchEnded(event);
        stopLongClick();
        return true;
    }

    return false;
}

From source file:cfb.com.dailydevelopment4.example12.library.TitlePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }//ww w.ja v a2s .c o  m
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage - 1);
                    }
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage + 1);
                    }
                    return true;
                }
            } else {
                //Middle third
                if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:cn.chuangblog.simplebanner1.indicator.TitlePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from w  w  w  .ja  v a2s.co m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = InfiniteViewPager.FakePositionHelper.getAdapterSize(mViewPager);
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage - 1);
                    }
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage + 1);
                    }
                    return true;
                }
            } else {
                //Middle third
                if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.along.altmcssd.pda.widget.viewpagerindicator.TitlePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }//from  w w w .  ja v  a  2s  .com
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage - 1);
                    }
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage + 1);
                    }
                    return true;
                }
            } else {
                // Middle third
                if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.android.core.view.indicator.TitlePageIndicator.java

@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from   w  w w  .j  av  a  2 s  .c  o  m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage - 1);
                    }
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    if (action != MotionEvent.ACTION_CANCEL) {
                        mViewPager.setCurrentItem(mCurrentPage + 1);
                    }
                    return true;
                }
            } else {
                //Middle third
                if (mCenterItemClickListener != null && action != MotionEvent.ACTION_CANCEL) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}