use of com.chad.library.adapter.base.BaseQuickAdapter 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 com.chad.library.adapter.base.BaseQuickAdapter in project BaseRecyclerViewAdapterHelper by CymChad.
the class PullToRefreshUseActivity method initAdapter.
private void initAdapter() {
pullToRefreshAdapter = new PullToRefreshAdapter();
pullToRefreshAdapter.setOnLoadMoreListener(this, mRecyclerView);
pullToRefreshAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);
// pullToRefreshAdapter.setAutoLoadMoreSize(3);
mRecyclerView.setAdapter(pullToRefreshAdapter);
mCurrentCounter = pullToRefreshAdapter.getData().size();
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
Toast.makeText(PullToRefreshUseActivity.this, Integer.toString(position), Toast.LENGTH_LONG).show();
}
});
}
use of com.chad.library.adapter.base.BaseQuickAdapter in project BaseRecyclerViewAdapterHelper by CymChad.
the class SectionUseActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_section_uer);
setBackBtn();
setTitle("Section Use");
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mData = DataServer.getSampleData();
SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
MySection mySection = mData.get(position);
if (mySection.isHeader)
Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
else
Toast.makeText(SectionUseActivity.this, mySection.t.getName(), Toast.LENGTH_LONG).show();
}
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(SectionUseActivity.this, "onItemChildClick" + position, Toast.LENGTH_LONG).show();
}
});
mRecyclerView.setAdapter(sectionAdapter);
}
use of com.chad.library.adapter.base.BaseQuickAdapter in project BaseRecyclerViewAdapterHelper by CymChad.
the class AnimationUseActivity method initAdapter.
private void initAdapter() {
mAnimationAdapter = new AnimationAdapter();
mAnimationAdapter.openLoadAnimation();
mAnimationAdapter.setNotDoAnimationCount(mFirstPageItemCount);
mRecyclerView.addOnItemTouchListener(new OnItemChildClickListener() {
@Override
public void onSimpleItemChildClick(BaseQuickAdapter adapter, View view, int position) {
String content = null;
Status status = (Status) adapter.getItem(position);
switch(view.getId()) {
case R.id.img:
content = "img:" + status.getUserAvatar();
Toast.makeText(AnimationUseActivity.this, content, Toast.LENGTH_LONG).show();
break;
case R.id.tweetName:
content = "name:" + status.getUserName();
Toast.makeText(AnimationUseActivity.this, content, Toast.LENGTH_LONG).show();
break;
case R.id.tweetText:
// you have set clickspan .so there should not solve any click event ,just empty
break;
}
}
});
mRecyclerView.setAdapter(mAnimationAdapter);
}
use of com.chad.library.adapter.base.BaseQuickAdapter in project BaseRecyclerViewAdapterHelper by CymChad.
the class HeaderAndFooterUseActivity method initAdapter.
private void initAdapter() {
headerAndFooterAdapter = new HeaderAndFooterAdapter(PAGE_SIZE);
headerAndFooterAdapter.openLoadAnimation();
mRecyclerView.setAdapter(headerAndFooterAdapter);
mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
@Override
public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(HeaderAndFooterUseActivity.this, "" + Integer.toString(position), Toast.LENGTH_LONG).show();
}
});
}
Aggregations