示例#1
0
  @Override
  public void onItemChecked(boolean isChecked, int position) {
    Media media = mMediaAdapter.getItem(position);
    boolean contains = contains(media);

    if (!contains && isChecked) {
      if (media.getMediaType() == MediaType.MEDIA_TYPE_VIDEO) {
        if (media.getSize() > MediaPickerConstants.SELECTED_VIDEO_SIZE_IN_MB * ByteUtil.MB) {
          Toast.makeText(
                  getActivity(),
                  getActivity()
                      .getString(
                          R.string.mp_video_size_too_big,
                          MediaPickerConstants.SELECTED_VIDEO_SIZE_IN_MB),
                  Toast.LENGTH_SHORT)
              .show();
          return;
        }
      }

      if (MediaPickerConstants.MAX_MEDIA_LIMIT == 1
          && MediaPickerConstants.SELECTED_MEDIA_COUNT == 1) {
        mSelectedMedias.remove(0);
        MediaPickerConstants.SELECTED_MEDIA_COUNT--;

        mMediaAdapter.resetItemState(mMediaGridView, position);
      } else {
        if ((MediaPickerConstants.SELECTED_MEDIA_COUNT == MediaPickerConstants.MAX_MEDIA_LIMIT)) {
          Toast.makeText(
                  getActivity(),
                  getActivity()
                      .getString(
                          R.string.mp_file_count_overflow_hint,
                          MediaPickerConstants.SELECTED_MEDIA_COUNT),
                  Toast.LENGTH_SHORT)
              .show();
          return;
        }
      }

      mSelectedMedias.add(media);
      MediaPickerConstants.SELECTED_MEDIA_COUNT++;
    } else if (contains && (!isChecked)) {
      mSelectedMedias.remove(media);
      MediaPickerConstants.SELECTED_MEDIA_COUNT--;
    }

    mMediaAdapter.updateItemState(mMediaGridView, position);

    if (mCallback != null) {
      mCallback.onMediaSelected(mSelectedMedias);
    }
  }
示例#2
0
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Media media = mMediaAdapter.getItem(position);

    if (media.getData().startsWith(Media.TYPE_CAMERA)) {
      openCamera();
    } else {
      ArrayList<Media> medias = new ArrayList<Media>();
      medias.addAll(mMediaAdapter.getMedias());
      if (MediaPickerConstants.SHOW_CAMERA) {
        medias.remove(0);
        launchPreviewActivity(medias, mSelectedMedias, position - 1);
      } else {
        launchPreviewActivity(medias, mSelectedMedias, position);
      }
    }
  }