use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PictureBaseActivity method compressImage.
/**
* compressImage
*/
protected void compressImage(final List<LocalMedia> result) {
showCompressDialog();
if (config.synOrAsy) {
Flowable.just(result).observeOn(Schedulers.io()).map(new Function<List<LocalMedia>, List<File>>() {
@Override
public List<File> apply(@NonNull List<LocalMedia> list) throws Exception {
List<File> files = Luban.with(mContext).setTargetDir(config.compressSavePath).ignoreBy(config.minimumCompressSize).loadLocalMedia(list).get();
if (files == null) {
files = new ArrayList<>();
}
return files;
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<List<File>>() {
@Override
public void accept(@NonNull List<File> files) throws Exception {
handleCompressCallBack(result, files);
}
});
} else {
Luban.with(this).loadLocalMedia(result).ignoreBy(config.minimumCompressSize).setTargetDir(config.compressSavePath).setCompressListener(new OnCompressListener() {
@Override
public void onStart() {
}
@Override
public void onSuccess(List<LocalMedia> list) {
RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
onResult(list);
}
@Override
public void onError(Throwable e) {
RxBus.getDefault().post(new EventEntity(PictureConfig.CLOSE_PREVIEW_FLAG));
onResult(result);
}
}).launch();
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method notifyCheckChanged.
/**
* 选择按钮更新
*/
private void notifyCheckChanged(LocalMedia imageBean) {
if (config.checkNumMode) {
check.setText("");
for (LocalMedia media : selectImages) {
if (media.getPath().equals(imageBean.getPath())) {
imageBean.setNum(media.getNum());
check.setText(String.valueOf(imageBean.getNum()));
}
}
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method onClick.
@Override
public void onClick(View view) {
int id = view.getId();
if (id == R.id.picture_left_back) {
onBackPressed();
}
if (id == R.id.id_ll_ok) {
// 如果设置了图片最小选择数量,则判断是否满足条件
int size = selectImages.size();
LocalMedia image = selectImages.size() > 0 ? selectImages.get(0) : null;
String pictureType = image != null ? image.getPictureType() : "";
if (config.minSelectNum > 0) {
if (size < config.minSelectNum && config.selectionMode == PictureConfig.MULTIPLE) {
boolean eqImg = pictureType.startsWith(PictureConfig.IMAGE);
String str = eqImg ? getString(R.string.picture_min_img_num, config.minSelectNum) : getString(R.string.picture_min_video_num, config.minSelectNum);
showToast(str);
return;
}
}
if (config.enableCrop && pictureType.startsWith(PictureConfig.IMAGE)) {
if (config.selectionMode == PictureConfig.SINGLE) {
originalPath = image.getPath();
startCrop(originalPath);
} else {
// 是图片和选择压缩并且是多张,调用批量压缩
ArrayList<String> cuts = new ArrayList<>();
for (LocalMedia media : selectImages) {
cuts.add(media.getPath());
}
startCrop(cuts);
}
} else {
onResult(selectImages);
}
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method subSelectPosition.
/**
* 更新选择的顺序
*/
private void subSelectPosition() {
for (int index = 0, len = selectImages.size(); index < len; index++) {
LocalMedia media = selectImages.get(index);
media.setNum(index + 1);
}
}
use of com.luck.picture.lib.weiui.library.entity.LocalMedia in project weiui by kuaifan.
the class PicturePreviewActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.picture_preview);
if (!RxBus.getDefault().isRegistered(this)) {
RxBus.getDefault().register(this);
}
mHandler = new Handler();
screenWidth = ScreenUtils.getScreenWidth(this);
int status_color = AttrsUtils.getTypeValueColor(this, R.attr.picture_status_color);
ToolbarUtil.setColorNoTranslucent(this, status_color);
LightStatusBarUtils.setLightStatusBar(this, previewStatusFont);
animation = OptAnimationLoader.loadAnimation(this, R.anim.modal_in);
animation.setAnimationListener(this);
picture_left_back = (ImageView) findViewById(R.id.picture_left_back);
viewPager = (PreviewViewPager) findViewById(R.id.preview_pager);
ll_check = (LinearLayout) findViewById(R.id.ll_check);
id_ll_ok = (LinearLayout) findViewById(R.id.id_ll_ok);
check = (TextView) findViewById(R.id.check);
picture_left_back.setOnClickListener(this);
tv_ok = (TextView) findViewById(R.id.tv_ok);
id_ll_ok.setOnClickListener(this);
tv_img_num = (TextView) findViewById(R.id.tv_img_num);
tv_title = (TextView) findViewById(R.id.picture_title);
position = getIntent().getIntExtra(PictureConfig.EXTRA_POSITION, 0);
tv_ok.setText(numComplete ? getString(R.string.picture_done_front_num, 0, config.selectionMode == PictureConfig.SINGLE ? 1 : config.maxSelectNum) : getString(R.string.picture_please_select));
tv_img_num.setSelected(config.checkNumMode ? true : false);
selectImages = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_SELECT_LIST);
boolean is_bottom_preview = getIntent().getBooleanExtra(PictureConfig.EXTRA_BOTTOM_PREVIEW, false);
if (is_bottom_preview) {
// 底部预览按钮过来
images = (List<LocalMedia>) getIntent().getSerializableExtra(PictureConfig.EXTRA_PREVIEW_SELECT_LIST);
} else {
images = ImagesObservable.getInstance().readLocalMedias();
}
initViewPageAdapterData();
ll_check.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (images != null && images.size() > 0) {
LocalMedia image = images.get(viewPager.getCurrentItem());
String pictureType = selectImages.size() > 0 ? selectImages.get(0).getPictureType() : "";
if (!TextUtils.isEmpty(pictureType)) {
boolean toEqual = PictureMimeType.mimeToEqual(pictureType, image.getPictureType());
if (!toEqual) {
showToast(getString(R.string.picture_rule));
return;
}
}
// 刷新图片列表中图片状态
boolean isChecked;
if (!check.isSelected()) {
isChecked = true;
check.setSelected(true);
check.startAnimation(animation);
} else {
isChecked = false;
check.setSelected(false);
}
if (selectImages.size() >= config.maxSelectNum && isChecked) {
showToast(getString(R.string.picture_message_max_num, config.maxSelectNum));
check.setSelected(false);
return;
}
if (isChecked) {
VoiceUtils.playVoice(mContext, config.openClickSound);
// 如果是单选,则清空已选中的并刷新列表(作单一选择)
if (config.selectionMode == PictureConfig.SINGLE) {
singleRadioMediaImage();
}
selectImages.add(image);
image.setNum(selectImages.size());
if (config.checkNumMode) {
check.setText(String.valueOf(image.getNum()));
}
} else {
for (LocalMedia media : selectImages) {
if (media.getPath().equals(image.getPath())) {
selectImages.remove(media);
subSelectPosition();
notifyCheckChanged(media);
break;
}
}
}
onSelectNumChange(true);
}
}
});
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
isPreviewEggs(config.previewEggs, position, positionOffsetPixels);
}
@Override
public void onPageSelected(int i) {
position = i;
tv_title.setText(position + 1 + "/" + images.size());
LocalMedia media = images.get(position);
index = media.getPosition();
if (!config.previewEggs) {
if (config.checkNumMode) {
check.setText(media.getNum() + "");
notifyCheckChanged(media);
}
onImageChecked(position);
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
Aggregations