/** * Update the visibility item according the current layout. * * @param view the current {@link com.airbnb.epoxy.EpoxyViewHolder}'s itemView * @param parent the {@link androidx.recyclerview.widget.RecyclerView} * @return true if the view has been measured */ boolean update(@NonNull View view, @NonNull RecyclerView parent, boolean detachEvent) { // Clear the rect before calling getLocalVisibleRect localVisibleRect.setEmpty(); boolean viewDrawn = view.getLocalVisibleRect(localVisibleRect) && !detachEvent; height = view.getHeight(); width = view.getWidth(); viewportHeight = parent.getHeight(); viewportWidth = parent.getWidth(); visibleHeight = viewDrawn ? localVisibleRect.height() : 0; visibleWidth = viewDrawn ? localVisibleRect.width() : 0; return height > 0 && width > 0; }
private int checkHorizontalSwipe(ViewHolder viewHolder, int flags) { if ((flags & (LEFT | RIGHT)) != 0) { final int dirFlag = mDx > 0 ? RIGHT : LEFT; if (mVelocityTracker != null && mActivePointerId > -1) { mVelocityTracker.computeCurrentVelocity(PIXELS_PER_SECOND, mCallback.getSwipeVelocityThreshold(mMaxSwipeVelocity)); final float xVelocity = mVelocityTracker.getXVelocity(mActivePointerId); final float yVelocity = mVelocityTracker.getYVelocity(mActivePointerId); final int velDirFlag = xVelocity > 0f ? RIGHT : LEFT; final float absXVelocity = Math.abs(xVelocity); if ((velDirFlag & flags) != 0 && dirFlag == velDirFlag && absXVelocity >= mCallback.getSwipeEscapeVelocity(mSwipeEscapeVelocity) && absXVelocity > Math.abs(yVelocity)) { return velDirFlag; } } final float threshold = mRecyclerView.getWidth() * mCallback .getSwipeThreshold(viewHolder); if ((flags & dirFlag) != 0 && Math.abs(mDx) > threshold) { return dirFlag; } } return 0; }
public void setup( RecyclerView rv, RecyclerView.ViewHolder vh, DraggingItemInfo info, int lastTouchX, int lastTouchY, ItemDraggableRange wrappedAdapterPange, ItemDraggableRange rootAdapterRange, boolean checkCanSwap) { this.rv = rv; this.draggingItemInfo = info; this.draggingItem = vh; this.lastTouchX = lastTouchX; this.lastTouchY = lastTouchY; this.wrappedAdapterRange = wrappedAdapterPange; this.rootAdapterRange = rootAdapterRange; this.checkCanSwap = checkCanSwap; this.layoutType = CustomRecyclerViewUtils.getLayoutType(rv); this.vertical = CustomRecyclerViewUtils.extractOrientation(this.layoutType) == CustomRecyclerViewUtils.ORIENTATION_VERTICAL; this.overlayItemLeft = this.overlayItemLeftNotClipped = lastTouchX - info.grabbedPositionX; this.overlayItemTop = this.overlayItemTopNotClipped = lastTouchY - info.grabbedPositionY; if (this.vertical) { this.overlayItemLeft = Math.max(this.overlayItemLeft, rv.getPaddingLeft()); this.overlayItemLeft = Math.min(this.overlayItemLeft, Math.max(0, rv.getWidth() - rv.getPaddingRight() - draggingItemInfo.width)); } else { this.overlayItemTop = Math.max(this.overlayItemTop, rv.getPaddingTop()); this.overlayItemTop = Math.min(this.overlayItemTop, Math.max(0, rv.getHeight() - rv.getPaddingBottom() - draggingItemInfo.height)); } }
c.rotate(180); if (clipToPadding) { c.translate(-parent.getWidth() + parent.getPaddingRight(), -parent.getHeight() + parent.getPaddingBottom()); } else { c.translate(-parent.getWidth(), -parent.getHeight()); c.rotate(90); if (clipToPadding) { c.translate(parent.getPaddingTop(), -parent.getWidth() + parent.getPaddingRight()); } else { c.translate(0, -parent.getWidth());
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { int childCount = parent.getChildCount(); RecyclerView.LayoutManager lm = parent.getLayoutManager(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); int right = (int) (lm.getDecoratedRight(child) + child.getTranslationX()); if (i == childCount - 1) { // Last item right = Math.max(right, parent.getWidth()); } // Right border c.drawRect(child.getRight() + child.getTranslationX(), 0, right, parent.getHeight(), grayBackgroundPaint); } } }
right = parent.getWidth() - parent.getPaddingRight(); } else { //horizontal top = parent.getPaddingTop();
final int rightDiff = curX + mSelected.itemView.getWidth() + mTmpRect.right - (mRecyclerView.getWidth() - mRecyclerView.getPaddingRight()); if (rightDiff > 0) { scrollX = rightDiff; scrollX = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getWidth(), scrollX, mRecyclerView.getWidth(), scrollDuration);
final int width = fc.rv.getWidth(); final int paddingLeft = (fc.vertical) ? fc.rv.getPaddingLeft() : 0; final int paddingTop = (!fc.vertical) ? fc.rv.getPaddingTop() : 0;
@Override void scrollToPosition(RecyclerView list, int pos) { if (list.getLayoutManager() instanceof LinearLayoutManager) { // Centering item in its parent final LinearLayoutManager manager = (LinearLayoutManager) list.getLayoutManager(); final boolean isHorizontal = manager.getOrientation() == LinearLayoutManager.HORIZONTAL; int offset = isHorizontal ? (list.getWidth() - list.getPaddingLeft() - list.getPaddingRight()) / 2 : (list.getHeight() - list.getPaddingTop() - list.getPaddingBottom()) / 2; final RecyclerView.ViewHolder holder = list.findViewHolderForAdapterPosition(pos); if (holder != null) { final View view = holder.itemView; offset -= isHorizontal ? view.getWidth() / 2 : view.getHeight() / 2; } manager.scrollToPositionWithOffset(pos, offset); } else { list.scrollToPosition(pos); } }
right = Math.max(right, parent.getWidth());
case END: targetTranslateY = 0; targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth(); break; case UP:
private void handleScrollOnDraggingInternalWithRecyclerView(RecyclerView rv, boolean horizontal) { final int edge = (horizontal) ? rv.getWidth() : rv.getHeight();
if (maxRight >= recyclerView.getWidth() - recyclerView.getPaddingRight()) { recyclerView.scrollToPosition(toPos);
private void measureView(@NonNull RecyclerView parent, @NonNull View header) { int widthSpec = View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY); int heightSpec = View.MeasureSpec.makeMeasureSpec(parent.getHeight(), View.MeasureSpec.UNSPECIFIED); int childWidth = ViewGroup.getChildMeasureSpec(widthSpec, parent.getPaddingLeft() + parent.getPaddingRight(), header.getLayoutParams().width); int childHeight = ViewGroup.getChildMeasureSpec(heightSpec, parent.getPaddingTop() + parent.getPaddingBottom(), header.getLayoutParams().height); header.measure(childWidth, childHeight); header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); }
@Override public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { int left = parent.getPaddingLeft(); int right = parent.getWidth() - parent.getPaddingRight(); int childCount = parent.getChildCount(); for (int i = 0; i < childCount; i++) { View child = parent.getChildAt(i); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); int top = child.getBottom() + params.bottomMargin; int bottom = top + divider.getIntrinsicHeight(); divider.setBounds(left, top, right, bottom); divider.draw(c); } } }
@Override public void onDrawOver(final Canvas canvas, final RecyclerView parent, final RecyclerView.State state) { paint.setColor(dividerColor); int parentWidth = parent.getWidth(); for (int i = 0; i < parent.getChildCount(); i++) { View view = parent.getChildAt(i); if (shouldDrawDividerAbove(view, parent)) { float top = view.getY(); canvas.drawRect(0, top, parentWidth, top + dividerHeight, paint); } } }
private void retrieveItemPosition(final RecyclerView.ViewHolder holder) { mDeltaX = mRecyclerView.getWidth() - mRecyclerView.getLayoutManager().getDecoratedLeft(holder.itemView); }
private void retrieveItemPosition(final RecyclerView.ViewHolder holder) { mDeltaX = mRecyclerView.getWidth() - mRecyclerView.getLayoutManager().getDecoratedLeft(holder.itemView); }
public HandleMoveListener(boolean rightHandle) { mRightHandle = rightHandle; mScroller = new RecyclerViewScrollerRunnable(mRecyclerView, (int scrollDir) -> { mRecyclerView.getLocationOnScreen(mTmpLocation); if (scrollDir < 0) onMoved(mTmpLocation[0], mTmpLocation[1] - 1); else if (scrollDir > 0) onMoved(mTmpLocation[0] + mRecyclerView.getWidth(), mTmpLocation[1] + mRecyclerView.getHeight() + 1); }); }