Search in sources :

Example 11 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method getNextSpan.

/**
 * Finds the span for the next view.
 */
private Span getNextSpan(int defaultLine, LayoutStateWrapper layoutState, LayoutManagerHelper helper) {
    OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    boolean preferLastSpan = false;
    if (helper.getOrientation() == HORIZONTAL) {
        preferLastSpan = (layoutState.getLayoutDirection() == LAYOUT_START) != helper.getReverseLayout();
    } else {
        preferLastSpan = ((layoutState.getLayoutDirection() == LAYOUT_START) == helper.getReverseLayout()) == helper.isDoLayoutRTL();
    }
    final int startIndex, endIndex, diff;
    if (preferLastSpan) {
        startIndex = mNumLanes - 1;
        endIndex = -1;
        diff = -1;
    } else {
        startIndex = 0;
        endIndex = mNumLanes;
        diff = 1;
    }
    if (layoutState.getLayoutDirection() == LAYOUT_END) {
        Span min = null;
        int minLine = Integer.MAX_VALUE;
        for (int i = startIndex; i != endIndex; i += diff) {
            final Span other = mSpans[i];
            int otherLine = other.getEndLine(defaultLine, orientationHelper);
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "end starIndex " + i + " end otherLine " + otherLine);
            }
            if (otherLine < minLine) {
                min = other;
                minLine = otherLine;
            }
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "end min " + min + " end minLine " + minLine);
            }
        }
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "final end min " + min + " final end minLine " + minLine);
        }
        return min;
    } else {
        Span max = null;
        int maxLine = Integer.MIN_VALUE;
        for (int i = startIndex; i != endIndex; i += diff) {
            final Span other = mSpans[i];
            int otherLine = other.getStartLine(defaultLine, orientationHelper);
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "start starIndex " + i + " start otherLine " + otherLine);
            }
            if (otherLine > maxLine) {
                max = other;
                maxLine = otherLine;
            }
            if (BuildConfig.DEBUG) {
                Log.d(TAG, "start max " + max + " start maxLine " + maxLine);
            }
        }
        if (BuildConfig.DEBUG) {
            Log.d(TAG, "final start max " + max + " final start maxLine " + maxLine);
        }
        return max;
    }
}
Also used : OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx)

Example 12 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method computeAlignOffset.

@Override
public int computeAlignOffset(int offset, boolean isLayoutEnd, boolean useAnchor, LayoutManagerHelper helper) {
    final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final View child = helper.findViewByPosition(offset + getRange().getLower());
    if (child == null) {
        return 0;
    }
    ensureLanes();
    if (layoutInVertical) {
        // in middle nothing need to do
        if (isLayoutEnd) {
            if (offset == getItemCount() - 1) {
                // the last item may not have the largest bottom, so calculate gaps between last items in every lane
                return mMarginBottom + mPaddingBottom + (getMaxEnd(orientationHelper.getDecoratedEnd(child), orientationHelper) - orientationHelper.getDecoratedEnd(child));
            } else if (!useAnchor) {
                final int minEnd = getMinEnd(orientationHelper.getDecoratedStart(child), orientationHelper);
                return minEnd - orientationHelper.getDecoratedEnd(child);
            }
        } else {
            if (offset == 0) {
                // the first item may not have the smallest top, so calculate gaps between first items in every lane
                return -mMarginTop - mPaddingTop - (orientationHelper.getDecoratedStart(child) - getMinStart(orientationHelper.getDecoratedStart(child), orientationHelper));
            } else if (!useAnchor) {
                final int maxStart = getMaxStart(orientationHelper.getDecoratedEnd(child), orientationHelper);
                return maxStart - orientationHelper.getDecoratedStart(child);
            }
        }
    } else {
    }
    return 0;
}
Also used : OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 13 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method recycleFromEnd.

private void recycleFromEnd(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    final int childCount = helper.getChildCount();
    int i;
    for (i = childCount - 1; i >= 0; i--) {
        View child = helper.getChildAt(i);
        if (child != null && orientationHelper.getDecoratedStart(child) > line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int position = lp.getViewPosition();
            Span span = findSpan(position, child, false);
            if (span != null) {
                span.popEnd(orientationHelper);
                helper.removeChildView(child);
                recycler.recycleView(child);
            }
        } else {
            // done
            return;
        }
    }
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 14 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method isRecyclable.

@Override
public boolean isRecyclable(int childPos, int startIndex, int endIndex, LayoutManagerHelper helper, boolean fromStart) {
    // startIndex == endIndex already be ignored in VirtualLayoutManager.recycleChildren
    final boolean recyclable = super.isRecyclable(childPos, startIndex, endIndex, helper, fromStart);
    if (recyclable) {
        View child = helper.findViewByPosition(childPos);
        if (child != null) {
            final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int position = lp.getViewPosition();
            if (helper.getReverseLayout()) {
                if (fromStart) {
                    // recycle from end
                    Span span = findSpan(position, child, true);
                    if (span != null) {
                        span.popEnd(orientationHelper);
                    }
                } else {
                    // recycle from start
                    Span span = findSpan(position, child, false);
                    if (span != null) {
                        span.popStart(orientationHelper);
                    }
                }
            } else {
                if (fromStart) {
                    // recycle from start
                    Span span = findSpan(position, child, true);
                    if (span != null) {
                        span.popStart(orientationHelper);
                    }
                } else {
                    // recycle from end
                    Span span = findSpan(position, child, false);
                    if (span != null) {
                        span.popEnd(orientationHelper);
                    }
                }
            }
        }
    }
    return recyclable;
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 15 with OrientationHelperEx

use of com.alibaba.android.vlayout.OrientationHelperEx in project vlayout by alibaba.

the class StaggeredGridLayoutHelper method recycleFromStart.

private void recycleFromStart(RecyclerView.Recycler recycler, int line, LayoutManagerHelper helper) {
    final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
    boolean changed = true;
    while (helper.getChildCount() > 0 && changed) {
        View child = helper.getChildAt(0);
        if (child != null && orientationHelper.getDecoratedEnd(child) < line) {
            LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int position = lp.getViewPosition();
            Span span = findSpan(position, child, true);
            if (span != null) {
                span.popStart(orientationHelper);
                helper.removeChildView(child);
                recycler.recycleView(child);
            } else {
                changed = false;
            }
        } else {
            // done
            return;
        }
    }
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) OrientationHelperEx(com.alibaba.android.vlayout.OrientationHelperEx) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)32 RecyclerView (android.support.v7.widget.RecyclerView)26 View (android.view.View)26 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)18 LayoutParams (com.alibaba.android.vlayout.VirtualLayoutManager.LayoutParams)10 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)5 Rect (android.graphics.Rect)2 ArrayMap (android.support.v4.util.ArrayMap)1 SimpleArrayMap (android.support.v4.util.SimpleArrayMap)1 ViewGroup (android.view.ViewGroup)1 LayoutParams (android.view.ViewGroup.LayoutParams)1 TextView (android.widget.TextView)1 LayoutHelper (com.alibaba.android.vlayout.LayoutHelper)1 Range (com.alibaba.android.vlayout.Range)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1