use of android.support.v7.widget.helper.ItemTouchHelper.END in project FastAdapter by mikepenz.
the class EndlessRecyclerOnTopScrollListener method findOneVisibleChild.
private View findOneVisibleChild(int fromIndex, int toIndex, boolean completelyVisible, boolean acceptPartiallyVisible) {
if (mLayoutManager.canScrollVertically() != mIsOrientationHelperVertical || mOrientationHelper == null) {
mIsOrientationHelperVertical = mLayoutManager.canScrollVertically();
mOrientationHelper = mIsOrientationHelperVertical ? OrientationHelper.createVerticalHelper(mLayoutManager) : OrientationHelper.createHorizontalHelper(mLayoutManager);
}
final int start = mOrientationHelper.getStartAfterPadding();
final int end = mOrientationHelper.getEndAfterPadding();
final int next = toIndex > fromIndex ? 1 : -1;
View partiallyVisible = null;
for (int i = fromIndex; i != toIndex; i += next) {
final View child = mLayoutManager.getChildAt(i);
if (child != null) {
final int childStart = mOrientationHelper.getDecoratedStart(child);
final int childEnd = mOrientationHelper.getDecoratedEnd(child);
if (childStart < end && childEnd > start) {
if (completelyVisible) {
if (childStart >= start && childEnd <= end) {
return child;
} else if (acceptPartiallyVisible && partiallyVisible == null) {
partiallyVisible = child;
}
} else {
return child;
}
}
}
}
return partiallyVisible;
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project BaseRecyclerViewAdapterHelper by CymChad.
the class ItemDragAndSwipeUseActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_item_touch_use);
setBackBtn();
setTitle("ItemDrag And Swipe");
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mData = generateData(50);
OnItemDragListener listener = new OnItemDragListener() {
@Override
public void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos) {
Log.d(TAG, "drag start");
BaseViewHolder holder = ((BaseViewHolder) viewHolder);
// holder.setTextColor(R.id.tv, Color.WHITE);
}
@Override
public void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to) {
Log.d(TAG, "move from: " + source.getAdapterPosition() + " to: " + target.getAdapterPosition());
}
@Override
public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) {
Log.d(TAG, "drag end");
BaseViewHolder holder = ((BaseViewHolder) viewHolder);
// holder.setTextColor(R.id.tv, Color.BLACK);
}
};
final Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setTextSize(20);
paint.setColor(Color.BLACK);
OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() {
@Override
public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos) {
Log.d(TAG, "view swiped start: " + pos);
BaseViewHolder holder = ((BaseViewHolder) viewHolder);
// holder.setTextColor(R.id.tv, Color.WHITE);
}
@Override
public void clearView(RecyclerView.ViewHolder viewHolder, int pos) {
Log.d(TAG, "View reset: " + pos);
BaseViewHolder holder = ((BaseViewHolder) viewHolder);
// holder.setTextColor(R.id.tv, Color.BLACK);
}
@Override
public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos) {
Log.d(TAG, "View Swiped: " + pos);
}
@Override
public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) {
canvas.drawColor(ContextCompat.getColor(ItemDragAndSwipeUseActivity.this, R.color.color_light_blue));
// canvas.drawText("Just some text", 0, 40, paint);
}
};
mAdapter = new ItemDragAdapter(mData);
mItemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter);
mItemTouchHelper = new ItemTouchHelper(mItemDragAndSwipeCallback);
mItemTouchHelper.attachToRecyclerView(mRecyclerView);
//mItemDragAndSwipeCallback.setDragMoveFlags(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN);
mItemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END);
mAdapter.enableSwipeItem();
mAdapter.setOnItemSwipeListener(onItemSwipeListener);
mAdapter.enableDragItem(mItemTouchHelper);
mAdapter.setOnItemDragListener(listener);
// mRecyclerView.addItemDecoration(new GridItemDecoration(this ,R.drawable.list_divider));
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
ToastUtils.showShortToast("点击了" + position);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class LayoutManager method smoothScrollToPosition.
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView, RecyclerView.State state, final int position) {
if (position < 0 || getItemCount() <= position) {
Log.e("SuperSLiM.LayoutManager", "Ignored smooth scroll to " + position + " as it is not within the item range 0 - " + getItemCount());
return;
}
// Temporarily disable sticky headers.
requestLayout();
recyclerView.getHandler().post(new Runnable() {
@Override
public void run() {
LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
@Override
protected void onChildAttachedToWindow(View child) {
super.onChildAttachedToWindow(child);
}
@Override
protected void onStop() {
super.onStop();
// Turn sticky headers back on.
requestLayout();
}
@Override
protected int getVerticalSnapPreference() {
return LinearSmoothScroller.SNAP_TO_START;
}
@Override
public int calculateDyToMakeVisible(View view, int snapPreference) {
final RecyclerView.LayoutManager layoutManager = getLayoutManager();
if (!layoutManager.canScrollVertically()) {
return 0;
}
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
final int top = layoutManager.getDecoratedTop(view) - params.topMargin;
final int bottom = layoutManager.getDecoratedBottom(view) + params.bottomMargin;
final int start = getPosition(view) == 0 ? layoutManager.getPaddingTop() : 0;
final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom();
int dy = calculateDtToFit(top, bottom, start, end, snapPreference);
return dy == 0 ? 1 : dy;
}
@Override
public PointF computeScrollVectorForPosition(int targetPosition) {
if (getChildCount() == 0) {
return null;
}
return new PointF(0, getDirectionToPosition(targetPosition));
}
};
smoothScroller.setTargetPosition(position);
startSmoothScroll(smoothScroller);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper.END 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.helper.ItemTouchHelper.END in project SuperSLiM by TonicArtos.
the class SectionLayoutManager method getLowestEdge.
/**
* Find the lowest displayed edge of the section. If there is no member found then return the
* default edge instead.
*
* @param sectionFirstPosition Section id, position of first item in the section.
* @param lastIndex Index to start looking from. Usually the index of the last
* attached view in this section.
* @param defaultEdge Default value.
* @return Lowest (attached) edge of the section.
*/
public int getLowestEdge(int sectionFirstPosition, int lastIndex, int defaultEdge) {
// Look from end to find children that are the lowest.
for (int i = lastIndex; i >= 0; i--) {
View child = mLayoutManager.getChildAt(i);
LayoutManager.LayoutParams params = (LayoutManager.LayoutParams) child.getLayoutParams();
if (params.getTestedFirstPosition() != sectionFirstPosition) {
break;
}
if (params.isHeader) {
continue;
}
// A more interesting layout would have to do something more here.
return mLayoutManager.getDecoratedBottom(child);
}
return defaultEdge;
}
Aggregations