Java Code Examples for android.support.v7.widget.RecyclerView#State

The following examples show how to use android.support.v7.widget.RecyclerView#State . 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: HomeGridItemAnimator.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public ItemHolderInfo recordPreLayoutInformation(RecyclerView.State state,
                                                 RecyclerView.ViewHolder viewHolder,
                                                 int changeFlags,
                                                 List<Object> payloads) {
    ItemHolderInfo info =
            super.recordPreLayoutInformation(state, viewHolder, changeFlags, payloads);
    if (info instanceof HomeGridItemHolderInfo) {
        HomeGridItemHolderInfo dnInfo = (HomeGridItemHolderInfo) info;
        dnInfo.animateAddToPocket = payloads.contains(ADD_TO_POCKET);
        dnInfo.returnFromComments = payloads.contains(STORY_COMMENTS_RETURN);
        return dnInfo;
    }
    return info;
}
 
Example 2
Source File: LadderLayoutManager.java    From LadderLayoutManager with Apache License 2.0 6 votes vote down vote up
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (state.getItemCount() == 0) {
        removeAndRecycleAllViews(recycler);
        return;
    }
    if (!mCheckedChildSize) {
        if (mOrientation == VERTICAL) {
            mChildSize[0] = getHorizontalSpace();
            mChildSize[1] = (int) (mItemHeightWidthRatio * mChildSize[0]);
        } else {
            mChildSize[1] = getVerticalSpace();
            mChildSize[0] = (int) (mChildSize[1] / mItemHeightWidthRatio);
        }
        mChildPeekSize = mChildPeekSizeInput == 0 ?
                (int) (mChildSize[mOrientation] * DEFAULT_CHILD_LAYOUT_OFFSET) : mChildPeekSizeInput;
        mCheckedChildSize = true;
    }
    int itemCount = getItemCount();
    if (mReverse) {
        mScrollOffset += (itemCount - mChildCount) * mChildSize[mOrientation];
    }
    mChildCount = itemCount;
    mScrollOffset = makeScrollOffsetWithinRange(mScrollOffset);
    fill(recycler);
}
 
Example 3
Source File: StickyHeaderDecoration.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);

    int headerHeight = 0;
    if (position != RecyclerView.NO_POSITION && hasHeader(position)) {
        View header = getHeader(parent, position).itemView;
        headerHeight = getHeaderHeightForLayout(header);
    }

    outRect.set(0, headerHeight, 0, 0);
}
 
Example 4
Source File: GalleryLayoutManager.java    From GalleryLayoutManager with Apache License 2.0 5 votes vote down vote up
/**
 * Layout the item view witch position special by {@link GalleryLayoutManager#mInitialSelectedPosition} first and then layout the other
 *
 * @param recycler
 * @param state
 */
private void firstFillWithVertical(RecyclerView.Recycler recycler, RecyclerView.State state) {
    detachAndScrapAttachedViews(recycler);
    int topEdge = getOrientationHelper().getStartAfterPadding();
    int bottomEdge = getOrientationHelper().getEndAfterPadding();
    int startPosition = mInitialSelectedPosition;
    int scrapWidth, scrapHeight;
    Rect scrapRect = new Rect();
    int width = getHorizontalSpace();
    int leftOffset;
    //layout the init position view
    View scrap = recycler.getViewForPosition(mInitialSelectedPosition);
    addView(scrap, 0);
    measureChildWithMargins(scrap, 0, 0);
    scrapWidth = getDecoratedMeasuredWidth(scrap);
    scrapHeight = getDecoratedMeasuredHeight(scrap);
    leftOffset = (int) (getPaddingLeft() + (width - scrapWidth) / 2.0f);
    int top = (int) (getPaddingTop() + (getVerticalSpace() - scrapHeight) / 2.f);
    scrapRect.set(leftOffset, top, leftOffset + scrapWidth, top + scrapHeight);
    layoutDecorated(scrap, scrapRect.left, scrapRect.top, scrapRect.right, scrapRect.bottom);
    if (getState().mItemsFrames.get(startPosition) == null) {
        getState().mItemsFrames.put(startPosition, scrapRect);
    } else {
        getState().mItemsFrames.get(startPosition).set(scrapRect);
    }
    mFirstVisiblePosition = mLastVisiblePos = startPosition;
    int topStartOffset = getDecoratedTop(scrap);
    int bottomStartOffset = getDecoratedBottom(scrap);
    //fill left of center
    fillTop(recycler, mInitialSelectedPosition - 1, topStartOffset, topEdge);
    //fill right of center
    fillBottom(recycler, mInitialSelectedPosition + 1, bottomStartOffset, bottomEdge);
}
 
Example 5
Source File: SpacesItemDecoration.java    From youqu_master with Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.left=space;
    outRect.right=space;
    outRect.bottom=space;
    if(parent.getChildAdapterPosition(view)==0){
        outRect.top=space;
    }
}
 
Example 6
Source File: AccordionLinearLayoutManager.java    From FancyAccordionView with Apache License 2.0 5 votes vote down vote up
@Override
protected int getExtraLayoutSpace(RecyclerView.State state) {
    final int extraSpace = super.getExtraLayoutSpace(state);
    if (state.willRunPredictiveAnimations()) {
        return Math.max(getHeight(), extraSpace);
    }
    return extraSpace;
}
 
Example 7
Source File: VerticalSpaceItemDecoration.java    From mvp-android with MIT License 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                           RecyclerView.State state) {
    if (parent.getChildAdapterPosition(view) != parent.getAdapter().getItemCount() - 1) {
        outRect.bottom = mVerticalSpaceHeight;
    }
}
 
Example 8
Source File: TypeActivity.java    From YCRefreshView with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent,
                   RecyclerView.State state) {
    canvas.save();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);

        int pos = parent.getChildAdapterPosition(child);
        if (pos == 0) {
            //画一半长度的线。上半部缺失。
            mDrawable.setBounds(marginLeft, (child.getTop() + child.getBottom()) / 2,
                    marginLeft + lineSize, child.getBottom());
            mDrawable.draw(canvas);
        } else if (pos == parent.getAdapter().getItemCount() - 1) {
            //画一半长度的线。下半部缺失。
            mDrawable.setBounds(marginLeft, child.getTop(), marginLeft + lineSize,
                    (child.getTop() + child.getBottom()) / 2);
            mDrawable.draw(canvas);
        } else {
            //画普通的线。
            mDrawable.setBounds(marginLeft, child.getTop(),
                    marginLeft + lineSize, child.getBottom());
            mDrawable.draw(canvas);
        }

        //后画覆盖在线上的圆球。
        canvas.drawCircle(marginLeft + lineSize / 2, (child.getTop() +
                child.getBottom()) / 2, (lineSize + marginLeft) / 2, mPaint);
    }

    canvas.restore();
}
 
Example 9
Source File: FlipLayoutManager.java    From FlipGank with Apache License 2.0 5 votes vote down vote up
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    final int before = mPosition * getItemHeightInPositon() + mPositionOffset;
    mPositionOffset += dy;
    checkPosition(state);
    final int after = mPosition * getItemHeightInPositon() + mPositionOffset;
    final int ans = (int) (after - before);

    fill(recycler, state);

    return ans;
}
 
Example 10
Source File: CoolBannerLayoutManager.java    From CarouselBanner with Apache License 2.0 5 votes vote down vote up
private int scrollBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (getChildCount() == 0 || dy == 0) {
        return 0;
    }
    if (mOrientationHelper == null) {
        mOrientationHelper = OrientationHelper.createOrientationHelper(this, mOrientation);
    }
    int willScroll = dy;

    float realDx = dy / getDistanceRatio();
    if (Math.abs(realDx) < 0.00000001f) {
        return 0;
    }
    float targetOffset = mOffset + realDx;

    //handle the boundary
    if (!mInfinite && targetOffset < getMinOffset()) {
        willScroll -= (targetOffset - getMinOffset()) * getDistanceRatio();
    } else if (!mInfinite && targetOffset > getMaxOffset()) {
        willScroll = (int) ((getMaxOffset() - mOffset) * getDistanceRatio());
    }


    realDx = willScroll / getDistanceRatio();

    mOffset += realDx;

    // we re-layout all current views in the right place
    for (int i = 0; i < getChildCount(); i++) {
        final View scrap = getChildAt(i);
        final float delta = propertyChangeWhenScroll(scrap) - realDx;
        layoutScrap(scrap, delta);
    }

    //handle recycle
    layoutItems(recycler);

    return willScroll;
}
 
Example 11
Source File: CustomItemAnimator.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public ItemHolderInfo recordPreLayoutInformation(
        @NonNull RecyclerView.State state, @NonNull RecyclerView.ViewHolder viewHolder,
        int changeFlags, @NonNull List<Object> payloads) {
    if (changeFlags == FLAG_CHANGED) {
        for (Object payload : payloads) {
            if (payload instanceof String) {
                return new CustomItemHolderInfo((String) payload);
            }
        }
    }
    return super.recordPreLayoutInformation(state, viewHolder, changeFlags, payloads);
}
 
Example 12
Source File: BaseDivider.java    From TitanRecyclerView with MIT License 4 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    RecyclerView.Adapter adapter = parent.getAdapter();
    if (adapter == null) {
        return;
    }

    int itemCount = adapter.getItemCount();
    int lastDividerOffset = getLastDividerOffset(parent);
    int validChildCount = parent.getChildCount();
    int lastChildPosition = -1;
    for (int i = 0; i < validChildCount; i++) {
        View child = parent.getChildAt(i);
        int childPosition = parent.getChildAdapterPosition(child);

        if (childPosition < lastChildPosition) {
            // Avoid remaining divider when animation starts
            continue;
        }
        lastChildPosition = childPosition;

        if (!mShowLastDivider && childPosition >= itemCount - lastDividerOffset) {
            // Don't draw divider for last line if mShowLastDivider = false
            continue;
        }

        if (wasDividerAlreadyDrawn(childPosition, parent)) {
            // No need to draw divider again as it was drawn already by previous column
            continue;
        }

        int groupIndex = getGroupIndex(childPosition, parent);
        if (mVisibilityProvider.shouldHideDivider(groupIndex, parent)) {
            continue;
        }

        Rect bounds = getDividerBound(groupIndex, parent, child);
        switch (mDividerType) {
            case DRAWABLE:
                Drawable drawable = mDrawableProvider.drawableProvider(groupIndex, parent);
                drawable.setBounds(bounds);
                drawable.draw(c);
                break;
            case PAINT:
                mPaint = mPaintProvider.dividerPaint(groupIndex, parent);
                c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
                break;
            case COLOR:
                mPaint.setColor(mColorProvider.dividerColor(groupIndex, parent));
                mPaint.setStrokeWidth(mSizeProvider.dividerSize(groupIndex, parent));
                c.drawLine(bounds.left, bounds.top, bounds.right, bounds.bottom, mPaint);
                break;
        }
    }
}
 
Example 13
Source File: ListItemDecorator.java    From Capstone-Project with MIT License 4 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
}
 
Example 14
Source File: StaticGridLayoutManager.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (getChildCount() == 0) {
        return 0;
    }

    //Take leftmost measurements from the top-left child
    final View topView = getChildAt(0);
    //Take rightmost measurements from the top-right child
    final View bottomView = getChildAt(mVisibleColumnCount-1);

    //Optimize the case where the entire data set is too small to scroll
    int viewSpan = getDecoratedRight(bottomView) - getDecoratedLeft(topView);
    if (viewSpan <= getHorizontalSpace()) {
        //We cannot scroll in either direction
        return 0;
    }

    int delta;
    boolean leftBoundReached = getFirstVisibleColumn() == 0;
    boolean rightBoundReached = getLastVisibleColumn() >= getTotalColumnCount();
    if (dx > 0) { // Contents are scrolling left
        //Check right bound
        if (rightBoundReached) {
            //If we've reached the last column, enforce limits
            int rightOffset = getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
            delta = Math.max(-dx, rightOffset);
        } else {
            //No limits while the last column isn't visible
            delta = -dx;
        }
    } else { // Contents are scrolling right
        //Check left bound
        if (leftBoundReached) {
            int leftOffset = -getDecoratedLeft(topView) + getPaddingLeft();
            delta = Math.min(-dx, leftOffset);
        } else {
            delta = -dx;
        }
    }

    offsetChildrenHorizontal(delta);

    if (dx > 0) {
        if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
            fillGrid(DIRECTION_END, recycler);
        } else if (!rightBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    } else {
        if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
            fillGrid(DIRECTION_START, recycler);
        } else if (!leftBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    }

    /*
     * Return value determines if a boundary has been reached
     * (for edge effects and flings). If returned value does not
     * match original delta (passed in), RecyclerView will draw
     * an edge effect.
     */
    return -delta;
}
 
Example 15
Source File: ExtGridLayoutManager.java    From dpad-aware-recycler-view with Apache License 2.0 4 votes vote down vote up
@Override
public void onMeasure(@NonNull RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec,
        int heightSpec) {
    boolean wrap;

    int orientation = getOrientation();
    int widthMode = View.MeasureSpec.getMode(widthSpec);
    int heightMode = View.MeasureSpec.getMode(heightSpec);

    if (orientation == VERTICAL) {
        wrap = widthMode == View.MeasureSpec.AT_MOST;
    } else {
        wrap = heightMode == View.MeasureSpec.AT_MOST;
    }

    if (wrap && getItemCount() > 0) {
        int spanCount = getSpanCount();
        View dummyChild = recycler.getViewForPosition(0);
        measureChildWithMargins(dummyChild, 0, 0);

        if (orientation == VERTICAL) {
            int widthSize = View.MeasureSpec.getSize(widthSpec);
            int supposedOccupiedWidth = dummyChild.getMeasuredWidth() * spanCount;

            if (supposedOccupiedWidth <= widthSize) {
                widthSpec = View.MeasureSpec.makeMeasureSpec(supposedOccupiedWidth, widthMode);
            }
        } else {
            int heightSize = View.MeasureSpec.getSize(heightSpec);
            int supposedOccupiedHeight = dummyChild.getMeasuredHeight() * spanCount;

            if (supposedOccupiedHeight <= heightSize) {
                heightSpec = View.MeasureSpec.makeMeasureSpec(supposedOccupiedHeight, heightMode);
            }
        }
    }

    super.onMeasure(recycler, state, widthSpec, heightSpec);

    if (getItemCount() > 0 && mSpanCount == AUTO_FIT) {
        resolveAutoFit(recycler);
    }
}
 
Example 16
Source File: BannerLayoutManager.java    From RecyclerBanner with Apache License 2.0 4 votes vote down vote up
@Override
public int computeHorizontalScrollOffset(RecyclerView.State state) {
    return computeScrollOffset();
}
 
Example 17
Source File: BlankSpaceItemDecoration.java    From CameraMaskDemo with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);
}
 
Example 18
Source File: RecycleViewDivider.java    From alpha-wallet-android with MIT License 4 votes vote down vote up
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
{
    outRect.set(0, 0, 0, this.mDivider.getIntrinsicHeight());
}
 
Example 19
Source File: DividerDecoration.java    From zulip-android with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    outRect.set(0, 0, 0, mHeight);
}
 
Example 20
Source File: ExpandModel.java    From ExpandLayoutManager with Apache License 2.0 votes vote down vote up
boolean checkRemeasureNeeded(ExpandLayoutManager expandLayoutManager, RecyclerView.Recycler recycler, final RecyclerView.State state);