Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

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

Prototype

int ACTION_MOVE

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

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:edu.sfsu.cs.orange.ocr.CaptureActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    checkFirstLaunch();//from ww w .  jav a 2s .c  om

    if (isFirstLaunch) {
        setDefaultPreferences();
    }

    Window window = getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.capture);
    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    cameraButtonView = findViewById(R.id.camera_button_view);
    resultView = findViewById(R.id.result_view);

    statusViewBottom = (TextView) findViewById(R.id.status_view_bottom);
    registerForContextMenu(statusViewBottom);
    statusViewTop = (TextView) findViewById(R.id.status_view_top);
    registerForContextMenu(statusViewTop);

    handler = null;
    lastResult = null;
    hasSurface = false;
    beepManager = new BeepManager(this);

    // Camera shutter button
    if (DISPLAY_SHUTTER_BUTTON) {
        shutterButton = (ShutterButton) findViewById(R.id.shutter_button);
        shutterButton.setOnShutterButtonListener(this);
    }

    ocrResultView = (TextView) findViewById(R.id.ocr_result_text_view);
    registerForContextMenu(ocrResultView);
    translationView = (TextView) findViewById(R.id.translation_text_view);
    registerForContextMenu(translationView);

    progressView = (View) findViewById(R.id.indeterminate_progress_indicator_view);

    cameraManager = new CameraManager(getApplication());
    viewfinderView.setCameraManager(cameraManager);

    // Set listener to change the size of the viewfinder rectangle.
    viewfinderView.setOnTouchListener(new View.OnTouchListener() {
        int lastX = -1;
        int lastY = -1;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                lastX = -1;
                lastY = -1;
                return true;
            case MotionEvent.ACTION_MOVE:
                int currentX = (int) event.getX();
                int currentY = (int) event.getY();

                try {
                    Rect rect = cameraManager.getFramingRect();

                    final int BUFFER = 50;
                    final int BIG_BUFFER = 60;
                    if (lastX >= 0) {
                        // Adjust the size of the viewfinder rectangle. Check if the touch event occurs in the corner areas first, because the regions overlap.
                        if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top left corner: adjust both top and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.top + BIG_BUFFER && currentY >= rect.top - BIG_BUFFER)
                                        || (lastY <= rect.top + BIG_BUFFER
                                                && lastY >= rect.top - BIG_BUFFER))) {
                            // Top right corner: adjust both top and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BIG_BUFFER && currentX <= rect.left + BIG_BUFFER)
                                || (lastX >= rect.left - BIG_BUFFER && lastX <= rect.left + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom left corner: adjust both bottom and left sides
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BIG_BUFFER && currentX <= rect.right + BIG_BUFFER)
                                || (lastX >= rect.right - BIG_BUFFER && lastX <= rect.right + BIG_BUFFER))
                                && ((currentY <= rect.bottom + BIG_BUFFER
                                        && currentY >= rect.bottom - BIG_BUFFER)
                                        || (lastY <= rect.bottom + BIG_BUFFER
                                                && lastY >= rect.bottom - BIG_BUFFER))) {
                            // Bottom right corner: adjust both bottom and right sides
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.left - BUFFER && currentX <= rect.left + BUFFER)
                                || (lastX >= rect.left - BUFFER && lastX <= rect.left + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting left side: event falls within BUFFER pixels of left side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (lastX - currentX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentX >= rect.right - BUFFER && currentX <= rect.right + BUFFER)
                                || (lastX >= rect.right - BUFFER && lastX <= rect.right + BUFFER))
                                && ((currentY <= rect.bottom && currentY >= rect.top)
                                        || (lastY <= rect.bottom && lastY >= rect.top))) {
                            // Adjusting right side: event falls within BUFFER pixels of right side, and between top and bottom side limits
                            cameraManager.adjustFramingRect(2 * (currentX - lastX), 0);
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.top + BUFFER && currentY >= rect.top - BUFFER)
                                || (lastY <= rect.top + BUFFER && lastY >= rect.top - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting top side: event falls within BUFFER pixels of top side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (lastY - currentY));
                            viewfinderView.removeResultText();
                        } else if (((currentY <= rect.bottom + BUFFER && currentY >= rect.bottom - BUFFER)
                                || (lastY <= rect.bottom + BUFFER && lastY >= rect.bottom - BUFFER))
                                && ((currentX <= rect.right && currentX >= rect.left)
                                        || (lastX <= rect.right && lastX >= rect.left))) {
                            // Adjusting bottom side: event falls within BUFFER pixels of bottom side, and between left and right side limits
                            cameraManager.adjustFramingRect(0, 2 * (currentY - lastY));
                            viewfinderView.removeResultText();
                        }
                    }
                } catch (NullPointerException e) {
                    Log.e(TAG, "Framing rect not available", e);
                }
                v.invalidate();
                lastX = currentX;
                lastY = currentY;
                return true;
            case MotionEvent.ACTION_UP:
                lastX = -1;
                lastY = -1;
                return true;
            }
            return false;
        }
    });

    isEngineReady = false;
    aq = new AQuery(this);
    beerQuery = new BeerQuery();

}

From source file:cc.solart.turbo.TurboRecyclerView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) {
        return super.onTouchEvent(e);
    }//from  w  w w .  j  a  v a 2  s.c  om

    if (dispatchOnItemTouch(e)) {
        return true;
    }

    if (getLayoutManager() == null) {
        return false;
    }

    final boolean canScrollHorizontally = getLayoutManager().canScrollHorizontally();
    final boolean canScrollVertically = getLayoutManager().canScrollVertically();

    final int action = MotionEventCompat.getActionMasked(e);
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final int index = MotionEventCompat.getActionIndex(e);
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialMotionX = getMotionEventX(e, index);
        mInitialMotionY = getMotionEventY(e, index);
    }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(e);
        mActivePointerId = MotionEventCompat.getPointerId(e, index);
        mInitialMotionX = getMotionEventX(e, index);
        mInitialMotionY = getMotionEventY(e, index);
    }
        break;

    case MotionEvent.ACTION_MOVE: {

        final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId);
        if (index < 0) {
            Log.w(TAG, "pointer index for id " + index + " not found. return super");
            return super.onTouchEvent(e);
        }

        final int x = getMotionEventX(e, index);
        final int y = getMotionEventY(e, index);

        int deltaY = y - mInitialMotionY;
        if (canScrollVertically && Math.abs(deltaY) > mTouchSlop && deltaY < 0) {
            float targetEnd = -dampAxis(deltaY);
            setTranslationY(targetEnd);
            return true;
        }

        int deltaX = x - mInitialMotionX;
        if (canScrollHorizontally && Math.abs(deltaX) > mTouchSlop && deltaX < 0) {
            float targetEnd = -dampAxis(deltaX);
            setTranslationX(targetEnd);
            return true;
        }
    }
        break;
    case MotionEventCompat.ACTION_POINTER_UP: {
        onPointerUp(e);
    }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL: {
        if (canScrollHorizontally)
            animateOffsetToEnd("translationX", mInterpolator, 0f);
        if (canScrollVertically)
            animateOffsetToEnd("translationY", mInterpolator, 0f);
        final int index = MotionEventCompat.findPointerIndex(e, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "Got ACTION_UP event but don't have an active pointer id.");
            return super.onTouchEvent(e);
        }

        final int y = getMotionEventY(e, index);
        final int x = getMotionEventX(e, index);
        final float overScrollBottom = (mInitialMotionY - y) * DRAG_RATE;
        final float overScrollRight = (mInitialMotionX - x) * DRAG_RATE;

        if ((canScrollVertically && overScrollBottom > mTotalDragDistance)
                || (canScrollHorizontally && overScrollRight > mTotalDragDistance)) {
            Log.i(TAG, "refreshing...");
            mIsLoading = true;
            dispatchOnLoadingMoreListeners();
            smoothScrollToPosition(mLastVisibleItemPosition + 1);
            mActivePointerId = INVALID_POINTER;
            return true;
        } else {
            mIsLoading = false;
            mActivePointerId = INVALID_POINTER;
        }

    }
        break;
    }
    return super.onTouchEvent(e);
}

From source file:com.bolaa.medical.view.banner.LoopCirclePageIndicator.java

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

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        //                invalidate();
        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) {
            if (!mViewPager.isFakeDragging()) {
                mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;

            // tyl ?beginFakeDrag()false,pagermFakeDragging???,
            // ?isFakeDragging()?false??fakeDragBy()
            if (mViewPager != null && mViewPager.isFakeDragging()) {
                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;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage - 1);
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                mViewPager.setCurrentItem(mCurrentPage + 1);
                return true;
            }
        }

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

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        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.spoiledmilk.ibikecph.map.MapActivity.java

protected boolean onImgSwiperTouch(View view, MotionEvent event) {
    if (leftContainer.getVisibility() != View.VISIBLE) {
        leftContainer.setVisibility(View.VISIBLE);
    }/*w w  w.  j ava  2s.  c  o m*/
    if (mapDisabledView.getVisibility() != View.VISIBLE) {
        mapDisabledView.setVisibility(View.VISIBLE);
    }
    switch (event.getAction()) {
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        view.setPressed(false);
        if (moveCount <= 3)
            translate(slidden ? -maxSlide : maxSlide, true);
        else
            translate(0, true);
        break;
    case MotionEvent.ACTION_DOWN:
        moveCount = 0;
        view.setPressed(true);
        touchX = event.getX();
        break;
    case MotionEvent.ACTION_MOVE:
        if (moveCount++ < 3)
            break;
        newTouchX = event.getX();
        delta = newTouchX - touchX;
        translate(delta, false);
        touchX = newTouchX;
        break;
    }

    if (slidden && mapDisabledView.getVisibility() != View.GONE) {
        mapDisabledView.setVisibility(View.GONE);
    }

    return true;
}

From source file:org.cocos2dx.lib.TextInputWraper.java

public boolean onTouchEvent(final MotionEvent event) {
    // these data are used in ACTION_MOVE and ACTION_CANCEL
    final int pointerNumber = event.getPointerCount();
    final int[] ids = new int[pointerNumber];
    final float[] xs = new float[pointerNumber];
    final float[] ys = new float[pointerNumber];

    for (int i = 0; i < pointerNumber; i++) {
        ids[i] = event.getPointerId(i);/*w  w w  .  j a  v  a2  s.  com*/
        xs[i] = event.getX(i);
        ys[i] = event.getY(i);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerDown = event.getPointerId(indexPointerDown);
        final float xPointerDown = event.getX(indexPointerDown);
        final float yPointerDown = event.getY(indexPointerDown);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
            }
        });
        break;

    case MotionEvent.ACTION_DOWN:
        // there are only one finger on the screen
        final int idDown = event.getPointerId(0);
        final float xDown = xs[0];
        final float yDown = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idDown, xDown, yDown);
            }
        });
        break;

    case MotionEvent.ACTION_MOVE:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionMove(ids, xs, ys);
            }
        });
        break;

    case MotionEvent.ACTION_POINTER_UP:
        final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerUp = event.getPointerId(indexPointUp);
        final float xPointerUp = event.getX(indexPointUp);
        final float yPointerUp = event.getY(indexPointUp);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
            }
        });
        break;

    case MotionEvent.ACTION_UP:
        // there are only one finger on the screen
        final int idUp = event.getPointerId(0);
        final float xUp = xs[0];
        final float yUp = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idUp, xUp, yUp);
            }
        });
        break;

    case MotionEvent.ACTION_CANCEL:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionCancel(ids, xs, ys);
            }
        });
        break;
    }

    if (debug) {
        dumpEvent(event);
    }
    return true;
}

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

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }/*  ww  w  .  ja v a 2 s .  co m*/
    int action = MotionEventCompat.getActionMasked(event);
    if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
        return true;
    }
    mViewDragHelper.processTouchEvent(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
    // to capture the bottom sheet in case it is not captured and the touch slop is passed.
    if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) {
        if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) {
            mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
        }
    }
    return !mIgnoreEvents;
}

From source file:com.coco.slidinguppanel.SlidingUpPanel.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    // This method JUST determines whether we want to intercept the motion.
    // If we return true, onMotionEvent will be called and we do the actual
    // scrolling there.
    final int action = MotionEventCompat.getActionMasked(ev);

    // Always take care of the touch gesture being complete.
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
        // Release the drag.
        DEBUG_LOG("Intercept done!");
        endDrag();//from   w  ww.j a  v  a 2s  .c o m
        return false;
    }

    // Nothing more to do here if we have decided whether or not we are dragging.
    if (action != MotionEvent.ACTION_DOWN) {
        if (mIsBeingDragged) {
            DEBUG_LOG("Intercept returning true!");
            return true;
        }
        if (mIsUnableToDrag) {
            DEBUG_LOG("Intercept returning false!");
            return false;
        }
    }

    // Check whether the user has moved far enough from his original down touch.
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        onTouchDown(ev, true);
        DEBUG_LOG("***Down at " + mLastMotionX + "," + mLastMotionY + " mIsBeingDragged=" + mIsBeingDragged
                + " mIsUnableToDrag=" + mIsUnableToDrag);
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            break;
        }
        final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        final float x = MotionEventCompat.getX(ev, pointerIndex);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float xDiff = Math.abs(x - mInitialMotionX);
        final float yDiff = Math.abs(y - mInitialMotionY);
        DEBUG_LOG("***Moved to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
        onTouchMove(x, y, xDiff, yDiff, true);
        break;
    }
    case MotionEvent.ACTION_POINTER_UP:
        onTouchPointerUp(ev);
        break;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    // The only time we want to intercept motion events is if we are in the drag mode.
    return mIsBeingDragged;
}

From source file:com.commonsware.cwac.crossport.design.widget.BottomSheetBehavior.java

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }/*w  w  w . ja  v a 2  s.  c om*/
    int action = event.getActionMasked();
    if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
        return true;
    }
    if (mViewDragHelper != null) {
        mViewDragHelper.processTouchEvent(event);
    }
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
    // to capture the bottom sheet in case it is not captured and the touch slop is passed.
    if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) {
        if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) {
            mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
        }
    }
    return !mIgnoreEvents;
}

From source file:com.cssweb.android.view.FTrendView.java

/**
 * true?,false??//from w w w.ja va 2s .com
 */
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        touchesBegan(event);
        break;

    case MotionEvent.ACTION_MOVE:
        touchesMoved(event);
        break;

    case MotionEvent.ACTION_UP:
        touchesEnded(event);
        break;

    case MotionEvent.ACTION_CANCEL:
        break;
    }
    return true;
}

From source file:agricultural.nxt.agriculturalsupervision.Activity.company.CompanyActivity.java

@Override
public void onTouch(MotionEvent motionEvent) {
    int action = motionEvent.getAction();
    switch (action) {
    case MotionEvent.ACTION_UP:
        sl.requestDisallowInterceptTouchEvent(false);
        break;/*from   ww w .j ava2s  . c om*/
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_MOVE:
        sl.requestDisallowInterceptTouchEvent(true);
        break;
    }
}