use of android.support.v7.widget.helper.ItemTouchHelper in project platform_frameworks_base by android.
the class NavBarTuner method onViewCreated.
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
RecyclerView recyclerView = (RecyclerView) view.findViewById(android.R.id.list);
final Context context = getContext();
recyclerView.setLayoutManager(new LinearLayoutManager(context));
mNavBarAdapter = new NavBarAdapter(context);
recyclerView.setAdapter(mNavBarAdapter);
recyclerView.addItemDecoration(new Dividers(context));
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mNavBarAdapter.mCallbacks);
mNavBarAdapter.setTouchHelper(itemTouchHelper);
itemTouchHelper.attachToRecyclerView(recyclerView);
TunerService.get(getContext()).addTunable(this, NAV_BAR_VIEWS);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project xRecyclerViewF by Dsiner.
the class ItemTouchRvActivity method init.
private void init() {
//step9-1:获取引用-!!!!!!!!!!不要使用XRecyclerView
recyclerView = (RecyclerView) this.findViewById(R.id.rv_list);
recyclerView.setHasFixedSize(true);
//step9-2:为RecyclerView指定布局管理对象
setLayoutManager();
//step9-3:setAdapter
ItemTouchAdapter adapter = new ItemTouchAdapter(this, datas, R.layout.item_touch);
adapter.setOnStartDragListener(this);
recyclerView.setAdapter(adapter);
//step9-4:关联ItemTouchHelper
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
itemTouchHelper = new ItemTouchHelper(callback);
//!!!!!!!!!!不要使用XRecyclerView-重要的事情说三遍
itemTouchHelper.attachToRecyclerView(recyclerView);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project AntennaPod by AntennaPod.
the class FavoriteEpisodesFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment);
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder) viewHolder;
Log.d(TAG, "remove(" + holder.getItemId() + ")");
if (subscription != null) {
subscription.unsubscribe();
}
FeedItem item = holder.getFeedItem();
if (item != null) {
DBWriter.removeFavoriteItem(item);
Snackbar snackbar = Snackbar.make(root, getString(R.string.removed_item), Snackbar.LENGTH_LONG);
snackbar.setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
snackbar.show();
}
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
return root;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project AntennaPod by AntennaPod.
the class QueueFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
((MainActivity) getActivity()).getSupportActionBar().setTitle(R.string.queue_label);
View root = inflater.inflate(R.layout.queue_fragment, container, false);
infoBar = (TextView) root.findViewById(R.id.info_bar);
recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()).build());
recyclerView.setHasFixedSize(true);
registerForContextMenu(recyclerView);
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
int from = viewHolder.getAdapterPosition();
int to = target.getAdapterPosition();
Log.d(TAG, "move(" + from + ", " + to + ")");
queue.add(to, queue.remove(from));
recyclerAdapter.notifyItemMoved(from, to);
DBWriter.moveQueueItem(from, to, true);
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
if (subscription != null) {
subscription.unsubscribe();
}
final int position = viewHolder.getAdapterPosition();
Log.d(TAG, "remove(" + position + ")");
final FeedItem item = queue.get(position);
final boolean isRead = item.isPlayed();
DBWriter.markItemPlayed(FeedItem.PLAYED, false, item.getId());
DBWriter.removeQueueItem(getActivity(), item, true);
Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_read_label), Snackbar.LENGTH_LONG);
snackbar.setAction(getString(R.string.undo), v -> {
DBWriter.addQueueItemAt(getActivity(), item.getId(), position, false);
if (!isRead) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
}
});
snackbar.show();
}
@Override
public boolean isLongPressDragEnabled() {
return !UserPreferences.isQueueLocked();
}
@Override
public boolean isItemViewSwipeEnabled() {
return !UserPreferences.isQueueLocked();
}
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
// We only want the active item
if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
if (viewHolder instanceof QueueRecyclerAdapter.ItemTouchHelperViewHolder) {
QueueRecyclerAdapter.ItemTouchHelperViewHolder itemViewHolder = (QueueRecyclerAdapter.ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemSelected();
}
}
super.onSelectedChanged(viewHolder, actionState);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
if (viewHolder instanceof QueueRecyclerAdapter.ItemTouchHelperViewHolder) {
QueueRecyclerAdapter.ItemTouchHelperViewHolder itemViewHolder = (QueueRecyclerAdapter.ItemTouchHelperViewHolder) viewHolder;
itemViewHolder.onItemClear();
}
}
});
itemTouchHelper.attachToRecyclerView(recyclerView);
txtvEmpty = (TextView) root.findViewById(android.R.id.empty);
txtvEmpty.setVisibility(View.GONE);
progLoading = (ProgressBar) root.findViewById(R.id.progLoading);
progLoading.setVisibility(View.VISIBLE);
return root;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project JustAndroid by chinaltz.
the class DragRecyleViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_recyclerview);
ButterKnife.bind(this);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
navToolBarBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbarTitle.setText("可拖拽的RecyleView");
for (int i = 0; i < 50; i++) {
str.add("data: " + i);
}
recyclerView.setLayoutManager(new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, false));
myAdapter = new MyAdapter();
recyclerView.setAdapter(myAdapter);
new ItemTouchHelper(new MyItemTouchHandler(myAdapter)).attachToRecyclerView(recyclerView);
}
Aggregations