private void createAdapter() {
    mAdapter = new PersonAdapter(mPersons, this);

    mAdapter.setOnItemClickListener(onItemClickListener);
    mAdapter.setOnItemLongClickListener(onItemLongClickListener);

    mRecyclerView.setAdapter(mAdapter);
  }
  private void closeActionMode() {
    mActionMode = null;
    mAdapter.clearItemsChecked();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }
  }
  private void openActionMode(int position) {
    mActionMode = startSupportActionMode(callback);
    mAdapter.setItemChecked(position);
    updateTitleBar();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.secondaryText));
    }
  }
  private void filterList(String newText) {
    int size = mPersons.size();

    for (int i = size - 1; i >= 0; i--) {
      String namePerson = mPersons.get(i).getName();
      if (!namePerson.contains(newText)) {
        mPersons.remove(i);
        mAdapter.notifyDataSetChanged();
      }
    }
  }
 @Override
 public void OnItemClick(View v, int position) {
   if (mActionMode != null) {
     mAdapter.setItemChecked(position);
     updateTitleBar();
   } else
     Toast.makeText(
             MainActivity.this,
             mPersons.get(position).getName() + " Click",
             Toast.LENGTH_LONG)
         .show();
 }
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
          if (item.getItemId() == R.id.action_delete) {
            mAdapter.delete();
            mActionMode.finish();

            Snackbar.make(
                    mRecyclerView,
                    getString(R.string.message_deleted, mAdapter.totalItemChecked()),
                    Snackbar.LENGTH_LONG)
                .setAction(
                    R.string.message_undo,
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        mAdapter.undoDelete();
                      }
                    })
                .setActionTextColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary))
                .show();
          }

          return false;
        }
 private void updateTitleBar() {
   int total = mAdapter.totalItemChecked();
   String selected = getResources().getQuantityString(R.plurals.total_selected, total, total);
   mActionMode.setTitle(selected);
 }