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;
}
}
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;
}
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;
}
}
}
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;
}
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;
}
}
}
Aggregations