use of android.support.v7.widget.helper.ItemTouchHelper in project apps-android-wikipedia by wikimedia.
the class FeedView method setCallback.
public void setCallback(@Nullable ItemTouchHelperSwipeAdapter.Callback callback) {
if (itemTouchHelper != null) {
itemTouchHelper.attachToRecyclerView(new DummyView(getContext()));
itemTouchHelper = null;
}
if (callback != null) {
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperSwipeAdapter(callback));
itemTouchHelper.attachToRecyclerView(this);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper in project TrekAdvisor by peterLaurence.
the class TracksManageFragment method generateTracks.
private void generateTracks(Map map) {
Context ctx = getContext();
RecyclerView recyclerView = new RecyclerView(ctx);
recyclerView.setHasFixedSize(false);
/* All cards are laid out vertically */
LinearLayoutManager llm = new LinearLayoutManager(ctx);
recyclerView.setLayoutManager(llm);
/* Apply item decoration (add an horizontal divider) */
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(ctx, DividerItemDecoration.VERTICAL);
Drawable divider = this.getContext().getDrawable(R.drawable.divider);
if (divider != null) {
dividerItemDecoration.setDrawable(divider);
}
recyclerView.addItemDecoration(dividerItemDecoration);
mTrackAdapter = new TrackAdapter(map, this, ctx.getColor(R.color.colorAccent), ctx.getColor(R.color.colorPrimaryTextWhite), ctx.getColor(R.color.colorPrimaryTextBlack));
recyclerView.setAdapter(mTrackAdapter);
/* Swipe to dismiss functionality */
ItemTouchHelper.SimpleCallback simpleCallback = 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 direction) {
/* Remove the track from the list and from the map */
mTrackAdapter.removeItem(viewHolder.getAdapterPosition());
/* Update the view */
if (mTrackChangeListener != null) {
mTrackChangeListener.onTrackVisibilityChanged();
}
/* Save */
saveChanges();
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
rootView.addView(recyclerView, 0);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project JustAndroid by chinaltz.
the class StaggeredActivity method setListener.
private void setListener() {
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
page = 1;
new GetData().execute("http://gank.io/api/data/福利/10/1");
}
});
itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
@Override
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
int dragFlags = 0;
if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN | ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
}
return makeMovementFlags(dragFlags, 0);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
int from = viewHolder.getAdapterPosition();
int to = target.getAdapterPosition();
StaggeredType moveItem = staggeredTypes.get(from);
staggeredTypes.remove(from);
staggeredTypes.add(to, moveItem);
mAdapter.notifyItemMoved(from, to);
return true;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
@Override
public boolean isLongPressDragEnabled() {
return false;
}
});
recyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
// 0:当前屏幕停止滚动;1时:屏幕在滚动 且 用户仍在触碰或手指还在屏幕上;2时:随用户的操作,屏幕上产生的惯性滑动;
if (newState == RecyclerView.SCROLL_STATE_IDLE && lastVisibleItem + 2 >= mLayoutManager.getItemCount()) {
new GetData().execute("http://gank.io/api/data/福利/10/" + (++page));
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int[] positions = mLayoutManager.findLastVisibleItemPositions(null);
lastVisibleItem = Math.max(positions[0], positions[1]);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper in project android_frameworks_base by crdroidandroid.
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 android_frameworks_base by AOSPA.
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);
}
Aggregations