Java Code Examples for android.support.v7.widget.RecyclerView.State#isPreLayout()
The following examples show how to use
android.support.v7.widget.RecyclerView.State#isPreLayout() .
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: GridLayoutManager.java From letv with Apache License 2.0 | 5 votes |
public void onLayoutChildren(Recycler recycler, State state) { if (state.isPreLayout()) { cachePreLayoutSpanMapping(); } super.onLayoutChildren(recycler, state); clearPreLayoutSpanMappingCache(); if (!state.isPreLayout()) { this.mPendingSpanCountChange = false; } }
Example 2
Source File: GridLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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(); }
Example 3
Source File: GridLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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; }
Example 4
Source File: GridLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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 5
Source File: GridLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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; }
Example 6
Source File: LinearLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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 7
Source File: LinearLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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; } }
Example 8
Source File: LinearLayoutManager.java From letv with Apache License 2.0 | 5 votes |
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 9
Source File: TwoWayLayoutManager.java From UltimateAndroid with Apache License 2.0 | 5 votes |
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 10
Source File: StaggeredGridLayoutManager.java From letv with Apache License 2.0 | 4 votes |
private void onLayoutChildren(Recycler recycler, State state, boolean shouldCheckForGaps) { boolean needToCheckForGaps = true; ensureOrientationHelper(); AnchorInfo anchorInfo = this.mAnchorInfo; anchorInfo.reset(); if (!(this.mPendingSavedState == null && this.mPendingScrollPosition == -1) && state.getItemCount() == 0) { removeAndRecycleAllViews(recycler); return; } if (this.mPendingSavedState != null) { applyPendingSavedState(anchorInfo); } else { resolveShouldLayoutReverse(); anchorInfo.mLayoutFromEnd = this.mShouldReverseLayout; } updateAnchorInfoForLayout(state, anchorInfo); if (this.mPendingSavedState == null && !(anchorInfo.mLayoutFromEnd == this.mLastLayoutFromEnd && isLayoutRTL() == this.mLastLayoutRTL)) { this.mLazySpanLookup.clear(); anchorInfo.mInvalidateOffsets = true; } if (getChildCount() > 0 && (this.mPendingSavedState == null || this.mPendingSavedState.mSpanOffsetsSize < 1)) { int i; if (anchorInfo.mInvalidateOffsets) { for (i = 0; i < this.mSpanCount; i++) { this.mSpans[i].clear(); if (anchorInfo.mOffset != Integer.MIN_VALUE) { this.mSpans[i].setLine(anchorInfo.mOffset); } } } else { for (i = 0; i < this.mSpanCount; i++) { this.mSpans[i].cacheReferenceLineAndClear(this.mShouldReverseLayout, anchorInfo.mOffset); } } } detachAndScrapAttachedViews(recycler); this.mLayoutState.mRecycle = false; this.mLaidOutInvalidFullSpan = false; updateMeasureSpecs(this.mSecondaryOrientation.getTotalSpace()); updateLayoutState(anchorInfo.mPosition, state); if (anchorInfo.mLayoutFromEnd) { setLayoutStateDirection(-1); fill(recycler, this.mLayoutState, state); setLayoutStateDirection(1); this.mLayoutState.mCurrentPosition = anchorInfo.mPosition + this.mLayoutState.mItemDirection; fill(recycler, this.mLayoutState, state); } else { setLayoutStateDirection(1); fill(recycler, this.mLayoutState, state); setLayoutStateDirection(-1); this.mLayoutState.mCurrentPosition = anchorInfo.mPosition + this.mLayoutState.mItemDirection; fill(recycler, this.mLayoutState, state); } repositionToWrapContentIfNecessary(); if (getChildCount() > 0) { if (this.mShouldReverseLayout) { fixEndGap(recycler, state, true); fixStartGap(recycler, state, false); } else { fixStartGap(recycler, state, true); fixEndGap(recycler, state, false); } } boolean hasGaps = false; if (shouldCheckForGaps && !state.isPreLayout()) { if (this.mGapStrategy == 0 || getChildCount() <= 0 || (!this.mLaidOutInvalidFullSpan && hasGapsToFix() == null)) { needToCheckForGaps = false; } if (needToCheckForGaps) { removeCallbacks(this.mCheckForGapsRunnable); if (checkForGaps()) { hasGaps = true; } } this.mPendingScrollPosition = -1; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; } this.mLastLayoutFromEnd = anchorInfo.mLayoutFromEnd; this.mLastLayoutRTL = isLayoutRTL(); this.mPendingSavedState = null; if (hasGaps) { onLayoutChildren(recycler, state, false); } }
Example 11
Source File: StaggeredGridLayoutManager.java From letv with Apache License 2.0 | 4 votes |
boolean updateAnchorFromPendingData(State state, AnchorInfo anchorInfo) { boolean z = false; if (state.isPreLayout() || this.mPendingScrollPosition == -1) { return false; } if (this.mPendingScrollPosition < 0 || this.mPendingScrollPosition >= state.getItemCount()) { this.mPendingScrollPosition = -1; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; return false; } else if (this.mPendingSavedState == null || this.mPendingSavedState.mAnchorPosition == -1 || this.mPendingSavedState.mSpanOffsetsSize < 1) { View child = findViewByPosition(this.mPendingScrollPosition); if (child != null) { anchorInfo.mPosition = this.mShouldReverseLayout ? getLastChildPosition() : getFirstChildPosition(); if (this.mPendingScrollPositionOffset != Integer.MIN_VALUE) { if (anchorInfo.mLayoutFromEnd) { anchorInfo.mOffset = (this.mPrimaryOrientation.getEndAfterPadding() - this.mPendingScrollPositionOffset) - this.mPrimaryOrientation.getDecoratedEnd(child); return true; } anchorInfo.mOffset = (this.mPrimaryOrientation.getStartAfterPadding() + this.mPendingScrollPositionOffset) - this.mPrimaryOrientation.getDecoratedStart(child); return true; } else if (this.mPrimaryOrientation.getDecoratedMeasurement(child) > this.mPrimaryOrientation.getTotalSpace()) { anchorInfo.mOffset = anchorInfo.mLayoutFromEnd ? this.mPrimaryOrientation.getEndAfterPadding() : this.mPrimaryOrientation.getStartAfterPadding(); return true; } else { int startGap = this.mPrimaryOrientation.getDecoratedStart(child) - this.mPrimaryOrientation.getStartAfterPadding(); if (startGap < 0) { anchorInfo.mOffset = -startGap; return true; } int endGap = this.mPrimaryOrientation.getEndAfterPadding() - this.mPrimaryOrientation.getDecoratedEnd(child); if (endGap < 0) { anchorInfo.mOffset = endGap; return true; } anchorInfo.mOffset = Integer.MIN_VALUE; return true; } } anchorInfo.mPosition = this.mPendingScrollPosition; if (this.mPendingScrollPositionOffset == Integer.MIN_VALUE) { if (calculateScrollDirectionForPosition(anchorInfo.mPosition) == 1) { z = true; } anchorInfo.mLayoutFromEnd = z; anchorInfo.assignCoordinateFromPadding(); } else { anchorInfo.assignCoordinateFromPadding(this.mPendingScrollPositionOffset); } anchorInfo.mInvalidateOffsets = true; return true; } else { anchorInfo.mOffset = Integer.MIN_VALUE; anchorInfo.mPosition = this.mPendingScrollPosition; return true; } }
Example 12
Source File: LinearLayoutManager.java From letv with Apache License 2.0 | 4 votes |
private boolean updateAnchorFromPendingData(State state, AnchorInfo anchorInfo) { boolean z = false; if (state.isPreLayout() || this.mPendingScrollPosition == -1) { return false; } if (this.mPendingScrollPosition < 0 || this.mPendingScrollPosition >= state.getItemCount()) { this.mPendingScrollPosition = -1; this.mPendingScrollPositionOffset = Integer.MIN_VALUE; return false; } anchorInfo.mPosition = this.mPendingScrollPosition; if (this.mPendingSavedState != null && this.mPendingSavedState.hasValidAnchor()) { anchorInfo.mLayoutFromEnd = this.mPendingSavedState.mAnchorLayoutFromEnd; if (anchorInfo.mLayoutFromEnd) { anchorInfo.mCoordinate = this.mOrientationHelper.getEndAfterPadding() - this.mPendingSavedState.mAnchorOffset; return true; } anchorInfo.mCoordinate = this.mOrientationHelper.getStartAfterPadding() + this.mPendingSavedState.mAnchorOffset; return true; } else if (this.mPendingScrollPositionOffset == Integer.MIN_VALUE) { View child = findViewByPosition(this.mPendingScrollPosition); if (child == null) { if (getChildCount() > 0) { boolean z2; if (this.mPendingScrollPosition < getPosition(getChildAt(0))) { z2 = true; } else { z2 = false; } if (z2 == this.mShouldReverseLayout) { z = true; } anchorInfo.mLayoutFromEnd = z; } anchorInfo.assignCoordinateFromPadding(); return true; } else if (this.mOrientationHelper.getDecoratedMeasurement(child) > this.mOrientationHelper.getTotalSpace()) { anchorInfo.assignCoordinateFromPadding(); return true; } else if (this.mOrientationHelper.getDecoratedStart(child) - this.mOrientationHelper.getStartAfterPadding() < 0) { anchorInfo.mCoordinate = this.mOrientationHelper.getStartAfterPadding(); anchorInfo.mLayoutFromEnd = false; return true; } else if (this.mOrientationHelper.getEndAfterPadding() - this.mOrientationHelper.getDecoratedEnd(child) < 0) { anchorInfo.mCoordinate = this.mOrientationHelper.getEndAfterPadding(); anchorInfo.mLayoutFromEnd = true; return true; } else { anchorInfo.mCoordinate = anchorInfo.mLayoutFromEnd ? this.mOrientationHelper.getDecoratedEnd(child) + this.mOrientationHelper.getTotalSpaceChange() : this.mOrientationHelper.getDecoratedStart(child); return true; } } else { anchorInfo.mLayoutFromEnd = this.mShouldReverseLayout; if (this.mShouldReverseLayout) { anchorInfo.mCoordinate = this.mOrientationHelper.getEndAfterPadding() - this.mPendingScrollPositionOffset; return true; } anchorInfo.mCoordinate = this.mOrientationHelper.getStartAfterPadding() + this.mPendingScrollPositionOffset; return true; } }