use of androidx.recyclerview.widget.RecyclerView in project BaseRecyclerViewAdapterHelper by CymChad.
the class GridItemDecoration method onDrawOver.
/**
* @param c
* @param parent
* @param state
*/
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
if (dividerDrawable == null) {
return;
}
int childCount = parent.getChildCount();
int rightV = parent.getWidth();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int leftV = parent.getPaddingLeft() + child.getPaddingLeft();
int bottomV = child.getTop() - params.topMargin;
int topV = bottomV - dividerDrawable.getIntrinsicHeight();
int topH = child.getTop() + params.topMargin;
int bottomH = child.getBottom() + params.bottomMargin;
int rightH = child.getLeft() - params.leftMargin;
int leftH = rightH - dividerDrawable.getIntrinsicWidth();
dividerDrawable.setBounds(leftH, topH, rightH, bottomH);
dividerDrawable.draw(c);
dividerDrawable.setBounds(leftV, topV, rightV, bottomV);
dividerDrawable.draw(c);
}
}
use of androidx.recyclerview.widget.RecyclerView in project BaseRecyclerViewAdapterHelper by CymChad.
the class DragAndSwipeCallback method onChildDrawOver.
@Override
public void onChildDrawOver(@NonNull Canvas c, @NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && !isViewCreateByAdapter(viewHolder)) {
View itemView = viewHolder.itemView;
c.save();
if (dX > 0) {
c.clipRect(itemView.getLeft(), itemView.getTop(), itemView.getLeft() + dX, itemView.getBottom());
c.translate(itemView.getLeft(), itemView.getTop());
} else {
c.clipRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
c.translate(itemView.getRight() + dX, itemView.getTop());
}
if (mDraggableModule != null) {
mDraggableModule.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
}
c.restore();
}
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class DragManager method onDrag.
@Override
public boolean onDrag(View v, DragEvent event) {
if (v != recyclerViewRef.get() || !(event.getLocalState() instanceof DragInfo)) {
return false;
}
final RecyclerView recyclerView = (RecyclerView) v;
final DragInfo dragInfo = (DragInfo) event.getLocalState();
final long itemId = dragInfo.itemId();
switch(event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
draggingId = itemId;
adapter.notifyItemChanged(recyclerView.findViewHolderForItemId(itemId).getAdapterPosition());
break;
case DragEvent.ACTION_DRAG_LOCATION:
float x = event.getX();
float y = event.getY();
int fromPosition = adapter.getPositionForId(itemId);
int toPosition = -1;
View child = recyclerView.findChildViewUnder(event.getX(), event.getY());
if (child != null) {
toPosition = recyclerView.getChildViewHolder(child).getAdapterPosition();
}
if (toPosition >= 0 && fromPosition != toPosition) {
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
boolean scheduleNextMove = nextMoveTouchPoint.equals(MIN_VALUE, MIN_VALUE);
nextMoveTouchPoint.set(x, y);
if (scheduleNextMove)
animator.isRunning(new RecyclerView.ItemAnimator.ItemAnimatorFinishedListener() {
@Override
public void onAnimationsFinished() {
if (nextMoveTouchPoint.equals(MIN_VALUE, MIN_VALUE)) {
return;
}
final int fromPosition = adapter.getPositionForId(itemId);
View child = recyclerView.findChildViewUnder(nextMoveTouchPoint.x, nextMoveTouchPoint.y);
if (child != null) {
final int toPosition = recyclerView.getChildViewHolder(child).getAdapterPosition();
if (adapter.move(fromPosition, toPosition)) {
if (fromPosition == 0 || toPosition == 0) {
// fix for weird scrolling when animating first item
recyclerView.scrollToPosition(0);
}
recyclerView.post(new Runnable() {
@Override
public void run() {
adapter.notifyItemMoved(fromPosition, toPosition);
}
});
}
}
// reset so we know to schedule listener again next time
clearNextMove();
}
});
}
lastDragInfo = dragInfo;
lastDragInfo.setDragPoint(x, y);
adapter.handleDragScroll(recyclerView, dragInfo);
break;
case DragEvent.ACTION_DRAG_ENDED:
draggingId = RecyclerView.NO_ID;
lastDragInfo = null;
// queue up the show animation until after all move animations are finished
recyclerView.getItemAnimator().isRunning(new RecyclerView.ItemAnimator.ItemAnimatorFinishedListener() {
@Override
public void onAnimationsFinished() {
int position = adapter.getPositionForId(itemId);
RecyclerView.ViewHolder vh = recyclerView.findViewHolderForItemId(itemId);
if (vh != null && vh.getAdapterPosition() != position) {
// if positions don't match, there's still an outstanding move animation
// so we try to reschedule the notifyItemChanged until after that
recyclerView.post(new Runnable() {
@Override
public void run() {
recyclerView.getItemAnimator().isRunning(new RecyclerView.ItemAnimator.ItemAnimatorFinishedListener() {
@Override
public void onAnimationsFinished() {
adapter.notifyItemChanged(adapter.getPositionForId(itemId));
}
});
}
});
} else {
adapter.notifyItemChanged(adapter.getPositionForId(itemId));
}
}
});
break;
case DragEvent.ACTION_DROP:
adapter.onDrop();
break;
case DragEvent.ACTION_DRAG_ENTERED:
// probably not used?
break;
case DragEvent.ACTION_DRAG_EXITED:
// TODO edge scrolling
break;
}
return true;
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class SwipeListViewTouchListener method makeScrollListener.
/**
* Return ScrollListener for ListView
*
* @return OnScrollListener
*/
public RecyclerView.OnScrollListener makeScrollListener() {
return new RecyclerView.OnScrollListener() {
private boolean isFirstItem = false;
private boolean isLastItem = false;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
setEnabled(newState != recyclerView.SCROLL_STATE_DRAGGING);
if (swipeClosesAllItemsWhenListMoves && newState == recyclerView.SCROLL_STATE_DRAGGING) {
closeOpenedItems();
}
if (newState == recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = true;
setEnabled(false);
}
if (newState != recyclerView.SCROLL_STATE_SETTLING && newState != recyclerView.SCROLL_STATE_DRAGGING) {
listViewMoving = false;
downPosition = ListView.INVALID_POSITION;
swipeListView.resetScrolling();
new Handler().postDelayed(new Runnable() {
public void run() {
setEnabled(true);
}
}, 500);
}
}
@Override
public void onScrolled(RecyclerView view, int dx, int dy) {
// if (isFirstItem) {
// boolean onSecondItemList = firstVisibleItem == 1;
// if (onSecondItemList) {
// isFirstItem = false;
// }
// } else {
// boolean onFirstItemList = firstVisibleItem == 0;
// if (onFirstItemList)
// isFirstItem = true;
// swipeListView.onFirstListItem();
// }
// }
// if (isLastItem) {
// boolean onBeforeLastItemList = firstVisibleItem + visibleItemCount == totalItemCount - 1;
// if (onBeforeLastItemList) {
// isLastItem = false;
// }
// } else {
// boolean onLastItemList = firstVisibleItem + visibleItemCount >= totalItemCount;
// if (onLastItemList) {
// isLastItem = true;
// swipeListView.onLastListItem();
// }
// }
}
};
}
use of androidx.recyclerview.widget.RecyclerView in project UltimateRecyclerView by cymcsg.
the class DividerItemDecoration method drawHorizontal.
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;
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
Aggregations