Example usage for android.view View isFocusable

List of usage examples for android.view View isFocusable

Introduction

In this page you can find the example usage for android.view View isFocusable.

Prototype

@ViewDebug.ExportedProperty(category = "focus")
public final boolean isFocusable() 

Source Link

Document

Returns whether this View is currently able to take focus.

Usage

From source file:com.alibaba.android.layoutmanager.ExposeLinearLayoutManagerEx.java

protected void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        com.alibaba.android.layoutmanager.layoutmanager.LayoutChunkResult result) {
    View view = layoutState.next(recycler);
    if (view == null) {
        if (DEBUG && layoutState.mScrapList == null) {
            throw new RuntimeException("received null view when unexpected");
        }//  w w  w  .j  av  a2 s .c  o  m
        // 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;
    }
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
    if (layoutState.mScrapList == null) {
        // can not find in scrapList
        if (mShouldReverseLayoutExpose == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) {
            addView(view);
        } else {
            addView(view, 0);
        }
    } else {
        if (mShouldReverseLayoutExpose == (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 (getOrientation() == 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);

        // whether this layout pass is layout form start to end or in reverse
        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();
}

From source file:com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx.java

protected void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        com.alibaba.android.vlayout.layout.LayoutChunkResult result) {
    View view = layoutState.next(recycler);
    if (view == null) {
        if (DEBUG && layoutState.mScrapList == null) {
            throw new RuntimeException("received null view when unexpected");
        }//from www .j  av a  2s . com
        // 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;
    }
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
    if (layoutState.mScrapList == null) {
        // can not find in scrapList
        if (mShouldReverseLayoutExpose == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) {
            addView(view);
        } else {
            addView(view, 0);
        }
    } else {
        if (mShouldReverseLayoutExpose == (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 (getOrientation() == 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);

        // whether this layout pass is layout form start to end or in reverse
        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();
}

From source file:android.support.v7.widget.ChatLinearLayoutManager.java

void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {//from w ww  . jav  a 2s.  co  m
    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;
    }
    RecyclerView.LayoutParams params = (RecyclerView.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();
}

From source file:cn.ismartv.tvrecyclerview.widget.LinearLayoutManager.java

void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {/*from www .j ava  2  s.  c o  m*/
    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.
    layoutDecoratedWithMargins(view, left, top, right, bottom);
    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();
}

From source file:com.example.administrator.myapplication.recyclerview.CardLayoutManager1.java

void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {/*from  w  ww  .  ja v a2s  .  c o  m*/
    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, top, right, bottom);
    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();
}

From source file:android.support.v7.widget.LinearLayoutManager.java

/**
 * The magic functions :). Fills the given layout, defined by the renderState. This is fairly
 * independent from the rest of the {@link android.support.v7.widget.LinearLayoutManager}
 * and with little change, can be made publicly available as a helper class.
 *
 * @param recycler        Current recycler that is attached to RecyclerView
 * @param renderState     Configuration on how we should fill out the available space.
 * @param state           Context passed by the RecyclerView to control scroll steps.
 * @param stopOnFocusable If true, filling stops in the first focusable new child
 * @return Number of pixels that it added. Useful for scoll functions.
 */// w  w w . jav  a  2 s  .c om
private int fill(RecyclerView.Recycler recycler, RenderState renderState, RecyclerView.State state,
        boolean stopOnFocusable) {
    // max offset we should set is mFastScroll + available
    final int start = renderState.mAvailable;
    if (renderState.mScrollingOffset != RenderState.SCOLLING_OFFSET_NaN) {
        // TODO ugly bug fix. should not happen
        if (renderState.mAvailable < 0) {
            renderState.mScrollingOffset += renderState.mAvailable;
        }
        recycleByRenderState(recycler, renderState);
    }
    int remainingSpace = renderState.mAvailable + renderState.mExtra;
    while (remainingSpace > 0 && renderState.hasMore(state)) {
        View view = renderState.next(recycler);
        if (view == null) {
            if (DEBUG && renderState.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.
            break;
        }
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        if (!params.isItemRemoved() && mRenderState.mScrapList == null) {
            if (mShouldReverseLayout == (renderState.mLayoutDirection == RenderState.LAYOUT_START)) {
                addView(view);
            } else {
                addView(view, 0);
            }
        }
        measureChildWithMargins(view, 0, 0);
        int consumed = 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 (renderState.mLayoutDirection == RenderState.LAYOUT_START) {
                bottom = renderState.mOffset;
                top = renderState.mOffset - consumed;
            } else {
                top = renderState.mOffset;
                bottom = renderState.mOffset + consumed;
            }
        } else {
            top = getPaddingTop();
            bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view);

            if (renderState.mLayoutDirection == RenderState.LAYOUT_START) {
                right = renderState.mOffset;
                left = renderState.mOffset - consumed;
            } else {
                left = renderState.mOffset;
                right = renderState.mOffset + consumed;
            }
        }
        // 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));
        }
        renderState.mOffset += consumed * renderState.mLayoutDirection;

        if (!params.isItemRemoved()) {
            renderState.mAvailable -= consumed;
            // we keep a separate remaining space because mAvailable is important for recycling
            remainingSpace -= consumed;
        }

        if (renderState.mScrollingOffset != RenderState.SCOLLING_OFFSET_NaN) {
            renderState.mScrollingOffset += consumed;
            if (renderState.mAvailable < 0) {
                renderState.mScrollingOffset += renderState.mAvailable;
            }
            recycleByRenderState(recycler, renderState);
        }
        if (stopOnFocusable && view.isFocusable()) {
            break;
        }

        if (state != null && state.getTargetScrollPosition() == getPosition(view)) {
            break;
        }
    }
    if (DEBUG) {
        validateChildOrder();
    }
    return start - renderState.mAvailable;
}

From source file:cn.ismartv.recyclerview.widget.LinearLayoutManager.java

void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {//from w w  w .ja va  2 s.  co m
    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();
}

From source file:android.support.v71.widget.LinearLayoutManager.java

void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {/* w  ww  .ja v a 2 s  .co  m*/
    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.
    // ?
    //TODO  ?View ?
    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();
}

From source file:android.support.v7.widget.GridLayoutManager.java

@Override
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {//  www  .ja  v  a  2s  . co  m
    final boolean layingOutInPrimaryDirection = layoutState.mItemDirection == LayoutState.ITEM_DIRECTION_TAIL;
    int count = 0;
    int consumedSpanCount = 0;
    int remainingSpan = mSpanCount;
    if (!layingOutInPrimaryDirection) {
        int itemSpanIndex = getSpanIndex(recycler, state, layoutState.mCurrentPosition);
        int itemSpanSize = getSpanSize(recycler, state, layoutState.mCurrentPosition);
        remainingSpan = itemSpanIndex + itemSpanSize;
    }
    while (count < mSpanCount && layoutState.hasMore(state) && remainingSpan > 0) {
        int pos = layoutState.mCurrentPosition;
        final int spanSize = getSpanSize(recycler, state, pos);
        if (spanSize > mSpanCount) {
            throw new IllegalArgumentException("Item at position " + pos + " requires " + spanSize
                    + " spans but GridLayoutManager has only " + mSpanCount + " spans.");
        }
        remainingSpan -= spanSize;
        if (remainingSpan < 0) {
            break; // item did not fit into this row or column
        }
        View view = layoutState.next(recycler);
        if (view == null) {
            break;
        }
        consumedSpanCount += spanSize;
        mSet[count] = view;
        count++;
    }

    if (count == 0) {
        result.mFinished = true;
        return;
    }

    int maxSize = 0;

    // we should assign spans before item decor offsets are calculated
    assignSpans(recycler, state, count, consumedSpanCount, layingOutInPrimaryDirection);
    for (int i = 0; i < count; i++) {
        View view = mSet[i];
        if (layoutState.mScrapList == null) {
            if (layingOutInPrimaryDirection) {
                addView(view);
            } else {
                addView(view, 0);
            }
        } else {
            if (layingOutInPrimaryDirection) {
                addDisappearingView(view);
            } else {
                addDisappearingView(view, 0);
            }
        }

        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        final int spec = View.MeasureSpec.makeMeasureSpec(
                mCachedBorders[lp.mSpanIndex + lp.mSpanSize] - mCachedBorders[lp.mSpanIndex],
                View.MeasureSpec.EXACTLY);
        if (mOrientation == VERTICAL) {
            measureChildWithDecorationsAndMargin(view, spec, getMainDirSpec(lp.height));
        } else {
            measureChildWithDecorationsAndMargin(view, getMainDirSpec(lp.width), spec);
        }
        final int size = mOrientationHelper.getDecoratedMeasurement(view);
        if (size > maxSize) {
            maxSize = size;
        }
    }

    // views that did not measure the maxSize has to be re-measured
    final int maxMeasureSpec = getMainDirSpec(maxSize);
    for (int i = 0; i < count; i++) {
        final View view = mSet[i];
        if (mOrientationHelper.getDecoratedMeasurement(view) != maxSize) {
            final LayoutParams lp = (LayoutParams) view.getLayoutParams();
            final int spec = View.MeasureSpec.makeMeasureSpec(
                    mCachedBorders[lp.mSpanIndex + lp.mSpanSize] - mCachedBorders[lp.mSpanIndex],
                    View.MeasureSpec.EXACTLY);
            if (mOrientation == VERTICAL) {
                measureChildWithDecorationsAndMargin(view, spec, maxMeasureSpec);
            } else {
                measureChildWithDecorationsAndMargin(view, maxMeasureSpec, spec);
            }
        }
    }

    result.mConsumed = maxSize;

    int left = 0, right = 0, top = 0, bottom = 0;
    if (mOrientation == VERTICAL) {
        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            bottom = layoutState.mOffset;
            top = bottom - maxSize;
        } else {
            top = layoutState.mOffset;
            bottom = top + maxSize;
        }
    } else {
        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            right = layoutState.mOffset;
            left = right - maxSize;
        } else {
            left = layoutState.mOffset;
            right = left + maxSize;
        }
    }
    for (int i = 0; i < count; i++) {
        View view = mSet[i];
        LayoutParams params = (LayoutParams) view.getLayoutParams();
        if (mOrientation == VERTICAL) {
            left = getPaddingLeft() + mCachedBorders[params.mSpanIndex];
            right = left + mOrientationHelper.getDecoratedMeasurementInOther(view);
        } else {
            top = getPaddingTop() + mCachedBorders[params.mSpanIndex];
            bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view);
        }
        // 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) + ", span:" + params.mSpanIndex + ", spanSize:"
                            + params.mSpanSize);
        }
        // Consume the available space if the view is not removed OR changed
        if (params.isItemRemoved() || params.isItemChanged()) {
            result.mIgnoreConsumed = true;
        }
        result.mFocusable |= view.isFocusable();
    }
    Arrays.fill(mSet, null);
}

From source file:android.support.v71.widget.GridLayoutManager.java

@Override
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutState layoutState,
        LayoutChunkResult result) {/*ww w  . j a  v a2s  .  c  o  m*/
    final boolean layingOutInPrimaryDirection = layoutState.mItemDirection == LayoutState.ITEM_DIRECTION_TAIL;
    int count = 0;
    int consumedSpanCount = 0;
    int remainingSpan = mSpanCount;
    if (!layingOutInPrimaryDirection) {
        int itemSpanIndex = getSpanIndex(recycler, state, layoutState.mCurrentPosition);
        int itemSpanSize = getSpanSize(recycler, state, layoutState.mCurrentPosition);
        remainingSpan = itemSpanIndex + itemSpanSize;
    }
    while (count < mSpanCount && layoutState.hasMore(state) && remainingSpan > 0) {
        int pos = layoutState.mCurrentPosition;
        final int spanSize = getSpanSize(recycler, state, pos);
        if (spanSize > mSpanCount) {
            throw new IllegalArgumentException("Item at position " + pos + " requires " + spanSize
                    + " spans but GridLayoutManager has only " + mSpanCount + " spans.");
        }
        remainingSpan -= spanSize;
        if (remainingSpan < 0) {
            break; // item did not fit into this row or column
        }
        View view = layoutState.next(recycler);
        if (view == null) {
            break;
        }
        consumedSpanCount += spanSize;
        mSet[count] = view;
        count++;
    }

    if (count == 0) {
        result.mFinished = true;
        return;
    }

    int maxSize = 0;

    // we should assign spans before item decor offsets are calculated
    assignSpans(recycler, state, count, consumedSpanCount, layingOutInPrimaryDirection);
    for (int i = 0; i < count; i++) {
        View view = mSet[i];
        if (layoutState.mScrapList == null) {
            if (layingOutInPrimaryDirection) {
                addView(view);
            } else {
                addView(view, 0);
            }
        } else {
            if (layingOutInPrimaryDirection) {
                addDisappearingView(view);
            } else {
                addDisappearingView(view, 0);
            }
        }

        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
        final int spec = View.MeasureSpec.makeMeasureSpec(
                mCachedBorders[lp.mSpanIndex + lp.mSpanSize] - mCachedBorders[lp.mSpanIndex],
                View.MeasureSpec.EXACTLY);
        if (mOrientation == VERTICAL) {
            measureChildWithDecorationsAndMargin(view, spec, getMainDirSpec(lp.height), false);
        } else {
            measureChildWithDecorationsAndMargin(view, getMainDirSpec(lp.width), spec, false);
        }
        final int size = mOrientationHelper.getDecoratedMeasurement(view);
        if (size > maxSize) {
            maxSize = size;
        }
    }

    // views that did not measure the maxSize has to be re-measured
    final int maxMeasureSpec = getMainDirSpec(maxSize);
    for (int i = 0; i < count; i++) {
        final View view = mSet[i];
        if (mOrientationHelper.getDecoratedMeasurement(view) != maxSize) {
            final LayoutParams lp = (LayoutParams) view.getLayoutParams();
            final int spec = View.MeasureSpec.makeMeasureSpec(
                    mCachedBorders[lp.mSpanIndex + lp.mSpanSize] - mCachedBorders[lp.mSpanIndex],
                    View.MeasureSpec.EXACTLY);
            if (mOrientation == VERTICAL) {
                measureChildWithDecorationsAndMargin(view, spec, maxMeasureSpec, true);
            } else {
                measureChildWithDecorationsAndMargin(view, maxMeasureSpec, spec, true);
            }
        }
    }

    result.mConsumed = maxSize;

    int left = 0, right = 0, top = 0, bottom = 0;
    if (mOrientation == VERTICAL) {
        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            bottom = layoutState.mOffset;
            top = bottom - maxSize;
        } else {
            top = layoutState.mOffset;
            bottom = top + maxSize;
        }
    } else {
        if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
            right = layoutState.mOffset;
            left = right - maxSize;
        } else {
            left = layoutState.mOffset;
            right = left + maxSize;
        }
    }
    for (int i = 0; i < count; i++) {
        View view = mSet[i];
        LayoutParams params = (LayoutParams) view.getLayoutParams();
        if (mOrientation == VERTICAL) {
            left = getPaddingLeft() + mCachedBorders[params.mSpanIndex];
            right = left + mOrientationHelper.getDecoratedMeasurementInOther(view);
        } else {
            top = getPaddingTop() + mCachedBorders[params.mSpanIndex];
            bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view);
        }
        // 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) + ", span:" + params.mSpanIndex + ", spanSize:"
                            + params.mSpanSize);
        }
        // Consume the available space if the view is not removed OR changed
        if (params.isItemRemoved() || params.isItemChanged()) {
            result.mIgnoreConsumed = true;
        }
        result.mFocusable |= view.isFocusable();
    }
    Arrays.fill(mSet, null);
}