use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class ExposeLinearLayoutManagerEx method recycleViewsFromStartExpose.
/**
* Recycles views that went out of bounds after scrolling towards the end of the layout.
*
* @param recycler Recycler instance of {@link RecyclerView}
* @param dt This can be used to add additional padding to the visible area. This is used
* to
* detect children that will go out of bounds after scrolling, without actually
* moving them.
*/
private void recycleViewsFromStartExpose(RecyclerView.Recycler recycler, int dt) {
if (dt < 0) {
if (DEBUG) {
Log.d(TAG, "Called recycle from start with a negative value. This might happen" + " during layout changes but may be sign of a bug");
}
return;
}
// ignore padding, ViewGroup may not clip children.
final int limit = dt;
final int childCount = getChildCount();
if (mShouldReverseLayoutExpose) {
for (int i = childCount - 1; i >= 0; i--) {
View child = getChildAt(i);
if (mOrientationHelper.getDecoratedEnd(child) + recycleOffset > limit) {
// stop here
recycleChildren(recycler, childCount - 1, i);
return;
}
}
} else {
for (int i = 0; i < childCount; i++) {
View child = getChildAt(i);
if (mOrientationHelper.getDecoratedEnd(child) + recycleOffset > limit) {
// stop here
recycleChildren(recycler, 0, i);
return;
}
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class FixLayoutHelper method layoutViews.
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, VirtualLayoutManager.LayoutStateWrapper layoutState, LayoutChunkResult result, final LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
if (!mShouldDrawn) {
layoutState.skipCurrentPosition();
return;
}
// find view in currentPosition
View view = mFixView;
if (view == null) {
view = layoutState.next(recycler);
} else {
layoutState.skipCurrentPosition();
}
if (view == null) {
result.mFinished = true;
return;
}
mDoNormalHandle = state.isPreLayout();
if (mDoNormalHandle) {
// in PreLayout do normal layout
helper.addChildView(layoutState, view);
}
mFixView = view;
doMeasureAndLayout(view, helper);
result.mConsumed = 0;
result.mIgnoreConsumed = true;
handleStateOnResult(result, view);
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class GridLayoutHelper method assignSpans.
private void assignSpans(RecyclerView.Recycler recycler, RecyclerView.State state, int count, int consumedSpanCount, boolean layingOutInPrimaryDirection, LayoutManagerHelper helper) {
int span, spanDiff, start, end, diff;
// make sure we traverse from min position to max position
if (layingOutInPrimaryDirection) {
start = 0;
end = count;
diff = 1;
} else {
start = count - 1;
end = -1;
diff = -1;
}
if (helper.getOrientation() == VERTICAL && helper.isDoLayoutRTL()) {
// start from last span
span = consumedSpanCount - 1;
spanDiff = -1;
} else {
span = 0;
spanDiff = 1;
}
for (int i = start; i != end; i += diff) {
View view = mSet[i];
int spanSize = getSpanSize(recycler, state, helper.getPosition(view));
if (spanDiff == -1 && spanSize > 1) {
mSpanIndices[i] = span - (spanSize - 1);
} else {
mSpanIndices[i] = span;
}
span += spanDiff * spanSize;
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class LinearLayoutHelper method layoutViews.
/**
* In {@link LinearLayoutHelper}, each iteration only consume one item,
* so it can let parent LayoutManager to decide whether the next item is in the range of this helper
*/
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, VirtualLayoutManager.LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
int currentPosition = layoutState.getCurrentPosition();
// find corresponding layout container
View view = nextView(recycler, layoutState, helper, result);
if (view == null) {
return;
}
final boolean isOverLapMargin = helper.isEnableMarginOverLap();
VirtualLayoutManager.LayoutParams params = (VirtualLayoutManager.LayoutParams) view.getLayoutParams();
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
int startSpace = 0, endSpace = 0, gap = 0;
boolean isLayoutEnd = layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_END;
boolean isStartLine = isLayoutEnd ? currentPosition == getRange().getLower().intValue() : currentPosition == getRange().getUpper().intValue();
boolean isEndLine = isLayoutEnd ? currentPosition == getRange().getUpper().intValue() : currentPosition == getRange().getLower().intValue();
if (isStartLine) {
startSpace = computeStartSpace(helper, layoutInVertical, isLayoutEnd, isOverLapMargin);
}
if (isEndLine) {
endSpace = computeEndSpace(helper, layoutInVertical, isLayoutEnd, isOverLapMargin);
}
if (!isStartLine) {
if (!isOverLapMargin) {
gap = mLayoutWithAnchor ? 0 : mDividerHeight;
} else {
// TODO check layout with anchor
if (isLayoutEnd) {
int marginTop = params.topMargin;
View sibling = helper.findViewByPosition(currentPosition - 1);
int lastMarginBottom = sibling != null ? ((LayoutParams) sibling.getLayoutParams()).bottomMargin : 0;
if (lastMarginBottom >= 0 && marginTop >= 0) {
gap = Math.max(lastMarginBottom, marginTop);
} else {
gap = lastMarginBottom + marginTop;
}
} else {
int marginBottom = params.bottomMargin;
View sibling = helper.findViewByPosition(currentPosition + 1);
int lastMarginTop = sibling != null ? ((LayoutParams) sibling.getLayoutParams()).topMargin : 0;
if (marginBottom >= 0 && lastMarginTop >= 0) {
gap = Math.max(marginBottom, lastMarginTop);
} else {
gap = marginBottom + lastMarginTop;
}
}
}
}
final int widthSize = helper.getContentWidth() - helper.getPaddingLeft() - helper.getPaddingRight() - getHorizontalMargin() - getHorizontalPadding();
int widthSpec = helper.getChildMeasureSpec(widthSize, params.width, !layoutInVertical);
int heightSpec;
float viewAspectRatio = params.mAspectRatio;
if (!Float.isNaN(viewAspectRatio) && viewAspectRatio > 0) {
heightSpec = View.MeasureSpec.makeMeasureSpec((int) (widthSize / viewAspectRatio + 0.5f), View.MeasureSpec.EXACTLY);
} else if (!Float.isNaN(mAspectRatio) && mAspectRatio > 0) {
heightSpec = View.MeasureSpec.makeMeasureSpec((int) (widthSize / mAspectRatio + 0.5), View.MeasureSpec.EXACTLY);
} else {
heightSpec = helper.getChildMeasureSpec(helper.getContentHeight() - helper.getPaddingTop() - helper.getPaddingBottom() - getVerticalMargin() - getVerticalPadding(), params.height, layoutInVertical);
}
if (!isOverLapMargin) {
helper.measureChildWithMargins(view, widthSpec, heightSpec);
} else {
helper.measureChild(view, widthSpec, heightSpec);
}
OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
result.mConsumed = orientationHelper.getDecoratedMeasurement(view) + startSpace + endSpace + gap;
int left, top, right, bottom;
if (helper.getOrientation() == VERTICAL) {
// not support RTL now
if (helper.isDoLayoutRTL()) {
right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight - mPaddingRight;
left = right - orientationHelper.getDecoratedMeasurementInOther(view);
} else {
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(view);
}
// whether this layout pass is layout to start or to end
if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) {
// fill start, from bottom to top
bottom = layoutState.getOffset() - startSpace - (isStartLine ? 0 : gap);
top = bottom - orientationHelper.getDecoratedMeasurement(view);
} else {
// fill end, from top to bottom
top = layoutState.getOffset() + startSpace + (isStartLine ? 0 : gap);
bottom = top + orientationHelper.getDecoratedMeasurement(view);
}
} else {
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(view);
if (layoutState.getLayoutDirection() == VirtualLayoutManager.LayoutStateWrapper.LAYOUT_START) {
// fill left, from right to left
right = layoutState.getOffset() - startSpace - (isStartLine ? 0 : gap);
left = right - orientationHelper.getDecoratedMeasurement(view);
} else {
// fill right, from left to right
left = layoutState.getOffset() + startSpace + (isStartLine ? 0 : gap);
right = left + orientationHelper.getDecoratedMeasurement(view);
}
}
// We calculate everything with View's bounding box (which includes decor and margins)
// To calculate correct layout position, we subtract margins.
layoutChildWithMargin(view, left, top, right, bottom, helper);
if (DEBUG) {
Log.d(TAG, "laid out child at position " + helper.getPosition(view) + ", with l:" + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin));
}
handleStateOnResult(result, view);
mLayoutWithAnchor = false;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project vlayout by alibaba.
the class OnePlusNLayoutHelper method layoutViews.
@Override
public void layoutViews(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutStateWrapper layoutState, LayoutChunkResult result, LayoutManagerHelper helper) {
// reach the end of this layout
if (isOutOfRange(layoutState.getCurrentPosition())) {
return;
}
final OrientationHelperEx orientationHelper = helper.getMainOrientationHelper();
final boolean layoutInVertical = helper.getOrientation() == VERTICAL;
final boolean layoutStart = layoutState.getLayoutDirection() == LayoutStateWrapper.LAYOUT_START;
final int parentWidth = helper.getContentWidth();
final int parentHeight = helper.getContentHeight();
final int parentHPadding = helper.getPaddingLeft() + helper.getPaddingRight() + getHorizontalMargin() + getHorizontalPadding();
final int parentVPadding = helper.getPaddingTop() + helper.getPaddingBottom() + getVerticalMargin() + getVerticalPadding();
final int currentPosition = layoutState.getCurrentPosition();
if (hasHeader && currentPosition == getRange().getLower()) {
View header = nextView(recycler, layoutState, helper, result);
int headerConsumed = handleHeader(header, layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
if (header != null) {
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
bottom = layoutState.getOffset();
top = bottom - headerConsumed;
} else {
top = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginTop + mPaddingTop);
bottom = top + headerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(header);
} else {
if (layoutStart) {
right = layoutState.getOffset();
left = right - headerConsumed;
} else {
left = layoutState.getOffset() + (mLayoutWithAnchor ? 0 : mMarginLeft + mPaddingLeft);
right = left + headerConsumed;
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(header);
}
layoutChildWithMargin(header, left, top, right, bottom, helper);
}
result.mConsumed = headerConsumed;
handleStateOnResult(result, header);
} else if (hasFooter && currentPosition == getRange().getUpper()) {
View footer = nextView(recycler, layoutState, helper, result);
int footerConsumed = handleFooter(footer, layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
if (footer != null) {
int left = 0, right = 0, top = 0, bottom = 0;
if (layoutInVertical) {
if (layoutStart) {
// TODO margin overlap
bottom = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginBottom + mPaddingBottom);
top = bottom - footerConsumed;
} else {
top = layoutState.getOffset();
bottom = top + footerConsumed;
}
left = helper.getPaddingLeft() + mMarginLeft + mPaddingLeft;
right = left + orientationHelper.getDecoratedMeasurementInOther(footer);
} else {
if (layoutStart) {
// TODO margin overlap
right = layoutState.getOffset() - (mLayoutWithAnchor ? 0 : mMarginRight + mPaddingRight);
left = right - footerConsumed;
} else {
left = layoutState.getOffset();
right = left + footerConsumed;
}
top = helper.getPaddingTop() + mMarginTop + mPaddingTop;
bottom = top + orientationHelper.getDecoratedMeasurementInOther(footer);
}
layoutChildWithMargin(footer, left, top, right, bottom, helper);
}
result.mConsumed = footerConsumed;
handleStateOnResult(result, footer);
} else {
int contentCount = getItemCount() - (hasHeader ? 1 : 0) - (hasFooter ? 1 : 0);
if (mChildrenViews == null || mChildrenViews.length != contentCount) {
mChildrenViews = new View[contentCount];
}
int count = getAllChildren(mChildrenViews, recycler, layoutState, result, helper);
if (count == 0 || count < contentCount) {
return;
}
int mainConsumed = 0;
if (contentCount == 1) {
mainConsumed = handleOne(layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
} else if (contentCount == 2) {
mainConsumed = handleTwo(layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
} else if (contentCount == 3) {
mainConsumed = handleThree(layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
} else if (contentCount == 4) {
mainConsumed = handleFour(layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
} else if (contentCount == 5) {
mainConsumed = handleFive(layoutState, result, helper, layoutInVertical, parentWidth, parentHeight, parentHPadding, parentVPadding);
}
result.mConsumed = mainConsumed;
Arrays.fill(mChildrenViews, null);
}
}
Aggregations