Example usage for android.view ViewParent requestDisallowInterceptTouchEvent

List of usage examples for android.view ViewParent requestDisallowInterceptTouchEvent

Introduction

In this page you can find the example usage for android.view ViewParent requestDisallowInterceptTouchEvent.

Prototype

public void requestDisallowInterceptTouchEvent(boolean disallowIntercept);

Source Link

Document

Called when a child does not want this parent and its ancestors to intercept touch events with ViewGroup#onInterceptTouchEvent(MotionEvent) .

Usage

From source file:com.example.pdftranslator.ScreenSlidePageFragment.java

@Override
public boolean onTouch(View v, MotionEvent event) {

    ViewParent parent = ((TextView) v).getParent();
    parent.requestDisallowInterceptTouchEvent(true);

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        determineWordSelected(v, event);
        break;//  w w  w.j  a v a  2s.c  o m

    default:
        break;
    }

    return true;
}

From source file:com.anl.wxb.jieqi.view.VerticalSeekBar.java

/**
 * Tries to claim the user's drag motion, and requests disallowing any
 * ancestors from stealing events in the drag.
 * *///from   w  w  w. j a v  a  2  s  .c o m
private void attemptClaimDrag(boolean active) {
    final ViewParent parent = getParent();
    if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(active);
    }
}

From source file:com.uzmap.pkg.uzmodules.uzBMap.methods.MapOpen.java

private void requestParentDisallowInterceptTouchEvent(boolean disallowIntercept) {
    final ViewParent parent = mMapView.getParent();
    if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(disallowIntercept);
    }/*from  ww  w . j  a  v a2  s.co  m*/
}

From source file:com.tr4android.recyclerviewslideitem.SwipeItem.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mDragHelper.processTouchEvent(ev);/*  w  w  w  . j  av  a 2s .  co m*/
    // handle parent scroll behaviour
    if (Math.abs(mSwipeItem.getLeft()) > mTouchSlop) {
        // disable parent scrolling
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(true);
    } else if (MotionEventCompat.getActionMasked(ev) == MotionEvent.ACTION_UP
            || MotionEventCompat.getActionMasked(ev) == MotionEvent.ACTION_CANCEL) {
        // enable parent scrolling
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(false);
    }
    return true;
}

From source file:com.conduit.plastic.widget.NestedWebView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (this.position == ScrollStateChangedListener.ScrollState.MIDDLE) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            this.mIsBeingDragged = false;
            this.mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            this.startNestedScroll(2);
            break;
        }//from   w  ww. j  a va2  s  .  co m
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            this.endTouch();
            break;
        }
        }
        super.onTouchEvent(ev);
        return true;
    }
    final int actionMasked = MotionEventCompat.getActionMasked(ev);
    initVelocityTrackerIfNotExists();
    MotionEvent vtev = MotionEvent.obtain(ev);
    final int index = MotionEventCompat.getActionIndex(ev);
    if (actionMasked == MotionEvent.ACTION_DOWN) {
        mNestedYOffset = 0;
    }
    vtev.offsetLocation(0, mNestedYOffset);
    this.consumedY = 0;
    this.direction = 0;
    boolean onTouchEvent = false;
    switch (actionMasked) {
    case MotionEvent.ACTION_DOWN: {
        // Remember where the motion event started
        onTouchEvent = super.onTouchEvent(ev);
        mLastMotionY = (int) (ev.getY() + 0.5f);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        this.preY = vtev.getY();
        this.mIsBeingDragged = false;
        startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        onTouchEvent = super.onTouchEvent(ev);
        mLastMotionY = (int) (MotionEventCompat.getY(ev, index) + 0.5f);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEvent.ACTION_MOVE:
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (activePointerIndex == -1) {
            Log.e(TAG, "Invalid pointerId=" + mActivePointerId + " in onTouchEvent");
            break;
        }
        if (!mIsBeingDragged && Math.abs(vtev.getY() - this.preY) > mTouchSlop) {
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
            mIsBeingDragged = true;
        }
        //                if(!mIsBeingDragged){
        //                    setLongClickEnable(true);
        //                }
        final int y = (int) (MotionEventCompat.getY(ev, activePointerIndex) + 0.5f);
        Log.i(TAG, "mLastMotionY=====" + mLastMotionY);
        Log.i(TAG, "YYYYYYY=====" + y);
        int deltaY = mLastMotionY - y;

        if (deltaY != 0) {
            this.direction = this.directionDetector.getDirection(deltaY, true, this.scrollStateChangedListener);
        }
        if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
            deltaY -= mScrollConsumed[1];
            vtev.offsetLocation(0, mScrollOffset[1]);
            mNestedYOffset += mScrollOffset[1];
        }
        if (mIsBeingDragged) {
            //                    setJavaScriptEnable(true);
            // Scroll to follow the motion event
            mLastMotionY = y - mScrollOffset[1];
            Log.i(TAG, "deltaY===" + deltaY);
            Log.i(TAG, "this.consumedY===" + this.consumedY);
            final int unconsumedY = deltaY - this.consumedY;

            Log.i(TAG, " child consumed = " + this.mScrollConsumed[1] + " un_consumed = " + unconsumedY
                    + " position = " + this.position + " direction = " + this.direction);
            onTouchEvent = super.onTouchEvent(ev);
            if (this.position == ScrollStateChangedListener.ScrollState.MIDDLE) {
                return true;
            }
            switch (this.direction) {
            case 1: {
                if ((this.position != ScrollStateChangedListener.ScrollState.BOTTOM)
                        && (this.contentHeight != this.webviewHeight)) {
                    scrollBy(0, unconsumedY);
                    break;
                }
                Log.i(TAG, "1111111consumedY===" + consumedY + "  unconsumedY==" + unconsumedY);
                if (dispatchNestedScroll(0, this.consumedY, 0, unconsumedY, this.mScrollOffset)) {
                    vtev.offsetLocation(0.0F, this.mScrollOffset[1]);
                    this.mNestedYOffset += this.mScrollOffset[1];
                    this.mLastMotionY -= this.mScrollOffset[1];
                }
            }
                break;
            case 2:
                if ((this.position == ScrollStateChangedListener.ScrollState.TOP)
                        || (this.contentHeight == this.webviewHeight)) {
                    Log.i(TAG, "2222222consumedY===" + consumedY + "  unconsumedY==" + unconsumedY);
                    if (dispatchNestedScroll(0, this.consumedY, 0, unconsumedY, this.mScrollOffset)) {
                        vtev.offsetLocation(0.0F, this.mScrollOffset[1]);
                        this.mNestedYOffset += this.mScrollOffset[1];
                        this.mLastMotionY -= this.mScrollOffset[1];
                    }
                } else {
                    scrollBy(0, unconsumedY);
                }
                break;
            default:
                break;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        onTouchEvent = super.onTouchEvent(ev);
        break;
    case MotionEvent.ACTION_UP:
        onTouchEvent = super.onTouchEvent(ev);
        if (mIsBeingDragged) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId);
            if ((Math.abs(initialVelocity) > mMinimumVelocity)) {
                flingWithNestedDispatch(-initialVelocity);
            }
        }
        mActivePointerId = INVALID_POINTER;
        endTouch();
        break;

    case MotionEventCompat.ACTION_POINTER_UP:
        onTouchEvent = super.onTouchEvent(ev);
        onSecondaryPointerUp(ev);
        mLastMotionY = (int) (MotionEventCompat.getY(ev,
                MotionEventCompat.findPointerIndex(ev, mActivePointerId)) + 0.5F);
        break;
    }
    if (mVelocityTracker != null) {
        mVelocityTracker.addMovement(vtev);
    }
    vtev.recycle();
    return onTouchEvent;
}

From source file:com.edgar.banner.BannerPagerView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mLastMotionX = ev.getX();//w  w w  . ja v  a  2s  . c  o  m
        mLastMotionY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        downPauseAutoPlay();
        break;
    case MotionEvent.ACTION_MOVE:
        if (isBannerLessThanOne())
            break;
        //?ViewPager.
        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 dx = x - mLastMotionX;
        final float xDiff = Math.abs(dx);
        final float y = MotionEventCompat.getY(ev, pointerIndex);
        final float yDiff = Math.abs(y - mLastMotionY);
        if (BuildConfig.DEBUG)
            Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
        if (xDiff > mTouchSlop && xDiff * 0.5f > yDiff) {
            ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }
        break;
    default:
        break;
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java

@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            ViewParent parent = v.getParent();
            // First, disable the Parent from intercepting the touch
            // event
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }//from ww w.ja v a2s  .co m

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (rect != null) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY(),
                            null));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (mScaleDragDetector != null) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (mGestureDetector != null && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

private void attemptClaimDrag() {
    ViewParent parent = getParent();
    if (parent != null) {
        parent.requestDisallowInterceptTouchEvent(true);
    }/* ww w . j a  v  a2  s  .  co m*/
}

From source file:com.huyn.demogroup.leaveblank.PhotoViewAttacher.java

@Override
public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && Util.hasDrawable((ImageView) v)) {
        switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            ViewParent parent = v.getParent();
            // First, disable the Parent from intercepting the touch
            // event
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }// w ww  . ja v a  2  s  .c  om

            // If we're flinging, and the user presses down, cancel
            // fling
            cancelFling();
            break;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            // If the user has zoomed less than min scale, zoom back
            // to min scale
            if (getScale() < mMinScale) {
                RectF rect = getDisplayRect();
                if (rect != null) {
                    v.post(new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY(),
                            null));
                    handled = true;
                }
            }
            break;
        }

        // Try the Scale/Drag detector
        if (mScaleDragDetector != null) {
            boolean wasScaling = mScaleDragDetector.isScaling();
            boolean wasDragging = mScaleDragDetector.isDragging();

            handled = mScaleDragDetector.onTouchEvent(ev);

            boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
            boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

            mBlockParentIntercept = didntScale && didntDrag;
        }

        // Check to see if the user double tapped
        if (mGestureDetector != null && mGestureDetector.onTouchEvent(ev)) {
            handled = true;
        }

    }

    return handled;
}

From source file:com.huyn.demogroup.freechild.FixedViewAttacher.java

@Override
public void onDrag(float dx, float dy) {
    if (mScaleDragDetector.isScaling()) {
        return; // Do not drag if we are already scaling
    }//from ww w  .j a  v  a2 s .  c  o  m

    System.out.println("++++ondrag:" + dx + "/" + dy);
    postTranslate(dx, dy);
    checkAndDisplayMatrix();

    /*
     * Here we decide whether to let the ImageView's parent to start taking
     * over the touch event.
     *
     * First we check whether this function is enabled. We never want the
     * parent to take over if we're scaling. We then check the edge we're
     * on, and the direction of the scroll (i.e. if we're pulling against
     * the edge, aka 'overscrolling', let the parent take over).
     */
    ViewParent parent = mImageView.getParent();
    if (mAllowParentInterceptOnEdge && !mScaleDragDetector.isScaling() && !mBlockParentIntercept) {
        if (mScrollEdge == EDGE_BOTH || (mScrollEdge == EDGE_LEFT && dx >= 1f)
                || (mScrollEdge == EDGE_RIGHT && dx <= -1f)) {
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(false);
            }
        }
    } else {
        if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
        }
    }
}