类android.support.v7.widget.RecyclerView.Recycler源码实例Demo

下面列出了怎么用android.support.v7.widget.RecyclerView.Recycler的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: letv   文件: 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);
}
 
源代码2 项目: letv   文件: LinearLayoutManager.java
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;
}
 
源代码3 项目: letv   文件: LinearLayoutManager.java
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;
}
 
源代码4 项目: letv   文件: LinearLayoutManager.java
private void recycleViewsFromEnd(Recycler recycler, int dt) {
    int childCount = getChildCount();
    if (dt >= 0) {
        int limit = this.mOrientationHelper.getEnd() - dt;
        int i;
        if (this.mShouldReverseLayout) {
            for (i = 0; i < childCount; i++) {
                if (this.mOrientationHelper.getDecoratedStart(getChildAt(i)) < limit) {
                    recycleChildren(recycler, 0, i);
                    return;
                }
            }
            return;
        }
        for (i = childCount - 1; i >= 0; i--) {
            if (this.mOrientationHelper.getDecoratedStart(getChildAt(i)) < limit) {
                recycleChildren(recycler, childCount - 1, i);
                return;
            }
        }
    }
}
 
源代码5 项目: UltimateAndroid   文件: GridLayoutManager.java
@Override
void moveLayoutToPosition(int position, int offset, Recycler recycler, State state) {
    final Lanes lanes = getLanes();
    lanes.reset(offset);

    getLaneForPosition(mTempLaneInfo, position, Direction.END);
    final int lane = mTempLaneInfo.startLane;
    if (lane == 0) {
        return;
    }

    final View child = recycler.getViewForPosition(position);
    measureChild(child, Direction.END);

    final int dimension =
            (isVertical() ? getDecoratedMeasuredHeight(child) : getDecoratedMeasuredWidth(child));

    for (int i = lane - 1; i >= 0; i--) {
        lanes.offset(i, dimension);
    }
}
 
源代码6 项目: ticdesign   文件: FocusableLinearLayoutManager.java
@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);
        }
    }
}
 
源代码7 项目: adt-leanback-support   文件: GridLayoutManager.java
@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;
}
 
源代码8 项目: vlayout   文件: 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);
}
 
源代码9 项目: vlayout   文件: RangeGridLayoutHelper.java
private int getSpanSize(SpanSizeLookup spanSizeLookup, RecyclerView.Recycler recycler, RecyclerView.State state, int pos) {
    if (!state.isPreLayout()) {
        return spanSizeLookup.getSpanSize(pos);
    }

    final int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(pos);
    if (adapterPosition == -1) {
        return 0;
    }

    return spanSizeLookup.getSpanSize(adapterPosition);
}
 
源代码10 项目: vlayout   文件: 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;
    }
}
 
源代码11 项目: vlayout   文件: AbstractFullFillLayoutHelper.java
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state,
                        LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
    mTempLayoutHelper = helper;

    doLayoutView(recycler, state, layoutState, result, helper);

    mTempLayoutHelper = null;
}
 
源代码12 项目: UltimateAndroid   文件: TwoWayLayoutManager.java
@Override
public int scrollHorizontallyBy(int dx, Recycler recycler, State state) {
    if (mIsVertical) {
        return 0;
    }

    return scrollBy(dx, recycler, state);
}
 
源代码13 项目: 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;
}
 
源代码14 项目: letv   文件: GridLayoutManager.java
public int getColumnCountForAccessibility(Recycler recycler, State state) {
    if (this.mOrientation == 1) {
        return this.mSpanCount;
    }
    if (state.getItemCount() < 1) {
        return 0;
    }
    return getSpanGroupIndex(recycler, state, state.getItemCount() - 1) + 1;
}
 
源代码15 项目: letv   文件: GridLayoutManager.java
public void onLayoutChildren(Recycler recycler, State state) {
    if (state.isPreLayout()) {
        cachePreLayoutSpanMapping();
    }
    super.onLayoutChildren(recycler, state);
    clearPreLayoutSpanMappingCache();
    if (!state.isPreLayout()) {
        this.mPendingSpanCountChange = false;
    }
}
 
源代码16 项目: letv   文件: GridLayoutManager.java
void onAnchorReady(Recycler recycler, State state, AnchorInfo anchorInfo, int itemDirection) {
    super.onAnchorReady(recycler, state, anchorInfo, itemDirection);
    updateMeasurements();
    if (state.getItemCount() > 0 && !state.isPreLayout()) {
        ensureAnchorIsInCorrectSpan(recycler, state, anchorInfo, itemDirection);
    }
    ensureViewSet();
}
 
源代码17 项目: UltimateAndroid   文件: BaseLayoutManager.java
@Override
public void onLayoutChildren(Recycler recycler, State state) {
    final boolean restoringLanes = (mLanesToRestore != null);
    if (restoringLanes) {
        mLanes = mLanesToRestore;
        mItemEntries = mItemEntriesToRestore;

        mLanesToRestore = null;
        mItemEntriesToRestore = null;
    }

    final boolean refreshingLanes = ensureLayoutState();

    // Still not able to create lanes, nothing we can do here,
    // just bail for now.
    if (mLanes == null) {
        return;
    }

    final int itemCount = state.getItemCount();
    mItemEntries.setAdapterSize(itemCount);

    final int anchorItemPosition = getAnchorItemPosition(state);

    // Only move layout if we're not restoring a layout state.
    if (anchorItemPosition > 0 && (refreshingLanes || !restoringLanes)) {
        moveLayoutToPosition(anchorItemPosition, getPendingScrollOffset(), recycler, state);
    }

    mLanes.reset(Direction.START);

    super.onLayoutChildren(recycler, state);
}
 
源代码18 项目: 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;
}
 
源代码19 项目: letv   文件: GridLayoutManager.java
private int getSpanGroupIndex(Recycler recycler, State state, int viewPosition) {
    if (!state.isPreLayout()) {
        return this.mSpanSizeLookup.getSpanGroupIndex(viewPosition, this.mSpanCount);
    }
    int adapterPosition = recycler.convertPreLayoutPositionToPostLayout(viewPosition);
    if (adapterPosition != -1) {
        return this.mSpanSizeLookup.getSpanGroupIndex(adapterPosition, this.mSpanCount);
    }
    Log.w(TAG, "Cannot find span size for pre layout position. " + viewPosition);
    return 0;
}
 
源代码20 项目: 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;
}
 
源代码21 项目: 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;
}
 
源代码22 项目: letv   文件: GridLayoutManager.java
private void assignSpans(Recycler recycler, State state, int count, int consumedSpanCount, boolean layingOutInPrimaryDirection) {
    int start;
    int end;
    int diff;
    int span;
    int spanDiff;
    if (layingOutInPrimaryDirection) {
        start = 0;
        end = count;
        diff = 1;
    } else {
        start = count - 1;
        end = -1;
        diff = -1;
    }
    if (this.mOrientation == 1 && isLayoutRTL()) {
        span = this.mSpanCount - 1;
        spanDiff = -1;
    } else {
        span = 0;
        spanDiff = 1;
    }
    for (int i = start; i != end; i += diff) {
        View view = this.mSet[i];
        LayoutParams params = (LayoutParams) view.getLayoutParams();
        params.mSpanSize = getSpanSize(recycler, state, getPosition(view));
        if (spanDiff != -1 || params.mSpanSize <= 1) {
            params.mSpanIndex = span;
        } else {
            params.mSpanIndex = span - (params.mSpanSize - 1);
        }
        span += params.mSpanSize * spanDiff;
    }
}
 
源代码23 项目: letv   文件: 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);
}
 
源代码24 项目: 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);
            }
        }
    }
}
 
源代码25 项目: letv   文件: StaggeredGridLayoutManager.java
private void recycle(Recycler recycler, LayoutState layoutState) {
    if (layoutState.mRecycle && !layoutState.mInfinite) {
        if (layoutState.mAvailable == 0) {
            if (layoutState.mLayoutDirection == -1) {
                recycleFromEnd(recycler, layoutState.mEndLine);
            } else {
                recycleFromStart(recycler, layoutState.mStartLine);
            }
        } else if (layoutState.mLayoutDirection == -1) {
            scrolled = layoutState.mStartLine - getMaxStart(layoutState.mStartLine);
            if (scrolled < 0) {
                line = layoutState.mEndLine;
            } else {
                line = layoutState.mEndLine - Math.min(scrolled, layoutState.mAvailable);
            }
            recycleFromEnd(recycler, line);
        } else {
            scrolled = getMinEnd(layoutState.mEndLine) - layoutState.mEndLine;
            if (scrolled < 0) {
                line = layoutState.mStartLine;
            } else {
                line = layoutState.mStartLine + Math.min(scrolled, layoutState.mAvailable);
            }
            recycleFromStart(recycler, line);
        }
    }
}
 
源代码26 项目: letv   文件: StaggeredGridLayoutManager.java
private void recycleFromStart(Recycler recycler, int line) {
    while (getChildCount() > 0) {
        View child = getChildAt(0);
        if (this.mPrimaryOrientation.getDecoratedEnd(child) <= line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mFullSpan) {
                int j = 0;
                while (j < this.mSpanCount) {
                    if (this.mSpans[j].mViews.size() != 1) {
                        j++;
                    } else {
                        return;
                    }
                }
                for (j = 0; j < this.mSpanCount; j++) {
                    this.mSpans[j].popStart();
                }
            } else if (lp.mSpan.mViews.size() != 1) {
                lp.mSpan.popStart();
            } else {
                return;
            }
            removeAndRecycleView(child, recycler);
        } else {
            return;
        }
    }
}
 
源代码27 项目: letv   文件: StaggeredGridLayoutManager.java
private void recycleFromEnd(Recycler recycler, int line) {
    int i = getChildCount() - 1;
    while (i >= 0) {
        View child = getChildAt(i);
        if (this.mPrimaryOrientation.getDecoratedStart(child) >= line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp.mFullSpan) {
                int j = 0;
                while (j < this.mSpanCount) {
                    if (this.mSpans[j].mViews.size() != 1) {
                        j++;
                    } else {
                        return;
                    }
                }
                for (j = 0; j < this.mSpanCount; j++) {
                    this.mSpans[j].popEnd();
                }
            } else if (lp.mSpan.mViews.size() != 1) {
                lp.mSpan.popEnd();
            } else {
                return;
            }
            removeAndRecycleView(child, recycler);
            i--;
        } else {
            return;
        }
    }
}
 
源代码28 项目: 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;
}
 
源代码29 项目: letv   文件: LinearLayoutManager.java
View next(Recycler recycler) {
    if (this.mScrapList != null) {
        return nextViewFromScrapList();
    }
    View view = recycler.getViewForPosition(this.mCurrentPosition);
    this.mCurrentPosition += this.mItemDirection;
    return view;
}
 
源代码30 项目: letv   文件: LinearLayoutManager.java
public void onDetachedFromWindow(RecyclerView view, Recycler recycler) {
    super.onDetachedFromWindow(view, recycler);
    if (this.mRecycleChildrenOnDetach) {
        removeAndRecycleAllViews(recycler);
        recycler.clear();
    }
}
 
 同包方法