Java Code Examples for com.luck.picture.lib.config.PictureConfig#SINGLE

The following examples show how to use com.luck.picture.lib.config.PictureConfig#SINGLE . 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: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onPictureClick(LocalMedia media, int position) {
    if (config.selectionMode == PictureConfig.SINGLE && config.isSingleDirectReturn) {
        List<LocalMedia> list = new ArrayList<>();
        list.add(media);
        if (config.enableCrop && PictureMimeType.isHasImage(media.getMimeType()) && !config.isCheckOriginalImage) {
            mAdapter.bindSelectData(list);
            startCrop(media.getPath(), media.getMimeType());
        } else {
            handlerResult(list);
        }
    } else {
        List<LocalMedia> data = mAdapter.getData();
        startPreview(data, position);
    }
}
 
Example 2
Source File: PictureSelectorWeChatStyleActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
protected void initWidgets() {
    super.initWidgets();
    rlAlbum = findViewById(R.id.rlAlbum);
    mPictureSendView = findViewById(R.id.picture_send);
    mPictureSendView.setOnClickListener(this);
    mPictureSendView.setText(getString(R.string.picture_send));
    mTvPicturePreview.setTextSize(16);
    mCbOriginal.setTextSize(16);
    boolean isChooseMode = config.selectionMode ==
            PictureConfig.SINGLE && config.isSingleDirectReturn;
    mPictureSendView.setVisibility(isChooseMode ? View.GONE : View.VISIBLE);
    if (rlAlbum.getLayoutParams() != null
            && rlAlbum.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) rlAlbum.getLayoutParams();
        if (isChooseMode) {
            lp.addRule(RelativeLayout.CENTER_HORIZONTAL);
        } else {
            lp.addRule(RelativeLayout.RIGHT_OF, R.id.pictureLeftBack);
        }
    }
}
 
Example 3
Source File: PictureSelectorPreviewWeChatStyleActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSelectedChange(boolean isAddRemove, LocalMedia media) {
    if (isAddRemove) {
        media.setChecked(true);
        if (config.selectionMode == PictureConfig.SINGLE) {
            mGalleryAdapter.addSingleMediaToData(media);
        }
    } else {
        media.setChecked(false);
        mGalleryAdapter.removeMediaToData(media);
        if (isBottomPreview) {
            if (selectData != null && selectData.size() > position) {
                selectData.get(position).setChecked(true);
            }
            if (mGalleryAdapter.isDataEmpty()) {
                onActivityBackPressed();
            } else {
                int currentItem = viewPager.getCurrentItem();
                adapter.remove(currentItem);
                adapter.removeCacheView(currentItem);
                position = currentItem;
                tvTitle.setText(getString(R.string.picture_preview_image_num,
                        position + 1, adapter.getSize()));
                check.setSelected(true);
                adapter.notifyDataSetChanged();
            }
        }
    }
    int itemCount = mGalleryAdapter.getItemCount();
    if (itemCount > 5) {
        mRvGallery.smoothScrollToPosition(itemCount - 1);
    }
}
 
Example 4
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Same type of image or video processing logic
 *
 * @param isHasImage
 * @param images
 */
private void separateMimeTypeWith(boolean isHasImage, List<LocalMedia> images) {
    LocalMedia image = images.size() > 0 ? images.get(0) : null;
    if (image == null) {
        return;
    }
    if (config.enableCrop && isHasImage) {
        if (config.selectionMode == PictureConfig.SINGLE) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = images.size();
            for (int i = 0; i < count; i++) {
                LocalMedia media = images.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            startCrop(cuts);
        }
    } else if (config.isCompress
            && isHasImage) {
        compressImage(images);
    } else {
        onResult(images);
    }
}
 
Example 5
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * Update Adapter Data
 *
 * @param media
 */
private void notifyAdapterData(LocalMedia media) {
    if (mAdapter != null) {
        boolean isAddSameImp = isAddSameImp(folderWindow.getFolder(0) != null ? folderWindow.getFolder(0).getImageNum() : 0);
        if (!isAddSameImp) {
            mAdapter.getData().add(0, media);
            mOpenCameraCount++;
        }
        if (checkVideoLegitimacy(media)) {
            if (config.selectionMode == PictureConfig.SINGLE) {
                dispatchHandleSingle(media);
            } else {
                dispatchHandleMultiple(media);
            }
        }
        mAdapter.notifyItemInserted(config.isCamera ? 1 : 0);
        mAdapter.notifyItemRangeChanged(config.isCamera ? 1 : 0, mAdapter.getSize());
        // Solve the problem that some mobile phones do not refresh the system library timely after using Camera
        if (config.isPageStrategy) {
            manualSaveFolderForPageModel(media);
        } else {
            manualSaveFolder(media);
        }
        mTvEmpty.setVisibility(mAdapter.getSize() > 0 || config.isSingleDirectReturn ? View.GONE : View.VISIBLE);
        // update all count
        if (folderWindow.getFolder(0) != null) {
            mTvPictureTitle.setTag(R.id.view_count_tag, folderWindow.getFolder(0).getImageNum());
        }
        allFolderSize = 0;
    }
}
 
Example 6
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * 同一类型的图片或视频处理逻辑
 *
 * @param mimeType
 * @param image
 */
private void separateMimeTypeWith(String mimeType, LocalMedia image) {
    if (config.enableCrop && PictureMimeType.isHasImage(mimeType)) {
        isCompleteOrSelected = false;
        if (config.selectionMode == PictureConfig.SINGLE) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            // 是图片和选择压缩并且是多张,调用批量压缩
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = selectData.size();
            for (int i = 0; i < count; i++) {
                LocalMedia media = selectData.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setAndroidQToPath(media.getAndroidQToPath());
                cutInfo.setId(media.getId());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            startCrop(cuts);
        }
    } else {
        onBackPressed();
    }
}
 
Example 7
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * preview image and video
 *
 * @param previewData
 * @param position
 */
public void startPreview(List<LocalMedia> previewData, int position) {
    LocalMedia media = previewData.get(position);
    String mimeType = media.getMimeType();
    Bundle bundle = new Bundle();
    List<LocalMedia> result = new ArrayList<>();
    if (PictureMimeType.isHasVideo(mimeType)) {
        // video
        if (config.selectionMode == PictureConfig.SINGLE && !config.enPreviewVideo) {
            result.add(media);
            onResult(result);
        } else {
            if (PictureSelectionConfig.customVideoPlayCallback != null) {
                PictureSelectionConfig.customVideoPlayCallback.startPlayVideo(media);
            } else {
                bundle.putParcelable(PictureConfig.EXTRA_MEDIA_KEY, media);
                JumpUtils.startPictureVideoPlayActivity(getContext(), bundle, PictureConfig.PREVIEW_VIDEO_CODE);
            }
        }
    } else if (PictureMimeType.isHasAudio(mimeType)) {
        // audio
        if (config.selectionMode == PictureConfig.SINGLE) {
            result.add(media);
            onResult(result);
        } else {
            AudioDialog(media.getPath());
        }
    } else {
        // image
        if (PictureSelectionConfig.onCustomImagePreviewCallback != null) {
            PictureSelectionConfig.onCustomImagePreviewCallback.onCustomPreviewCallback(getContext(), previewData, position);
            return;
        }
        List<LocalMedia> selectedData = mAdapter.getSelectedData();
        ImagesObservable.getInstance().savePreviewMediaData(new ArrayList<>(previewData));
        bundle.putParcelableArrayList(PictureConfig.EXTRA_SELECT_LIST, (ArrayList<? extends Parcelable>) selectedData);
        bundle.putInt(PictureConfig.EXTRA_POSITION, position);
        bundle.putBoolean(PictureConfig.EXTRA_CHANGE_ORIGINAL, config.isCheckOriginalImage);
        bundle.putBoolean(PictureConfig.EXTRA_SHOW_CAMERA, mAdapter.isShowCamera());
        bundle.putLong(PictureConfig.EXTRA_BUCKET_ID, ValueOf.toLong(mTvPictureTitle.getTag(R.id.view_tag)));
        bundle.putInt(PictureConfig.EXTRA_PAGE, mPage);
        bundle.putParcelable(PictureConfig.EXTRA_CONFIG, config);
        bundle.putInt(PictureConfig.EXTRA_DATA_COUNT, ValueOf.toInt(mTvPictureTitle.getTag(R.id.view_count_tag)));
        bundle.putString(PictureConfig.EXTRA_IS_CURRENT_DIRECTORY, mTvPictureTitle.getText().toString());
        JumpUtils.startPicturePreviewActivity(getContext(), config.isWeChatStyle, bundle,
                config.selectionMode == PictureConfig.SINGLE ? UCrop.REQUEST_CROP : UCrop.REQUEST_MULTI_CROP);
        overridePendingTransition(config.windowAnimationStyle != null
                && config.windowAnimationStyle.activityPreviewEnterAnimation != 0
                ? config.windowAnimationStyle.activityPreviewEnterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
    }
}
 
Example 8
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * 两者不同类型的处理方式
 *
 * @param mimeType
 * @param image
 */
private void bothMimeTypeWith(String mimeType, LocalMedia image) {
    if (config.enableCrop) {
        isCompleteOrSelected = false;
        boolean isHasImage = PictureMimeType.isHasImage(mimeType);
        if (config.selectionMode == PictureConfig.SINGLE && isHasImage) {
            config.originalPath = image.getPath();
            startCrop(config.originalPath, image.getMimeType());
        } else {
            // 是图片和选择压缩并且是多张,调用批量压缩
            ArrayList<CutInfo> cuts = new ArrayList<>();
            int count = selectData.size();
            int imageNum = 0;
            for (int i = 0; i < count; i++) {
                LocalMedia media = selectData.get(i);
                if (media == null
                        || TextUtils.isEmpty(media.getPath())) {
                    continue;
                }
                if (PictureMimeType.isHasImage(media.getMimeType())) {
                    imageNum++;
                }
                CutInfo cutInfo = new CutInfo();
                cutInfo.setId(media.getId());
                cutInfo.setPath(media.getPath());
                cutInfo.setImageWidth(media.getWidth());
                cutInfo.setImageHeight(media.getHeight());
                cutInfo.setMimeType(media.getMimeType());
                cutInfo.setAndroidQToPath(media.getAndroidQToPath());
                cutInfo.setId(media.getId());
                cutInfo.setDuration(media.getDuration());
                cutInfo.setRealPath(media.getRealPath());
                cuts.add(cutInfo);
            }
            if (imageNum <= 0) {
                // 全是视频
                isCompleteOrSelected = true;
                onBackPressed();
            } else {
                // 图片和视频共存
                startCrop(cuts);
            }
        }
    } else {
        onBackPressed();
    }
}
 
Example 9
Source File: PictureSelectorUtils.java    From DevUtils with Apache License 2.0 3 votes vote down vote up
/**
 * 设置相册选择模式
 * <pre>
 *     多选 PictureConfig.MULTIPLE
 *     单选 PictureConfig.SINGLE
 * </pre>
 * @param selectionMode 相册选择模式
 * @return {@link PicConfig}
 */
public PicConfig setSelectionMode(final int selectionMode) {
    if (selectionMode >= PictureConfig.MULTIPLE) {
        this.selectionMode = PictureConfig.MULTIPLE;
    } else if (selectionMode <= PictureConfig.SINGLE) {
        this.selectionMode = PictureConfig.SINGLE;
    }
    return this;
}