/** * 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; }
/** * Scroll the deck list so that it is centered on the current deck. * * @param did The deck ID of the deck to select. */ private void scrollDecklistToDeck(long did) { int position = mDeckListAdapter.findDeckPosition(did); mRecyclerViewLayoutManager.scrollToPositionWithOffset(position, (mRecyclerView.getHeight() / 2)); }
private int checkVerticalSwipe(ViewHolder viewHolder, int flags) { if ((flags & (UP | DOWN)) != 0) { final int dirFlag = mDy > 0 ? DOWN : UP; 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 = yVelocity > 0f ? DOWN : UP; final float absYVelocity = Math.abs(yVelocity); if ((velDirFlag & flags) != 0 && velDirFlag == dirFlag && absYVelocity >= mCallback.getSwipeEscapeVelocity(mSwipeEscapeVelocity) && absYVelocity > Math.abs(xVelocity)) { return velDirFlag; } } final float threshold = mRecyclerView.getHeight() * mCallback .getSwipeThreshold(viewHolder); if ((flags & dirFlag) != 0 && Math.abs(mDy) > threshold) { return dirFlag; } } return 0; }
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.getHeight() + parent.getPaddingTop(), parent.getPaddingLeft()); } else { c.translate(-parent.getHeight(), 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)); } }
@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); } } }
int groupItemBottom = vh.itemView.getBottom(); int parentHeight = mRecyclerView.getHeight();
} else { //horizontal top = parent.getPaddingTop(); bottom = parent.getHeight() - parent.getPaddingBottom();
} else if (mDy > 0) { final int bottomDiff = curY + mSelected.itemView.getHeight() + mTmpRect.bottom - (mRecyclerView.getHeight() - mRecyclerView.getPaddingBottom()); if (bottomDiff > 0) { scrollY = bottomDiff; scrollY = mCallback.interpolateOutOfBoundsScroll(mRecyclerView, mSelected.itemView.getHeight(), scrollY, mRecyclerView.getHeight(), scrollDuration);
private static RecyclerView.ViewHolder findSwapTargetItemForGridLayoutManagerInternal2(FindSwapTargetContext fc) { final int height = fc.rv.getHeight(); final int width = fc.rv.getWidth(); final int paddingLeft = (fc.vertical) ? fc.rv.getPaddingLeft() : 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); } }
@Override public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { for (int i = 0; i < parent.getChildCount(); i++) { View child = parent.getChildAt(i); if (!isHeader(child, parent)) continue; RecyclerView.LayoutManager lm = parent.getLayoutManager(); float top = lm.getDecoratedTop(child) + child.getTranslationY(); float bottom = lm.getDecoratedBottom(child) + child.getTranslationY(); if (i == parent.getChildCount() - 1) { // Draw to bottom if last item bottom = Math.max(parent.getHeight(), bottom); } float right = lm.getDecoratedRight(child) + child.getTranslationX(); float left = lm.getDecoratedLeft(child) + child.getTranslationX(); c.drawRect(left, top, right, bottom, paint); } } }
case DOWN: targetTranslateX = 0; targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight(); break; default:
private void handleScrollOnDraggingInternalWithRecyclerView(RecyclerView rv, boolean horizontal) { final int edge = (horizontal) ? rv.getWidth() : rv.getHeight();
if (maxBottom >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) { recyclerView.scrollToPosition(toPos);
@Override public void onLayoutFinished(View child, RecyclerView parent) { // Figure out % progress from top to bottom. float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight(); float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; // Normalizes for center. mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); // Adjusts to the maximum scale. mProgressToCenter = Math.min(mProgressToCenter, MAX_CHILD_SCALE); child.setScaleX(1 - mProgressToCenter); child.setScaleY(1 - mProgressToCenter); } }
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()); }
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); }); }
int getAvailableScrollHeight() { int visibleHeight = materialScrollBar.recyclerView.getHeight(); int scrollHeight; if(customScroller != null) { scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + customScroller.getTotalDepth() + materialScrollBar.recyclerView.getPaddingBottom(); } else { scrollHeight = materialScrollBar.recyclerView.getPaddingTop() + getRowCount() * scrollPosState.rowHeight + materialScrollBar.recyclerView.getPaddingBottom(); } return scrollHeight - visibleHeight; }