public void updateActionBarTitle() {
   actionBar.setTitle(
       getString(
           R.string.image_index,
           pagerFragment.getViewPager().getCurrentItem() + 1,
           pagerFragment.getPaths().size()));
 }
  @Override
  public void onBackPressed() {

    Intent intent = new Intent();
    intent.putExtra(PhotoPickerActivity.KEY_SELECTED_PHOTOS, pagerFragment.getPaths());
    setResult(RESULT_OK, intent);
    finish();

    super.onBackPressed();
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == android.R.id.home) {
      onBackPressed();
      return true;
    }

    if (item.getItemId() == R.id.delete) {
      final int index = pagerFragment.getCurrentItem();

      final String deletedPath = pagerFragment.getPaths().get(index);

      // Snackbar snackbar = Snackbar.make(pagerFragment.getView(), R.string.deleted_a_photo,
      //    Snackbar.LENGTH_LONG);

      if (pagerFragment.getPaths().size() <= 1) {

        // show confirm dialog
        new AlertDialog.Builder(this)
            .setTitle(R.string.confirm_to_delete)
            .setPositiveButton(
                R.string.yes,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                    setResult(RESULT_OK);
                    finish();
                  }
                })
            .setNegativeButton(
                R.string.cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.dismiss();
                  }
                })
            .show();

      } else {
        Toast.makeText(this, R.string.deleted_a_photo, Toast.LENGTH_SHORT).show();
        // snackbar.show();

        pagerFragment.getPaths().remove(index);
        // pagerFragment.getViewPager().removeViewAt(index);
        pagerFragment.getViewPager().getAdapter().notifyDataSetChanged();
      }

      //      snackbar.setAction(R.string.undo, new View.OnClickListener() {
      //        @Override public void onClick(View view) {
      //          if (pagerFragment.getPaths().size() > 0) {
      //            pagerFragment.getPaths().add(index, deletedPath);
      //          } else {
      //            pagerFragment.getPaths().add(deletedPath);
      //          }
      //          pagerFragment.getViewPager().getAdapter().notifyDataSetChanged();
      //          pagerFragment.getViewPager().setCurrentItem(index, true);
      //        }
      //      });

      return true;
    }

    return super.onOptionsItemSelected(item);
  }