Search in sources :

Example 21 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class PictureSelectorActivity method onClick.

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.picture_left_back || id == R.id.picture_right) {
        if (folderWindow.isShowing()) {
            folderWindow.dismiss();
        } else {
            closeActivity();
        }
    }
    if (id == R.id.picture_title) {
        if (folderWindow.isShowing()) {
            folderWindow.dismiss();
        } else {
            if (images != null && images.size() > 0) {
                folderWindow.showAsDropDown(rl_picture_title);
                List<LocalMedia> selectedImages = adapter.getSelectedImages();
                folderWindow.notifyDataCheckedStatus(selectedImages);
            }
        }
    }
    if (id == R.id.picture_id_preview) {
        List<LocalMedia> selectedImages = adapter.getSelectedImages();
        List<LocalMedia> medias = new ArrayList<>();
        for (LocalMedia media : selectedImages) {
            medias.add(media);
        }
        Bundle bundle = new Bundle();
        bundle.putSerializable(PictureConfig.EXTRA_PREVIEW_SELECT_LIST, (Serializable) medias);
        bundle.putSerializable(PictureConfig.EXTRA_SELECT_LIST, (Serializable) selectedImages);
        bundle.putBoolean(PictureConfig.EXTRA_BOTTOM_PREVIEW, true);
        startActivity(PicturePreviewActivity.class, bundle, config.selectionMode == PictureConfig.SINGLE ? UCrop.REQUEST_CROP : UCropMulti.REQUEST_MULTI_CROP);
        overridePendingTransition(R.anim.a5, 0);
    }
    if (id == R.id.id_ll_ok) {
        List<LocalMedia> images = adapter.getSelectedImages();
        LocalMedia image = images.size() > 0 ? images.get(0) : null;
        String pictureType = image != null ? image.getPictureType() : "";
        // 如果设置了图片最小选择数量,则判断是否满足条件
        int size = images.size();
        boolean eqImg = pictureType.startsWith(PictureConfig.IMAGE);
        if (config.minSelectNum > 0 && config.selectionMode == PictureConfig.MULTIPLE) {
            if (size < config.minSelectNum) {
                String str = eqImg ? getString(R.string.picture_min_img_num, config.minSelectNum) : getString(R.string.picture_min_video_num, config.minSelectNum);
                showToast(str);
                return;
            }
        }
        if (config.enableCrop && eqImg) {
            if (config.selectionMode == PictureConfig.SINGLE) {
                originalPath = image.getPath();
                startCrop(originalPath);
            } else {
                // 是图片和选择压缩并且是多张,调用批量压缩
                ArrayList<String> medias = new ArrayList<>();
                for (LocalMedia media : images) {
                    medias.add(media.getPath());
                }
                startCrop(medias);
            }
        } else if (config.isCompress && eqImg) {
            // 图片才压缩,视频不管
            compressImage(images);
        } else {
            onResult(images);
        }
    }
}
Also used : Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 22 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class PictureImageGridAdapter method singleRadioMediaImage.

/**
 * 单选模式
 */
private void singleRadioMediaImage() {
    if (selectImages != null && selectImages.size() > 0) {
        LocalMedia media = selectImages.get(0);
        notifyItemChanged(config.isCamera ? media.position : isGo ? media.position : media.position > 0 ? media.position - 1 : 0);
        selectImages.clear();
        isGo = true;
    }
}
Also used : LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 23 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

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.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 24 with LocalMedia

use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.

the class SimpleFragmentAdapter method instantiateItem.

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.picture_image_preview, container, false);
    // 常规图控件
    final PhotoView imageView = (PhotoView) contentView.findViewById(R.id.preview_image);
    // 长图控件
    final SubsamplingScaleImageView longImg = (SubsamplingScaleImageView) contentView.findViewById(R.id.longImg);
    ImageView iv_play = (ImageView) contentView.findViewById(R.id.iv_play);
    LocalMedia media = images.get(position);
    if (media != null) {
        final String pictureType = media.getPictureType();
        boolean eqVideo = pictureType.startsWith(PictureConfig.VIDEO);
        iv_play.setVisibility(eqVideo ? View.VISIBLE : View.GONE);
        final String path;
        if (media.isCut() && !media.isCompressed()) {
            // 裁剪过
            path = media.getCutPath();
        } else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
            // 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
            path = media.getCompressPath();
        } else {
            path = media.getPath();
        }
        boolean isGif = PictureMimeType.isGif(pictureType);
        final boolean eqLongImg = PictureMimeType.isLongImg(media);
        imageView.setVisibility(eqLongImg && !isGif ? View.GONE : View.VISIBLE);
        longImg.setVisibility(eqLongImg && !isGif ? View.VISIBLE : View.GONE);
        // 压缩过的gif就不是gif了
        if (isGif && !media.isCompressed()) {
            RequestOptions gifOptions = new RequestOptions().override(480, 800).priority(Priority.HIGH).diskCacheStrategy(DiskCacheStrategy.NONE);
            Glide.with(contentView.getContext()).asGif().load(path).apply(gifOptions).into(imageView);
        } else {
            RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL);
            Glide.with(contentView.getContext()).asBitmap().load(path).apply(options).into(new SimpleTarget<Bitmap>(480, 800) {

                @Override
                public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                    if (eqLongImg) {
                        displayLongPic(resource, longImg);
                    } else {
                        imageView.setImageBitmap(resource);
                    }
                }
            });
        }
        imageView.setOnViewTapListener(new OnViewTapListener() {

            @Override
            public void onViewTap(View view, float x, float y) {
                if (onBackPressed != null) {
                    onBackPressed.onActivityBackPressed();
                }
            }
        });
        longImg.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (onBackPressed != null) {
                    onBackPressed.onActivityBackPressed();
                }
            }
        });
        iv_play.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("video_path", path);
                intent.putExtras(bundle);
                intent.setClass(mContext, PictureVideoPlayActivity.class);
                mContext.startActivity(intent);
            }
        });
    }
    (container).addView(contentView, 0);
    return contentView;
}
Also used : OnViewTapListener(com.luck.picture.lib.weiui.library.photoview.OnViewTapListener) RequestOptions(vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions) Bundle(android.os.Bundle) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) PhotoView(com.luck.picture.lib.weiui.library.photoview.PhotoView) PhotoView(com.luck.picture.lib.weiui.library.photoview.PhotoView) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) PictureVideoPlayActivity(com.luck.picture.lib.weiui.library.PictureVideoPlayActivity)

Aggregations

LocalMedia (com.luck.picture.lib.weiui.library.entity.LocalMedia)24 ArrayList (java.util.ArrayList)8 File (java.io.File)4 Bundle (android.os.Bundle)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 EventEntity (com.luck.picture.lib.weiui.library.entity.EventEntity)3 Intent (android.content.Intent)2 TextView (android.widget.TextView)2 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 JSMethod (com.taobao.weex.annotation.JSMethod)2 List (java.util.List)2 RequestOptions (vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions)2 Activity (android.app.Activity)1 Bitmap (android.graphics.Bitmap)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 UiThread (android.support.annotation.UiThread)1