Java Code Examples for android.support.v7.widget.RecyclerView.LayoutParams#isItemRemoved()

The following examples show how to use android.support.v7.widget.RecyclerView.LayoutParams#isItemRemoved() . 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: LinearLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
public View nextViewInLimitedList(View ignore) {
    int size = this.mScrapList.size();
    View closest = null;
    int closestDistance = Integer.MAX_VALUE;
    for (int i = 0; i < size; i++) {
        View view = ((ViewHolder) this.mScrapList.get(i)).itemView;
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!(view == ignore || lp.isItemRemoved())) {
            int distance = (lp.getViewLayoutPosition() - this.mCurrentPosition) * this.mItemDirection;
            if (distance >= 0 && distance < closestDistance) {
                closest = view;
                closestDistance = distance;
                if (distance == 0) {
                    break;
                }
            }
        }
    }
    return closest;
}
 
Example 2
Source File: BaseLayoutManager.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
protected void layoutChild(View child, Direction direction) {
    getLaneForChild(mTempLaneInfo, child, direction);

    mLanes.getChildFrame(mChildFrame, getDecoratedMeasuredWidth(child),
            getDecoratedMeasuredHeight(child), mTempLaneInfo, direction);
    final ItemEntry entry = cacheChildFrame(child, mChildFrame);

    layoutDecorated(child, mChildFrame.left, mChildFrame.top, mChildFrame.right,
            mChildFrame.bottom);

    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
    if (!lp.isItemRemoved()) {
        pushChildFrame(entry, mChildFrame, mTempLaneInfo.startLane,
                getLaneSpanForChild(child), direction);
    }
}
 
Example 3
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the next item from the scrap list.
 * <p>
 * Upon finding a valid VH, sets current item position to VH.itemPosition + mItemDirection
 *
 * @return View if an item in the current position or direction exists if not null.
 */
private View nextViewFromScrapList() {
    final int size = mScrapList.size();
    for (int i = 0; i < size; i++) {
        final View view = mScrapList.get(i).itemView;
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (lp.isItemRemoved()) {
            continue;
        }
        if (mCurrentPosition == lp.getViewLayoutPosition()) {
            assignPositionFromScrapList(view);
            return view;
        }
    }
    return null;
}
 
Example 4
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 5 votes vote down vote up
void prependToSpan(View view, OrientationHelperEx helper) {
    LayoutParams lp = getLayoutParams(view);
    mViews.add(0, view);
    mCachedStart = INVALID_LINE;
    if (mViews.size() == 1) {
        mCachedEnd = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize += helper.getDecoratedMeasurement(view);
    }
}
 
Example 5
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 5 votes vote down vote up
void appendToSpan(View view, OrientationHelperEx helper) {
    LayoutParams lp = getLayoutParams(view);
    mViews.add(view);
    mCachedEnd = INVALID_LINE;
    if (mViews.size() == 1) {
        mCachedStart = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize += helper.getDecoratedMeasurement(view);
    }
}
 
Example 6
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 5 votes vote down vote up
void popEnd(OrientationHelperEx helper) {
    final int size = mViews.size();
    View end = mViews.remove(size - 1);
    final LayoutParams lp = getLayoutParams(end);
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize -= helper.getDecoratedMeasurement(end);
    }
    if (size == 1) {
        mCachedStart = INVALID_LINE;
    }
    mCachedEnd = INVALID_LINE;
}
 
Example 7
Source File: StaggeredGridLayoutHelper.java    From vlayout with MIT License 5 votes vote down vote up
void popStart(OrientationHelperEx helper) {
    View start = mViews.remove(0);
    final LayoutParams lp = getLayoutParams(start);
    if (mViews.size() == 0) {
        mCachedEnd = INVALID_LINE;
    }
    if (lp.isItemRemoved() || lp.isItemChanged()) {
        mDeletedSize -= helper.getDecoratedMeasurement(start);
    }
    mCachedStart = INVALID_LINE;
}
 
Example 8
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 5 votes vote down vote up
private View nextViewFromScrapList() {
    int size = this.mScrapList.size();
    for (int i = 0; i < size; i++) {
        View view = ((ViewHolder) this.mScrapList.get(i)).itemView;
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (!lp.isItemRemoved() && this.mCurrentPosition == lp.getViewLayoutPosition()) {
            assignPositionFromScrapList(view);
            return view;
        }
    }
    return null;
}
 
Example 9
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 5 votes vote down vote up
public View nextViewInLimitedList(View ignore) {
    int size = mScrapList.size();
    View closest = null;
    int closestDistance = Integer.MAX_VALUE;
    if (DEBUG && mIsPreLayout) {
        throw new IllegalStateException("Scrap list cannot be used in pre layout");
    }
    for (int i = 0; i < size; i++) {
        View view = mScrapList.get(i).itemView;
        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        if (view == ignore || lp.isItemRemoved()) {
            continue;
        }
        final int distance = (lp.getViewLayoutPosition() - mCurrentPosition) *
                mItemDirection;
        if (distance < 0) {
            continue; // item is not in current direction
        }
        if (distance < closestDistance) {
            closest = view;
            closestDistance = distance;
            if (distance == 0) {
                break;
            }
        }
    }
    return closest;
}
 
Example 10
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 4 votes vote down vote up
private boolean isViewValidAsAnchor(View child, State state) {
    LayoutParams lp = (LayoutParams) child.getLayoutParams();
    return !lp.isItemRemoved() && lp.getViewLayoutPosition() >= 0 && lp.getViewLayoutPosition() < state.getItemCount();
}
 
Example 11
Source File: LinearLayoutManager.java    From letv with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 12
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 4 votes vote down vote up
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state,
        LayoutState layoutState, LayoutChunkResult result) {
    View view = layoutState.next(recycler);
    if (view == null) {
        if (DEBUG && layoutState.mScrapList == null) {
            throw new RuntimeException("received null view when unexpected");
        }
        // if we are laying out views in scrap, this may return null which means there is
        // no more items to layout.
        result.mFinished = true;
        return;
    }
    LayoutParams params = (LayoutParams) view.getLayoutParams();
    if (layoutState.mScrapList == null) {
        if (mShouldReverseLayout == (layoutState.mLayoutDirection
                == LayoutState.LAYOUT_START)) {
            addView(view);
        } else {
            addView(view, 0);
        }
    } else {
        if (mShouldReverseLayout == (layoutState.mLayoutDirection
                == LayoutState.LAYOUT_START)) {
            addDisappearingView(view);
        } else {
            addDisappearingView(view, 0);
        }
    }
    measureChildWithMargins(view, 0, 0);
    result.mConsumed = mOrientationHelper.getDecoratedMeasurement(view);
    int left, top, right, bottom;
    if (mOrientation == VERTICAL) {
        if (isLayoutRTL()) {
            right = getWidth() - getPaddingRight();
            left = right - mOrientationHelper.getDecoratedMeasurementInOther(view);
        } else {
            left = getPaddingLeft();
            right = left + mOrientationHelper.getDecoratedMeasurementInOther(view);
        }
        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            bottom = layoutState.mOffset;
            top = layoutState.mOffset - result.mConsumed;
        } else {
            top = layoutState.mOffset;
            bottom = layoutState.mOffset + result.mConsumed;
        }
    } else {
        top = getPaddingTop();
        bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view);

        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            right = layoutState.mOffset;
            left = layoutState.mOffset - result.mConsumed;
        } else {
            left = layoutState.mOffset;
            right = layoutState.mOffset + result.mConsumed;
        }
    }
    // We calculate everything with View's bounding box (which includes decor and margins)
    // To calculate correct layout position, we subtract margins.
    layoutDecorated(view, left + params.leftMargin, top + params.topMargin,
            right - params.rightMargin, bottom - params.bottomMargin);
    if (DEBUG) {
        Log.d(TAG, "laid out child at position " + getPosition(view) + ", with l:"
                + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:"
                + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin));
    }
    // Consume the available space if the view is not removed OR changed
    if (params.isItemRemoved() || params.isItemChanged()) {
        result.mIgnoreConsumed = true;
    }
    result.mFocusable = view.isFocusable();
}
 
Example 13
Source File: LinearLayoutManager.java    From Mupdf with Apache License 2.0 4 votes vote down vote up
private boolean isViewValidAsAnchor(View child, RecyclerView.State state) {
    LayoutParams lp = (LayoutParams) child.getLayoutParams();
    return !lp.isItemRemoved() && lp.getViewLayoutPosition() >= 0
            && lp.getViewLayoutPosition() < state.getItemCount();
}