use of android.support.v7.widget.helper.ItemTouchHelper in project GitTest by xiaoxige.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
tvProgress = (TextView) findViewById(R.id.tvProgress);
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mItems = new ArrayList<>();
for (int i = 0; i < 50; i++) {
mItems.add("" + i);
}
adapter = new TestAdapter(MainActivity.this, mItems);
recyclerView.addItemDecoration(new TestItemDecoration());
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
ItemTouchHelper.Callback callback = new RecyclerItemTouchHelper();
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(recyclerView);
((RecyclerItemTouchHelper) callback).setListener(new TestRecyclerViewMoveListener() {
@Override
public void move(int from, int to) {
Collections.swap(mItems, from, to);
adapter.notifyItemMoved(from, to);
}
});
}
use of android.support.v7.widget.helper.ItemTouchHelper in project vlc-android by videolan.
the class VideoPlayerActivity method initPlaylistUi.
private void initPlaylistUi() {
if (mService.hasPlaylist()) {
mHasPlaylist = true;
mPlaylistAdapter = new PlaylistAdapter(this);
mPlaylistAdapter.setService(mService);
final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mPlaylist.setLayoutManager(layoutManager);
mPlaylistToggle.setVisibility(View.VISIBLE);
mHudBinding.playlistPrevious.setVisibility(View.VISIBLE);
mHudBinding.playlistNext.setVisibility(View.VISIBLE);
mPlaylistToggle.setOnClickListener(VideoPlayerActivity.this);
final ItemTouchHelper.Callback callback = new SwipeDragItemTouchHelperCallback(mPlaylistAdapter);
final ItemTouchHelper touchHelper = new ItemTouchHelper(callback);
touchHelper.attachToRecyclerView(mPlaylist);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper in project Rocket by mozilla-tw.
the class TabTrayFragment method setupSwipeToDismiss.
private void setupSwipeToDismiss(RecyclerView recyclerView) {
int swipeFlag = ENABLE_SWIPE_TO_DISMISS ? ItemTouchHelper.START | ItemTouchHelper.END : 0;
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, swipeFlag) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
}
}).attachToRecyclerView(recyclerView);
}
use of android.support.v7.widget.helper.ItemTouchHelper in project noChange by Khalidtoak.
the class ChangeRecord method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_change_record, container, false);
// find the recycler view in its xml by its id
recyclerView = rootView.findViewById(R.id.recyclcer_view_change);
// find the searView ById
searchView = rootView.findViewById(R.id.sv1);
// setLayout manager to a vertical linear layout manager
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
// setFixed size for recycler view
recyclerView.setHasFixedSize(true);
// initialize database
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
// initialize the adapter and pass in the context of the activity and retrieve by calling the method we
// created in the database and passing it in as the cursor
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"), getContext());
// /set the adapter of the recycler view
recyclerView.setAdapter(adapters);
// When the text in the search view changes .. we listen to it and re-do our querying
// by initializing the adapter and passing in the new cursor
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// get the query and convert it to a string
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewPagerAndSearchedText(query, "Change"), getContext());
// re set the adapter
recyclerView.setAdapter(adapters);
return true;
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(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(final RecyclerView.ViewHolder viewHolder, int direction) {
// get the id of the row yo want to delete
final long id1 = (long) viewHolder.itemView.getTag();
// /create a dialog message that confirms if you want to delete it or not
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if yes is selected
// delete that customer and pass in the id
// delete the News with id that was swiped off
removeCustomer(id1);
// create a snack bar that tells the user iif it has been deleted or not
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"));
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// if no is clicked... just swap cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Change"));
}
}).show();
Log.d(TAG, "onSwiped: did something happen here??");
}
}).attachToRecyclerView(recyclerView);
return rootView;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project noChange by Khalidtoak.
the class DashBoardFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootV = inflater.inflate(R.layout.fragment_dash_board, container, false);
recyclerView = rootV.findViewById(R.id.recyclcer_view_dash);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
searchView = rootV.findViewById(R.id.sv);
sqLiteDatabase = creditorsAndDebtorsDataBase.getWritableDatabase();
adapters = new Adapters(getAllSaved(), getContext());
recyclerView.setAdapter(adapters);
floatingActionButton = rootV.findViewById(R.id.fab_for_recyclcer_view_dash);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), AddChangeOrDebt.class);
startActivity(intent);
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(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(final RecyclerView.ViewHolder viewHolder, int direction) {
final long id1 = (long) viewHolder.itemView.getTag();
// delete the News with id that was swiped off
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete the Customer with id that was swiped off
removeCustomer(id1);
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(getAllSaved());
Log.d(TAG, "onSwiped: did something happen here??");
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapters.swapCursor(getAllSaved());
}
}).show();
}
}).attachToRecyclerView(recyclerView);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieve(query), getContext());
recyclerView.setAdapter(adapters);
return true;
}
});
return rootV;
}
Aggregations