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

The following examples show how to use com.luck.picture.lib.config.PictureConfig#TYPE_IMAGE . 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: PictureSelectorUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 获取本地资源路径
 * @param localMedia {@link LocalMedia}
 * @param original   是否使用原图地址
 * @return 本地资源路径
 */
public static String getLocalMediaPath(final LocalMedia localMedia, final boolean original) {
    if (localMedia != null) {
        if (original) return localMedia.getPath();
        // 判断资源类型
        switch (localMedia.getMimeType()) {
            case PictureConfig.TYPE_IMAGE: // 图片
                if (localMedia.isCompressed()) { // 是否压缩图片
                    return localMedia.getCompressPath();
                } else if (localMedia.isCut()) { // 是否裁减图片
                    return localMedia.getCutPath();
                } else { // 获取原图
                    return localMedia.getPath();
                }
            case PictureConfig.TYPE_VIDEO: // 视频
            case PictureConfig.TYPE_AUDIO: // 音频
                return localMedia.getPath();
        }
    }
    return null;
}
 
Example 2
Source File: PictureSelectorCameraEmptyActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * Open the Camera by type
 */
private void startCamera() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
        case PictureConfig.TYPE_IMAGE:
            startOpenCamera();
            break;
        case PictureConfig.TYPE_VIDEO:
            startOpenCameraVideo();
            break;
        case PictureConfig.TYPE_AUDIO:
            startOpenCameraAudio();
            break;
        default:
            break;
    }
}
 
Example 3
Source File: MainActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
        public void onCameraClick(Context context, PictureSelectionConfig config, int type) {
            // TODO  必须使用context.startActivityForResult(activity.class,PictureConfig.REQUEST_CAMERA);
            // TODO  为防止拍照内存不足导致Activity被回收的情况,最好把config类通过bundle.putParcelable(PictureConfig.EXTRA_CONFIG,config);传入到用户自定义相机页面,拍照成功后在.setResult()带回来
            // TODO 注意:使用自定义相机时,需要设置PictureSelectionConfig ${config.cameraPath#config.cameraMimeType}
            //  1、config.cameraPath (文件输出路径)
            //  2、config.cameraMimeType (PictureMimeType.ofImage() or ofVideo)

            switch (type) {
                case PictureConfig.TYPE_IMAGE:
                    // 拍照
//                    if (context instanceof Activity) {
//                        Intent intent = new Intent(context, PictureCustomCameraActivity.class);
//                        ((Activity) context).startActivityForResult(intent, PictureConfig.REQUEST_CAMERA);
//                        PictureWindowAnimationStyle windowAnimationStyle = config.windowAnimationStyle;
//                        ((Activity) context).overridePendingTransition(windowAnimationStyle != null &&
//                                windowAnimationStyle.activityEnterAnimation != 0 ?
//                                windowAnimationStyle.activityEnterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
//                    }
                    ToastUtils.s(context, "Click Camera Image");
                    break;
                case PictureConfig.TYPE_VIDEO:
                    // 录视频
                    ToastUtils.s(context, "Click Camera Video");
                    break;
                case PictureConfig.TYPE_AUDIO:
                    // 录音
                    ToastUtils.s(context, "Click Camera Recording");
                    break;
                default:
                    break;
            }
        }
 
Example 4
Source File: LocalMediaLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String getSelection() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            // Get all, not including audio
            return getSelectionArgsForAllMediaCondition(getDurationCondition(0, 0), config.isGif);
        case PictureConfig.TYPE_IMAGE:
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return config.isGif ? SELECTION : SELECTION_NOT_GIF;
        case PictureConfig.TYPE_VIDEO:
            // Access to video
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return getSelectionArgsForSingleMediaCondition();
        case PictureConfig.TYPE_AUDIO:
            // Access to the audio
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the image of the specified type
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "'";
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, AUDIO_DURATION));
    }
    return null;
}
 
Example 5
Source File: LocalMediaLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getSelectionArgs() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            return SELECTION_ALL_ARGS;
        case PictureConfig.TYPE_IMAGE:
            // Get Image
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
        case PictureConfig.TYPE_VIDEO:
            // Get Video
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
        case PictureConfig.TYPE_AUDIO:
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO);
    }
    return null;
}
 
Example 6
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getPageSelectionArgs(long bucketId) {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            if (bucketId == -1) {
                // ofAll
                return new String[]{
                        String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
                        String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
                };
            }
            //  Gets the specified album directory
            return new String[]{
                    String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE),
                    String.valueOf(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO),
                    ValueOf.toString(bucketId)
            };
        case PictureConfig.TYPE_IMAGE:
            // Get photo
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE, bucketId);
        case PictureConfig.TYPE_VIDEO:
            // Get video
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO, bucketId);
        case PictureConfig.TYPE_AUDIO:
            // Get audio
            return getSelectionArgsForPageSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO, bucketId);
    }
    return null;
}
 
Example 7
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String getSelection() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            // Get all, not including audio
            return getSelectionArgsForAllMediaCondition(getDurationCondition(0, 0), config.isGif);
        case PictureConfig.TYPE_IMAGE:
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // 获取指定类型的图片
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            if (SdkVersionUtils.checkedAndroid_Q()) {
                return config.isGif ? SELECTION_29 : SELECTION_NOT_GIF_29;
            }
            return config.isGif ? SELECTION : SELECTION_NOT_GIF;
        case PictureConfig.TYPE_VIDEO:
            // 获取视频
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the specified album directory
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, 0));
        case PictureConfig.TYPE_AUDIO:
            // Get Audio
            if (!TextUtils.isEmpty(config.specifiedFormat)) {
                // Gets the specified album directory
                if (SdkVersionUtils.checkedAndroid_Q()) {
                    return SELECTION_SPECIFIED_FORMAT_29 + "='" + config.specifiedFormat + "' AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return SELECTION_SPECIFIED_FORMAT + "='" + config.specifiedFormat + "') AND " + MediaStore.MediaColumns.SIZE + ">0)" + GROUP_BY_BUCKET_Id;
            }
            return getSelectionArgsForSingleMediaCondition(getDurationCondition(0, AUDIO_DURATION));
    }
    return null;
}
 
Example 8
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
private String[] getSelectionArgs() {
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            return SELECTION_ALL_ARGS;
        case PictureConfig.TYPE_IMAGE:
            // Get photo
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE);
        case PictureConfig.TYPE_VIDEO:
            // Get video
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO);
        case PictureConfig.TYPE_AUDIO:
            return getSelectionArgsForSingleMediaType(MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO);
    }
    return null;
}
 
Example 9
Source File: PictureBaseActivity.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
/**
 * start to camera、preview、crop
 */
protected void startOpenCamera() {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (cameraIntent.resolveActivity(getPackageManager()) != null) {
        Uri imageUri;
        if (SdkVersionUtils.checkedAndroid_Q()) {
            imageUri = MediaUtils.createImageUri(getApplicationContext(), config.suffixType);
            if (imageUri != null) {
                config.cameraPath = imageUri.toString();
            } else {
                ToastUtils.s(getContext(), "open is camera error,the uri is empty ");
                if (config.camera) {
                    closeActivity();
                }
                return;
            }
        } else {
            int chooseMode = config.chooseMode == PictureConfig.TYPE_ALL ? PictureConfig.TYPE_IMAGE
                    : config.chooseMode;
            String cameraFileName = "";
            if (!TextUtils.isEmpty(config.cameraFileName)) {
                boolean isSuffixOfImage = PictureMimeType.isSuffixOfImage(config.cameraFileName);
                config.cameraFileName = !isSuffixOfImage ? StringUtils.renameSuffix(config.cameraFileName, PictureMimeType.JPEG) : config.cameraFileName;
                cameraFileName = config.camera ? config.cameraFileName : StringUtils.rename(config.cameraFileName);
            }

            File cameraFile = PictureFileUtils.createCameraFile(getApplicationContext(),
                    chooseMode, cameraFileName, config.suffixType, config.outPutCameraPath);
            if (cameraFile != null) {
                config.cameraPath = cameraFile.getAbsolutePath();
                imageUri = PictureFileUtils.parUri(this, cameraFile);
            } else {
                ToastUtils.s(getContext(), "open is camera error,the uri is empty ");
                if (config.camera) {
                    closeActivity();
                }
                return;
            }
        }
        config.cameraMimeType = PictureMimeType.ofImage();
        if (config.isCameraAroundState) {
            cameraIntent.putExtra(PictureConfig.CAMERA_FACING, PictureConfig.CAMERA_BEFORE);
        }
        cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(cameraIntent, PictureConfig.REQUEST_CAMERA);
    }
}
 
Example 10
Source File: LocalMediaPageLoader.java    From PictureSelector with Apache License 2.0 4 votes vote down vote up
private String getPageSelection(long bucketId) {
    String durationCondition = getDurationCondition(0, 0);
    boolean isSpecifiedFormat = !TextUtils.isEmpty(config.specifiedFormat);
    switch (config.chooseMode) {
        case PictureConfig.TYPE_ALL:
            if (bucketId == -1) {
                // ofAll
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                        + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                    + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                    + " OR " + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";

        case PictureConfig.TYPE_IMAGE:
            // Gets the image of the specified type
            if (bucketId == -1) {
                // ofAll
                if (isSpecifiedFormat) {
                    return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                            + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF + " AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'")
                            + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                        + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            if (isSpecifiedFormat) {
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                        + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF + " AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'")
                        + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=?"
                    + (config.isGif ? "" : " AND " + MediaStore.MediaColumns.MIME_TYPE + NOT_GIF)
                    + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
        case PictureConfig.TYPE_VIDEO:
        case PictureConfig.TYPE_AUDIO:
            if (bucketId == -1) {
                // ofAll
                if (isSpecifiedFormat) {
                    return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'" + " AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
                }
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            // Gets the specified album directory
            if (isSpecifiedFormat) {
                return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + MediaStore.MediaColumns.MIME_TYPE + "='" + config.specifiedFormat + "'" + " AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
            }
            return "(" + MediaStore.Files.FileColumns.MEDIA_TYPE + "=? AND " + durationCondition + ") AND " + COLUMN_BUCKET_ID + "=? AND " + MediaStore.MediaColumns.SIZE + ">0";
    }
    return null;
}