示例#1
0
  private void pickAlbum(int slotIndex) {
    if (!mIsActive) return;

    MediaSet targetSet = mAlbumSetDataAdapter.getMediaSet(slotIndex);
    if (targetSet == null) return; // Content is dirty, we shall reload soon
    if (targetSet.getTotalMediaItemCount() == 0) {
      showEmptyAlbumToast(Toast.LENGTH_SHORT);
      return;
    }
    hideEmptyAlbumToast();

    String mediaPath = targetSet.getPath().toString();

    Bundle data = new Bundle(getData());
    int[] center = new int[2];
    getSlotCenter(slotIndex, center);
    data.putIntArray(AlbumPage.KEY_SET_CENTER, center);
    if (mGetAlbum && targetSet.isLeafAlbum()) {
      Activity activity = mActivity;
      Intent result =
          new Intent().putExtra(AlbumPicker.KEY_ALBUM_PATH, targetSet.getPath().toString());
      activity.setResult(Activity.RESULT_OK, result);
      activity.finish();
    } else if (targetSet.getSubMediaSetCount() > 0) {
      data.putString(AlbumSetPage.KEY_MEDIA_PATH, mediaPath);
      mActivity
          .getStateManager()
          .startStateForResult(AlbumSetPage.class, REQUEST_DO_ANIMATION, data);
    } else {
      if (!mGetContent && (targetSet.getSupportedOperations() & MediaObject.SUPPORT_IMPORT) != 0) {
        data.putBoolean(AlbumPage.KEY_AUTO_SELECT_ALL, true);
      } else if (!mGetContent && albumShouldOpenInFilmstrip(targetSet)) {
        data.putParcelable(
            PhotoPage.KEY_OPEN_ANIMATION_RECT, mSlotView.getSlotRect(slotIndex, mRootPane));
        data.putInt(PhotoPage.KEY_INDEX_HINT, 0);
        data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mediaPath);
        data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, true);
        data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, targetSet.isCameraRoll());
        mActivity
            .getStateManager()
            .startStateForResult(PhotoPage.class, AlbumPage.REQUEST_PHOTO, data);
        return;
      }
      data.putString(AlbumPage.KEY_MEDIA_PATH, mediaPath);

      // We only show cluster menu in the first AlbumPage in stack
      boolean inAlbum = mActivity.getStateManager().hasStateClass(AlbumPage.class);
      data.putBoolean(AlbumPage.KEY_SHOW_CLUSTER_MENU, !inAlbum);
      mActivity.getStateManager().startStateForResult(AlbumPage.class, REQUEST_DO_ANIMATION, data);
    }
  }
  private void pickPhoto(int slotIndex, boolean startInFilmstrip) {
    if (!mIsActive) return;

    if (!startInFilmstrip) {
      // Launch photos in lights out mode
      mActivity.getGLRoot().setLightsOutMode(true);
    }

    MediaItem item = mAlbumDataAdapter.get(slotIndex);
    if (item == null) return; // Item not ready yet, ignore the click
    if (mGetContent) {
      onGetContent(item);
    } else if (mLaunchedFromPhotoPage) {
      TransitionStore transitions = mActivity.getTransitionStore();
      transitions.put(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_PICKED);
      transitions.put(PhotoPage.KEY_INDEX_HINT, slotIndex);
      onBackPressed();
    } else {
      // Get into the PhotoPage.
      // mAlbumView.savePositions(PositionRepository.getInstance(mActivity));
      Bundle data = new Bundle();
      data.putInt(PhotoPage.KEY_INDEX_HINT, slotIndex);
      data.putParcelable(
          PhotoPage.KEY_OPEN_ANIMATION_RECT, mSlotView.getSlotRect(slotIndex, mRootPane));
      data.putString(PhotoPage.KEY_MEDIA_SET_PATH, mMediaSetPath.toString());
      data.putString(PhotoPage.KEY_MEDIA_ITEM_PATH, item.getPath().toString());
      data.putInt(PhotoPage.KEY_ALBUMPAGE_TRANSITION, PhotoPage.MSG_ALBUMPAGE_STARTED);
      data.putBoolean(PhotoPage.KEY_START_IN_FILMSTRIP, startInFilmstrip);
      data.putBoolean(PhotoPage.KEY_IN_CAMERA_ROLL, mMediaSet.isCameraRoll());
      if (startInFilmstrip) {
        mActivity.getStateManager().switchState(this, FilmstripPage.class, data);
      } else {
        mActivity.getStateManager().startStateForResult(SinglePhotoPage.class, REQUEST_PHOTO, data);
      }
    }
  }