Java Code Examples for androidx.customview.widget.ViewDragHelper#STATE_IDLE

The following examples show how to use androidx.customview.widget.ViewDragHelper#STATE_IDLE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SwipeBackLayout.java    From AndroidNavigation with MIT License 6 votes vote down vote up
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final boolean drawContent = child == mCapturedView;
    int index = indexOfChild(child);
    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && index == getChildCount() - 2) {
        View lastChild = getChildAt(getChildCount() - 1);
        canvas.save();
        canvas.clipRect(0, 0, lastChild.getLeft(), getHeight());
    }

    boolean ret = super.drawChild(canvas, child, drawingTime);

    if (mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE && index == getChildCount() - 2) {
        canvas.restore();
    }

    if (mTabBar != null && drawContent) {
        drawTabBar(canvas, child);
    }

    if (mScrimOpacity > 0 && drawContent
            && mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE) {
        drawScrim(canvas, child);
    }
    return ret;
}
 
Example 2
Source File: PullDismissLayout.java    From StoryView with MIT License 5 votes vote down vote up
public boolean onInterceptTouchEvent(MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);

    boolean pullingDown = false;

    switch (action) {
        case MotionEvent.ACTION_DOWN:
            verticalTouchSlop = event.getY();
        case MotionEvent.ACTION_MOVE:
            final float dy = event.getY() - verticalTouchSlop;
            if (dy > dragHelper.getTouchSlop()) {
                pullingDown = true;
                mTouchCallbacks.touchPull();
            }else{
                mTouchCallbacks.touchDown(event.getX(), event.getY());
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            verticalTouchSlop = 0.0f;
            mTouchCallbacks.touchUp();
            break;
    }

    if (!dragHelper.shouldInterceptTouchEvent(event) && pullingDown) {
        if (dragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE &&
                dragHelper.checkTouchSlop(ViewDragHelper.DIRECTION_VERTICAL)) {

            View child = getChildAt(0);
            if (child != null && !listener.onShouldInterceptTouchEvent()) {
                dragHelper.captureChildView(child, event.getPointerId(0));
                return dragHelper.getViewDragState() == ViewDragHelper.STATE_DRAGGING;
            }
        }
    }
    return false;
}
 
Example 3
Source File: PullDismissLayout.java    From StoryView with MIT License 5 votes vote down vote up
public void onViewDragStateChanged(int state) {
    if (capturedView != null && dismissed && state == ViewDragHelper.STATE_IDLE) {
        pullDismissLayout.removeView(capturedView);
        if (pullDismissLayout.listener != null) {
            pullDismissLayout.listener.onDismissed();
        }
    }
}
 
Example 4
Source File: SwipeBackLayout.java    From AndroidNavigation with MIT License 5 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!mListener.shouldSwipeBack()) {
        return super.onTouchEvent(event);
    }
    mDragHelper.processTouchEvent(event);
    return mDragHelper.getViewDragState() != ViewDragHelper.STATE_IDLE;
}
 
Example 5
Source File: SwipeBackLayout.java    From AndroidNavigation with MIT License 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    if (state == ViewDragHelper.STATE_IDLE) {
        mCapturedView = null;
        mLeft = 0;
        int count = getChildCount();
        if (count > 1) {
            View underlying = getChildAt(count - 2);
            underlying.setX(0);
        }
    }
    mListener.onViewDragStateChanged(state, mScrollPercent);
}
 
Example 6
Source File: SwipeBackLayout.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
    super.onViewDragStateChanged(state);
    if (state == ViewDragHelper.STATE_IDLE) {
        if (mSwipeBackListener != null) {
            if (swipeBackFraction == 0) {
                mSwipeBackListener.onViewSwipeFinished(mDragContentView, false);
            } else if (swipeBackFraction == 1) {
                mSwipeBackListener.onViewSwipeFinished(mDragContentView, true);
            }
        }
    }
}
 
Example 7
Source File: NowPlayingView.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called when a layout is requested from the graphics system.
 *
 * @param changed If the layout is changed (size, ...)
 * @param l       Left position
 * @param t       Top position
 * @param r       Right position
 * @param b       Bottom position
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    // Calculate the maximal range that the view is allowed to be dragged
    mDragRange = (getMeasuredHeight() - mHeaderView.getMeasuredHeight());

    // New temporary top position, to fix the view at top or bottom later if state is idle.
    int newTop = mTopPosition;

    // fix height at top or bottom if state idle
    if (mDragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
        newTop = (int) (mDragRange * mDragOffset);
    }

    // Request the upper part of the NowPlayingView (header)
    mHeaderView.layout(
            0,
            newTop,
            r,
            newTop + mHeaderView.getMeasuredHeight());

    // Request the lower part of the NowPlayingView (main part)
    mMainView.layout(
            0,
            newTop + mHeaderView.getMeasuredHeight(),
            r,
            newTop + b);
}
 
Example 8
Source File: QuickAttachmentDrawer.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewDragStateChanged(int state) {
  if (dragHelper.getViewDragState() == ViewDragHelper.STATE_IDLE) {
    setDrawerState(drawerState);
    slideOffset = getTargetSlideOffset();
    requestLayout();
  }
}
 
Example 9
Source File: SwipeLayout.java    From SwipeLayout with MIT License 4 votes vote down vote up
private boolean isIdleAfterMoving(int state) {
    return (currentDraggingState == ViewDragHelper.STATE_DRAGGING
            || currentDraggingState == ViewDragHelper.STATE_SETTLING)
            && state == ViewDragHelper.STATE_IDLE;
}
 
Example 10
Source File: SwipeLayout.java    From SwipeLayout with MIT License 4 votes vote down vote up
private boolean isDragIdle(int state) {
    return state == ViewDragHelper.STATE_IDLE;
}
 
Example 11
Source File: NowPlayingView.java    From odyssey with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Called when the drag state changed. Informs observers that it is either dragged up or down.
 * Also sets the visibility of button groups in the header
 *
 * @param state New drag state
 */
@Override
public void onViewDragStateChanged(int state) {
    super.onViewDragStateChanged(state);

    // Check if the new state is the idle state. If then notify the observer (if one is registered)
    if (state == ViewDragHelper.STATE_IDLE) {
        // Enable scrolling of the text views
        mTrackTitle.setSelected(true);
        mTrackSubtitle.setSelected(true);

        if (mDragOffset == 0.0f) {
            // Called when dragged up
            mDraggedDownButtons.setVisibility(INVISIBLE);
            mDraggedUpButtons.setVisibility(VISIBLE);
            mCoverImage.setVisibility(VISIBLE);
            if (mDragStatusReceiver != null) {
                mDragStatusReceiver.onStatusChanged(NowPlayingDragStatusReceiver.DRAG_STATUS.DRAGGED_UP);
            }
        } else {
            // Called when dragged down
            mDraggedDownButtons.setVisibility(VISIBLE);
            mDraggedUpButtons.setVisibility(INVISIBLE);
            mCoverImage.setVisibility(INVISIBLE);
            if (mDragStatusReceiver != null) {
                mDragStatusReceiver.onStatusChanged(NowPlayingDragStatusReceiver.DRAG_STATUS.DRAGGED_DOWN);
            }

            // stop refresh task
            stopRefreshTask();
        }
    } else {
        /*
         * Show both layouts to enable a smooth transition via
         * alpha values of the layouts.
         */
        mDraggedDownButtons.setVisibility(VISIBLE);
        mDraggedUpButtons.setVisibility(VISIBLE);
        mCoverImage.setVisibility(VISIBLE);
    }
}