Search in sources :

Example 1 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImagePreviewFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View contentView = inflater.inflate(R.layout.picture_fragment_image_preview, container, false);
    final PhotoView imageView = (PhotoView) contentView.findViewById(R.id.preview_image);
    LocalMedia media = (LocalMedia) getArguments().getSerializable(PictureConfig.EXTRA_MEDIA);
    if (media.isCompressed()) {
        // 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
        path = media.getCompressPath();
    } else {
        path = media.getPath();
    }
    String pictureType = media.getPictureType();
    isSave = getArguments().getBoolean("isSave");
    directory_path = getArguments().getString(PictureConfig.DIRECTORY_PATH);
    if (!isSave && path.startsWith("http")) {
        showPleaseDialog();
    }
    boolean isGif = PictureMimeType.isGif(pictureType);
    // 压缩过的gif就不是gif了
    if (isGif && !media.isCompressed()) {
        Glide.with(container.getContext()).load(path).asGif().override(480, 800).diskCacheStrategy(DiskCacheStrategy.SOURCE).priority(Priority.HIGH).into(imageView);
        dismissDialog();
    } else {
        Glide.with(container.getContext()).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).into(new SimpleTarget<Bitmap>(480, 800) {

            @Override
            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                imageView.setImageBitmap(resource);
                dismissDialog();
            }
        });
    }
    imageView.setOnViewTapListener(new PhotoViewAttacher.OnViewTapListener() {

        @Override
        public void onViewTap(View view, float x, float y) {
            getActivity().finish();
            getActivity().overridePendingTransition(0, R.anim.a3);
        }
    });
    imageView.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            // 内部预览不保存
            if (!isSave) {
                if (hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
                    showDownLoadDialog(path);
                } else {
                    requestPermission(Constant.WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                }
            }
            return true;
        }
    });
    return contentView;
}
Also used : View(android.view.View) PhotoView(uk.co.senab.photoview.PhotoView) TextView(android.widget.TextView) PhotoViewAttacher(uk.co.senab.photoview.PhotoViewAttacher) PhotoView(uk.co.senab.photoview.PhotoView) Bitmap(android.graphics.Bitmap) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia) Nullable(android.support.annotation.Nullable)

Example 2 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureSelectorActivity method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        LocalMedia media;
        switch(requestCode) {
            case PictureConfig.REQUEST_CAMERA:
                // on take photo success
                final File file = new File(cameraPath);
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
                String toType = PictureMimeType.fileToType(file);
                DebugUtil.i(TAG, "camera result:" + toType);
                int degree = PictureFileUtils.readPictureDegree(file.getAbsolutePath());
                rotateImage(degree, file);
                // 生成新拍照片或视频对象
                media = new LocalMedia();
                media.setPath(cameraPath);
                List<LocalMedia> result = new ArrayList<>();
                boolean eqVideo = toType.startsWith(PictureConfig.VIDEO);
                int duration = eqVideo ? PictureMimeType.getLocalVideoDuration(cameraPath) : 0;
                String pictureType = eqVideo ? PictureMimeType.createVideoType(cameraPath) : PictureMimeType.createImageType(cameraPath);
                media.setPictureType(pictureType);
                media.setDuration(duration);
                media.setMimeType(mimeType);
                // 因为加入了单独拍照功能,所有如果是单独拍照的话也默认为单选状态
                if (selectionMode == PictureConfig.SINGLE || camera) {
                    // 如果是单选 拍照后直接返回
                    boolean eqImg = toType.startsWith(PictureConfig.IMAGE);
                    if (isCompress && eqImg) {
                        // 去压缩
                        result.add(media);
                        compressImage(result);
                        if (adapter != null) {
                            images.add(0, media);
                            adapter.notifyDataSetChanged();
                        }
                    } else {
                        // 不裁剪 不压缩 直接返回结果
                        result.add(media);
                        onResult(result);
                    }
                } else {
                    // 多选 返回列表并选中当前拍照的
                    images.add(0, media);
                    if (adapter != null) {
                        List<LocalMedia> selectedImages = adapter.getSelectedImages();
                        // 没有到最大选择量 才做默认选中刚拍好的
                        if (selectedImages.size() < maxSelectNum) {
                            pictureType = selectedImages.size() > 0 ? selectedImages.get(0).getPictureType() : "";
                            boolean toEqual = PictureMimeType.mimeToEqual(pictureType, media.getPictureType());
                            // 类型相同或还没有选中才加进选中集合中
                            if (toEqual || selectedImages.size() == 0) {
                                if (selectedImages.size() < maxSelectNum) {
                                    selectedImages.add(media);
                                    adapter.bindSelectImages(selectedImages);
                                    changeImageNumber(selectedImages);
                                }
                            }
                            tv_empty.setVisibility(images.size() > 0 ? View.INVISIBLE : View.VISIBLE);
                            adapter.notifyDataSetChanged();
                        }
                        // 解决部分手机拍照完Intent.ACTION_MEDIA_SCANNER_SCAN_FILE不及时刷新问题手动添加
                        manualSaveFolder(media);
                    }
                }
                break;
        }
    } else if (resultCode == RESULT_CANCELED) {
        if (camera) {
            closeActivity();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia) File(java.io.File)

Example 3 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImageGridAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    if (getItemViewType(position) == PictureConfig.TYPE_CAMERA) {
        HeaderViewHolder headerHolder = (HeaderViewHolder) holder;
        headerHolder.headerView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (imageSelectChangedListener != null) {
                    imageSelectChangedListener.onTakePhoto();
                }
            }
        });
    } else {
        final ViewHolder contentHolder = (ViewHolder) holder;
        DebugUtil.i("onBindViewHolder:", "this is refresh position--->" + position);
        final LocalMedia image = images.get(showCamera ? position - 1 : position);
        image.position = contentHolder.getAdapterPosition();
        String path = image.getPath();
        final String pictureType = image.getPictureType();
        contentHolder.ll_check.setVisibility(selectMode == PictureConfig.SINGLE ? View.GONE : View.VISIBLE);
        if (is_checked_num) {
            notifyCheckChanged(contentHolder, image);
        }
        selectImage(contentHolder, isSelected(image), false);
        final int picture = PictureMimeType.isPictureType(pictureType);
        boolean gif = PictureMimeType.isGif(pictureType);
        contentHolder.tv_isGif.setVisibility(gif ? View.VISIBLE : View.GONE);
        contentHolder.tv_duration.setVisibility(picture == PictureConfig.TYPE_VIDEO ? View.VISIBLE : View.GONE);
        int width = image.getWidth();
        int height = image.getHeight();
        int h = width * 5;
        contentHolder.tv_long_chart.setVisibility(height > h ? View.VISIBLE : View.GONE);
        long duration = image.getDuration();
        contentHolder.tv_duration.setText(DateUtils.timeParse(duration));
        Glide.with(context).load(path).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).centerCrop().placeholder(R.drawable.image_placeholder).override(overrideWidth, overrideHeight).into(contentHolder.iv_picture);
        if (enablePreview || enablePreviewVideo) {
            contentHolder.ll_check.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    changeCheckboxState(contentHolder, image);
                }
            });
        }
        contentHolder.contentView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (picture == PictureConfig.TYPE_IMAGE && (enablePreview || selectMode == PictureConfig.SINGLE)) {
                    int index = showCamera ? position - 1 : position;
                    imageSelectChangedListener.onPictureClick(image, index);
                } else if (picture == PictureConfig.TYPE_VIDEO && (enablePreviewVideo || selectMode == PictureConfig.SINGLE)) {
                    int index = showCamera ? position - 1 : position;
                    imageSelectChangedListener.onPictureClick(image, index);
                } else {
                    changeCheckboxState(contentHolder, image);
                }
            }
        });
    }
}
Also used : LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 4 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImageGridAdapter method bindSelectImages.

public void bindSelectImages(List<LocalMedia> images) {
    // 这里重新构构造一个新集合,不然会产生已选集合一变,结果集合也会添加的问题
    List<LocalMedia> selection = new ArrayList<>();
    for (LocalMedia media : images) {
        selection.add(media);
    }
    this.selectImages = selection;
    subSelectPosition();
    if (imageSelectChangedListener != null) {
        imageSelectChangedListener.onChange(selectImages);
    }
}
Also used : ArrayList(java.util.ArrayList) LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Example 5 with LocalMedia

use of com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia in project JustAndroid by chinaltz.

the class PictureImageGridAdapter method subSelectPosition.

/**
 * 更新选择的顺序
 */
private void subSelectPosition() {
    if (is_checked_num) {
        int size = selectImages.size();
        for (int index = 0, length = size; index < length; index++) {
            LocalMedia media = selectImages.get(index);
            media.setNum(index + 1);
            notifyItemChanged(media.position);
        }
    }
}
Also used : LocalMedia(com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)

Aggregations

LocalMedia (com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMedia)18 View (android.view.View)4 RecyclerView (android.support.v7.widget.RecyclerView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 Bundle (android.os.Bundle)2 File (java.io.File)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Nullable (android.support.annotation.Nullable)1 GridImageAdapter (com.litingzhe.justandroid.someOther.imagePicker.adapter.GridImageAdapter)1 FullyGridLayoutManager (com.litingzhe.justandroid.someOther.imagePicker.utils.FullyGridLayoutManager)1 LocalMediaFolder (com.ningcui.mylibrary.viewLib.Imagepicker.entity.LocalMediaFolder)1 RxPermissions (com.ningcui.mylibrary.viewLib.Imagepicker.permissions.RxPermissions)1 Disposable (io.reactivex.disposables.Disposable)1 PhotoView (uk.co.senab.photoview.PhotoView)1 PhotoViewAttacher (uk.co.senab.photoview.PhotoViewAttacher)1