use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method getAnchorAtStart.
/**
* Get the first view in the section that intersects the start edge. Only returns the header if
* it is the last one displayed.
*
* @return View in section at start edge.
*/
private View getAnchorAtStart() {
View child = getChildAt(0);
LayoutParams params = (LayoutParams) child.getLayoutParams();
int sfp = params.getTestedFirstPosition();
if (!params.isHeader) {
return child;
}
int i = 1;
if (i < getChildCount()) {
View candidate = getChildAt(i);
LayoutParams candidateParams = (LayoutParams) candidate.getLayoutParams();
if (candidateParams.getTestedFirstPosition() == sfp) {
return candidate;
}
}
return child;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method fillToEnd.
/**
* Fill the space between the last content item and the leadingEdge.
*
* @param leadingEdge Line to fill up to. Content will not be wholly beyond this line.
* @param state Layout state. @return Line to which content has been filled. If the line
* is before the leading edge then the end of the data set has been reached.
*/
private int fillToEnd(int leadingEdge, LayoutState state) {
final View anchor = getAnchorAtEnd();
LayoutParams anchorParams = (LayoutParams) anchor.getLayoutParams();
final int sfp = anchorParams.getTestedFirstPosition();
final View first = getHeaderOrFirstViewForSection(sfp, Direction.END, state);
final SectionData sd = new SectionData(this, first);
final SectionLayoutManager slm = getSlm(sd);
int markerLine = slm.finishFillToEnd(leadingEdge, anchor, sd, state);
View header = findAttachedHeaderForSectionFromEnd(sd.firstPosition);
markerLine = updateHeaderForEnd(header, markerLine);
if (markerLine <= leadingEdge) {
markerLine = fillNextSectionToEnd(leadingEdge, markerLine, state);
}
return markerLine;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method updateHeaderForStart.
/**
* Update header for an already existing section when filling towards the start.
*
* @param header Header to update.
* @param leadingEdge Leading edge to align sticky headers against.
* @param markerLine Start of section.
* @param sd Section data.
* @param state Layout state.
* @return Updated line for the start of the section content including the header.
*/
private int updateHeaderForStart(View header, int leadingEdge, int markerLine, SectionData sd, LayoutState state) {
if (!sd.hasHeader) {
return markerLine;
}
SectionLayoutManager slm = getSlm(sd);
int sli = findLastIndexForSection(sd.firstPosition);
int sectionBottom = getHeight();
for (int i = sli == -1 ? 0 : sli; i < getChildCount(); i++) {
View view = getChildAt(i);
LayoutParams params = (LayoutParams) view.getLayoutParams();
if (params.getTestedFirstPosition() != sd.firstPosition) {
View first = findAttachedHeaderOrFirstViewForSection(params.getTestedFirstPosition(), i, Direction.START);
if (first == null) {
sectionBottom = getDecoratedTop(view);
} else {
sectionBottom = getDecoratedTop(first);
}
break;
}
}
// Fix erroneous marker line position with empty section.
if (sli == -1 && sd.headerParams.isHeaderInline() && !sd.headerParams.isHeaderOverlay()) {
markerLine = sectionBottom;
}
int offset = 0;
if (!sd.headerParams.isHeaderInline() || sd.headerParams.isHeaderOverlay()) {
View firstVisibleView = slm.getFirstVisibleView(sd.firstPosition, true);
if (firstVisibleView == null) {
offset = 0;
} else {
offset = slm.computeHeaderOffset(getPosition(firstVisibleView), sd, state);
}
}
markerLine = layoutHeaderTowardsStart(header, leadingEdge, markerLine, offset, sectionBottom, sd, state);
attachHeaderForStart(header, leadingEdge, sd, state);
return markerLine;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method getAnchorAtEnd.
/**
* Find an anchor to fill to end from.
*
* @return Non-header view closest to the end edge.
*/
private View getAnchorAtEnd() {
if (getChildCount() == 1) {
return getChildAt(0);
}
View candidate = getChildAt(getChildCount() - 1);
LayoutParams candidateParams = (LayoutParams) candidate.getLayoutParams();
if (candidateParams.isHeader) {
// Try one above.
View check = getChildAt(getChildCount() - 2);
LayoutParams checkParams = (LayoutParams) check.getLayoutParams();
if (checkParams.getTestedFirstPosition() == candidateParams.getTestedFirstPosition()) {
candidate = check;
}
}
return candidate;
}
use of android.support.v7.widget.RecyclerView.LayoutParams in project SuperSLiM by TonicArtos.
the class LayoutManager method getFractionOfContentBelow.
private float getFractionOfContentBelow(RecyclerView.State state, boolean ignorePosition) {
final float parentHeight = getHeight();
View child = getChildAt(getChildCount() - 1);
final int anchorPosition = getPosition(child);
int countAfter = 0;
SectionData sd = new SectionData(this, child);
float fractionOffscreen = 0;
int lastPosition = -1;
SparseArray<Boolean> positionsOffscreen = new SparseArray<>();
// Run through all views in the section and add up values offscreen.
for (int i = 1; i <= getChildCount(); i++) {
child = getChildAt(getChildCount() - i);
LayoutParams lp = (LayoutParams) child.getLayoutParams();
if (!sd.sameSectionManager(lp)) {
break;
}
int position = getPosition(child);
if (!lp.isHeader && !ignorePosition && position > anchorPosition) {
countAfter += 1;
}
float bottom = getDecoratedBottom(child);
float top = getDecoratedTop(child);
if (bottom <= parentHeight) {
continue;
} else if (parentHeight < top) {
fractionOffscreen += 1;
} else {
float height = getDecoratedMeasuredHeight(child);
fractionOffscreen += (bottom - parentHeight) / height;
}
if (!lp.isHeader) {
if (lastPosition == -1) {
lastPosition = position;
}
positionsOffscreen.put(position, true);
}
}
return fractionOffscreen - countAfter - getSlm(sd).howManyMissingBelow(lastPosition, positionsOffscreen);
}
Aggregations