com.yanzhenjie.album.AlbumFile Java Examples

The following examples show how to use com.yanzhenjie.album.AlbumFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FormPresenter.java    From NoHttp with Apache License 2.0 6 votes vote down vote up
@Override
public void addFile() {
    Album.image(this)
      .multipleChoice()
      .selectCount(3)
      .camera(true)
      .checkedList(mAlbumList)
      .onResult(new Action<ArrayList<AlbumFile>>() {
          @Override
          public void onAction(@NonNull ArrayList<AlbumFile> albumFiles) {
              mAlbumList = albumFiles;

              mFileItems = new ArrayList<>();
              for (AlbumFile albumFile : mAlbumList) {
                  FileItem fileItem = new FileItem();
                  fileItem.setAlbumFile(albumFile);
                  mFileItems.add(fileItem);
              }
              mView.setFileList(mFileItems);

              mView.setStatusText(getString(R.string.form_upload_wait));
          }
      })
      .start();
}
 
Example #2
Source File: GalleryActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
@Override
public void onCurrentChanged(int position) {
    sCurrentPosition = position;
    mView.setTitle(sCurrentPosition + 1 + " / " + sAlbumFiles.size());

    AlbumFile albumFile = sAlbumFiles.get(position);
    mView.setChecked(albumFile.isChecked());
    mView.setLayerDisplay(albumFile.isDisable());

    if (albumFile.getMediaType() == AlbumFile.TYPE_VIDEO) {
        mView.setDuration(AlbumUtils.convertDuration(albumFile.getDuration()));
        mView.setDurationDisplay(true);
    } else {
        mView.setDurationDisplay(false);
    }
}
 
Example #3
Source File: GalleryAlbumActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
@Override
public void onCurrentChanged(int position) {
    mCurrentPosition = position;
    mView.setSubTitle(position + 1 + " / " + mAlbumFiles.size());

    AlbumFile albumFile = mAlbumFiles.get(position);
    if (mCheckable) mView.setChecked(albumFile.isChecked());
    mView.setLayerDisplay(albumFile.isDisable());

    if (albumFile.getMediaType() == AlbumFile.TYPE_VIDEO) {
        if (!mCheckable) mView.setBottomDisplay(true);
        mView.setDuration(AlbumUtils.convertDuration(albumFile.getDuration()));
        mView.setDurationDisplay(true);
    } else {
        if (!mCheckable) mView.setBottomDisplay(false);
        mView.setDurationDisplay(false);
    }
}
 
Example #4
Source File: L3PostActivity.java    From smart-farmer-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_l3_post);
    ARouter.getInstance().inject(this);
    initView();
    disableSlideBack();

    AlbumFile albumFile = getIntent().getParcelableExtra("media");
    if (albumFile != null) {
        defaultContent.pictures.add(albumFile);
        mPresenter.upload(albumFile);
    }

    initContent();
    initKeyBoard();

    currentPostContent = defaultContent;
}
 
Example #5
Source File: AlbumFilterActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
/**
 * Preview image, to album.
 */
private void previewAlbum(int position) {
    if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
        Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
    } else {
        Album.galleryAlbum(this)
                .checkable(true)
                .checkedList(mAlbumFiles)
                .currentPosition(position)
                .widget(
                        Widget.newDarkBuilder(this)
                                .title(mToolbar.getTitle().toString())
                                .build()
                )
                .onResult(new Action<ArrayList<AlbumFile>>() {
                    @Override
                    public void onAction(@NonNull ArrayList<AlbumFile> result) {
                        mAlbumFiles = result;
                        mAdapter.notifyDataSetChanged(mAlbumFiles);
                        mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
                    }
                })
                .start();
    }
}
 
Example #6
Source File: ImageActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
/**
 * Preview image, to album.
 */
private void previewImage(int position) {
    if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
        Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
    } else {
        Album.galleryAlbum(this)
                .checkable(true)
                .checkedList(mAlbumFiles)
                .currentPosition(position)
                .widget(
                        Widget.newDarkBuilder(this)
                                .title(mToolbar.getTitle().toString())
                                .build()
                )
                .onResult(new Action<ArrayList<AlbumFile>>() {
                    @Override
                    public void onAction(@NonNull ArrayList<AlbumFile> result) {
                        mAlbumFiles = result;
                        mAdapter.notifyDataSetChanged(mAlbumFiles);
                        mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
                    }
                })
                .start();
    }
}
 
Example #7
Source File: AlbumActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
/**
 * Preview image, to album.
 */
private void previewAlbum(int position) {
    if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
        Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
    } else {
        Album.galleryAlbum(this)
                .checkable(true)
                .checkedList(mAlbumFiles)
                .currentPosition(position)
                .widget(
                        Widget.newDarkBuilder(this)
                                .title(mToolbar.getTitle().toString())
                                .build()
                )
                .onResult(new Action<ArrayList<AlbumFile>>() {
                    @Override
                    public void onAction(@NonNull ArrayList<AlbumFile> result) {
                        mAlbumFiles = result;
                        mAdapter.notifyDataSetChanged(mAlbumFiles);
                        mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
                    }
                })
                .start();
    }
}
 
Example #8
Source File: VideoActivity.java    From Album with Apache License 2.0 6 votes vote down vote up
/**
 * Preview image, to album.
 */
private void previewVideo(int position) {
    if (mAlbumFiles == null || mAlbumFiles.size() == 0) {
        Toast.makeText(this, R.string.no_selected, Toast.LENGTH_LONG).show();
    } else {
        Album.galleryAlbum(this)
                .checkable(true)
                .checkedList(mAlbumFiles)
                .currentPosition(position)
                .widget(
                        Widget.newDarkBuilder(this)
                                .title(mToolbar.getTitle().toString())
                                .build()
                )
                .onResult(new Action<ArrayList<AlbumFile>>() {
                    @Override
                    public void onAction(@NonNull ArrayList<AlbumFile> result) {
                        mAlbumFiles = result;
                        mAdapter.notifyDataSetChanged(mAlbumFiles);
                        mTvMessage.setVisibility(result.size() > 0 ? View.VISIBLE : View.GONE);
                    }
                })
                .start();
    }
}
 
Example #9
Source File: AlbumAdapter.java    From Album with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
    switch (getItemViewType(position)) {
        case TYPE_BUTTON: {
            // Nothing.
            break;
        }
        case TYPE_IMAGE:
        case TYPE_VIDEO: {
            MediaViewHolder mediaHolder = (MediaViewHolder) holder;
            int camera = hasCamera ? 1 : 0;
            position = holder.getAdapterPosition() - camera;
            AlbumFile albumFile = mAlbumFiles.get(position);
            mediaHolder.setData(albumFile);
            break;
        }
        default: {
            throw new AssertionError("This should not be the case.");
        }
    }
}
 
Example #10
Source File: CameraActivity.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@Nullable
public static AlbumFile getVideoOrPicture(Intent data) {
    if (data == null) {
        return null;
    }
    if (data.hasExtra(OUT_DATA)) {
        return data.getParcelableExtra(OUT_DATA);
    }
    return null;
}
 
Example #11
Source File: PostModelImpl.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Observable<JsonObject> onUpload(AlbumFile albumFile, Map<String, Object> params, IProgressListener<AlbumFile> listener) {
    if (albumFile.getMediaType() == AlbumFile.TYPE_VIDEO) {
        return uploadVideo(albumFile, params, listener);
    } else {
        return uploadPicture(albumFile, params, listener);
    }
}
 
Example #12
Source File: PictureFileUtils.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
public static AlbumFile createAlbumFile(File file, boolean isVideo){
        AlbumFile albumFile = new AlbumFile();
        albumFile.setMediaType(isVideo ? AlbumFile.TYPE_VIDEO : AlbumFile.TYPE_IMAGE);
        albumFile.setPath(file.getAbsolutePath());
        String name = file.getName();
        albumFile.setName(name);
        int lastPoint = name.lastIndexOf(".");
        if (lastPoint != -1){
            albumFile.setTitle(name.substring(0, lastPoint));
        } else {
            albumFile.setTitle(name);
        }
        albumFile.setBucketName(file.getParent());
        if (lastPoint != -1 && lastPoint != name.length() - 1){
            albumFile.setMimeType(MimeTypeMap.getSingleton().getMimeTypeFromExtension(name.substring(lastPoint + 1)));
        }
        long date = System.currentTimeMillis();
        albumFile.setAddDate(date);
        albumFile.setModifyDate(date);
        albumFile.setLatitude(0);
        albumFile.setLongitude(0);
        albumFile.setSize(file.length());
        albumFile.setThumbPath(null);
        albumFile.setChecked(true);
        albumFile.setEnable(true);

//        if (!isVideo) {
//            int degree = PictureFileUtils.readPictureDegree(file.getAbsolutePath());
//            rotateImage(degree, file);
//        }

        if (isVideo) {
            int[] size = readVideoInfo(file.getPath());
            albumFile.setWidth(size[0]);
            albumFile.setHeight(size[1]);
            albumFile.setDuration(size[2]);
        }
        return albumFile;
    }
 
Example #13
Source File: PostModelImpl.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
private Observable<JsonObject> uploadPicture(AlbumFile albumFile, Map<String, Object> params, IProgressListener<AlbumFile> listener) {

        File file = FileUtils.getFileByPath(albumFile.getPath());
        RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);

        return API.getInstance(APIPostService.class).upload_img(params, part).compose(RxHelper.handleResult());
    }
 
Example #14
Source File: PostModelImpl.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
private Observable<JsonObject> uploadVideo(AlbumFile albumFile, Map<String, Object> params, IProgressListener<AlbumFile> listener) {

        File file = FileUtils.getFileByPath(albumFile.getPath());
        RequestBody requestBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part part = MultipartBody.Part.createFormData("file", file.getName(), requestBody);

        return API.getInstance(APIPostService.class).upload_video(params, part).compose(RxHelper.handleResult());
    }
 
Example #15
Source File: AlbumAdapter.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public int getItemViewType(int position) {
    switch (position) {
        case 0: {
            return hasCamera ? TYPE_BUTTON : TYPE_IMAGE;
        }
        default: {
            position = hasCamera ? position - 1 : position;
            AlbumFile albumFile = mAlbumFiles.get(position);
            return albumFile.getMediaType() == AlbumFile.TYPE_VIDEO ? TYPE_VIDEO : TYPE_IMAGE;
        }
    }
}
 
Example #16
Source File: GalleryActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged() {
    AlbumFile albumFile = sAlbumFiles.get(sCurrentPosition);
    if (albumFile.isChecked()) {
        albumFile.setChecked(false);
        sCallback.onPreviewChanged(albumFile);
        sCheckedCount--;
    } else {
        if (sCheckedCount >= mAllowSelectCount) {
            int messageRes;
            switch (mFunction) {
                case Album.FUNCTION_CHOICE_IMAGE: {
                    messageRes = R.plurals.album_check_image_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_VIDEO: {
                    messageRes = R.plurals.album_check_video_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_ALBUM: {
                    messageRes = R.plurals.album_check_album_limit;
                    break;
                }
                default: {
                    throw new AssertionError("This should not be the case.");
                }
            }
            mView.toast(getResources().getQuantityString(messageRes, mAllowSelectCount, mAllowSelectCount));
            mView.setChecked(false);
        } else {
            albumFile.setChecked(true);
            sCallback.onPreviewChanged(albumFile);
            sCheckedCount++;
        }
    }

    setCheckedCount();
}
 
Example #17
Source File: L3PostActivity.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onUploadFailed(AlbumFile albumFile, Throwable throwable) {
    throwable.printStackTrace();
    for (AlbumPicturesGridAdapter adapter : picAdapterHolder) {
        adapter.setState(albumFile, BasePicturesGridAdapter.State.FAILED);
    }
}
 
Example #18
Source File: GalleryAlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
private void setCheckedCount() {
    int checkedCount = 0;
    for (AlbumFile albumFile : mAlbumFiles) {
        if (albumFile.isChecked()) checkedCount += 1;
    }

    String completeText = getString(R.string.album_menu_finish);
    completeText += "(" + checkedCount + " / " + mAlbumFiles.size() + ")";
    mView.setCompleteText(completeText);
}
 
Example #19
Source File: GalleryAlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void onCheckedChanged() {
    AlbumFile albumFile = mAlbumFiles.get(mCurrentPosition);
    albumFile.setChecked(!albumFile.isChecked());

    setCheckedCount();
}
 
Example #20
Source File: GalleryAlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void complete() {
    if (sResult != null) {
        ArrayList<AlbumFile> checkedList = new ArrayList<>();
        for (AlbumFile albumFile : mAlbumFiles) {
            if (albumFile.isChecked()) checkedList.add(albumFile);
        }
        sResult.onAction(checkedList);
    }
    finish();
}
 
Example #21
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
protected void onPermissionGranted(int code) {
    ArrayList<AlbumFile> checkedList = getIntent().getParcelableArrayListExtra(Album.KEY_INPUT_CHECKED_LIST);
    MediaReader mediaReader = new MediaReader(this, sSizeFilter, sMimeFilter, sDurationFilter, mFilterVisibility);
    mMediaReadTask = new MediaReadTask(mFunction, checkedList, mediaReader, this);
    mMediaReadTask.execute();
}
 
Example #22
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void onScanCallback(ArrayList<AlbumFolder> albumFolders, ArrayList<AlbumFile> checkedFiles) {
    mMediaReadTask = null;
    switch (mChoiceMode) {
        case Album.MODE_MULTIPLE: {
            mView.setCompleteDisplay(true);
            break;
        }
        case Album.MODE_SINGLE: {
            mView.setCompleteDisplay(false);
            break;
        }
        default: {
            throw new AssertionError("This should not be the case.");
        }
    }

    mView.setLoadingDisplay(false);
    mAlbumFolders = albumFolders;
    mCheckedList = checkedFiles;

    if (mAlbumFolders.get(0).getAlbumFiles().isEmpty()) {
        Intent intent = new Intent(this, NullActivity.class);
        intent.putExtras(getIntent());
        startActivityForResult(intent, CODE_ACTIVITY_NULL);
    } else {
        showFolderAlbumFiles(0);
        int count = mCheckedList.size();
        mView.setCheckedCount(count);
        mView.setSubTitle(count + "/" + mLimitCount);
    }
}
 
Example #23
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void onConvertCallback(AlbumFile albumFile) {
    albumFile.setChecked(!albumFile.isDisable());
    if (albumFile.isDisable()) {
        if (mFilterVisibility) addFileToList(albumFile);
        else mView.toast(getString(R.string.album_take_file_unavailable));
    } else {
        addFileToList(albumFile);
    }

    dismissLoadingDialog();
}
 
Example #24
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void tryCheckItem(CompoundButton button, int position) {
    AlbumFile albumFile = mAlbumFolders.get(mCurrentFolder).getAlbumFiles().get(position);
    if (button.isChecked()) {
        if (mCheckedList.size() >= mLimitCount) {
            int messageRes;
            switch (mFunction) {
                case Album.FUNCTION_CHOICE_IMAGE: {
                    messageRes = R.plurals.album_check_image_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_VIDEO: {
                    messageRes = R.plurals.album_check_video_limit;
                    break;
                }
                case Album.FUNCTION_CHOICE_ALBUM: {
                    messageRes = R.plurals.album_check_album_limit;
                    break;
                }
                default: {
                    throw new AssertionError("This should not be the case.");
                }
            }
            mView.toast(getResources().getQuantityString(messageRes, mLimitCount, mLimitCount));
            button.setChecked(false);
        } else {
            albumFile.setChecked(true);
            mCheckedList.add(albumFile);
            setCheckedCount();
        }
    } else {
        albumFile.setChecked(false);
        mCheckedList.remove(albumFile);
        setCheckedCount();
    }
}
 
Example #25
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
    public void tryPreviewItem(int position) {
        switch (mChoiceMode) {
            case Album.MODE_SINGLE: {
                AlbumFile albumFile = mAlbumFolders.get(mCurrentFolder).getAlbumFiles().get(position);
//                albumFile.setChecked(true);
//                mView.notifyItem(position);
                mCheckedList.add(albumFile);
                setCheckedCount();

                callbackResult();
                break;
            }
            case Album.MODE_MULTIPLE: {
                GalleryActivity.sAlbumFiles = mAlbumFolders.get(mCurrentFolder).getAlbumFiles();
                GalleryActivity.sCheckedCount = mCheckedList.size();
                GalleryActivity.sCurrentPosition = position;
                GalleryActivity.sCallback = this;
                Intent intent = new Intent(this, GalleryActivity.class);
                intent.putExtras(getIntent());
                startActivity(intent);
                break;
            }
            default: {
                throw new AssertionError("This should not be the case.");
            }
        }
    }
 
Example #26
Source File: AlbumActivity.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void onPreviewChanged(AlbumFile albumFile) {
    ArrayList<AlbumFile> albumFiles = mAlbumFolders.get(mCurrentFolder).getAlbumFiles();
    int position = albumFiles.indexOf(albumFile);
    int notifyPosition = mHasCamera ? position + 1 : position;
    mView.notifyItem(notifyPosition);

    if (albumFile.isChecked()) {
        if (!mCheckedList.contains(albumFile)) mCheckedList.add(albumFile);
    } else {
        if (mCheckedList.contains(albumFile)) mCheckedList.remove(albumFile);
    }
    setCheckedCount();
}
 
Example #27
Source File: AlbumAdapter.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void setData(AlbumFile albumFile) {
    Album.getAlbumConfig().getAlbumLoader().load(mIvImage, albumFile);
    mCheckBox.setChecked(albumFile.isChecked());
    mTvDuration.setText(AlbumUtils.convertDuration(albumFile.getDuration()));

    mLayoutLayer.setVisibility(albumFile.isDisable() ? View.VISIBLE : View.GONE);
}
 
Example #28
Source File: FolderAdapter.java    From Album with Apache License 2.0 5 votes vote down vote up
public void setData(AlbumFolder albumFolder) {
    List<AlbumFile> albumFiles = albumFolder.getAlbumFiles();
    mTvTitle.setText("(" + albumFiles.size() + ") " + albumFolder.getName());
    mCheckBox.setChecked(albumFolder.isChecked());

    Album.getAlbumConfig().getAlbumLoader().load(mIvImage, albumFiles.get(0));
}
 
Example #29
Source File: AlbumAdapter.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
public void setData(AlbumFile albumFile) {
    mCheckBox.setChecked(albumFile.isChecked());
    Album.getAlbumConfig()
            .getAlbumLoader()
            .load(mIvImage, albumFile);

    mLayoutLayer.setVisibility(albumFile.isDisable() ? View.VISIBLE : View.GONE);
}
 
Example #30
Source File: ThumbnailBuildTask.java    From Album with Apache License 2.0 5 votes vote down vote up
@Override
protected ArrayList<AlbumFile> doInBackground(Void... params) {
    for (AlbumFile albumFile : mAlbumFiles) {
        int mediaType = albumFile.getMediaType();
        if (mediaType == AlbumFile.TYPE_IMAGE) {
            albumFile.setThumbPath(mThumbnailBuilder.createThumbnailForImage(albumFile.getPath()));
        } else if (mediaType == AlbumFile.TYPE_VIDEO) {
            albumFile.setThumbPath(mThumbnailBuilder.createThumbnailForVideo(albumFile.getPath()));
        }
    }
    return mAlbumFiles;
}