use of android.support.v7.widget.helper.ItemTouchHelper.UP 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.helper.ItemTouchHelper.UP 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;
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project SuperSLiM by TonicArtos.
the class LayoutManager method scrollVerticallyBy.
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
int numChildren = getChildCount();
if (numChildren == 0) {
return 0;
}
LayoutState layoutState = new LayoutState(this, recycler, state);
final Direction direction = dy > 0 ? Direction.END : Direction.START;
final boolean isDirectionEnd = direction == Direction.END;
final int height = getHeight();
final int leadingEdge = isDirectionEnd ? height + dy : dy;
// from the bottom up.
if (isDirectionEnd) {
final View end = getAnchorAtEnd();
LayoutParams params = (LayoutParams) end.getLayoutParams();
SectionLayoutManager slm = getSlm(params);
final int endEdge = slm.getLowestEdge(params.getTestedFirstPosition(), getChildCount() - 1, getDecoratedBottom(end));
if (endEdge < height - getPaddingBottom() && getPosition(end) == (state.getItemCount() - 1)) {
return 0;
}
}
final int fillEdge = fillUntil(leadingEdge, direction, layoutState);
final int delta;
if (isDirectionEnd) {
// Add padding so we scroll to inset area at scroll end.
int fillDelta = fillEdge - height + getPaddingBottom();
delta = fillDelta < dy ? fillDelta : dy;
} else {
int fillDelta = fillEdge - getPaddingTop();
delta = fillDelta > dy ? fillDelta : dy;
}
if (delta != 0) {
offsetChildrenVertical(-delta);
trimTail(isDirectionEnd ? Direction.START : Direction.END, layoutState);
}
layoutState.recycleCache();
return delta;
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Synthese_2BIN by TheYoungSensei.
the class ItemDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_detail);
Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
setSupportActionBar(toolbar);
// Show the Up button in the action bar.
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
//
if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(ItemDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(ItemDetailFragment.ARG_ITEM_ID));
ItemDetailFragment fragment = new ItemDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().add(R.id.item_detail_container, fragment).commit();
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.UP in project Synthese_2BIN by TheYoungSensei.
the class BusinessDayDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_businessday_detail);
Toolbar toolbar = (Toolbar) findViewById(R.id.detail_toolbar);
setSupportActionBar(toolbar);
// Show the Up button in the action bar.
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
//
if (savedInstanceState == null) {
// Create the detail fragment and add it to the activity
// using a fragment transaction.
Bundle arguments = new Bundle();
arguments.putString(BusinessDayDetailFragment.ARG_ITEM_ID, getIntent().getStringExtra(BusinessDayDetailFragment.ARG_ITEM_ID));
BusinessDayDetailFragment fragment = new BusinessDayDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction().add(R.id.businessday_detail_container, fragment).commit();
}
}
Aggregations