use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project UltimateAndroid by cymcsg.
the class GridDividerDecoration method drawHorizontal.
/** Draw dividers to the right of each child view */
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getRight() + params.rightMargin + mInsets;
final int right = left + mDivider.getIntrinsicWidth();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project UltimateAndroid by cymcsg.
the class GridDividerDecoration method drawVertical.
/** Draw dividers at each expected grid interval */
public void drawVertical(Canvas c, RecyclerView parent) {
if (parent.getChildCount() == 0)
return;
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final View child = parent.getChildAt(0);
if (child.getHeight() == 0)
return;
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin + mInsets;
int bottom = top + mDivider.getIntrinsicHeight();
final int parentBottom = parent.getHeight() - parent.getPaddingBottom();
while (bottom < parentBottom) {
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
top += mInsets + params.topMargin + child.getHeight() + params.bottomMargin + mInsets;
bottom = top + mDivider.getIntrinsicHeight();
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project UltimateAndroid by cymcsg.
the class StaticGridLayoutManager method scrollHorizontallyBy.
/*
* This method describes how far RecyclerView thinks the contents should scroll horizontally.
* You are responsible for verifying edge boundaries, and determining if this scroll
* event somehow requires that new views be added or old views get recycled.
*/
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getChildCount() == 0) {
return 0;
}
//Take leftmost measurements from the top-left child
final View topView = getChildAt(0);
//Take rightmost measurements from the top-right child
final View bottomView = getChildAt(mVisibleColumnCount - 1);
//Optimize the case where the entire data set is too small to scroll
int viewSpan = getDecoratedRight(bottomView) - getDecoratedLeft(topView);
if (viewSpan <= getHorizontalSpace()) {
//We cannot scroll in either direction
return 0;
}
int delta;
boolean leftBoundReached = getFirstVisibleColumn() == 0;
boolean rightBoundReached = getLastVisibleColumn() >= getTotalColumnCount();
if (dx > 0) {
//Check right bound
if (rightBoundReached) {
//If we've reached the last column, enforce limits
int rightOffset = getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
delta = Math.max(-dx, rightOffset);
} else {
//No limits while the last column isn't visible
delta = -dx;
}
} else {
//Check left bound
if (leftBoundReached) {
int leftOffset = -getDecoratedLeft(topView) + getPaddingLeft();
delta = Math.min(-dx, leftOffset);
} else {
delta = -dx;
}
}
offsetChildrenHorizontal(delta);
if (dx > 0) {
if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
fillGrid(DIRECTION_END, recycler);
} else if (!rightBoundReached) {
fillGrid(DIRECTION_NONE, recycler);
}
} else {
if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
fillGrid(DIRECTION_START, recycler);
} else if (!leftBoundReached) {
fillGrid(DIRECTION_NONE, recycler);
}
}
/*
* Return value determines if a boundary has been reached
* (for edge effects and flings). If returned value does not
* match original delta (passed in), RecyclerView will draw
* an edge effect.
*/
return -delta;
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project UltimateAndroid by cymcsg.
the class StaticGridLayoutManager method scrollVerticallyBy.
/*
* This method describes how far RecyclerView thinks the contents should scroll vertically.
* You are responsible for verifying edge boundaries, and determining if this scroll
* event somehow requires that new views be added or old views get recycled.
*/
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getChildCount() == 0) {
return 0;
}
//Take top measurements from the top-left child
final View topView = getChildAt(0);
//Take bottom measurements from the bottom-right child.
final View bottomView = getChildAt(getChildCount() - 1);
//Optimize the case where the entire data set is too small to scroll
int viewSpan = getDecoratedBottom(bottomView) - getDecoratedTop(topView);
if (viewSpan <= getVerticalSpace()) {
//We cannot scroll in either direction
return 0;
}
int delta;
int maxRowCount = getTotalRowCount();
boolean topBoundReached = getFirstVisibleRow() == 0;
boolean bottomBoundReached = getLastVisibleRow() >= maxRowCount;
if (dy > 0) {
//Check against bottom bound
if (bottomBoundReached) {
//If we've reached the last row, enforce limits
int bottomOffset;
if (rowOfIndex(getChildCount() - 1) >= (maxRowCount - 1)) {
//We are truly at the bottom, determine how far
bottomOffset = getVerticalSpace() - getDecoratedBottom(bottomView) + getPaddingBottom();
} else {
/*
* Extra space added to account for allowing bottom space in the grid.
* This occurs when the overlap in the last row is not large enough to
* ensure that at least one element in that row isn't fully recycled.
*/
bottomOffset = getVerticalSpace() - (getDecoratedBottom(bottomView) + mDecoratedChildHeight) + getPaddingBottom();
}
delta = Math.max(-dy, bottomOffset);
} else {
//No limits while the last row isn't visible
delta = -dy;
}
} else {
//Check against top bound
if (topBoundReached) {
int topOffset = -getDecoratedTop(topView) + getPaddingTop();
delta = Math.min(-dy, topOffset);
} else {
delta = -dy;
}
}
offsetChildrenVertical(delta);
if (dy > 0) {
if (getDecoratedBottom(topView) < 0 && !bottomBoundReached) {
fillGrid(DIRECTION_DOWN, recycler);
} else if (!bottomBoundReached) {
fillGrid(DIRECTION_NONE, recycler);
}
} else {
if (getDecoratedTop(topView) > 0 && !topBoundReached) {
fillGrid(DIRECTION_UP, recycler);
} else if (!topBoundReached) {
fillGrid(DIRECTION_NONE, recycler);
}
}
/*
* Return value determines if a boundary has been reached
* (for edge effects and flings). If returned value does not
* match original delta (passed in), RecyclerView will draw
* an edge effect.
*/
return -delta;
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project UltimateAndroid by cymcsg.
the class StaticGridLayoutManager method onLayoutChildren.
/*
* This method is your initial call from the framework. You will receive it when you
* need to start laying out the initial set of views. This method will not be called
* repeatedly, so don't rely on it to continually process changes during user
* interaction.
*
* This method will be called when the data set in the adapter changes, so it can be
* used to update a layout based on a new item count.
*/
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
//We have nothing to show for an empty data set but clear any existing views
if (getItemCount() == 0) {
detachAndScrapAttachedViews(recycler);
return;
}
//Make the grid as square as possible, column count is root of the data set
mTotalColumnCount = (int) Math.round(Math.sqrt(getItemCount()));
if (getChildCount() == 0) {
//First or empty layout
//Scrap measure one child
View scrap = recycler.getViewForPosition(0);
addView(scrap);
measureChildWithMargins(scrap, 0, 0);
/*
* We make some assumptions in this code based on every child
* view being the same size (i.e. a uniform grid). This allows
* us to compute the following values up front because they
* won't change.
*/
mDecoratedChildWidth = getDecoratedMeasuredWidth(scrap);
mDecoratedChildHeight = getDecoratedMeasuredHeight(scrap);
detachAndScrapView(scrap, recycler);
}
//Always update the visible row/column counts
updateWindowSizing();
int childLeft;
int childTop;
if (getChildCount() == 0) {
//First or empty layout
/*
* Reset the visible and scroll positions
*/
mFirstVisiblePosition = 0;
childLeft = childTop = 0;
} else if (getVisibleChildCount() > getItemCount()) {
//Data set is too small to scroll fully, just reset position
mFirstVisiblePosition = 0;
childLeft = childTop = 0;
} else {
//Adapter data set changes
/*
* Keep the existing initial position, and save off
* the current scrolled offset.
*/
final View topChild = getChildAt(0);
if (mForceClearOffsets) {
childLeft = childTop = 0;
mForceClearOffsets = false;
} else {
childLeft = getDecoratedLeft(topChild);
childTop = getDecoratedTop(topChild);
}
/*
* Adjust the visible position if out of bounds in the
* new layout. This occurs when the new item count in an adapter
* is much smaller than it was before, and you are scrolled to
* a location where no items would exist.
*/
int lastVisiblePosition = positionOfIndex(getVisibleChildCount() - 1);
if (lastVisiblePosition >= getItemCount()) {
lastVisiblePosition = (getItemCount() - 1);
int lastColumn = mVisibleColumnCount - 1;
int lastRow = mVisibleRowCount - 1;
//Adjust to align the last position in the bottom-right
mFirstVisiblePosition = Math.max(lastVisiblePosition - lastColumn - (lastRow * getTotalColumnCount()), 0);
childLeft = getHorizontalSpace() - (mDecoratedChildWidth * mVisibleColumnCount);
childTop = getVerticalSpace() - (mDecoratedChildHeight * mVisibleRowCount);
// This happens on data sets too small to scroll in a direction.
if (getFirstVisibleRow() == 0) {
childTop = Math.min(childTop, 0);
}
if (getFirstVisibleColumn() == 0) {
childLeft = Math.min(childLeft, 0);
}
}
}
//Clear all attached views into the recycle bin
detachAndScrapAttachedViews(recycler);
//Fill the grid for the initial layout of views
fillGrid(DIRECTION_NONE, childLeft, childTop, recycler);
}
Aggregations