@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (requestCode == MediaGalleryPickerActivity.REQUEST_CODE) {
     if (resultCode == RESULT_OK) {
       ArrayList<String> ids = data.getStringArrayListExtra(MediaGalleryPickerActivity.RESULT_IDS);
       mMediaGalleryEditFragment.setMediaIds(ids);
     }
   }
   super.onActivityResult(requestCode, resultCode, data);
 }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (WordPress.wpDB == null) {
      Toast.makeText(this, R.string.fatal_db_error, Toast.LENGTH_LONG).show();
      finish();
      return;
    }

    setTitle(R.string.media_gallery_edit);

    setContentView(R.layout.media_gallery_activity);

    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
      actionBar.setDisplayShowTitleEnabled(true);
    }

    FragmentManager fm = getFragmentManager();

    mMediaGallery = (MediaGallery) getIntent().getSerializableExtra(PARAMS_MEDIA_GALLERY);
    if (mMediaGallery == null) {
      mMediaGallery = new MediaGallery();
    }

    mMediaGalleryEditFragment =
        (MediaGalleryEditFragment) fm.findFragmentById(R.id.mediaGalleryEditFragment);
    mMediaGallerySettingsFragment =
        (MediaGallerySettingsFragment) fm.findFragmentById(R.id.mediaGallerySettingsFragment);
    if (savedInstanceState == null) {
      // if not null, the fragments will remember its state
      mMediaGallerySettingsFragment.setRandom(mMediaGallery.isRandom());
      mMediaGallerySettingsFragment.setNumColumns(mMediaGallery.getNumColumns());
      mMediaGallerySettingsFragment.setType(mMediaGallery.getType());

      mMediaGalleryEditFragment.setMediaIds(mMediaGallery.getIds());
    }

    mSlidingPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.media_gallery_root);
    if (mSlidingPanelLayout != null) {
      // sliding panel layout is on phone only

      mSlidingPanelLayout.setDragView(mMediaGallerySettingsFragment.getDragView());
      mSlidingPanelLayout.setPanelHeight(DisplayUtils.dpToPx(this, 48));
      mSlidingPanelLayout.setPanelSlideListener(
          new PanelSlideListener() {
            @Override
            public void onPanelSlide(View panel, float slideOffset) {}

            @Override
            public void onPanelExpanded(View panel) {
              mMediaGallerySettingsFragment.onPanelExpanded();
              mIsPanelCollapsed = false;
            }

            @Override
            public void onPanelCollapsed(View panel) {
              mMediaGallerySettingsFragment.onPanelCollapsed();
              mIsPanelCollapsed = true;
            }
          });
    }

    if (getIntent().hasExtra(PARAMS_LAUNCH_PICKER)) {
      handleAddMedia();
    }
  }