use of android.support.v7.widget.RecyclerView.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);
}
use of android.support.v7.widget.RecyclerView.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);
}
}
}
use of android.support.v7.widget.RecyclerView.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;
}
use of android.support.v7.widget.RecyclerView.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;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method fillToStart.
/**
* Fill towards the start edge.
*
* @param leadingEdge Line to fill up to. Content will not be wholly beyond this line.
* @param state Layout state.
* @return Line content was filled up to.
*/
private int fillToStart(int leadingEdge, LayoutState state) {
View anchor = getAnchorAtStart();
LayoutParams anchorParams = (LayoutParams) anchor.getLayoutParams();
final int sfp = anchorParams.getTestedFirstPosition();
final View first = getHeaderOrFirstViewForSection(sfp, Direction.START, state);
final SectionData sd = new SectionData(this, first);
final SectionLayoutManager slm = getSlm(sd);
int markerLine;
int anchorPosition = getPosition(anchor);
if (anchorPosition == sd.firstPosition) {
markerLine = getDecoratedTop(anchor);
} else {
if (anchorPosition - 1 == sd.firstPosition && sd.hasHeader) {
// Already at first content position, so no more to do.
markerLine = getDecoratedTop(anchor);
} else {
markerLine = slm.finishFillToStart(leadingEdge, anchor, sd, state);
}
}
markerLine = updateHeaderForStart(first, leadingEdge, markerLine, sd, state);
if (markerLine > leadingEdge) {
markerLine = fillNextSectionToStart(leadingEdge, markerLine, state);
}
return markerLine;
}
Aggregations