Search in sources :

Example 66 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method getAnchorAtStart.

/**
     * Get the first view in the section that intersects the start edge. Only returns the header if
     * it is the last one displayed.
     *
     * @return View in section at start edge.
     */
private View getAnchorAtStart() {
    View child = getChildAt(0);
    LayoutParams params = (LayoutParams) child.getLayoutParams();
    int sfp = params.getTestedFirstPosition();
    if (!params.isHeader) {
        return child;
    }
    int i = 1;
    if (i < getChildCount()) {
        View candidate = getChildAt(i);
        LayoutParams candidateParams = (LayoutParams) candidate.getLayoutParams();
        if (candidateParams.getTestedFirstPosition() == sfp) {
            return candidate;
        }
    }
    return child;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 67 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method fillToEnd.

/**
     * Fill the space between the last content item and the leadingEdge.
     *
     * @param leadingEdge Line to fill up to. Content will not be wholly beyond this line.
     * @param state       Layout state.  @return Line to which content has been filled. If the line
     *                    is before the leading edge then the end of the data set has been reached.
     */
private int fillToEnd(int leadingEdge, LayoutState state) {
    final View anchor = getAnchorAtEnd();
    LayoutParams anchorParams = (LayoutParams) anchor.getLayoutParams();
    final int sfp = anchorParams.getTestedFirstPosition();
    final View first = getHeaderOrFirstViewForSection(sfp, Direction.END, state);
    final SectionData sd = new SectionData(this, first);
    final SectionLayoutManager slm = getSlm(sd);
    int markerLine = slm.finishFillToEnd(leadingEdge, anchor, sd, state);
    View header = findAttachedHeaderForSectionFromEnd(sd.firstPosition);
    markerLine = updateHeaderForEnd(header, markerLine);
    if (markerLine <= leadingEdge) {
        markerLine = fillNextSectionToEnd(leadingEdge, markerLine, state);
    }
    return markerLine;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 68 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method updateHeaderForStart.

/**
     * Update header for an already existing section when filling towards the start.
     *
     * @param header      Header to update.
     * @param leadingEdge Leading edge to align sticky headers against.
     * @param markerLine  Start of section.
     * @param sd          Section data.
     * @param state       Layout state.
     * @return Updated line for the start of the section content including the header.
     */
private int updateHeaderForStart(View header, int leadingEdge, int markerLine, SectionData sd, LayoutState state) {
    if (!sd.hasHeader) {
        return markerLine;
    }
    SectionLayoutManager slm = getSlm(sd);
    int sli = findLastIndexForSection(sd.firstPosition);
    int sectionBottom = getHeight();
    for (int i = sli == -1 ? 0 : sli; i < getChildCount(); i++) {
        View view = getChildAt(i);
        LayoutParams params = (LayoutParams) view.getLayoutParams();
        if (params.getTestedFirstPosition() != sd.firstPosition) {
            View first = findAttachedHeaderOrFirstViewForSection(params.getTestedFirstPosition(), i, Direction.START);
            if (first == null) {
                sectionBottom = getDecoratedTop(view);
            } else {
                sectionBottom = getDecoratedTop(first);
            }
            break;
        }
    }
    // Fix erroneous marker line position with empty section.
    if (sli == -1 && sd.headerParams.isHeaderInline() && !sd.headerParams.isHeaderOverlay()) {
        markerLine = sectionBottom;
    }
    int offset = 0;
    if (!sd.headerParams.isHeaderInline() || sd.headerParams.isHeaderOverlay()) {
        View firstVisibleView = slm.getFirstVisibleView(sd.firstPosition, true);
        if (firstVisibleView == null) {
            offset = 0;
        } else {
            offset = slm.computeHeaderOffset(getPosition(firstVisibleView), sd, state);
        }
    }
    markerLine = layoutHeaderTowardsStart(header, leadingEdge, markerLine, offset, sectionBottom, sd, state);
    attachHeaderForStart(header, leadingEdge, sd, state);
    return markerLine;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 69 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method getAnchorAtEnd.

/**
     * Find an anchor to fill to end from.
     *
     * @return Non-header view closest to the end edge.
     */
private View getAnchorAtEnd() {
    if (getChildCount() == 1) {
        return getChildAt(0);
    }
    View candidate = getChildAt(getChildCount() - 1);
    LayoutParams candidateParams = (LayoutParams) candidate.getLayoutParams();
    if (candidateParams.isHeader) {
        // Try one above.
        View check = getChildAt(getChildCount() - 2);
        LayoutParams checkParams = (LayoutParams) check.getLayoutParams();
        if (checkParams.getTestedFirstPosition() == candidateParams.getTestedFirstPosition()) {
            candidate = check;
        }
    }
    return candidate;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 70 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.

the class LayoutManager method getFractionOfContentBelow.

private float getFractionOfContentBelow(RecyclerView.State state, boolean ignorePosition) {
    final float parentHeight = getHeight();
    View child = getChildAt(getChildCount() - 1);
    final int anchorPosition = getPosition(child);
    int countAfter = 0;
    SectionData sd = new SectionData(this, child);
    float fractionOffscreen = 0;
    int lastPosition = -1;
    SparseArray<Boolean> positionsOffscreen = new SparseArray<>();
    // Run through all views in the section and add up values offscreen.
    for (int i = 1; i <= getChildCount(); i++) {
        child = getChildAt(getChildCount() - i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!sd.sameSectionManager(lp)) {
            break;
        }
        int position = getPosition(child);
        if (!lp.isHeader && !ignorePosition && position > anchorPosition) {
            countAfter += 1;
        }
        float bottom = getDecoratedBottom(child);
        float top = getDecoratedTop(child);
        if (bottom <= parentHeight) {
            continue;
        } else if (parentHeight < top) {
            fractionOffscreen += 1;
        } else {
            float height = getDecoratedMeasuredHeight(child);
            fractionOffscreen += (bottom - parentHeight) / height;
        }
        if (!lp.isHeader) {
            if (lastPosition == -1) {
                lastPosition = position;
            }
            positionsOffscreen.put(position, true);
        }
    }
    return fractionOffscreen - countAfter - getSlm(sd).howManyMissingBelow(lastPosition, positionsOffscreen);
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

View (android.view.View)77 RecyclerView (android.support.v7.widget.RecyclerView)67 ViewGroup (android.view.ViewGroup)21 TextView (android.widget.TextView)21 ImageView (android.widget.ImageView)13 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)12 Toolbar (android.support.v7.widget.Toolbar)9 FrameLayout (android.widget.FrameLayout)9 Rect (android.graphics.Rect)8 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)8 BindView (butterknife.BindView)8 ActionMenuView (android.support.v7.widget.ActionMenuView)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 LinearLayout (android.widget.LinearLayout)6 CollapsibleActionView (android.support.v7.view.CollapsibleActionView)5 MenuView (android.support.v7.view.menu.MenuView)5 EditText (android.widget.EditText)5 ImageView (carbon.widget.ImageView)5 TextView (carbon.widget.TextView)5 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)5