use of jp.wasabeef.recyclerview.animators.SlideInLeftAnimator in project recyclerview-animators by wasabeef.
the class AnimatorSampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animator_sample);
Toolbar toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.list);
if (getIntent().getBooleanExtra("GRID", true)) {
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
} else {
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
recyclerView.setItemAnimator(new SlideInLeftAnimator());
final MainAdapter adapter = new MainAdapter(this, new ArrayList<>(Arrays.asList(data)));
recyclerView.setAdapter(adapter);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
for (Type type : Type.values()) {
spinnerAdapter.add(type.name());
}
spinner.setAdapter(spinnerAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
recyclerView.setItemAnimator(Type.values()[position].getAnimator());
recyclerView.getItemAnimator().setAddDuration(500);
recyclerView.getItemAnimator().setRemoveDuration(500);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.add("newly added item", 1);
}
});
findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.remove(1);
}
});
}
use of jp.wasabeef.recyclerview.animators.SlideInLeftAnimator in project CustomViews by AndroidStudy233.
the class RecyclerViewActivity method fillContentView.
private void fillContentView() {
View view = View.inflate(this, R.layout.layout_recycler_main, null);
// 初始化SwipeRefreshLayout
swipe_main = (SwipeRefreshLayout) view.findViewById(R.id.swipe_recycler_main);
swipe_main.setColorSchemeResources(R.color.swipe_schema_red, swipe_schema_blue, R.color.swipe_schema_green);
swipe_main.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
MyApplication.getHandler().postDelayed(new Runnable() {
@Override
public void run() {
showToast("刷新成功~");
swipe_main.setRefreshing(false);
}
}, 1500);
}
});
// 初始化RecyclerView
recycler_main = (RecyclerView) view.findViewById(R.id.recycler_recycler_main);
// 设置布局管理者,采用线性布局管理者,竖直排列,不用反转(反转就是数据反序)
recycler_main.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
adapter = new SimpleRecyclerAdapter(this, new SimpleRecyclerAdapter.OnItemClickListener() {
@Override
public void onClick(int position, ImgAndText bean) {
/*
这里有个要注意的地方就是,在adapter中设置侦听的时候你要是用onBindViewHolder方法中的参数position
那么remove之后会position错乱BUG.这是RecyclerView的一个大坑...要用holder.getAdapterPosition传递
*/
System.arraycopy(hits, 1, hits, 0, hits.length - 1);
hits[hits.length - 1] = SystemClock.uptimeMillis();
if (hits[0] >= SystemClock.uptimeMillis() - 500) {
MyLogUtil.debug("position: " + position);
adapter.removeItem(position);
} else {
ToastUtil.toastShort(RecyclerViewActivity.this, "点击了图片");
}
}
});
// 设置拖拽监听, 首先定义一个callback定义拖拽功能, callback中定义listener与adapter传递事件
// 然后将callback传给helper, 并由helper绑定recycle
ItemTouchHelper.Callback callback = new OnRecyclerItemTouchCallBack(adapter);
ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(recycler_main);
/*
细节注意, 上述方式是通过长按条目来实现拖拽, 比如条目右边有个图标, 希望按住图标实现拖拽呢?
adapter的holder中设置图标触摸事件setOnTouchListener. 这就需要在onTouch方法中调用上面helper的
onStartDrag方法, 怎么调用呢? adapter定义一个接口OnIconDragHandler. 里边定义
onHandleDrag(RecyclerView.ViewHolder viewHolder); 然后通过构造传进来.
这样再让当前activity实现接口, 调用helper的onStartDrag方法. 然后new adapter的时候传过去.
最后具体一下图标的ouTouch方法
如果按下
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN){
回调RecyclerViewActivity中的onHandleDrag方法
让mItemTouchHelper执行拖拽操作
handler.startDrag(holder);
}
*/
// recycler_main.setAdapter(adapter);
// 使用第三方库中简单的动画来设置适配器,其对象可以setDuration、setInterpolator,甚至可以继续传入形成装饰者
// recycler_main.setAdapter(new ScaleInAnimationAdapter(adapter));
recycler_main.setAdapter(new SlideInLeftAnimationAdapter(adapter));
/*
这里有个非常重要的问题,如果你想使用增删动画,那么在增删操作的时候
你就不能使用notifyDataSetChanged,不然动画不会执行的,需要使用notifyItemRemoved(posi)、notifyItemInserted(posi)
*/
// 设置条目动画,增删的时候会用到
SlideInLeftAnimator animator = new SlideInLeftAnimator();
animator.setInterpolator(new OvershootInterpolator());
recycler_main.setItemAnimator(animator);
// 将填充好的View放到主页面上
frame_main.addView(view);
}
use of jp.wasabeef.recyclerview.animators.SlideInLeftAnimator in project MaterialList by dexafree.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Save a reference to the context
mContext = this;
// Bind the MaterialListView to a variable
mListView = (MaterialListView) findViewById(R.id.material_listview);
mListView.setItemAnimator(new SlideInLeftAnimator());
mListView.getItemAnimator().setAddDuration(300);
mListView.getItemAnimator().setRemoveDuration(300);
final ImageView emptyView = (ImageView) findViewById(R.id.imageView);
emptyView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
mListView.setEmptyView(emptyView);
Picasso.with(this).load("https://www.skyverge.com/wp-content/uploads/2012/05/github-logo.png").resize(100, 100).centerInside().into(emptyView);
// Fill the array withProvider mock content
fillArray();
// Set the dismiss listener
mListView.setOnDismissCallback(new OnDismissCallback() {
@Override
public void onDismiss(@NonNull Card card, int position) {
// Show a toast
Toast.makeText(mContext, "You have dismissed a " + card.getTag(), Toast.LENGTH_SHORT).show();
}
});
// Add the ItemTouchListener
mListView.addOnItemTouchListener(new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(@NonNull Card card, int position) {
Log.d("CARD_TYPE", "" + card.getTag());
}
@Override
public void onItemLongClick(@NonNull Card card, int position) {
Log.d("LONG_CLICK", "" + card.getTag());
}
});
}
Aggregations