com.luck.picture.lib.config.PictureConfig Java Examples

The following examples show how to use com.luck.picture.lib.config.PictureConfig. 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: PictureSelectorCameraEmptyActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * open camera
 */
private void onTakePhoto() {
    if (PermissionChecker
            .checkSelfPermission(this, Manifest.permission.CAMERA)) {
        boolean isPermissionChecker = true;
        if (config != null && config.isUseCustomCamera) {
            isPermissionChecker = PermissionChecker.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO);
        }
        if (isPermissionChecker) {
            startCamera();
        } else {
            PermissionChecker
                    .requestPermissions(this,
                            new String[]{Manifest.permission.RECORD_AUDIO}, PictureConfig.APPLY_RECORD_AUDIO_PERMISSIONS_CODE);
        }
    } else {
        PermissionChecker.requestPermissions(this,
                new String[]{Manifest.permission.CAMERA}, PictureConfig.APPLY_CAMERA_PERMISSIONS_CODE);
    }
}
 
Example #4
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 #5
Source File: PictureExternalPreviewActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
            // 存储权限
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    showDownLoadDialog();
                } else {
                    ToastUtils.s(getContext(), getString(R.string.picture_jurisdiction));
                }
            }
            break;
    }
}
 
Example #6
Source File: PictureVideoPlayActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.pictureLeftBack) {
        onBackPressed();
    } else if (id == R.id.iv_play) {
        mVideoView.start();
        iv_play.setVisibility(View.INVISIBLE);
    } else if (id == R.id.tv_confirm) {
        List<LocalMedia> result = new ArrayList<>();
        result.add(getIntent().getParcelableExtra(PictureConfig.EXTRA_MEDIA_KEY));
        setResult(RESULT_OK, new Intent()
                .putParcelableArrayListExtra(PictureConfig.EXTRA_SELECT_LIST,
                        (ArrayList<? extends Parcelable>) result));
        onBackPressed();
    }
}
 
Example #7
Source File: PictureExternalPreviewActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
protected void initWidgets() {
    super.initWidgets();
    titleViewBg = findViewById(R.id.titleViewBg);
    tvTitle = findViewById(R.id.picture_title);
    ibLeftBack = findViewById(R.id.left_back);
    ibDelete = findViewById(R.id.ib_delete);
    viewPager = findViewById(R.id.preview_pager);
    position = getIntent().getIntExtra(PictureConfig.EXTRA_POSITION, 0);
    images = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST);
    ibLeftBack.setOnClickListener(this);
    ibDelete.setOnClickListener(this);
    ibDelete.setVisibility(config.style != null ? config.style.pictureExternalPreviewGonePreviewDelete
            ? View.VISIBLE : View.GONE : View.GONE);
    initViewPageAdapterData();
}
 
Example #8
Source File: PhotoFragmentActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
            // 存储权限
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    PictureFileUtils.deleteCacheDirFile(PhotoFragmentActivity.this, PictureMimeType.ofImage());
                } else {
                    Toast.makeText(PhotoFragmentActivity.this,
                            getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
                }
            }
            break;
    }
}
 
Example #9
Source File: PhotoFragmentActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_simp);
    // 在部分低端手机,调用单独拍照时内存不足时会导致activity被回收,所以不重复创建fragment
    if (savedInstanceState == null) {
        // 添加显示第一个fragment
        fragment = new PhotoFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.tab_content, fragment,
                PictureConfig.EXTRA_FC_TAG).show(fragment)
                .commit();
    } else {
        fragment = (PhotoFragment) getSupportFragmentManager()
                .findFragmentByTag(PictureConfig.EXTRA_FC_TAG);
    }
}
 
Example #10
Source File: MainActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }
    if (BroadcastAction.ACTION_DELETE_PREVIEW_POSITION.equals(action)) {
        // 外部预览删除按钮回调
        Bundle extras = intent.getExtras();
        if (extras != null) {
            int position = extras.getInt(PictureConfig.EXTRA_PREVIEW_DELETE_POSITION);
            ToastUtils.s(getContext(), "delete image index:" + position);
            mAdapter.remove(position);
            mAdapter.notifyItemRemoved(position);
        }
    }
}
 
Example #11
Source File: MainActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
            // 存储权限
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    PictureFileUtils.deleteCacheDirFile(getContext(), PictureMimeType.ofImage());
                } else {
                    Toast.makeText(MainActivity.this,
                            getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
                }
            }
            break;
    }
}
 
Example #12
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onTakePhoto() {
    // Check the permissions
    if (PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA)) {
        if (PermissionChecker
                .checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) &&
                PermissionChecker
                        .checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
            startCamera();
        } else {
            PermissionChecker.requestPermissions(this, new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE}, PictureConfig.APPLY_CAMERA_STORAGE_PERMISSIONS_CODE);
        }
    } else {
        PermissionChecker
                .requestPermissions(this,
                        new String[]{Manifest.permission.CAMERA}, PictureConfig.APPLY_CAMERA_PERMISSIONS_CODE);
    }
}
 
Example #13
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemClick(View view, int position) {
    switch (position) {
        case PhotoItemSelectedDialog.IMAGE_CAMERA:
            if (PictureSelectionConfig.onCustomCameraInterfaceListener != null) {
                PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_IMAGE);
                config.cameraMimeType = PictureMimeType.ofImage();
            } else {
                startOpenCamera();
            }
            break;
        case PhotoItemSelectedDialog.VIDEO_CAMERA:
            if (PictureSelectionConfig.onCustomCameraInterfaceListener != null) {
                PictureSelectionConfig.onCustomCameraInterfaceListener.onCameraClick(getContext(), config, PictureConfig.TYPE_IMAGE);
                config.cameraMimeType = PictureMimeType.ofVideo();
            } else {
                startOpenCameraVideo();
            }
            break;
        default:
            break;
    }
}
 
Example #14
Source File: PhotoFragment.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (TextUtils.isEmpty(action)) {
        return;
    }
    if (BroadcastAction.ACTION_DELETE_PREVIEW_POSITION.equals(action)) {// 外部预览删除按钮回调
        Bundle extras = intent.getExtras();
        if (extras != null) {
            int position = extras.getInt(PictureConfig.EXTRA_PREVIEW_DELETE_POSITION);
            ToastUtils.s(context, "delete image index:" + position);
            mAdapter.remove(position);
            mAdapter.notifyItemRemoved(position);
        }
    }
}
 
Example #15
Source File: PhotoFragment.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case PictureConfig.APPLY_STORAGE_PERMISSIONS_CODE:
            // 存储权限
            for (int i = 0; i < grantResults.length; i++) {
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                    PictureFileUtils.deleteCacheDirFile(getContext(), PictureMimeType.ofImage());
                } else {
                    Toast.makeText(getContext(),
                            getString(R.string.picture_jurisdiction), Toast.LENGTH_SHORT).show();
                }
            }
            break;
    }
}
 
Example #16
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 #17
Source File: RNSyanImagePickerModule.java    From react-native-syan-image-picker with MIT License 6 votes vote down vote up
@Override
public void onActivityResult(Activity activity, int requestCode, int resultCode, final Intent data) {
    if (resultCode == -1) {
        if (requestCode == PictureConfig.CHOOSE_REQUEST) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    onGetResult(data);
                }
            }).run();
        } else if (requestCode == PictureConfig.REQUEST_CAMERA) {
            onGetVideoResult(data);
        }
    } else {
        invokeError(resultCode);
    }

}
 
Example #18
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * Open Custom Camera
 */
private void startCustomCamera() {
    if (PermissionChecker.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)) {
        Intent intent = new Intent(this, PictureCustomCameraActivity.class);
        startActivityForResult(intent, PictureConfig.REQUEST_CAMERA);
        PictureWindowAnimationStyle windowAnimationStyle = config.windowAnimationStyle;
        overridePendingTransition(windowAnimationStyle != null &&
                windowAnimationStyle.activityEnterAnimation != 0 ?
                windowAnimationStyle.activityEnterAnimation :
                R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
    } else {
        PermissionChecker
                .requestPermissions(this,
                        new String[]{Manifest.permission.RECORD_AUDIO}, PictureConfig.APPLY_RECORD_AUDIO_PERMISSIONS_CODE);
    }
}
 
Example #19
Source File: RNSyanImagePickerModule.java    From react-native-syan-image-picker with MIT License 6 votes vote down vote up
/**
 * 拍摄视频
 */
private void openVideo() {
    int quality = this.cameraOptions.getInt("quality");
    int MaxSecond = this.cameraOptions.getInt("MaxSecond");
    int MinSecond = this.cameraOptions.getInt("MinSecond");
    int recordVideoSecond = this.cameraOptions.getInt("recordVideoSecond");
    int imageCount = this.cameraOptions.getInt("imageCount");
    Activity currentActivity = getCurrentActivity();
    PictureSelector.create(currentActivity)
            .openCamera(PictureMimeType.ofVideo())//全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
            .loadImageEngine(GlideEngine.createGlideEngine())
            .selectionMedia(selectList) // 当前已选中的图片 List
            .openClickSound(false)// 是否开启点击声音 true or false
            .maxSelectNum(imageCount)// 最大图片选择数量 int
            .minSelectNum(0)// 最小选择数量 int
            .imageSpanCount(4)// 每行显示个数 int
            .selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
            .previewVideo(true)// 是否可预览视频 true or false
            .videoQuality(quality)// 视频录制质量 0 or 1 int
            .videoMaxSecond(MaxSecond)// 显示多少秒以内的视频or音频也可适用 int
            .videoMinSecond(MinSecond)// 显示多少秒以内的视频or音频也可适用 int
            .recordVideoSecond(recordVideoSecond)//视频秒数录制 默认60s int
            .forResult(PictureConfig.REQUEST_CAMERA);//结果回调onActivityResult code
}
 
Example #20
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 从本地获取数据
 */
private void loadData() {
    long bucketId = getIntent().getLongExtra(PictureConfig.EXTRA_BUCKET_ID, -1);
    mPage++;
    LocalMediaPageLoader.getInstance(getContext(), config).loadPageMediaData(bucketId, mPage, config.pageSize,
            (OnQueryDataResultListener<LocalMedia>) (result, currentPage, isHasMore) -> {
                if (!isFinishing()) {
                    this.isHasMore = isHasMore;
                    if (isHasMore) {
                        int size = result.size();
                        if (size > 0 && adapter != null) {
                            adapter.getData().addAll(result);
                            adapter.notifyDataSetChanged();
                        } else {
                            // 这种情况就是开启过滤损坏文件刚好导致某一页全是损坏的虽然result为0,但还要请求下一页数据
                            loadMoreData();
                        }
                    }
                }
            });
}
 
Example #21
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * 加载更多
 */
private void loadMoreData() {
    long bucketId = getIntent().getLongExtra(PictureConfig.EXTRA_BUCKET_ID, -1);
    mPage++;
    LocalMediaPageLoader.getInstance(getContext(), config).loadPageMediaData(bucketId, mPage, config.pageSize,
            (OnQueryDataResultListener<LocalMedia>) (result, currentPage, isHasMore) -> {
                if (!isFinishing()) {
                    this.isHasMore = isHasMore;
                    if (isHasMore) {
                        int size = result.size();
                        if (size > 0 && adapter != null) {
                            adapter.getData().addAll(result);
                            adapter.notifyDataSetChanged();
                        } else {
                            // 这种情况就是开启过滤损坏文件刚好导致某一页全是损坏的虽然result为0,但还要请求下一页数据
                            loadMoreData();
                        }
                    }
                }
            });
}
 
Example #22
Source File: PictureSelector.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
/**
 * set preview image
 *
 * @param position
 * @param medias
 * @param directory_path
 */
public void externalPicturePreview(int position, String directory_path, List<LocalMedia> medias, int enterAnimation) {
    if (!DoubleUtils.isFastDoubleClick()) {
        if (getActivity() != null) {
            Intent intent = new Intent(getActivity(), PictureExternalPreviewActivity.class);
            intent.putParcelableArrayListExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (ArrayList<? extends Parcelable>) medias);
            intent.putExtra(PictureConfig.EXTRA_POSITION, position);
            intent.putExtra(PictureConfig.EXTRA_DIRECTORY_PATH, directory_path);
            getActivity().startActivity(intent);
            getActivity().overridePendingTransition(enterAnimation != 0
                    ? enterAnimation : R.anim.picture_anim_enter, R.anim.picture_anim_fade_in);
        } else {
            throw new NullPointerException("Starting the PictureSelector Activity cannot be empty ");
        }
    }
}
 
Example #23
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (mAdapter != null) {
        // Save the number of pictures or videos in the current list
        outState.putInt(PictureConfig.EXTRA_OLD_CURRENT_LIST_SIZE, mAdapter.getSize());
        // Save the number of Camera film and Camera folder files
        int size = folderWindow.getFolderData().size();
        if (size > 0) {
            outState.putInt(PictureConfig.EXTRA_ALL_FOLDER_SIZE, folderWindow.getFolder(0).getImageNum());
        }
        if (mAdapter.getSelectedData() != null) {
            List<LocalMedia> selectedImages = mAdapter.getSelectedData();
            PictureSelector.saveSelectorList(outState, selectedImages);
        }
    }
}
 
Example #24
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 #25
Source File: PicturePreviewActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putBoolean(PictureConfig.EXTRA_COMPLETE_SELECTED, isCompleteOrSelected);
    outState.putBoolean(PictureConfig.EXTRA_CHANGE_SELECTED_DATA, isChangeSelectedData);
    PictureSelector.saveSelectorList(outState, selectData);
}
 
Example #26
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 #27
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
/**
 * load more data
 */
private void loadMoreData() {
    if (mAdapter != null) {
        if (isHasMore) {
            mPage++;
            long bucketId = ValueOf.toLong(mTvPictureTitle.getTag(R.id.view_tag));
            LocalMediaPageLoader.getInstance(getContext(), config).loadPageMediaData(bucketId, mPage, getPageLimit(),
                    (OnQueryDataResultListener<LocalMedia>) (result, currentPage, isHasMore) -> {
                        if (!isFinishing()) {
                            this.isHasMore = isHasMore;
                            if (isHasMore) {
                                hideDataNull();
                                int size = result.size();
                                if (size > 0) {
                                    int positionStart = mAdapter.getSize();
                                    mAdapter.getData().addAll(result);
                                    int itemCount = mAdapter.getItemCount();
                                    mAdapter.notifyItemRangeChanged(positionStart, itemCount);
                                } else {
                                    onRecyclerViewPreloadMore();
                                }
                                if (size < PictureConfig.MIN_PAGE_SIZE) {
                                    mRecyclerView.onScrolled(mRecyclerView.getScrollX(), mRecyclerView.getScrollY());
                                }
                            } else {
                                boolean isEmpty = mAdapter.isDataEmpty();
                                if (isEmpty) {
                                    showDataNull(bucketId == -1 ? getString(R.string.picture_empty) : getString(R.string.picture_data_null), R.drawable.picture_icon_no_data);
                                }
                            }
                        }
                    });
        }
    }
}
 
Example #28
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 #29
Source File: PictureSelectorActivity.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (savedInstanceState != null) {
        allFolderSize = savedInstanceState.getInt(PictureConfig.EXTRA_ALL_FOLDER_SIZE);
        oldCurrentListSize = savedInstanceState.getInt(PictureConfig.EXTRA_OLD_CURRENT_LIST_SIZE, 0);
        selectionMedias = PictureSelector.obtainSelectorList(savedInstanceState);
        if (mAdapter != null) {
            isStartAnimation = true;
            mAdapter.bindSelectData(selectionMedias);
        }
    }
}
 
Example #30
Source File: PictureImageGridAdapter.java    From PictureSelector with Apache License 2.0 5 votes vote down vote up
@Override
public int getItemViewType(int position) {
    if (showCamera && position == 0) {
        return PictureConfig.TYPE_CAMERA;
    } else {
        return PictureConfig.TYPE_PICTURE;
    }
}