android.support.v7.widget.RecyclerView.State Java Examples

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: FocusableLinearLayoutManager.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
@Override
public void onLayoutChildren(Recycler recycler, State state) {
    super.onLayoutChildren(recycler, state);

    if (mFocusStateRequest.notifyOnNextLayout) {
        mFocusStateRequest.notifyOnNextLayout = false;
        // If the notify has a animation, we should make sure the notify is later than
        // RecyclerView's animation. So they will not conflict.
        if (mFocusStateRequest.animate) {
            postOnAnimation(new Runnable() {
                @Override
                public void run() {
                    // We wait for animation time begin and notify on next main loop,
                    // So we can sure the notify is follow the state change animation.
                    notifyAfterLayoutOnNextMainLoop();
                }
            });
        } else {
            requestNotifyChildrenStateChanged(mFocusStateRequest);
        }
    }
}
 
Example #2
Source File: WidgetsContainerView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    mContent = findViewById(R.id.content);
    mView = (WidgetsRecyclerView) findViewById(R.id.widgets_list_view);
    mView.setAdapter(mAdapter);

    // This extends the layout space so that preloading happen for the {@link RecyclerView}
    mView.setLayoutManager(new LinearLayoutManager(getContext()) {
        @Override
        protected int getExtraLayoutSpace(State state) {
            DeviceProfile grid = mLauncher.getDeviceProfile();
            return super.getExtraLayoutSpace(state)
                    + grid.availableHeightPx * PRELOAD_SCREEN_HEIGHT_MULTIPLE;
        }
    });
    mPadding.set(getPaddingLeft(), getPaddingTop(), getPaddingRight(),
            getPaddingBottom());
    setScroller();
    updateBackgroundAndPaddings();
}
 
Example #3
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
int scrollBy(int dy, Recycler recycler, State state) {
    int i = 0;
    if (!(getChildCount() == 0 || dy == 0)) {
        this.mLayoutState.mRecycle = true;
        ensureLayoutState();
        int layoutDirection = dy > 0 ? 1 : -1;
        int absDy = Math.abs(dy);
        updateLayoutState(layoutDirection, absDy, true, state);
        int consumed = this.mLayoutState.mScrollingOffset + fill(recycler, this.mLayoutState, state, false);
        if (consumed >= 0) {
            if (absDy > consumed) {
                i = layoutDirection * consumed;
            } else {
                i = dy;
            }
            this.mOrientationHelper.offsetChildren(-i);
            this.mLayoutState.mLastScrollDelta = i;
        }
    }
    return i;
}
 
Example #4
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
protected int getAnchorItemPosition(State state) {
    final int itemCount = state.getItemCount();

    int pendingPosition = getPendingScrollPosition();
    if (pendingPosition != RecyclerView.NO_POSITION) {
        if (pendingPosition < 0 || pendingPosition >= itemCount) {
            pendingPosition = RecyclerView.NO_POSITION;
        }
    }

    if (pendingPosition != RecyclerView.NO_POSITION) {
        return pendingPosition;
    } else if (getChildCount() > 0) {
        return findFirstValidChildPosition(itemCount);
    } else {
        return 0;
    }
}
 
Example #5
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public int scrollVerticallyBy(int dy, Recycler recycler, RecyclerView.State state) {
    if (DEBUG) Log.v(getTag(), "scrollVerticallyBy " + dy);
    if (!mLayoutEnabled || !hasDoneFirstLayout()) {
        return 0;
    }
    saveContext(recycler, state);
    int result;
    if (mOrientation == VERTICAL) {
        result = scrollDirectionPrimary(dy);
    } else {
        result = scrollDirectionSecondary(dy);
    }
    leaveContext();
    return result;
}
 
Example #6
Source File: GridLayoutManager.java    From adt-leanback-support with Apache License 2.0 6 votes vote down vote up
@Override
public int scrollHorizontallyBy(int dx, Recycler recycler, RecyclerView.State state) {
    if (DEBUG) Log.v(getTag(), "scrollHorizontallyBy " + dx);
    if (!mLayoutEnabled || !hasDoneFirstLayout()) {
        return 0;
    }
    saveContext(recycler, state);
    int result;
    if (mOrientation == HORIZONTAL) {
        result = scrollDirectionPrimary(dx);
    } else {
        result = scrollDirectionSecondary(dx);
    }
    leaveContext();
    return result;
}
 
Example #7
Source File: StaggeredGridLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
public void smoothScrollToPosition(RecyclerView recyclerView, State state, int position) {
    LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
        public PointF computeScrollVectorForPosition(int targetPosition) {
            int direction = StaggeredGridLayoutManager.this.calculateScrollDirectionForPosition(targetPosition);
            if (direction == 0) {
                return null;
            }
            if (StaggeredGridLayoutManager.this.mOrientation == 0) {
                return new PointF((float) direction, 0.0f);
            }
            return new PointF(0.0f, (float) direction);
        }
    };
    scroller.setTargetPosition(position);
    startSmoothScroll(scroller);
}
 
Example #8
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
private int fixLayoutStartGap(int startOffset, Recycler recycler, State state, boolean canOffsetChildren) {
    int gap = startOffset - this.mOrientationHelper.getStartAfterPadding();
    if (gap <= 0) {
        return 0;
    }
    int fixOffset = -scrollBy(gap, recycler, state);
    startOffset += fixOffset;
    if (canOffsetChildren) {
        gap = startOffset - this.mOrientationHelper.getStartAfterPadding();
        if (gap > 0) {
            this.mOrientationHelper.offsetChildren(-gap);
            return fixOffset - gap;
        }
    }
    return fixOffset;
}
 
Example #9
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollOffset(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled, boolean reverseLayout) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    int itemsBefore = reverseLayout ? Math.max(0, (state.getItemCount() - Math.max(lm.getPosition(startChild), lm.getPosition(endChild))) - 1) : Math.max(0, Math.min(lm.getPosition(startChild), lm.getPosition(endChild)));
    if (!smoothScrollbarEnabled) {
        return itemsBefore;
    }
    return Math.round((((float) itemsBefore) * (((float) Math.abs(orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild))) / ((float) (Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1)))) + ((float) (orientation.getStartAfterPadding() - orientation.getDecoratedStart(startChild))));
}
 
Example #10
Source File: GridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
View findReferenceChild(Recycler recycler, State state, int start, int end, int itemCount) {
    ensureLayoutState();
    View invalidMatch = null;
    View outOfBoundsMatch = null;
    int boundsStart = this.mOrientationHelper.getStartAfterPadding();
    int boundsEnd = this.mOrientationHelper.getEndAfterPadding();
    int diff = end > start ? 1 : -1;
    for (int i = start; i != end; i += diff) {
        View childAt = getChildAt(i);
        int position = getPosition(childAt);
        if (position >= 0 && position < itemCount && getSpanIndex(recycler, state, position) == 0) {
            if (((android.support.v7.widget.RecyclerView.LayoutParams) childAt.getLayoutParams()).isItemRemoved()) {
                if (invalidMatch == null) {
                    invalidMatch = childAt;
                }
            } else if (this.mOrientationHelper.getDecoratedStart(childAt) < boundsEnd && this.mOrientationHelper.getDecoratedEnd(childAt) >= boundsStart) {
                return childAt;
            } else {
                if (outOfBoundsMatch == null) {
                    outOfBoundsMatch = childAt;
                }
            }
        }
    }
    if (outOfBoundsMatch == null) {
        outOfBoundsMatch = invalidMatch;
    }
    return outOfBoundsMatch;
}
 
Example #11
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void fillAfter(int position, Recycler recycler, State state, int extraSpace) {
    final int limit = getEndWithPadding() + extraSpace;

    final int itemCount = state.getItemCount();
    while (canAddMoreViews(Direction.END, limit) && position < itemCount) {
        makeAndAddView(position, Direction.END, recycler);
        position++;
    }
}
 
Example #12
Source File: GridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public void onLayoutChildren(Recycler recycler, State state) {
    if (state.isPreLayout()) {
        cachePreLayoutSpanMapping();
    }
    super.onLayoutChildren(recycler, state);
    clearPreLayoutSpanMappingCache();
    if (!state.isPreLayout()) {
        this.mPendingSpanCountChange = false;
    }
}
 
Example #13
Source File: GridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
public int getRowCountForAccessibility(Recycler recycler, State state) {
    if (this.mOrientation == 0) {
        return this.mSpanCount;
    }
    if (state.getItemCount() < 1) {
        return 0;
    }
    return getSpanGroupIndex(recycler, state, state.getItemCount() - 1) + 1;
}
 
Example #14
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollRange(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    if (!smoothScrollbarEnabled) {
        return state.getItemCount();
    }
    return (int) ((((float) (orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild))) / ((float) (Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1))) * ((float) state.getItemCount()));
}
 
Example #15
Source File: ScrollbarHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
static int computeScrollExtent(State state, OrientationHelper orientation, View startChild, View endChild, LayoutManager lm, boolean smoothScrollbarEnabled) {
    if (lm.getChildCount() == 0 || state.getItemCount() == 0 || startChild == null || endChild == null) {
        return 0;
    }
    if (!smoothScrollbarEnabled) {
        return Math.abs(lm.getPosition(startChild) - lm.getPosition(endChild)) + 1;
    }
    return Math.min(orientation.getTotalSpace(), orientation.getDecoratedEnd(endChild) - orientation.getDecoratedStart(startChild));
}
 
Example #16
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
int fill(Recycler recycler, LayoutState layoutState, State state, boolean stopOnFocusable) {
    int start = layoutState.mAvailable;
    if (layoutState.mScrollingOffset != Integer.MIN_VALUE) {
        if (layoutState.mAvailable < 0) {
            layoutState.mScrollingOffset += layoutState.mAvailable;
        }
        recycleByLayoutState(recycler, layoutState);
    }
    int remainingSpace = layoutState.mAvailable + layoutState.mExtra;
    LayoutChunkResult layoutChunkResult = new LayoutChunkResult();
    while (true) {
        if ((!layoutState.mInfinite && remainingSpace <= 0) || !layoutState.hasMore(state)) {
            break;
        }
        layoutChunkResult.resetInternal();
        layoutChunk(recycler, state, layoutState, layoutChunkResult);
        if (!layoutChunkResult.mFinished) {
            layoutState.mOffset += layoutChunkResult.mConsumed * layoutState.mLayoutDirection;
            if (!(layoutChunkResult.mIgnoreConsumed && this.mLayoutState.mScrapList == null && state.isPreLayout())) {
                layoutState.mAvailable -= layoutChunkResult.mConsumed;
                remainingSpace -= layoutChunkResult.mConsumed;
            }
            if (layoutState.mScrollingOffset != Integer.MIN_VALUE) {
                layoutState.mScrollingOffset += layoutChunkResult.mConsumed;
                if (layoutState.mAvailable < 0) {
                    layoutState.mScrollingOffset += layoutState.mAvailable;
                }
                recycleByLayoutState(recycler, layoutState);
            }
            if (stopOnFocusable && layoutChunkResult.mFocusable) {
                break;
            }
        } else {
            break;
        }
    }
    return start - layoutState.mAvailable;
}
 
Example #17
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private int scrollBy(int delta, Recycler recycler, State state) {
    final int childCount = getChildCount();
    if (childCount == 0 || delta == 0) {
        return 0;
    }

    final int start = getStartWithPadding();
    final int end = getEndWithPadding();
    final int firstPosition = getFirstVisiblePosition();

    final int totalSpace = getTotalSpace();
    if (delta < 0) {
        delta = Math.max(-(totalSpace - 1), delta);
    } else {
        delta = Math.min(totalSpace - 1, delta);
    }

    final boolean cannotScrollBackward = (firstPosition == 0 &&
            mLayoutStart >= start && delta <= 0);
    final boolean cannotScrollForward = (firstPosition + childCount == state.getItemCount() &&
            mLayoutEnd <= end && delta >= 0);

    if (cannotScrollForward || cannotScrollBackward) {
        return 0;
    }

    offsetChildren(-delta);

    final Direction direction = (delta > 0 ? Direction.END : Direction.START);
    recycleChildrenOutOfBounds(direction, recycler);

    final int absDelta = Math.abs(delta);
    if (canAddMoreViews(Direction.START, start - absDelta) ||
        canAddMoreViews(Direction.END, end + absDelta)) {
        fillGap(direction, recycler, state);
    }

    return delta;
}
 
Example #18
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
protected void onLayoutScrapList(Recycler recycler, State state) {
    final int childCount = getChildCount();
    if (childCount == 0 || state.isPreLayout() || !supportsPredictiveItemAnimations()) {
        return;
    }

    final List<ViewHolder> scrapList = recycler.getScrapList();
    fillFromScrapList(scrapList, Direction.START);
    fillFromScrapList(scrapList, Direction.END);
}
 
Example #19
Source File: GridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int getSpanIndex(Recycler recycler, State state, int pos) {
    if (!state.isPreLayout()) {
        return this.mSpanSizeLookup.getCachedSpanIndex(pos, this.mSpanCount);
    }
    int cached = this.mPreLayoutSpanIndexCache.get(pos, -1);
    if (cached != -1) {
        return cached;
    }
    int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(pos);
    if (adapterPosition != -1) {
        return this.mSpanSizeLookup.getCachedSpanIndex(adapterPosition, this.mSpanCount);
    }
    Log.w(TAG, "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + pos);
    return 0;
}
 
Example #20
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int computeScrollRange(State state) {
    boolean z = false;
    if (getChildCount() == 0) {
        return 0;
    }
    ensureLayoutState();
    OrientationHelper orientationHelper = this.mOrientationHelper;
    View findFirstVisibleChildClosestToStart = findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true);
    if (!this.mSmoothScrollbarEnabled) {
        z = true;
    }
    return ScrollbarHelper.computeScrollRange(state, orientationHelper, findFirstVisibleChildClosestToStart, findFirstVisibleChildClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled);
}
 
Example #21
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int computeScrollOffset(State state) {
    boolean z = false;
    if (getChildCount() == 0) {
        return 0;
    }
    ensureLayoutState();
    OrientationHelper orientationHelper = this.mOrientationHelper;
    View findFirstVisibleChildClosestToStart = findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true);
    if (!this.mSmoothScrollbarEnabled) {
        z = true;
    }
    return ScrollbarHelper.computeScrollOffset(state, orientationHelper, findFirstVisibleChildClosestToStart, findFirstVisibleChildClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled, this.mShouldReverseLayout);
}
 
Example #22
Source File: TwoWayLayoutManager.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void correctTooHigh(int childCount, Recycler recycler, State state) {
    // First see if the last item is visible. If it is not, it is OK for the
    // top of the list to be pushed up.
    final int lastPosition = getLastVisiblePosition();
    if (lastPosition != state.getItemCount() - 1 || childCount == 0) {
        return;
    }

    // This is bottom of our drawable area.
    final int start = getStartWithPadding();
    final int end = getEndWithPadding();
    final int firstPosition = getFirstVisiblePosition();

    // This is how far the end edge of the last view is from the end of the
    // drawable area.
    int endOffset = end - mLayoutEnd;

    // Make sure we are 1) Too high, and 2) Either there are more rows above the
    // first row or the first row is scrolled off the top of the drawable area
    if (endOffset > 0 && (firstPosition > 0 || mLayoutStart < start))  {
        if (firstPosition == 0) {
            // Don't pull the top too far down.
            endOffset = Math.min(endOffset, start - mLayoutStart);
        }

        // Move everything down
        offsetChildren(endOffset);

        if (firstPosition > 0) {
            // Fill the gap that was opened above first position with more
            // children, if possible.
            fillBefore(firstPosition - 1, recycler);

            // Close up the remaining gap.
            adjustViewsStartOrEnd();
        }
    }
}
 
Example #23
Source File: StaggeredGridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int computeScrollOffset(State state) {
    boolean z = false;
    if (getChildCount() == 0) {
        return 0;
    }
    ensureOrientationHelper();
    OrientationHelper orientationHelper = this.mPrimaryOrientation;
    View findFirstVisibleItemClosestToStart = findFirstVisibleItemClosestToStart(!this.mSmoothScrollbarEnabled, true);
    if (!this.mSmoothScrollbarEnabled) {
        z = true;
    }
    return ScrollbarHelper.computeScrollOffset(state, orientationHelper, findFirstVisibleItemClosestToStart, findFirstVisibleItemClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled, this.mShouldReverseLayout);
}
 
Example #24
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private int computeScrollExtent(State state) {
    boolean z = false;
    if (getChildCount() == 0) {
        return 0;
    }
    ensureLayoutState();
    OrientationHelper orientationHelper = this.mOrientationHelper;
    View findFirstVisibleChildClosestToStart = findFirstVisibleChildClosestToStart(!this.mSmoothScrollbarEnabled, true);
    if (!this.mSmoothScrollbarEnabled) {
        z = true;
    }
    return ScrollbarHelper.computeScrollExtent(state, orientationHelper, findFirstVisibleChildClosestToStart, findFirstVisibleChildClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled);
}
 
Example #25
Source File: DividerGridItemDecoration.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, State state)
{

    drawHorizontal(c, parent);
    drawVertical(c, parent);

}
 
Example #26
Source File: StaggeredGridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private void fixStartGap(Recycler recycler, State state, boolean canOffsetChildren) {
    int minStartLine = getMinStart(Integer.MAX_VALUE);
    if (minStartLine != Integer.MAX_VALUE) {
        int gap = minStartLine - this.mPrimaryOrientation.getStartAfterPadding();
        if (gap > 0) {
            gap -= scrollBy(gap, recycler, state);
            if (canOffsetChildren && gap > 0) {
                this.mPrimaryOrientation.offsetChildren(-gap);
            }
        }
    }
}
 
Example #27
Source File: StaggeredGridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private void updateLayoutState(int anchorPosition, State state) {
    boolean z = true;
    this.mLayoutState.mAvailable = 0;
    this.mLayoutState.mCurrentPosition = anchorPosition;
    int startExtra = 0;
    int endExtra = 0;
    if (isSmoothScrolling()) {
        int targetPos = state.getTargetScrollPosition();
        if (targetPos != -1) {
            boolean z2;
            boolean z3 = this.mShouldReverseLayout;
            if (targetPos < anchorPosition) {
                z2 = true;
            } else {
                z2 = false;
            }
            if (z3 == z2) {
                endExtra = this.mPrimaryOrientation.getTotalSpace();
            } else {
                startExtra = this.mPrimaryOrientation.getTotalSpace();
            }
        }
    }
    if (getClipToPadding()) {
        this.mLayoutState.mStartLine = this.mPrimaryOrientation.getStartAfterPadding() - startExtra;
        this.mLayoutState.mEndLine = this.mPrimaryOrientation.getEndAfterPadding() + endExtra;
    } else {
        this.mLayoutState.mEndLine = this.mPrimaryOrientation.getEnd() + endExtra;
        this.mLayoutState.mStartLine = -startExtra;
    }
    this.mLayoutState.mStopInFocusable = false;
    this.mLayoutState.mRecycle = true;
    LayoutState layoutState = this.mLayoutState;
    if (this.mPrimaryOrientation.getMode() != 0) {
        z = false;
    }
    layoutState.mInfinite = z;
}
 
Example #28
Source File: StaggeredGridLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
int scrollBy(int dt, Recycler recycler, State state) {
    int layoutDir;
    int referenceChildPosition;
    int totalScroll;
    ensureOrientationHelper();
    if (dt > 0) {
        layoutDir = 1;
        referenceChildPosition = getLastChildPosition();
    } else {
        layoutDir = -1;
        referenceChildPosition = getFirstChildPosition();
    }
    this.mLayoutState.mRecycle = true;
    updateLayoutState(referenceChildPosition, state);
    setLayoutStateDirection(layoutDir);
    this.mLayoutState.mCurrentPosition = this.mLayoutState.mItemDirection + referenceChildPosition;
    int absDt = Math.abs(dt);
    this.mLayoutState.mAvailable = absDt;
    int consumed = fill(recycler, this.mLayoutState, state);
    if (absDt < consumed) {
        totalScroll = dt;
    } else if (dt < 0) {
        totalScroll = -consumed;
    } else {
        totalScroll = consumed;
    }
    this.mPrimaryOrientation.offsetChildren(-totalScroll);
    this.mLastLayoutFromEnd = this.mShouldReverseLayout;
    return totalScroll;
}
 
Example #29
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private void layoutForPredictiveAnimations(Recycler recycler, State state, int startOffset, int endOffset) {
    if (state.willRunPredictiveAnimations() && getChildCount() != 0 && !state.isPreLayout() && supportsPredictiveItemAnimations()) {
        int scrapExtraStart = 0;
        int scrapExtraEnd = 0;
        List<ViewHolder> scrapList = recycler.getScrapList();
        int scrapSize = scrapList.size();
        int firstChildPos = getPosition(getChildAt(0));
        for (int i = 0; i < scrapSize; i++) {
            ViewHolder scrap = (ViewHolder) scrapList.get(i);
            if (!scrap.isRemoved()) {
                if (((scrap.getLayoutPosition() < firstChildPos) != this.mShouldReverseLayout ? -1 : 1) == -1) {
                    scrapExtraStart += this.mOrientationHelper.getDecoratedMeasurement(scrap.itemView);
                } else {
                    scrapExtraEnd += this.mOrientationHelper.getDecoratedMeasurement(scrap.itemView);
                }
            }
        }
        this.mLayoutState.mScrapList = scrapList;
        if (scrapExtraStart > 0) {
            updateLayoutStateToFillStart(getPosition(getChildClosestToStart()), startOffset);
            this.mLayoutState.mExtra = scrapExtraStart;
            this.mLayoutState.mAvailable = 0;
            this.mLayoutState.assignPositionFromScrapList();
            fill(recycler, this.mLayoutState, state, false);
        }
        if (scrapExtraEnd > 0) {
            updateLayoutStateToFillEnd(getPosition(getChildClosestToEnd()), endOffset);
            this.mLayoutState.mExtra = scrapExtraEnd;
            this.mLayoutState.mAvailable = 0;
            this.mLayoutState.assignPositionFromScrapList();
            fill(recycler, this.mLayoutState, state, false);
        }
        this.mLayoutState.mScrapList = null;
    }
}
 
Example #30
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private boolean updateAnchorFromChildren(Recycler recycler, State state, AnchorInfo anchorInfo) {
    if (getChildCount() == 0) {
        return false;
    }
    View focused = getFocusedChild();
    if (focused != null && anchorInfo.isViewValidAsAnchor(focused, state)) {
        anchorInfo.assignFromViewAndKeepVisibleRect(focused);
        return true;
    } else if (this.mLastStackFromEnd != this.mStackFromEnd) {
        return false;
    } else {
        View referenceChild = anchorInfo.mLayoutFromEnd ? findReferenceChildClosestToEnd(recycler, state) : findReferenceChildClosestToStart(recycler, state);
        if (referenceChild == null) {
            return false;
        }
        anchorInfo.assignFromView(referenceChild);
        if (!state.isPreLayout() && supportsPredictiveItemAnimations()) {
            boolean notVisible;
            if (this.mOrientationHelper.getDecoratedStart(referenceChild) >= this.mOrientationHelper.getEndAfterPadding() || this.mOrientationHelper.getDecoratedEnd(referenceChild) < this.mOrientationHelper.getStartAfterPadding()) {
                notVisible = true;
            } else {
                notVisible = false;
            }
            if (notVisible) {
                anchorInfo.mCoordinate = anchorInfo.mLayoutFromEnd ? this.mOrientationHelper.getEndAfterPadding() : this.mOrientationHelper.getStartAfterPadding();
            }
        }
        return true;
    }
}