use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateRecyclerView by cymcsg.
the class SimpleItemTouchHelperCallback method onChildDraw.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
// Fade out the view as it is swiped out of the parent's bounds
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
View itemView = viewHolder.itemView;
final float alpha = ALPHA_FULL - Math.abs(dX) / (float) itemView.getWidth();
itemView.setAlpha(alpha);
}
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateRecyclerView by cymcsg.
the class LauncherActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
ultimateRecyclerView = (UltimateRecyclerView) findViewById(R.id.ultimate_recycler_view);
ultimateRecyclerView.setHasFixedSize(false);
final List<String> stringList = new ArrayList<>();
stringList.add("111");
stringList.add("aaa");
stringList.add("222");
stringList.add("33");
stringList.add("44");
stringList.add("55");
stringList.add("66");
stringList.add("11771");
simpleRecyclerViewAdapter = new SimpleAdapter(stringList);
linearLayoutManager = new LinearLayoutManager(this);
ultimateRecyclerView.setLayoutManager(linearLayoutManager);
StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(simpleRecyclerViewAdapter);
ultimateRecyclerView.addItemDecoration(headersDecor);
//// ultimateRecyclerView.setEmptyView(getResources().getIdentifier("empty_view","layout",getPackageName()));
// ultimateRecyclerView.showEmptyView();
// ultimateRecyclerView.enableLoadmore();
//simpleRecyclerViewAdapter.setCustomLoadMoreView(LayoutInflater.from(this)
// .inflate(R.layout.custom_bottom_progressbar, null));
ultimateRecyclerView.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.custom_bottom_progressbar, null));
ultimateRecyclerView.setParallaxHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
// // ultimateRecyclerView.setNormalHeader(getLayoutInflater().inflate(R.layout.parallax_recyclerview_header, ultimateRecyclerView.mRecyclerView, false));
ultimateRecyclerView.setOnParallaxScroll(new UltimateRecyclerView.OnParallaxScroll() {
@Override
public void onParallaxScroll(float percentage, float offset, View parallax) {
Drawable c = toolbar.getBackground();
c.setAlpha(Math.round(127 + percentage * 128));
toolbar.setBackgroundDrawable(c);
}
});
ultimateRecyclerView.setRecylerViewBackgroundColor(Color.parseColor("#ffffff"));
ultimateRecyclerView.setDefaultOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
simpleRecyclerViewAdapter.insert(moreNum++ + " Refresh things", 0);
ultimateRecyclerView.setRefreshing(false);
// ultimateRecyclerView.scrollBy(0, -50);
linearLayoutManager.scrollToPosition(0);
// ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
// simpleRecyclerViewAdapter.notifyDataSetChanged();
}
}, 1000);
}
});
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(simpleRecyclerViewAdapter);
mItemTouchHelper = new ItemTouchHelper(callback);
mItemTouchHelper.attachToRecyclerView(ultimateRecyclerView.mRecyclerView);
simpleRecyclerViewAdapter.setOnDragStartListener(new SimpleAdapter.OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
mItemTouchHelper.startDrag(viewHolder);
}
});
ultimateRecyclerView.reenableLoadmore();
ultimateRecyclerView.setAdapter(simpleRecyclerViewAdapter);
ultimateRecyclerView.setOnLoadMoreListener(new UltimateRecyclerView.OnLoadMoreListener() {
@Override
public void loadMore(int itemsCount, final int maxLastVisiblePosition) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
simpleRecyclerViewAdapter.insert("More " + moreNum++, simpleRecyclerViewAdapter.getAdapterItemCount());
// linearLayoutManager.scrollToPositionWithOffset(maxLastVisiblePosition,-1);
// linearLayoutManager.scrollToPosition(maxLastVisiblePosition);
}
}, 1000);
}
});
// ultimateRecyclerView.setDefaultSwipeToRefreshColorScheme(getResources().getColor(android.R.color.holo_blue_bright),
// getResources().getColor(android.R.color.holo_green_light),
// getResources().getColor(android.R.color.holo_orange_light),
// getResources().getColor(android.R.color.holo_red_light));
// ultimateRecyclerView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() {
// @Override
// public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
//
// }
//
// @Override
// public void onDownMotionEvent() {
//
// }
//
// @Override
// public void onUpOrCancelMotionEvent(ObservableScrollState observableScrollState) {
//// if (observableScrollState == ObservableScrollState.DOWN) {
//// ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
//// ultimateRecyclerView.showFloatingActionMenu();
//// } else if (observableScrollState == ObservableScrollState.UP) {
//// ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
//// ultimateRecyclerView.hideFloatingActionMenu();
//// } else if (observableScrollState == ObservableScrollState.STOP) {
//// }
// URLogs.d("onUpOrCancelMotionEvent");
// if (observableScrollState == ObservableScrollState.UP) {
// ultimateRecyclerView.hideToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
// ultimateRecyclerView.hideFloatingActionMenu();
// } else if (observableScrollState == ObservableScrollState.DOWN) {
// ultimateRecyclerView.showToolbar(toolbar, ultimateRecyclerView, getScreenHeight());
// ultimateRecyclerView.showFloatingActionMenu();
// }
// }
// });
ultimateRecyclerView.showFloatingButtonView();
//
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) {
ultimateRecyclerView.setItemAnimator(Type.values()[position].getAnimator());
ultimateRecyclerView.getItemAnimator().setAddDuration(500);
ultimateRecyclerView.getItemAnimator().setRemoveDuration(500);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
simpleRecyclerViewAdapter.insert("newly added item", 1);
}
});
findViewById(R.id.del).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
simpleRecyclerViewAdapter.remove(1);
}
});
//
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project UltimateRecyclerView by cymcsg.
the class SimpleAdapter method onCreateViewHolder.
@Override
public UltimateRecyclerviewViewHolder onCreateViewHolder(ViewGroup parent) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_adapter, parent, false);
ViewHolder vh = new ViewHolder(v);
return vh;
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project AndroidSwipeLayout by daimajia.
the class RecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
String item = mDataset.get(position);
viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
@Override
public void onOpen(SwipeLayout layout) {
YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.trash));
}
});
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
@Override
public void onDoubleClick(SwipeLayout layout, boolean surface) {
Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
}
});
viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mItemManger.removeShownLayouts(viewHolder.swipeLayout);
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
mItemManger.closeAllItems();
Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show();
}
});
viewHolder.textViewPos.setText((position + 1) + ".");
viewHolder.textViewData.setText(item);
mItemManger.bind(viewHolder.itemView, position);
}
use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.
the class FlexibleItemAnimator method runRemoveAnimation.
//1st Remove
private void runRemoveAnimation() {
// Reverse sorting removal animations
Collections.sort(mPendingRemovals, new Comparator<ViewHolder>() {
@Override
public int compare(ViewHolder vh1, ViewHolder vh2) {
return (int) (vh2.getItemId() - vh1.getItemId());
}
});
Runnable remover = new Runnable() {
@Override
public void run() {
int index = 0;
for (ViewHolder holder : mPendingRemovals) {
doAnimateRemove(holder, index++);
}
mPendingRemovals.clear();
}
};
remover.run();
}
Aggregations