Search in sources :

Example 16 with LocalMedia

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

the class weiuiPictureModule method create.

/**
 ************************************************************************************************
 */
/**
 ************************************************************************************************
 */
/**
 ************************************************************************************************
 */
/**
 * 打开相册
 * @param object
 * @param callback
 */
@JSMethod
public void create(String object, final JSCallback callback) {
    final JSONObject json = weiuiJson.parseObject(object);
    // 
    PageActivity.startTransparentPage(mWXSDKInstance.getContext(), new JSCallback() {

        @Override
        public void invoke(Object data) {
            if (callback != null) {
                callback.invoke(data);
            }
        }

        @Override
        public void invokeAndKeepAlive(Object data) {
            Map<String, Object> retData = weiuiMap.objectToMap(data);
            String pageName = weiuiParse.parseStr(retData.get("pageName"));
            String status = weiuiParse.parseStr(retData.get("status"));
            PageBean mBean = weiuiPage.getPageBean(pageName);
            if (mBean == null) {
                return;
            }
            switch(status) {
                case "create":
                    List<LocalMedia> selected = new ArrayList<>();
                    JSONArray selectedList = weiuiJson.parseArray(json.getString("selected"));
                    for (int i = 0; i < selectedList.size(); i++) {
                        JSONObject tempJson = weiuiJson.parseObject(selectedList.get(i));
                        LocalMedia tempMedia = new LocalMedia();
                        tempMedia.setDuration(tempJson.getInteger("duration"));
                        tempMedia.setPath(tempJson.getString("path"));
                        tempMedia.setCut(tempJson.getBoolean("cut"));
                        tempMedia.setNum(tempJson.getInteger("num"));
                        tempMedia.setWidth(tempJson.getInteger("width"));
                        tempMedia.setHeight(tempJson.getInteger("height"));
                        tempMedia.setChecked(tempJson.getBoolean("checked"));
                        tempMedia.setMimeType(tempJson.getInteger("mimeType"));
                        tempMedia.setPosition(tempJson.getInteger("position"));
                        tempMedia.setCompressed(tempJson.getBoolean("compressed"));
                        tempMedia.setPictureType(tempJson.getString("pictureType"));
                        selected.add(tempMedia);
                    }
                    PictureSelectionModel model;
                    if (weiuiJson.getString(json, "type", "gallery").equals("camera")) {
                        model = PictureSelector.create(mBean.getActivity()).openCamera(// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                        weiuiJson.getInt(json, "gallery", PictureMimeType.ofAll()));
                    } else {
                        model = PictureSelector.create(mBean.getActivity()).openGallery(// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
                        weiuiJson.getInt(json, "gallery", PictureMimeType.ofAll()));
                    }
                    // 最大选择数量 int
                    model.maxSelectNum(weiuiJson.getInt(json, "maxNum", 9)).minSelectNum(// 最小选择数量 int
                    weiuiJson.getInt(json, "minNum", 0)).imageSpanCount(// 每行显示个数 int
                    weiuiJson.getInt(json, "spanCount", 4)).selectionMode(// 多选 or 单选 PictureConfig.MULTIPLE or PictureConfig.SINGLE
                    weiuiJson.getInt(json, "mode", PictureConfig.MULTIPLE)).previewImage(// 是否可预览图片 true or false
                    weiuiJson.getBoolean(json, "previewImage", true)).previewVideo(// 是否可预览视频 true or false
                    weiuiJson.getBoolean(json, "previewVideo", true)).enablePreviewAudio(// 是否可播放音频 true or false
                    weiuiJson.getBoolean(json, "previewAudio", true)).isCamera(// 是否显示拍照按钮 true or false
                    weiuiJson.getBoolean(json, "camera", true)).imageFormat(// 拍照保存图片格式后缀,默认jpeg
                    weiuiJson.getString(json, "format", PictureMimeType.JPEG)).isZoomAnim(// 图片列表点击 缩放效果 默认true
                    weiuiJson.getBoolean(json, "zoomAnim", true)).sizeMultiplier(// glide 加载图片大小 0~1之间 如设置 .glideOverride()无效
                    weiuiJson.getFloat(json, "multiplier", 0.5f)).enableCrop(// 是否裁剪 true or false
                    weiuiJson.getBoolean(json, "crop", false)).compress(// 是否压缩 true or false
                    weiuiJson.getBoolean(json, "compress", false)).glideOverride(weiuiJson.getInt(json, "overrideWidth", 100), // int glide 加载宽高,越小图片列表越流畅,但会影响列表图片浏览的清晰度
                    weiuiJson.getInt(json, "overrideHeight", 100)).withAspectRatio(weiuiJson.getInt(json, "ratioX", 1), // int 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
                    weiuiJson.getInt(json, "ratioY", 1)).hideBottomControls(// 是否显示uCrop工具栏,默认不显示 true or false
                    weiuiJson.getBoolean(json, "cropControls", false)).isGif(// 是否显示gif图片 true or false
                    weiuiJson.getBoolean(json, "git", false)).freeStyleCropEnabled(// 裁剪框是否可拖拽 true or false
                    weiuiJson.getBoolean(json, "freeCrop", false)).circleDimmedLayer(// 是否圆形裁剪 true or false
                    weiuiJson.getBoolean(json, "circle", false)).showCropFrame(// 是否显示裁剪矩形边框 圆形裁剪时建议设为false   true or false
                    weiuiJson.getBoolean(json, "cropFrame", true)).showCropGrid(// 是否显示裁剪矩形网格 圆形裁剪时建议设为false    true or false
                    weiuiJson.getBoolean(json, "cropGrid", true)).openClickSound(// 是否开启点击声音 true or false
                    weiuiJson.getBoolean(json, "clickSound", false)).selectionMedia(// 是否传入已选图片 List<LocalMedia> list
                    selected).previewEggs(// 预览图片时 是否增强左右滑动图片体验(图片滑动一半即可看到上一张是否选中) true or false
                    weiuiJson.getBoolean(json, "eggs", false)).cropCompressQuality(// 裁剪压缩质量 默认90 int
                    weiuiJson.getInt(json, "quality", 90)).minimumCompressSize(// 小于100kb的图片不压缩
                    weiuiJson.getInt(json, "compressSize", 100)).synOrAsy(// 同步true或异步false 压缩 默认同步
                    weiuiJson.getBoolean(json, "sync", true)).cropWH(weiuiJson.getInt(json, "cropWidth", 0), // 裁剪宽高比,设置如果大于图片本身宽高则无效 int
                    weiuiJson.getInt(json, "cropHeight", 0)).rotateEnabled(// 裁剪是否可旋转图片 true or false
                    weiuiJson.getBoolean(json, "rotate", true)).scaleEnabled(// 裁剪是否可放大缩小图片 true or false
                    weiuiJson.getBoolean(json, "scale", true)).videoQuality(// 视频录制质量 0 or 1 int
                    weiuiJson.getInt(json, "videoQuality", 0)).videoMaxSecond(// 显示多少秒以内的视频or音频也可适用 int
                    weiuiJson.getInt(json, "videoMaxSecond", 15)).videoMinSecond(// 显示多少秒以内的视频or音频也可适用 int
                    weiuiJson.getInt(json, "videoMinSecond", 10)).recordVideoSecond(// 视频秒数录制 默认60s int
                    weiuiJson.getInt(json, "recordVideoSecond", 60)).forResult(PictureConfig.CHOOSE_REQUEST);
                    break;
                case "activityResult":
                    int requestCode = weiuiParse.parseInt(retData.get("requestCode"));
                    int resultCode = weiuiParse.parseInt(retData.get("resultCode"));
                    if (resultCode == RESULT_OK) {
                        switch(requestCode) {
                            case PictureConfig.CHOOSE_REQUEST:
                                if (callback != null) {
                                    Map<String, Object> callData = new HashMap<>();
                                    callData.put("status", "success");
                                    callData.put("lists", PictureSelector.obtainMultipleResult((Intent) retData.get("resultData")));
                                    callback.invokeAndKeepAlive(callData);
                                }
                                break;
                        }
                    }
                    mBean.getActivity().finish();
                    break;
            }
            if (callback != null) {
                callback.invokeAndKeepAlive(data);
            }
        }
    });
}
Also used : PictureSelectionModel(com.luck.picture.lib.weiui.library.PictureSelectionModel) JSONArray(com.alibaba.fastjson.JSONArray) JSCallback(com.taobao.weex.bridge.JSCallback) PageBean(vip.kuaifan.weiui.extend.bean.PageBean) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) HashMap(java.util.HashMap) vip.kuaifan.weiui.extend.module.weiuiMap(vip.kuaifan.weiui.extend.module.weiuiMap) Map(java.util.Map) JSMethod(com.taobao.weex.annotation.JSMethod)

Example 17 with LocalMedia

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

the class FolderPopWindow method notifyDataCheckedStatus.

/**
 * 设置选中状态
 */
public void notifyDataCheckedStatus(List<LocalMedia> medias) {
    try {
        // 获取选中图片
        List<LocalMediaFolder> folders = adapter.getFolderData();
        for (LocalMediaFolder folder : folders) {
            folder.setCheckedNum(0);
        }
        if (medias.size() > 0) {
            for (LocalMediaFolder folder : folders) {
                // 记录当前相册下有多少张是选中的
                int num = 0;
                List<LocalMedia> images = folder.getImages();
                for (LocalMedia media : images) {
                    String path = media.getPath();
                    for (LocalMedia m : medias) {
                        if (path.equals(m.getPath())) {
                            num++;
                            folder.setCheckedNum(num);
                        }
                    }
                }
            }
        }
        adapter.bindFolderData(folders);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : LocalMediaFolder(com.luck.picture.lib.weiui.library.entity.LocalMediaFolder) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 18 with LocalMedia

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

the class PictureBaseActivity method handleCompressCallBack.

/**
 * 重新构造已压缩的图片返回集合
 *
 * @param images
 * @param files
 */
private void handleCompressCallBack(List<LocalMedia> images, List<File> files) {
    if (files.size() == images.size()) {
        for (int i = 0, j = images.size(); i < j; i++) {
            // 压缩成功后的地址
            String path = files.get(i).getPath();
            LocalMedia image = images.get(i);
            // 如果是网络图片则不压缩
            boolean http = PictureMimeType.isHttp(path);
            boolean eqTrue = !TextUtils.isEmpty(path) && http;
            image.setCompressed(eqTrue ? false : true);
            image.setCompressPath(eqTrue ? "" : path);
        }
    }
    RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
    onResult(images);
}
Also used : EventEntity(com.luck.picture.lib.weiui.library.entity.EventEntity) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 19 with LocalMedia

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

the class PicturePreviewActivity method initViewPageAdapterData.

/**
 * 初始化ViewPage数据
 */
private void initViewPageAdapterData() {
    tv_title.setText(position + 1 + "/" + images.size());
    adapter = new SimpleFragmentAdapter(images, this, this);
    viewPager.setAdapter(adapter);
    viewPager.setCurrentItem(position);
    onSelectNumChange(false);
    onImageChecked(position);
    if (images.size() > 0) {
        LocalMedia media = images.get(position);
        index = media.getPosition();
        if (config.checkNumMode) {
            tv_img_num.setSelected(true);
            check.setText(media.getNum() + "");
            notifyCheckChanged(media);
        }
    }
}
Also used : SimpleFragmentAdapter(com.luck.picture.lib.weiui.library.adapter.SimpleFragmentAdapter) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

Example 20 with LocalMedia

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

the class PicturePreviewActivity method isPreviewEggs.

/**
 * 这里没实际意义,好处是预览图片时 滑动到屏幕一半以上可看到下一张图片是否选中了
 *
 * @param previewEggs          是否显示预览友好体验
 * @param positionOffsetPixels 滑动偏移量
 */
private void isPreviewEggs(boolean previewEggs, int position, int positionOffsetPixels) {
    if (previewEggs) {
        if (images.size() > 0 && images != null) {
            LocalMedia media;
            int num;
            if (positionOffsetPixels < screenWidth / 2) {
                media = images.get(position);
                check.setSelected(isSelected(media));
                if (config.checkNumMode) {
                    num = media.getNum();
                    check.setText(num + "");
                    notifyCheckChanged(media);
                    onImageChecked(position);
                }
            } else {
                media = images.get(position + 1);
                check.setSelected(isSelected(media));
                if (config.checkNumMode) {
                    num = media.getNum();
                    check.setText(num + "");
                    notifyCheckChanged(media);
                    onImageChecked(position + 1);
                }
            }
        }
    }
}
Also used : LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia)

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