@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE_CAPTURE && resultCode == Activity.RESULT_OK) {
      Uri captured = mMediaStoreCompat.getCapturedPhotoUri(data, mCapturePhotoUriHolder);
      if (captured != null) {
        mCollection.add(captured);
        mMediaStoreCompat.cleanUp(mCapturePhotoUriHolder);
      }
      supportInvalidateOptionsMenu();
    } else if (requestCode == REQUEST_CODE_PREVIEW && resultCode == Activity.RESULT_OK) {
      ArrayList<Uri> checked =
          data.getParcelableArrayListExtra(ImagePreviewActivity.EXTRA_RESULT_CHECKED);
      mCollection.overwrite(checked);
      PhotoSelectionViewHelper.refreshGridView(this);
      supportInvalidateOptionsMenu();
    }
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.l_activity_select_photo);
   PhotoSelectionViewHelper.setUpActivity(this);
   mMediaStoreCompat = new MediaStoreCompat(this, HandlerUtils.getMainHandler());
   mCapturePhotoUriHolder =
       savedInstanceState != null ? savedInstanceState.getString(STATE_CAPTURE_PHOTO_URI) : "";
   mCollection.onCreate(savedInstanceState);
   mCollection.prepareSelectionSpec(
       getIntent().<SelectionSpec>getParcelableExtra(EXTRA_SELECTION_SPEC));
   mCollection.setDefaultSelection(
       getIntent().<Uri>getParcelableArrayListExtra(EXTRA_RESUME_LIST));
   mDrawer = (DrawerLayout) findViewById(R.id.l_container_drawer);
   Toolbar toolbar = (Toolbar) findViewById(R.id.l_toolbar);
   mToggle = new PhotoSelectionActivityDrawerToggle(this, mDrawer, toolbar);
   setSupportActionBar(toolbar);
   mToggle.setUpActionBar(getSupportActionBar());
   mDrawer.setDrawerListener(mToggle);
 }
 @Override
 public void onBackPressed() {
   if (mCollection.isEmpty()) {
     setResult(Activity.RESULT_CANCELED);
     super.onBackPressed();
     return;
   }
   ConfirmationDialogFragment dialog =
       ConfirmationDialogFragment.newInstance(
           R.string.l_confirm_dialog_title, R.string.l_confirm_dialog_message);
   dialog.show(getSupportFragmentManager(), ConfirmationDialogFragment.TAG);
 }
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   mCollection.onSaveInstanceState(outState);
   outState.putString(STATE_CAPTURE_PHOTO_URI, mCapturePhotoUriHolder);
   super.onSaveInstanceState(outState);
 }