Search in sources :

Example 11 with LayoutParams

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

the class LayoutManager method findFirstVisibleItem.

/**
     * Find the position of the first visible item.
     *
     * @return Position of first visible item.
     */
public View findFirstVisibleItem() {
    SectionData sd = new SectionData(this, getChildAt(0));
    final SectionLayoutManager slm = getSlm(sd);
    View firstVisibleView = slm.getFirstVisibleView(sd.firstPosition, false);
    int position = getPosition(firstVisibleView);
    if (position > sd.firstPosition + 1 || position == sd.firstPosition) {
        return firstVisibleView;
    }
    View first = findAttachedHeaderOrFirstViewForSection(sd.firstPosition, 0, Direction.START);
    if (first == null) {
        return firstVisibleView;
    }
    if (getDecoratedBottom(first) <= getDecoratedTop(firstVisibleView)) {
        return first;
    }
    LayoutParams firstParams = (LayoutParams) first.getLayoutParams();
    if ((!firstParams.isHeaderInline() || firstParams.isHeaderOverlay()) && getDecoratedTop(first) == getDecoratedTop(firstVisibleView)) {
        return first;
    }
    return firstVisibleView;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with LayoutParams

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

the class LayoutManager method getFractionOfContentAbove.

private float getFractionOfContentAbove(RecyclerView.State state, boolean ignorePosition) {
    float fractionOffscreen = 0;
    View child = getChildAt(0);
    final int anchorPosition = getPosition(child);
    int numBeforeAnchor = 0;
    float top = getDecoratedTop(child);
    float bottom = getDecoratedBottom(child);
    if (bottom < 0) {
        fractionOffscreen = 1;
    } else if (0 <= top) {
        fractionOffscreen = 0;
    } else {
        float height = getDecoratedMeasuredHeight(child);
        fractionOffscreen = -top / height;
    }
    SectionData sd = new SectionData(this, child);
    if (sd.headerParams.isHeader && sd.headerParams.isHeaderInline()) {
        // Header must not be stickied as it is not attached after section items.
        return fractionOffscreen;
    }
    // Run through all views in the section and add up values offscreen.
    int firstPosition = -1;
    SparseArray<Boolean> positionsOffscreen = new SparseArray<>();
    for (int i = 1; i < getChildCount(); i++) {
        child = getChildAt(i);
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (!sd.sameSectionManager(lp)) {
            break;
        }
        final int position = getPosition(child);
        if (!ignorePosition && position < anchorPosition) {
            numBeforeAnchor += 1;
        }
        top = getDecoratedTop(child);
        bottom = getDecoratedBottom(child);
        if (bottom < 0) {
            fractionOffscreen += 1;
        } else if (0 <= top) {
            continue;
        } else {
            float height = getDecoratedMeasuredHeight(child);
            fractionOffscreen += -top / height;
        }
        if (!lp.isHeader) {
            if (firstPosition == -1) {
                firstPosition = position;
            }
            positionsOffscreen.put(position, true);
        }
    }
    return fractionOffscreen - numBeforeAnchor - getSlm(sd).howManyMissingAbove(firstPosition, positionsOffscreen);
}
Also used : SparseArray(android.util.SparseArray) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 13 with LayoutParams

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

the class LayoutManager method trimStart.

/**
     * Trim content wholly beyond the start edge.
     *
     * @param state Layout state.
     */
private void trimStart(LayoutState state) {
    // Find the first view visible on the screen.
    View anchor = null;
    int anchorIndex = 0;
    for (int i = 0; i < getChildCount(); i++) {
        View look = getChildAt(i);
        if (getDecoratedBottom(look) > 0) {
            anchor = look;
            anchorIndex = i;
            break;
        }
    }
    if (anchor == null) {
        detachAndScrapAttachedViews(state.recycler);
        return;
    }
    LayoutParams anchorParams = (LayoutParams) anchor.getLayoutParams();
    if (anchorParams.isHeader) {
        for (int i = anchorIndex - 1; i >= 0; i--) {
            View look = getChildAt(i);
            LayoutParams lookParams = (LayoutParams) look.getLayoutParams();
            if (lookParams.getTestedFirstPosition() == anchorParams.getTestedFirstPosition()) {
                anchor = look;
                anchorParams = lookParams;
                anchorIndex = i;
                break;
            }
        }
    }
    for (int i = 0; i < anchorIndex; i++) {
        removeAndRecycleViewAt(0, state.recycler);
    }
    int sfp = anchorParams.getTestedFirstPosition();
    View header = findAttachedHeaderForSection(sfp, Direction.START);
    if (header != null) {
        if (getDecoratedTop(header) < 0) {
            updateHeaderForTrimFromStart(header);
        }
        if (getDecoratedBottom(header) <= 0) {
            removeAndRecycleView(header, state.recycler);
        }
    }
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 14 with LayoutParams

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

the class LayoutManager method getAnchorChild.

/**
     * Find the first view in the hierarchy that can act as an anchor.
     *
     * @return The anchor view, or null if no view is a valid anchor.
     */
private View getAnchorChild() {
    if (getChildCount() == 0) {
        return null;
    }
    final View child = getChildAt(0);
    final LayoutParams params = (LayoutParams) child.getLayoutParams();
    final int sfp = params.getTestedFirstPosition();
    final View first = findAttachedHeaderOrFirstViewForSection(sfp, 0, Direction.START);
    if (first == null) {
        return child;
    }
    final LayoutParams firstParams = (LayoutParams) first.getLayoutParams();
    if (!firstParams.isHeader) {
        return child;
    }
    if (firstParams.isHeaderInline() && !firstParams.isHeaderOverlay()) {
        if (getDecoratedBottom(first) <= getDecoratedTop(child)) {
            return first;
        } else {
            return child;
        }
    }
    if (getDecoratedTop(child) < getDecoratedTop(first)) {
        return child;
    }
    if (sfp + 1 == getPosition(child)) {
        return first;
    }
    return child;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Example 15 with LayoutParams

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

the class LayoutManager method findAttachedHeaderForSectionFromEnd.

/**
     * The header is almost guaranteed to be at the end so just use look there.
     *
     * @param sfp Section identifier.
     * @return Header, or null if not found.
     */
private View findAttachedHeaderForSectionFromEnd(int sfp) {
    for (int i = getChildCount() - 1; i >= 0; i--) {
        View child = getChildAt(i);
        LayoutParams params = (LayoutParams) child.getLayoutParams();
        if (params.getTestedFirstPosition() != sfp) {
            break;
        } else if (params.isHeader) {
            return child;
        }
    }
    return null;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

View (android.view.View)138 RecyclerView (android.support.v7.widget.RecyclerView)128 TextView (android.widget.TextView)52 ImageView (android.widget.ImageView)36 LinearLayout (android.widget.LinearLayout)32 ViewGroup (android.view.ViewGroup)31 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)16 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)15 FrameLayout (android.widget.FrameLayout)15 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)13 Paint (android.graphics.Paint)12 RelativeLayout (android.widget.RelativeLayout)12 BindView (butterknife.BindView)12 Rect (android.graphics.Rect)11 Toolbar (android.support.v7.widget.Toolbar)11 EditText (android.widget.EditText)10 DialogInterface (android.content.DialogInterface)9 Handler (android.os.Handler)9 AdapterView (android.widget.AdapterView)9 Intent (android.content.Intent)8