use of com.yalantis.ucrop.weiui.library.model.CutInfo 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.yalantis.ucrop.weiui.library.model.CutInfo in project weiui by kuaifan.
the class PictureMultiCuttingActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ucrop_picture_activity_multi_cutting);
final Intent intent = getIntent();
list = getIntent().getStringArrayListExtra(UCropMulti.Options.EXTRA_CUT_CROP);
// Crop cut list
if (list != null && list.size() > 0) {
CutInfo cutInfo;
for (String path : list) {
cutInfo = new CutInfo(path, false);
cutInfos.add(cutInfo);
}
initData();
}
setupViews(intent);
setInitialState();
addBlockingView();
setImageData(intent);
}
use of com.yalantis.ucrop.weiui.library.model.CutInfo in project weiui by kuaifan.
the class PictureMultiCuttingActivity method initData.
private void initData() {
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
recyclerView.setLayoutManager(mLayoutManager);
for (CutInfo info : cutInfos) {
info.setCut(false);
}
cutInfos.get(cutIndex).setCut(true);
adapter = new PicturePhotoGalleryAdapter(this, cutInfos);
recyclerView.setAdapter(adapter);
}
use of com.yalantis.ucrop.weiui.library.model.CutInfo in project weiui by kuaifan.
the class PicturePhotoGalleryAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
String path = "";
CutInfo photoInfo = list.get(position);
if (photoInfo != null) {
path = photoInfo.getPath();
}
if (photoInfo.isCut()) {
holder.iv_dot.setVisibility(View.VISIBLE);
holder.iv_dot.setImageResource(R.drawable.ucrop_oval_true);
} else {
holder.iv_dot.setVisibility(View.GONE);
}
RequestOptions options = new RequestOptions().placeholder(R.color.ucrop_color_grey).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with(context).load(path).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(holder.mIvPhoto);
}
use of com.yalantis.ucrop.weiui.library.model.CutInfo in project weiui by kuaifan.
the class PictureMultiCuttingActivity method setResultUri.
protected void setResultUri(Uri uri, float resultAspectRatio, int offsetX, int offsetY, int imageWidth, int imageHeight) {
try {
CutInfo info = cutInfos.get(cutIndex);
info.setCutPath(uri.getPath());
info.setCut(true);
info.setResultAspectRatio(resultAspectRatio);
info.setOffsetX(offsetX);
info.setOffsetY(offsetY);
info.setImageWidth(imageWidth);
info.setImageHeight(imageHeight);
cutIndex++;
if (cutIndex >= cutInfos.size()) {
setResult(RESULT_OK, new Intent().putExtra(UCropMulti.EXTRA_OUTPUT_URI_LIST, (Serializable) cutInfos));
closeActivity();
} else {
resetCutData();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations