use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method singleRadioMediaImage.
/**
* 单选图片
*/
private void singleRadioMediaImage() {
if (selectImages != null && selectImages.size() > 0) {
LocalMedia media = selectImages.get(0);
RxBus.getDefault().post(new EventEntity(PictureConfig.UPDATE_FLAG, selectImages, media.getPosition()));
selectImages.clear();
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method onImageChecked.
/**
* 判断当前图片是否选中
*
* @param position
*/
public void onImageChecked(int position) {
if (images != null && images.size() > 0) {
LocalMedia media = images.get(position);
check.setSelected(isSelected(media));
} else {
check.setSelected(false);
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PictureSelectorActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
List<LocalMedia> medias = new ArrayList<>();
LocalMedia media;
String imageType;
switch(requestCode) {
case UCrop.REQUEST_CROP:
Uri resultUri = UCrop.getOutput(data);
String cutPath = resultUri.getPath();
if (adapter != null) {
// 取单张裁剪已选中图片的path作为原图
List<LocalMedia> mediaList = adapter.getSelectedImages();
media = mediaList != null && mediaList.size() > 0 ? mediaList.get(0) : null;
if (media != null) {
originalPath = media.getPath();
media = new LocalMedia(originalPath, media.getDuration(), false, media.getPosition(), media.getNum(), config.mimeType);
media.setCutPath(cutPath);
media.setCut(true);
imageType = PictureMimeType.createImageType(cutPath);
media.setPictureType(imageType);
medias.add(media);
handlerResult(medias);
}
} else if (config.camera) {
// 单独拍照
media = new LocalMedia(cameraPath, 0, false, config.isCamera ? 1 : 0, 0, config.mimeType);
media.setCut(true);
media.setCutPath(cutPath);
imageType = PictureMimeType.createImageType(cutPath);
media.setPictureType(imageType);
medias.add(media);
handlerResult(medias);
}
break;
case UCropMulti.REQUEST_MULTI_CROP:
List<CutInfo> mCuts = UCropMulti.getOutput(data);
for (CutInfo c : mCuts) {
media = new LocalMedia();
imageType = PictureMimeType.createImageType(c.getPath());
media.setCut(true);
media.setPath(c.getPath());
media.setCutPath(c.getCutPath());
media.setPictureType(imageType);
media.setMimeType(config.mimeType);
medias.add(media);
}
handlerResult(medias);
break;
case PictureConfig.REQUEST_CAMERA:
isAudio(data);
// 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);
if (config.mimeType != PictureMimeType.ofAudio()) {
int degree = PictureFileUtils.readPictureDegree(file.getAbsolutePath());
rotateImage(degree, file);
}
// 生成新拍照片或视频对象
media = new LocalMedia();
media.setPath(cameraPath);
boolean eqVideo = toType.startsWith(PictureConfig.VIDEO);
int duration = eqVideo ? PictureMimeType.getLocalVideoDuration(cameraPath) : 0;
String pictureType = "";
if (config.mimeType == PictureMimeType.ofAudio()) {
pictureType = "audio/mpeg";
duration = PictureMimeType.getLocalVideoDuration(cameraPath);
} else {
pictureType = eqVideo ? PictureMimeType.createVideoType(cameraPath) : PictureMimeType.createImageType(cameraPath);
}
media.setPictureType(pictureType);
media.setDuration(duration);
media.setMimeType(config.mimeType);
// 因为加入了单独拍照功能,所有如果是单独拍照的话也默认为单选状态
if (config.camera) {
// 如果是单选 拍照后直接返回
boolean eqImg = toType.startsWith(PictureConfig.IMAGE);
if (config.enableCrop && eqImg) {
// 去裁剪
originalPath = cameraPath;
startCrop(cameraPath);
} else if (config.isCompress && eqImg) {
// 去压缩
medias.add(media);
compressImage(medias);
if (adapter != null) {
images.add(0, media);
adapter.notifyDataSetChanged();
}
} else {
// 不裁剪 不压缩 直接返回结果
medias.add(media);
onResult(medias);
}
} else {
// 多选 返回列表并选中当前拍照的
images.add(0, media);
if (adapter != null) {
List<LocalMedia> selectedImages = adapter.getSelectedImages();
// 没有到最大选择量 才做默认选中刚拍好的
if (selectedImages.size() < config.maxSelectNum) {
pictureType = selectedImages.size() > 0 ? selectedImages.get(0).getPictureType() : "";
boolean toEqual = PictureMimeType.mimeToEqual(pictureType, media.getPictureType());
// 类型相同或还没有选中才加进选中集合中
if (toEqual || selectedImages.size() == 0) {
if (selectedImages.size() < config.maxSelectNum) {
// 如果是单选,则清空已选中的并刷新列表(作单一选择)
if (config.selectionMode == PictureConfig.SINGLE) {
singleRadioMediaImage();
}
selectedImages.add(media);
adapter.bindSelectImages(selectedImages);
}
}
}
adapter.notifyDataSetChanged();
}
}
if (adapter != null) {
// 解决部分手机拍照完Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
// 不及时刷新问题手动添加
manualSaveFolder(media);
tv_empty.setVisibility(images.size() > 0 ? View.INVISIBLE : View.VISIBLE);
}
if (config.mimeType != PictureMimeType.ofAudio()) {
int lastImageId = getLastImageId(eqVideo);
if (lastImageId != -1) {
removeImage(lastImageId, eqVideo);
}
}
break;
}
} else if (resultCode == RESULT_CANCELED) {
if (config.camera) {
closeActivity();
}
} else if (resultCode == UCrop.RESULT_ERROR) {
Throwable throwable = (Throwable) data.getSerializableExtra(UCrop.EXTRA_ERROR);
showToast(throwable.getMessage());
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PictureSelectorActivity method startPreview.
/**
* preview image and video
*
* @param previewImages
* @param position
*/
public void startPreview(List<LocalMedia> previewImages, int position) {
LocalMedia media = previewImages.get(position);
String pictureType = media.getPictureType();
Bundle bundle = new Bundle();
List<LocalMedia> result = new ArrayList<>();
int mediaType = PictureMimeType.isPictureType(pictureType);
switch(mediaType) {
case PictureConfig.TYPE_IMAGE:
// image
List<LocalMedia> selectedImages = adapter.getSelectedImages();
ImagesObservable.getInstance().saveLocalMedia(previewImages);
bundle.putSerializable(PictureConfig.EXTRA_SELECT_LIST, (Serializable) selectedImages);
bundle.putInt(PictureConfig.EXTRA_POSITION, position);
startActivity(PicturePreviewActivity.class, bundle, config.selectionMode == PictureConfig.SINGLE ? UCrop.REQUEST_CROP : UCropMulti.REQUEST_MULTI_CROP);
overridePendingTransition(R.anim.a5, 0);
break;
case PictureConfig.TYPE_VIDEO:
// video
if (config.selectionMode == PictureConfig.SINGLE) {
result.add(media);
onResult(result);
} else {
bundle.putString("video_path", media.getPath());
startActivity(PictureVideoPlayActivity.class, bundle);
}
break;
case PictureConfig.TYPE_AUDIO:
// audio
if (config.selectionMode == PictureConfig.SINGLE) {
result.add(media);
onResult(result);
} else {
audioDialog(media.getPath());
}
break;
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PictureImageGridAdapter method notifyCheckChanged.
/**
* 选择按钮更新
*/
private void notifyCheckChanged(ViewHolder viewHolder, LocalMedia imageBean) {
viewHolder.check.setText("");
for (LocalMedia media : selectImages) {
if (media.getPath().equals(imageBean.getPath())) {
imageBean.setNum(media.getNum());
media.setPosition(imageBean.getPosition());
viewHolder.check.setText(String.valueOf(imageBean.getNum()));
}
}
}
Aggregations