Java 类android.support.v7.widget.RecyclerView.State 实例源码

项目:boohee_v5.6    文件:LinearLayoutManager.java   
private int fixLayoutEndGap(int endOffset, Recycler recycler, State state, boolean canOffsetChildren) {
    int gap = this.mOrientationHelper.getEndAfterPadding() - endOffset;
    if (gap <= 0) {
        return 0;
    }
    int fixOffset = -scrollBy(-gap, recycler, state);
    endOffset += fixOffset;
    if (canOffsetChildren) {
        gap = this.mOrientationHelper.getEndAfterPadding() - endOffset;
        if (gap > 0) {
            this.mOrientationHelper.offsetChildren(gap);
            return gap + fixOffset;
        }
    }
    return fixOffset;
}
项目:RecyclerViewEvent    文件:DividerGridItemDecoration.java   
@Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
        boolean b = state.willRunPredictiveAnimations();
        int itemPosition = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
        int spanCount = getSpanCount(parent);
        int childCount = parent.getAdapter().getItemCount();
//        if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
//        {
//            outRect.set(0, 0, lineWidth, 0);
//        }
//        else if (isLastColum(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
//        {
////            if (b){
////                outRect.set(0, 0, lineWidth, lineWidth);
////            }else {
//                outRect.set(0, 0, 0, lineWidth);
////            }
//        }
//        else {
        outRect.set(0, 0, lineWidth, lineWidth);
//        }
    }
项目:boohee_v5.6    文件:GridLayoutManager.java   
public void onInitializeAccessibilityNodeInfoForItem(Recycler recycler, State state, View host, AccessibilityNodeInfoCompat info) {
    android.view.ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (lp instanceof LayoutParams) {
        LayoutParams glp = (LayoutParams) lp;
        int spanGroupIndex = getSpanGroupIndex(recycler, state, glp.getViewLayoutPosition());
        if (this.mOrientation == 0) {
            int spanIndex = glp.getSpanIndex();
            int spanSize = glp.getSpanSize();
            boolean z = this.mSpanCount > 1 && glp.getSpanSize() == this.mSpanCount;
            info.setCollectionItemInfo(CollectionItemInfoCompat.obtain(spanIndex, spanSize, spanGroupIndex, 1, z, false));
            return;
        }
        int spanIndex2 = glp.getSpanIndex();
        int spanSize2 = glp.getSpanSize();
        boolean z2 = this.mSpanCount > 1 && glp.getSpanSize() == this.mSpanCount;
        info.setCollectionItemInfo(CollectionItemInfoCompat.obtain(spanGroupIndex, 1, spanIndex2, spanSize2, z2, false));
        return;
    }
    super.onInitializeAccessibilityNodeInfoForItem(host, info);
}
项目:letv    文件:LinearLayoutManager.java   
private int fixLayoutEndGap(int endOffset, Recycler recycler, State state, boolean canOffsetChildren) {
    int gap = this.mOrientationHelper.getEndAfterPadding() - endOffset;
    if (gap <= 0) {
        return 0;
    }
    int fixOffset = -scrollBy(-gap, recycler, state);
    endOffset += fixOffset;
    if (canOffsetChildren) {
        gap = this.mOrientationHelper.getEndAfterPadding() - endOffset;
        if (gap > 0) {
            this.mOrientationHelper.offsetChildren(gap);
            return gap + fixOffset;
        }
    }
    return fixOffset;
}
项目:boohee_v5.6    文件:GridLayoutManager.java   
public void onLayoutChildren(Recycler recycler, State state) {
    if (state.isPreLayout()) {
        cachePreLayoutSpanMapping();
    }
    super.onLayoutChildren(recycler, state);
    clearPreLayoutSpanMappingCache();
    if (!state.isPreLayout()) {
        this.mPendingSpanCountChange = false;
    }
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
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;
}
项目:boohee_v5.6    文件:GridLayoutManager.java   
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;
}
项目:GitHub    文件:RangeGridLayoutHelper.java   
private void assignSpans(GridRangeStyle rangeStyle, RecyclerView.Recycler recycler, RecyclerView.State state, int count,
    int consumedSpanCount, boolean layingOutInPrimaryDirection, LayoutManagerHelper helper) {
    int span, spanDiff, start, end, diff;
    // make sure we traverse from min position to max position
    if (layingOutInPrimaryDirection) {
        start = 0;
        end = count;
        diff = 1;
    } else {
        start = count - 1;
        end = -1;
        diff = -1;
    }

    if (helper.getOrientation() == VERTICAL && helper.isDoLayoutRTL()) { // start from last span
        span = consumedSpanCount - 1;
        spanDiff = -1;
    } else {
        span = 0;
        spanDiff = 1;
    }

    for (int i = start; i != end; i += diff) {
        View view = rangeStyle.mSet[i];
        int spanSize = getSpanSize(rangeStyle.mSpanSizeLookup, recycler, state, helper.getPosition(view));
        if (spanDiff == -1 && spanSize > 1) {
            rangeStyle.mSpanIndices[i] = span - (spanSize - 1);
        } else {
            rangeStyle.mSpanIndices[i] = span;
        }
        span += spanDiff * spanSize;
    }
}
项目:GitHub    文件:RangeGridLayoutHelper.java   
private int getSpanIndex(SpanSizeLookup spanSizeLookup, int spanCount, RecyclerView.Recycler recycler, RecyclerView.State state, int pos) {
    if (!state.isPreLayout()) {
        return spanSizeLookup.getCachedSpanIndex(pos, spanCount);
    }

    final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(pos);
    if (adapterPosition == -1) {
        return 0;
    }
    return spanSizeLookup.getCachedSpanIndex(adapterPosition, spanCount);
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
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);
}
项目:KUtils    文件:DividerGridItemDecoration.java   
@Override
public void onDraw(Canvas c, RecyclerView parent, State state) {
    /**画item底部的分割线*/
    drawVertical(c, parent);
    /**画item右边的分割线*/
    drawHorizontal(c, parent);
}
项目:boohee_v5.6    文件:ScrollbarHelper.java   
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()));
}
项目:FancyAccordionView    文件:ItemAnimator.java   
@Override
public
@NonNull
ItemHolderInfo recordPreLayoutInformation(@NonNull State state,
                                          @NonNull ViewHolder viewHolder, @AdapterChanges int changeFlags,
                                          @NonNull List<Object> payloads) {
    final ItemHolderInfo itemHolderInfo = super.recordPreLayoutInformation(state, viewHolder,
            changeFlags, payloads);
    if (itemHolderInfo instanceof PayloadItemHolderInfo) {
        ((PayloadItemHolderInfo) itemHolderInfo).setPayloads(payloads);
    }
    return itemHolderInfo;
}
项目:letv    文件:LinearSmoothScroller.java   
protected void onTargetFound(View targetView, State state, Action action) {
    int dx = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference());
    int dy = calculateDyToMakeVisible(targetView, getVerticalSnapPreference());
    int time = calculateTimeForDeceleration((int) Math.sqrt((double) ((dx * dx) + (dy * dy))));
    if (time > 0) {
        action.update(-dx, -dy, time, this.mDecelerateInterpolator);
    }
}
项目:letv    文件:LinearSmoothScroller.java   
protected void onSeekTargetStep(int dx, int dy, State state, Action action) {
    if (getChildCount() == 0) {
        stop();
        return;
    }
    this.mInterimTargetDx = clampApplyScroll(this.mInterimTargetDx, dx);
    this.mInterimTargetDy = clampApplyScroll(this.mInterimTargetDy, dy);
    if (this.mInterimTargetDx == 0 && this.mInterimTargetDy == 0) {
        updateActionForInterimTarget(action);
    }
}
项目:boohee_v5.6    文件:LinearLayoutManager.java   
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);
}
项目:letv    文件:ScrollbarHelper.java   
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));
}
项目:letv    文件:GridLayoutManager.java   
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;
}
项目:boohee_v5.6    文件:ItemTouchHelper.java   
public void onDrawOver(Canvas c, RecyclerView parent, State state) {
    float dx = 0.0f;
    float dy = 0.0f;
    if (this.mSelected != null) {
        getSelectedDxDy(this.mTmpPosition);
        dx = this.mTmpPosition[0];
        dy = this.mTmpPosition[1];
    }
    this.mCallback.onDrawOver(c, parent, this.mSelected, this.mRecoverAnimations, this.mActionState, dx, dy);
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
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;
}
项目:boohee_v5.6    文件:LinearSmoothScroller.java   
protected void onTargetFound(View targetView, State state, Action action) {
    int dx = calculateDxToMakeVisible(targetView, getHorizontalSnapPreference());
    int dy = calculateDyToMakeVisible(targetView, getVerticalSnapPreference());
    int time = calculateTimeForDeceleration((int) Math.sqrt((double) ((dx * dx) + (dy * dy))));
    if (time > 0) {
        action.update(-dx, -dy, time, this.mDecelerateInterpolator);
    }
}
项目:letv    文件:GridLayoutManager.java   
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;
}
项目:letv    文件:GridLayoutManager.java   
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;
}
项目:letv    文件:GridLayoutManager.java   
private int getSpanSize(Recycler recycler, State state, int pos) {
    if (!state.isPreLayout()) {
        return this.mSpanSizeLookup.getSpanSize(pos);
    }
    int cached = this.mPreLayoutSpanSizeCache.get(pos, -1);
    if (cached != -1) {
        return cached;
    }
    int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(pos);
    if (adapterPosition != -1) {
        return this.mSpanSizeLookup.getSpanSize(adapterPosition);
    }
    Log.w(TAG, "Cannot find span size for pre layout position. It is not cached, not in the adapter. Pos:" + pos);
    return 1;
}
项目:letv    文件:GridLayoutManager.java   
public View onFocusSearchFailed(View focused, int focusDirection, Recycler recycler, State state) {
    View prevFocusedChild = findContainingItemView(focused);
    if (prevFocusedChild == null) {
        return null;
    }
    LayoutParams lp = (LayoutParams) prevFocusedChild.getLayoutParams();
    int prevSpanStart = lp.mSpanIndex;
    int prevSpanEnd = lp.mSpanIndex + lp.mSpanSize;
    if (super.onFocusSearchFailed(focused, focusDirection, recycler, state) == null) {
        return null;
    }
    int start;
    int inc;
    int limit;
    if ((convertFocusDirectionToLayoutDirection(focusDirection) == 1) != this.mShouldReverseLayout) {
        start = getChildCount() - 1;
        inc = -1;
        limit = -1;
    } else {
        start = 0;
        inc = 1;
        limit = getChildCount();
    }
    boolean preferLastSpan = this.mOrientation == 1 && isLayoutRTL();
    View weakCandidate = null;
    int weakCandidateSpanIndex = -1;
    int weakCandidateOverlap = 0;
    for (int i = start; i != limit; i += inc) {
        View candidate = getChildAt(i);
        if (candidate == prevFocusedChild) {
            break;
        }
        if (candidate.isFocusable()) {
            LayoutParams candidateLp = (LayoutParams) candidate.getLayoutParams();
            int candidateStart = candidateLp.mSpanIndex;
            int candidateEnd = candidateLp.mSpanIndex + candidateLp.mSpanSize;
            if (candidateStart == prevSpanStart && candidateEnd == prevSpanEnd) {
                return candidate;
            }
            boolean assignAsWeek = false;
            if (weakCandidate == null) {
                assignAsWeek = true;
            } else {
                int overlap = Math.min(candidateEnd, prevSpanEnd) - Math.max(candidateStart, prevSpanStart);
                if (overlap > weakCandidateOverlap) {
                    assignAsWeek = true;
                } else if (overlap == weakCandidateOverlap) {
                    if (preferLastSpan == (candidateStart > weakCandidateSpanIndex)) {
                        assignAsWeek = true;
                    }
                }
            }
            if (assignAsWeek) {
                weakCandidate = candidate;
                weakCandidateSpanIndex = candidateLp.mSpanIndex;
                weakCandidateOverlap = Math.min(candidateEnd, prevSpanEnd) - Math.max(candidateStart, prevSpanStart);
            }
        }
    }
    return weakCandidate;
}
项目:boohee_v5.6    文件:GridLayoutManager.java   
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;
}
项目:letv    文件:LinearLayoutManager.java   
private void updateLayoutState(int layoutDirection, int requiredSpace, boolean canUseExistingSpace, State state) {
    LayoutState layoutState;
    int scrollingOffset;
    int i = 1;
    this.mLayoutState.mInfinite = this.mOrientationHelper.getMode() == 0;
    this.mLayoutState.mExtra = getExtraLayoutSpace(state);
    this.mLayoutState.mLayoutDirection = layoutDirection;
    View child;
    if (layoutDirection == 1) {
        layoutState = this.mLayoutState;
        layoutState.mExtra += this.mOrientationHelper.getEndPadding();
        child = getChildClosestToEnd();
        layoutState = this.mLayoutState;
        if (this.mShouldReverseLayout) {
            i = -1;
        }
        layoutState.mItemDirection = i;
        this.mLayoutState.mCurrentPosition = getPosition(child) + this.mLayoutState.mItemDirection;
        this.mLayoutState.mOffset = this.mOrientationHelper.getDecoratedEnd(child);
        scrollingOffset = this.mOrientationHelper.getDecoratedEnd(child) - this.mOrientationHelper.getEndAfterPadding();
    } else {
        child = getChildClosestToStart();
        layoutState = this.mLayoutState;
        layoutState.mExtra += this.mOrientationHelper.getStartAfterPadding();
        layoutState = this.mLayoutState;
        if (!this.mShouldReverseLayout) {
            i = -1;
        }
        layoutState.mItemDirection = i;
        this.mLayoutState.mCurrentPosition = getPosition(child) + this.mLayoutState.mItemDirection;
        this.mLayoutState.mOffset = this.mOrientationHelper.getDecoratedStart(child);
        scrollingOffset = (-this.mOrientationHelper.getDecoratedStart(child)) + this.mOrientationHelper.getStartAfterPadding();
    }
    this.mLayoutState.mAvailable = requiredSpace;
    if (canUseExistingSpace) {
        layoutState = this.mLayoutState;
        layoutState.mAvailable -= scrollingOffset;
    }
    this.mLayoutState.mScrollingOffset = scrollingOffset;
}
项目:letv    文件:StaggeredGridLayoutManager.java   
private int computeScrollExtent(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.computeScrollExtent(state, orientationHelper, findFirstVisibleItemClosestToStart, findFirstVisibleItemClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled);
}
项目:letv    文件:LinearLayoutManager.java   
public View onFocusSearchFailed(View focused, int focusDirection, Recycler recycler, State state) {
    resolveShouldLayoutReverse();
    if (getChildCount() == 0) {
        return null;
    }
    int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
    if (layoutDir == Integer.MIN_VALUE) {
        return null;
    }
    View referenceChild;
    ensureLayoutState();
    if (layoutDir == -1) {
        referenceChild = findReferenceChildClosestToStart(recycler, state);
    } else {
        referenceChild = findReferenceChildClosestToEnd(recycler, state);
    }
    if (referenceChild == null) {
        return null;
    }
    View nextFocus;
    ensureLayoutState();
    updateLayoutState(layoutDir, (int) (MAX_SCROLL_FACTOR * ((float) this.mOrientationHelper.getTotalSpace())), false, state);
    this.mLayoutState.mScrollingOffset = Integer.MIN_VALUE;
    this.mLayoutState.mRecycle = false;
    fill(recycler, this.mLayoutState, state, true);
    if (layoutDir == -1) {
        nextFocus = getChildClosestToStart();
    } else {
        nextFocus = getChildClosestToEnd();
    }
    if (nextFocus == referenceChild || !nextFocus.isFocusable()) {
        return null;
    }
    return nextFocus;
}
项目:letv    文件:StaggeredGridLayoutManager.java   
private int computeScrollRange(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.computeScrollRange(state, orientationHelper, findFirstVisibleItemClosestToStart, findFirstVisibleItemClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled);
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
private int computeScrollExtent(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.computeScrollExtent(state, orientationHelper, findFirstVisibleItemClosestToStart, findFirstVisibleItemClosestToEnd(z, true), this, this.mSmoothScrollbarEnabled);
}
项目:letv    文件:StaggeredGridLayoutManager.java   
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);
            }
        }
    }
}
项目:boohee_v5.6    文件:LinearLayoutManager.java   
private void updateLayoutState(int layoutDirection, int requiredSpace, boolean canUseExistingSpace, State state) {
    LayoutState layoutState;
    int scrollingOffset;
    int i = 1;
    this.mLayoutState.mInfinite = this.mOrientationHelper.getMode() == 0;
    this.mLayoutState.mExtra = getExtraLayoutSpace(state);
    this.mLayoutState.mLayoutDirection = layoutDirection;
    View child;
    if (layoutDirection == 1) {
        layoutState = this.mLayoutState;
        layoutState.mExtra += this.mOrientationHelper.getEndPadding();
        child = getChildClosestToEnd();
        layoutState = this.mLayoutState;
        if (this.mShouldReverseLayout) {
            i = -1;
        }
        layoutState.mItemDirection = i;
        this.mLayoutState.mCurrentPosition = getPosition(child) + this.mLayoutState.mItemDirection;
        this.mLayoutState.mOffset = this.mOrientationHelper.getDecoratedEnd(child);
        scrollingOffset = this.mOrientationHelper.getDecoratedEnd(child) - this.mOrientationHelper.getEndAfterPadding();
    } else {
        child = getChildClosestToStart();
        layoutState = this.mLayoutState;
        layoutState.mExtra += this.mOrientationHelper.getStartAfterPadding();
        layoutState = this.mLayoutState;
        if (!this.mShouldReverseLayout) {
            i = -1;
        }
        layoutState.mItemDirection = i;
        this.mLayoutState.mCurrentPosition = getPosition(child) + this.mLayoutState.mItemDirection;
        this.mLayoutState.mOffset = this.mOrientationHelper.getDecoratedStart(child);
        scrollingOffset = (-this.mOrientationHelper.getDecoratedStart(child)) + this.mOrientationHelper.getStartAfterPadding();
    }
    this.mLayoutState.mAvailable = requiredSpace;
    if (canUseExistingSpace) {
        layoutState = this.mLayoutState;
        layoutState.mAvailable -= scrollingOffset;
    }
    this.mLayoutState.mScrollingOffset = scrollingOffset;
}
项目:letv    文件:LinearLayoutManager.java   
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;
}
项目:letv    文件:StaggeredGridLayoutManager.java   
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;
}
项目:boohee_v5.6    文件:LinearLayoutManager.java   
void layoutChunk(Recycler recycler, State state, LayoutState layoutState, LayoutChunkResult result) {
    View view = layoutState.next(recycler);
    if (view == null) {
        result.mFinished = true;
        return;
    }
    int right;
    int left;
    int bottom;
    int top;
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    if (layoutState.mScrapList == null) {
        if (this.mShouldReverseLayout == (layoutState.mLayoutDirection == -1)) {
            addView(view);
        } else {
            addView(view, 0);
        }
    } else {
        if (this.mShouldReverseLayout == (layoutState.mLayoutDirection == -1)) {
            addDisappearingView(view);
        } else {
            addDisappearingView(view, 0);
        }
    }
    measureChildWithMargins(view, 0, 0);
    result.mConsumed = this.mOrientationHelper.getDecoratedMeasurement(view);
    if (this.mOrientation == 1) {
        if (isLayoutRTL()) {
            right = getWidth() - getPaddingRight();
            left = right - this.mOrientationHelper.getDecoratedMeasurementInOther(view);
        } else {
            left = getPaddingLeft();
            right = left + this.mOrientationHelper.getDecoratedMeasurementInOther(view);
        }
        if (layoutState.mLayoutDirection == -1) {
            bottom = layoutState.mOffset;
            top = layoutState.mOffset - result.mConsumed;
        } else {
            top = layoutState.mOffset;
            bottom = layoutState.mOffset + result.mConsumed;
        }
    } else {
        top = getPaddingTop();
        bottom = top + this.mOrientationHelper.getDecoratedMeasurementInOther(view);
        if (layoutState.mLayoutDirection == -1) {
            right = layoutState.mOffset;
            left = layoutState.mOffset - result.mConsumed;
        } else {
            left = layoutState.mOffset;
            right = layoutState.mOffset + result.mConsumed;
        }
    }
    layoutDecorated(view, left + params.leftMargin, top + params.topMargin, right - params.rightMargin, bottom - params.bottomMargin);
    if (params.isItemRemoved() || params.isItemChanged()) {
        result.mIgnoreConsumed = true;
    }
    result.mFocusable = view.isFocusable();
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
private void fixStartGap(Recycler recycler, State state, boolean canOffsetChildren) {
    int minStartLine = getMinStart(ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED);
    if (minStartLine != ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED) {
        int gap = minStartLine - this.mPrimaryOrientation.getStartAfterPadding();
        if (gap > 0) {
            gap -= scrollBy(gap, recycler, state);
            if (canOffsetChildren && gap > 0) {
                this.mPrimaryOrientation.offsetChildren(-gap);
            }
        }
    }
}
项目:letv    文件:LinearLayoutManager.java   
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;
    }
}
项目:boohee_v5.6    文件:StaggeredGridLayoutManager.java   
public void onInitializeAccessibilityNodeInfoForItem(Recycler recycler, State state, View host, AccessibilityNodeInfoCompat info) {
    android.view.ViewGroup.LayoutParams lp = host.getLayoutParams();
    if (lp instanceof LayoutParams) {
        LayoutParams sglp = (LayoutParams) lp;
        if (this.mOrientation == 0) {
            info.setCollectionItemInfo(CollectionItemInfoCompat.obtain(sglp.getSpanIndex(), sglp.mFullSpan ? this.mSpanCount : 1, -1, -1, sglp.mFullSpan, false));
            return;
        } else {
            info.setCollectionItemInfo(CollectionItemInfoCompat.obtain(-1, -1, sglp.getSpanIndex(), sglp.mFullSpan ? this.mSpanCount : 1, sglp.mFullSpan, false));
            return;
        }
    }
    super.onInitializeAccessibilityNodeInfoForItem(host, info);
}
项目:boohee_v5.6    文件:ScrollbarHelper.java   
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))));
}