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);
}
}
});
}
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();
}
}
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);
}
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);
}
}
}
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);
}
}
}
}
}
Aggregations