use of androidx.recyclerview.widget.ItemTouchHelper 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 androidx.recyclerview.widget.ItemTouchHelper in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ContextualCardsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = getContext();
final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
mCardsContainer = rootView.findViewById(R.id.card_container);
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT, GridLayoutManager.VERTICAL, false);
mCardsContainer.setLayoutManager(mLayoutManager);
mContextualCardsAdapter = new ContextualCardsAdapter(context, this, /* lifecycleOwner */
mContextualCardManager);
mCardsContainer.setAdapter(mContextualCardsAdapter);
mContextualCardManager.setListener(mContextualCardsAdapter);
mCardsContainer.setListener(this);
mItemTouchHelper = new ItemTouchHelper(new SwipeDismissalDelegate(mContextualCardsAdapter));
mItemTouchHelper.attachToRecyclerView(mCardsContainer);
return rootView;
}
use of androidx.recyclerview.widget.ItemTouchHelper in project AntennaPod by AntennaPod.
the class NewEpisodesFragment method onCreateView.
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = super.onCreateView(inflater, container, savedInstanceState);
emptyView.setTitle(R.string.no_new_episodes_head_label);
emptyView.setMessage(R.string.no_new_episodes_label);
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, 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) {
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder;
FeedItemMenuHandler.removeNewFlagWithUndo(NewEpisodesFragment.this, holder.getFeedItem());
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
return root;
}
use of androidx.recyclerview.widget.ItemTouchHelper in project kdeconnect-android by KDE.
the class CustomDevicesAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelperCallback(adapterPos -> callback.onCustomDeviceDismissed(customDevices.get(adapterPos))));
itemTouchHelper.attachToRecyclerView(recyclerView);
}
use of androidx.recyclerview.widget.ItemTouchHelper in project materialistic by hidroh.
the class SinglePageItemRecyclerViewAdapter method attach.
@Override
public void attach(Context context, RecyclerView recyclerView) {
super.attach(context, recyclerView);
mLevelIndicatorWidth = AppUtils.getDimensionInDp(mContext, R.dimen.level_indicator_width);
mColors = mResourcesProvider.obtainTypedArray(R.array.color_codes);
mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
Item item = getItem(viewHolder.getAdapterPosition());
if (item == null || item.getKidCount() == 0) {
return 0;
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
Item item = getItem(position);
if (item != null) {
notifyItemChanged(position);
toggleKids(item);
}
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
float swipeWidth = viewHolder.itemView.getWidth() * getSwipeThreshold(viewHolder);
dX = Math.max(dX, -swipeWidth);
dX = Math.min(dX, swipeWidth);
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
return 0.1f;
}
});
mItemTouchHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(mScrollListener);
}
Aggregations