Java Code Examples for android.support.v4.widget.ViewDragHelper#EDGE_LEFT

The following examples show how to use android.support.v4.widget.ViewDragHelper#EDGE_LEFT . 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: SwipeRevealLayout.java    From SwipeRevealLayoutExample with MIT License 6 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    super.onEdgeDragStarted(edgeFlags, pointerId);

    if (mLockDrag) {
        return;
    }

    boolean edgeStartLeft = (mDragEdge == DRAG_EDGE_RIGHT)
            && edgeFlags == ViewDragHelper.EDGE_LEFT;

    boolean edgeStartRight = (mDragEdge == DRAG_EDGE_LEFT)
            && edgeFlags == ViewDragHelper.EDGE_RIGHT;

    if (edgeStartLeft || edgeStartRight) {
        mDragHelper.captureChildView(mMainView, pointerId);
    }
}
 
Example 2
Source File: SwipeLayout.java    From FragmentRigger with MIT License 6 votes vote down vote up
@Override
public void onViewReleased(@NonNull View releasedChild, float xvel, float yvel) {
    final int childWidth = releasedChild.getWidth();
    final int childHeight = releasedChild.getHeight();

    int left = 0, top = 0;
    if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_LEFT) != 0) {
        left = xvel > 0 || xvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? (childWidth) : 0;
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_RIGHT) != 0) {
        left = xvel < 0 || xvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? -(childWidth) : 0;
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_TOP) != 0) {
        top = yvel < 0 || yvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? (childHeight) : 0;
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_BOTTOM) != 0) {
        top = yvel < 0 || yvel == 0 && mScrollPercent > SCROLL_FINISH_THRESHOLD ? -(childHeight) : 0;
    }

    mDragHelper.settleCapturedViewAt(left, top);
    invalidate();
}
 
Example 3
Source File: SwipeRevealLayout.java    From SwipeRevealLayout with MIT License 6 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    super.onEdgeDragStarted(edgeFlags, pointerId);

    if (mLockDrag) {
        return;
    }

    boolean edgeStartLeft = (mDragEdge == DRAG_EDGE_RIGHT)
            && edgeFlags == ViewDragHelper.EDGE_LEFT;

    boolean edgeStartRight = (mDragEdge == DRAG_EDGE_LEFT)
            && edgeFlags == ViewDragHelper.EDGE_RIGHT;

    boolean edgeStartTop = (mDragEdge == DRAG_EDGE_BOTTOM)
            && edgeFlags == ViewDragHelper.EDGE_TOP;

    boolean edgeStartBottom = (mDragEdge == DRAG_EDGE_TOP)
            && edgeFlags == ViewDragHelper.EDGE_BOTTOM;

    if (edgeStartLeft || edgeStartRight || edgeStartTop || edgeStartBottom) {
        mDragHelper.captureChildView(mMainView, pointerId);
    }
}
 
Example 4
Source File: SwipeLayout.java    From FragmentRigger with MIT License 5 votes vote down vote up
@Override
public boolean tryCaptureView(@NonNull View child, int pointerId) {
    if (!mIsEnable || mEdgeFlag == EDGE_FLAG_NONE) {
        return false;
    }
    boolean dragEnable = mDragHelper.isEdgeTouched(mEdgeFlag, pointerId);
    if (dragEnable) {
        if (mDragHelper.isEdgeTouched(ViewDragHelper.EDGE_LEFT, pointerId)) {
            mCurrentSwipeOrientation = ViewDragHelper.EDGE_LEFT;
        } else if (mDragHelper.isEdgeTouched(ViewDragHelper.EDGE_RIGHT, pointerId)) {
            mCurrentSwipeOrientation = ViewDragHelper.EDGE_RIGHT;
        } else if (mDragHelper.isEdgeTouched(ViewDragHelper.EDGE_TOP, pointerId)) {
            mCurrentSwipeOrientation = ViewDragHelper.EDGE_TOP;
        } else if (mDragHelper.isEdgeTouched(ViewDragHelper.EDGE_BOTTOM, pointerId)) {
            mCurrentSwipeOrientation = ViewDragHelper.EDGE_BOTTOM;
        } else {
            mCurrentSwipeOrientation = -1;
        }
    }
    if (mOnSwipeChangedListener != null) {
        SwipeEdge swipeEdge = null;
        if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_LEFT) != 0) {
            swipeEdge = SwipeEdge.LEFT;
        } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_RIGHT) != 0) {
            swipeEdge = SwipeEdge.RIGHT;
        } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_TOP) != 0) {
            swipeEdge = SwipeEdge.TOP;
        } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_BOTTOM) != 0) {
            swipeEdge = SwipeEdge.BOTTOM;
        }
        if (swipeEdge != null) {
            mOnSwipeChangedListener.onEdgeTouched(SwipeLayout.this, swipeEdge, mPuppetHost);
        }
    }
    return dragEnable;
}
 
Example 5
Source File: SwipeLayout.java    From FragmentRigger with MIT License 5 votes vote down vote up
@Override
public int clampViewPositionHorizontal(@NonNull View child, int left, int dx) {
    int ret = 0;
    if (canSwipe(SwipeEdge.LEFT) && (mCurrentSwipeOrientation & ViewDragHelper.EDGE_LEFT) != 0) {
        ret = Math.min(child.getWidth(), Math.max(left, 0));
    } else if (canSwipe(SwipeEdge.RIGHT) && (mCurrentSwipeOrientation & ViewDragHelper.EDGE_RIGHT) != 0) {
        ret = Math.min(0, Math.max(left, -child.getWidth()));
    }
    return ret;
}
 
Example 6
Source File: SwipeLayout.java    From FragmentRigger with MIT License 5 votes vote down vote up
private void drawShadow(@NonNull Canvas canvas, @NonNull View child) {
    if (mShadowDrawables == null || mShadowDrawables.length == 0) {
        return;
    }
    final Rect childRect = mTmpRect;
    child.getHitRect(childRect);

    if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_LEFT) != 0) {
        drawShadowChild(canvas, mShadowDrawables[0], childRect.left - mShadowWidth,
                childRect.top, childRect.left, childRect.bottom);
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_RIGHT) != 0) {
        if (mShadowDrawables.length > 1) {
            drawShadowChild(canvas, mShadowDrawables[1], childRect.right,
                    childRect.top, childRect.right + mShadowWidth, childRect.bottom);
        }
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_TOP) != 0) {
        if (mShadowDrawables.length > 2) {
            drawShadowChild(canvas, mShadowDrawables[2], childRect.left,
                    childRect.top - mShadowWidth, childRect.right, childRect.top);
        }
    } else if ((mCurrentSwipeOrientation & ViewDragHelper.EDGE_BOTTOM) != 0) {
        if (mShadowDrawables.length > 3) {
            drawShadowChild(canvas, mShadowDrawables[3], childRect.left,
                    childRect.bottom, childRect.right, childRect.bottom + mShadowWidth);
        }
    }
}
 
Example 7
Source File: SwipeLayout.java    From FragmentRigger with MIT License 5 votes vote down vote up
private void computeScroll(@Nullable View view) {
    if (view == null) {
        return;
    }
    view.setX(0);
    view.setY(0);
    View capturedView = mDragHelper.getCapturedView();
    if (capturedView == null) {
        return;
    }
    int xOffset = 0;
    int yOffset = 0;
    switch (mCurrentSwipeOrientation) {
        case ViewDragHelper.EDGE_LEFT:
            xOffset = (capturedView.getLeft() - getWidth());
            break;
        case ViewDragHelper.EDGE_RIGHT:
            xOffset = (capturedView.getLeft() + getWidth());
            break;
        case ViewDragHelper.EDGE_TOP:
            yOffset = (capturedView.getTop() - getHeight());
            break;
        case ViewDragHelper.EDGE_BOTTOM:
            yOffset = (capturedView.getTop() + getHeight());
            break;
    }
    if (mParallaxOffset >= 0) {
        xOffset *= mScrimOpacity * mParallaxOffset;
        yOffset *= mScrimOpacity * mParallaxOffset;
    }
    view.setX(xOffset);
    view.setY(yOffset);
}
 
Example 8
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    final View toCapture;
    if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
        toCapture = findDrawerWithGravity(Gravity.LEFT);
    } else {
        toCapture = findDrawerWithGravity(Gravity.RIGHT);
    }

    if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
        mDragger.captureChildView(toCapture, pointerId);
    }
}
 
Example 9
Source File: MarginDrawerLayout.java    From something.apk with MIT License 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    final View toCapture;
    if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
        toCapture = findDrawerWithGravity(Gravity.LEFT);
    } else {
        toCapture = findDrawerWithGravity(Gravity.RIGHT);
    }

    if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
        mDragger.captureChildView(toCapture, pointerId);
    }
}
 
Example 10
Source File: KlyphDrawerLayout.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
    final View toCapture;
    if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
        toCapture = findDrawerWithGravity(Gravity.LEFT);
    } else {
        toCapture = findDrawerWithGravity(Gravity.RIGHT);
    }

    if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
        mDragger.captureChildView(toCapture, pointerId);
    }
}
 
Example 11
Source File: DebugDrawerLayout.java    From debugdrawer with Apache License 2.0 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
	final View toCapture;
	if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
		toCapture = findDrawerWithGravity(Gravity.LEFT);
	} else {
		toCapture = findDrawerWithGravity(Gravity.RIGHT);
	}

	if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
		mDragger.captureChildView(toCapture, pointerId);
	}
}
 
Example 12
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
@Override
public void onEdgeDragStarted(int edgeFlags, int pointerId) {
  final View toCapture;
  if ((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT) {
    toCapture = findDrawerWithGravity(Gravity.LEFT);
  } else {
    toCapture = findDrawerWithGravity(Gravity.RIGHT);
  }

  if (toCapture != null && getDrawerLockMode(toCapture) == LOCK_MODE_UNLOCKED) {
    mDragger.captureChildView(toCapture, pointerId);
  }
}
 
Example 13
Source File: DragViewGroup.java    From AndroidDigIn with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onEdgeLock(int edgeFlags) {
    Log.i(TAG, "onEdgeLock: " + edgeFlags);
    return (edgeFlags&ViewDragHelper.EDGE_LEFT)==ViewDragHelper.EDGE_LEFT;
}
 
Example 14
Source File: SwipeLayout.java    From FragmentRigger with MIT License 4 votes vote down vote up
public void setSwipeEdgeSide(SwipeEdge[] swipeEdgeSide) {
    if (swipeEdgeSide == null || swipeEdgeSide.length == 0) {
        mSwipeEdgeSide = new ArrayList<>();
        setEnableSwipe(false);
        return;
    }
    mSwipeEdgeSide = Arrays.asList(swipeEdgeSide);
    for (SwipeEdge edge : mSwipeEdgeSide) {
        if (edge == SwipeEdge.NONE) {
            if (swipeEdgeSide.length > 1) {
                throw new IllegalArgumentException("The Swiper#edgeSide can not contain other value as" +
                        " the SwipeEdge.NONE is contained.");
            }
            setEnableSwipe(false);
            return;
        } else if (edge == SwipeEdge.ALL) {
            if (swipeEdgeSide.length > 1) {
                throw new IllegalArgumentException("The Swiper#edgeSide can not contain other value as" +
                        " the SwipeEdge.ALL is contained.");
            }
        }
    }
    setEnableSwipe(true);

    if (canSwipe(SwipeEdge.NONE)) {
        mEdgeFlag = EDGE_FLAG_NONE;
        return;
    }
    if (canSwipe(SwipeEdge.ALL)) {
        mEdgeFlag = ViewDragHelper.EDGE_ALL;
        return;
    }
    mEdgeFlag = EDGE_FLAG_NONE;
    if (canSwipe(SwipeEdge.LEFT)) {
        if (mEdgeFlag > 0) {
            mEdgeFlag |= ViewDragHelper.EDGE_LEFT;
        } else {
            mEdgeFlag = ViewDragHelper.EDGE_LEFT;
        }
    }
    if (canSwipe(SwipeEdge.RIGHT)) {
        if (mEdgeFlag > 0) {
            mEdgeFlag |= ViewDragHelper.EDGE_RIGHT;
        } else {
            mEdgeFlag = ViewDragHelper.EDGE_RIGHT;
        }
    }
    if (canSwipe(SwipeEdge.TOP)) {
        if (mEdgeFlag > 0) {
            mEdgeFlag |= ViewDragHelper.EDGE_TOP;
        } else {
            mEdgeFlag = ViewDragHelper.EDGE_TOP;
        }
    }
    if (canSwipe(SwipeEdge.BOTTOM)) {
        if (mEdgeFlag > 0) {
            mEdgeFlag |= ViewDragHelper.EDGE_BOTTOM;
        } else {
            mEdgeFlag = ViewDragHelper.EDGE_BOTTOM;
        }
    }
}
 
Example 15
Source File: BehaviorDelegate.java    From DrawerBehavior with Apache License 2.0 4 votes vote down vote up
@Override public void onEdgeDragStarted(int edgeFlags, int pointerId) {
  if (((edgeFlags & ViewDragHelper.EDGE_LEFT) == ViewDragHelper.EDGE_LEFT && isLeft)
      || ((edgeFlags & ViewDragHelper.EDGE_RIGHT) == ViewDragHelper.EDGE_RIGHT && !isLeft)) {
    dragger.captureChildView(child, pointerId);
  }
}