Java Code Examples for android.support.v7.widget.helper.ItemTouchHelper#Callback

The following examples show how to use android.support.v7.widget.helper.ItemTouchHelper#Callback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecyclerGridFragment.java    From Android-ItemTouchHelper-Demo with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final RecyclerListAdapter adapter = new RecyclerListAdapter(getActivity(), this);

    RecyclerView recyclerView = (RecyclerView) view;
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(adapter);

    final int spanCount = getResources().getInteger(R.integer.grid_columns);
    final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), spanCount);
    recyclerView.setLayoutManager(layoutManager);

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 2
Source File: MainActivity.java    From TimePicker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new GridLayoutManager(null, 2));
    recyclerView.setAdapter(adapter);

    ItemTouchHelper.Callback callback = new MyItemTouchCallback(adapter);
    ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
    touchHelper.attachToRecyclerView(recyclerView);
}
 
Example 3
Source File: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
private void populateRecyclerView() {
    stringArrayList.add("Item 1");
    stringArrayList.add("Item 2");
    stringArrayList.add("Item 3");
    stringArrayList.add("Item 4");
    stringArrayList.add("Item 5");
    stringArrayList.add("Item 6");
    stringArrayList.add("Item 7");
    stringArrayList.add("Item 8");
    stringArrayList.add("Item 9");
    stringArrayList.add("Item 10");

    mAdapter = new RecyclerViewAdapter(stringArrayList,this);

    ItemTouchHelper.Callback callback =
            new ItemMoveCallback(mAdapter);
    touchHelper  = new ItemTouchHelper(callback);
    touchHelper.attachToRecyclerView(recyclerView);

    recyclerView.setAdapter(mAdapter);
}
 
Example 4
Source File: ShopCartDelegate.java    From FastWaiMai with MIT License 6 votes vote down vote up
@Override
public void onSuccess(String response) {
    final LinkedList<MultipleItemEntity> data =
            new ShopCartDataConverter().setJsonData(response).convert();
    final LinearLayoutManager manager = new LinearLayoutManager(getContext());
    mAdapter = new ShopCartAdapter(data);
 mAdapter.setCartItemListener(this);
    final ItemTouchHelper.Callback callback = new ShopCartItemTouchHelperCallback(mAdapter);
    final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setLayoutManager(manager);
    checkItemCount();
    final double totalPrice = mAdapter.getTotalPrice();
    mTvTotalPrice.setText(String.valueOf(totalPrice));
}
 
Example 5
Source File: PlaybackQueueFragment.java    From vk_music_android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_playbackqueue, container, false);

    binding.rcvAudio.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
    binding.rcvAudio.setAdapter(adapter);
    binding.clearQueue.setOnClickListener(v -> onClearQueueClicked());

    ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(adapter);
    touchHelper = new ItemTouchHelper(callback);
    touchHelper.attachToRecyclerView(binding.rcvAudio);

    updateQueueSizeLabel();

    return binding.getRoot();
}
 
Example 6
Source File: SelectedAppsView.java    From FastAccess with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void onFragmentCreated(View view, @Nullable Bundle savedInstanceState) {
    recycler.setEmptyView(empty);
    emptyText.setText(R.string.no_apps_selected);
    adapter = new DeviceAppsAdapter(new ArrayList<AppsModel>(), getPresenter(), selection, true);
    recycler.setAdapter(adapter);
    loader = getLoaderManager().initLoader(0, null, getPresenter());
    if (!selection.isEmpty()) {
        actionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(getPresenter());
        actionMode.setTitle(getString(R.string.selected) + " ( " + adapter.selectionSize() + " )");
    }
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(getPresenter(), false);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recycler);
}
 
Example 7
Source File: ActivityWithRecycler.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
protected void postOnCreate() {

        RecyclerView.LayoutManager mLayoutManager = new CustomLinearLayoutManager(this);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setAdapter(mAdapter);

        ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter);
        mItemTouchHelper = new ItemTouchHelper(callback);
        mItemTouchHelper.attachToRecyclerView(recyclerView);
    }
 
Example 8
Source File: CategoriesFragment.java    From outlay with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ButterKnife.bind(this, view);

    setToolbar(toolbar);
    setDisplayHomeAsUpEnabled(true);
    getActivity().setTitle(getString(app.outlay.R.string.caption_categories));

    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 4);
    categoriesGrid.setLayoutManager(gridLayoutManager);

    adapter = new CategoriesDraggableGridAdapter(getOutlayTheme());
    adapter.setDragListener(this);
    adapter.setOnCategoryClickListener(c -> Navigator.goToCategoryDetails(getActivity(), c.getId()));
    categoriesGrid.setAdapter(adapter);

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(adapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(categoriesGrid);

    fab.setImageDrawable(getResourceHelper().getFabIcon(app.outlay.R.string.ic_material_add));
    fab.setOnClickListener(v -> Navigator.goToCategoryDetails(getActivity(), null));

    Drawable noCategoryIcon = IconUtils.getIconMaterialIcon(
            getContext(),
            MaterialDesignIconic.Icon.gmi_label,
            getOutlayTheme().inactiveIconColor,
            app.outlay.R.dimen.icon_no_results,
            16
    );
    noContentImage.setImageDrawable(noCategoryIcon);
}
 
Example 9
Source File: PlansManagerActivity.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
private void initPlanList() {
    mPlanList = new ArrayList<>();
    //Log.d("PlansManager:", plans.size() + "ge");
    planListView = (RecyclerView) findViewById(R.id.plan_list);
    LinearLayoutManager llm = new LinearLayoutManager(this);
    planListView.setLayoutManager(llm);
    mPlansAdapter = new PlansAdapter(PlansManagerActivity.this, mPlanList);
    //planList.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
    planListView.setAdapter(mPlansAdapter);

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mPlansAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(planListView);
}
 
Example 10
Source File: StepListFragment.java    From friendly-plans with GNU General Public License v3.0 5 votes vote down vote up
private void setUpListContent(long taskId) {
    RecyclerView recyclerView = (RecyclerView) getActivity().findViewById(R.id.rv_step_list);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    stepListRecyclerViewAdapter = new StepListRecyclerViewAdapter(stepItemClickListener);
    recyclerView.setAdapter(stepListRecyclerViewAdapter);

    stepListRecyclerViewAdapter.setStepItemListItems(stepTemplateRepository.getAll(taskId));

    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(stepListRecyclerViewAdapter);
    ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 11
Source File: RecyclerViewElasticityAdapter.java    From elasticity with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected void setUpTouchHelperCallback(final ItemTouchHelper.Callback itemTouchHelperCallback) {
    new ItemTouchHelper(new ItemTouchHelperCallbackWrapper(itemTouchHelperCallback) {
        @Override
        public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
            mIsItemTouchInEffect = actionState != 0;
            super.onSelectedChanged(viewHolder, actionState);
        }
    }).attachToRecyclerView(mRecyclerView);
}
 
Example 12
Source File: EditActivity.java    From homeassist with Apache License 2.0 5 votes vote down vote up
private void setupRecyclerView() {
    mRecyclerView = findViewById(R.id.recycler_view);

    mItems.clear();
    mItems.addAll(DatabaseManager.getInstance(this).getDashboard(mGroup.groupId));

    mAdapter = new EntityAdapter(mItems);
    mRecyclerView.setAdapter(mAdapter);
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter);
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(mRecyclerView);
    updateRecyclerViewLayout();
}
 
Example 13
Source File: NewTabPageAdapter.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/** Returns callbacks to configure the interactions with the RecyclerView's items. */
public ItemTouchHelper.Callback getItemTouchCallbacks() {
    return mItemTouchCallbacks;
}
 
Example 14
Source File: RecyclerViewElasticityAdapter.java    From elasticity with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public RecyclerViewElasticityAdapter(RecyclerView recyclerView, ItemTouchHelper.Callback itemTouchHelperCallback) {
    this(recyclerView);
    setUpTouchHelperCallback(itemTouchHelperCallback);
}
 
Example 15
Source File: ItemTouchHelperProvider.java    From PracticalRecyclerView with Apache License 2.0 4 votes vote down vote up
static void init(ItemTouchHelper.Callback callback) {
    ourInstance = new ItemTouchHelper(callback);
}
 
Example 16
Source File: RecyclerViewElasticityAdapter.java    From elasticity with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public RecyclerViewElasticityAdapter(RecyclerView recyclerView, Impl impl, ItemTouchHelper.Callback itemTouchHelperCallback) {
    this(recyclerView, impl);
    setUpTouchHelperCallback(itemTouchHelperCallback);
}
 
Example 17
Source File: RecyclerViewElasticityAdapter.java    From elasticity with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private ItemTouchHelperCallbackWrapper(ItemTouchHelper.Callback callback) {
    mCallback = callback;
}
 
Example 18
Source File: CategoryRecyclerAdapter.java    From SimpleNews with Apache License 2.0 4 votes vote down vote up
public void initTouch(EmptyObservableRecyclerView recyclerView) {
    ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(this);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(recyclerView);
}
 
Example 19
Source File: DragAndDeleteActivity.java    From Collection-Android with MIT License 4 votes vote down vote up
@Override
public void init() {

	defineActionBarConfig.setTitle(getString(R.string.activity_drag_delete_title));

	LinearLayoutManager layoutManager = new LinearLayoutManager(this);
	layoutManager.setOrientation(LinearLayoutManager.VERTICAL);

	mRecyclerView.setLayoutManager(layoutManager);

	for(int i=0;i<20;i++){
		mDatas.add((i+1)+"   左右滑动删除/长按拖动");
	}


	dragAndDeleteAdapter=new DragAndDeleteAdapter(this,mDatas);
	dragAndDeleteAdapter.setDragAndDeleteListener(this);
	mRecyclerView.setAdapter(dragAndDeleteAdapter);

	ItemTouchHelper.Callback callback=new BaseRecycleItemTouchHelper(dragAndDeleteAdapter);
	ItemTouchHelper itemTouchHelper=new ItemTouchHelper(callback);
	itemTouchHelper.attachToRecyclerView(mRecyclerView);

}
 
Example 20
Source File: SectionDataManager.java    From sectioned-recycler-view with MIT License 2 votes vote down vote up
/**
 * Returns Callback for RecyclerView's ItemTouchHelper, which interacts with sections passing
 * calls to SectionItemSwipeCallbacks.
 *
 * @return ItemTouchHelper.Callback implementation.
 */
public ItemTouchHelper.Callback getSwipeCallback() {
    return swipeCallback;
}