use of com.luck.picture.lib.weiui.library.PictureSelectionModel 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);
}
}
});
}
Aggregations