use of com.luck.picture.lib.weiui.library.photoview.PhotoView in project weiui by kuaifan.
the class SimpleFragmentAdapter method instantiateItem.
@Override
public Object instantiateItem(ViewGroup container, int position) {
final View contentView = LayoutInflater.from(container.getContext()).inflate(R.layout.picture_image_preview, container, false);
// 常规图控件
final PhotoView imageView = (PhotoView) contentView.findViewById(R.id.preview_image);
// 长图控件
final SubsamplingScaleImageView longImg = (SubsamplingScaleImageView) contentView.findViewById(R.id.longImg);
ImageView iv_play = (ImageView) contentView.findViewById(R.id.iv_play);
LocalMedia media = images.get(position);
if (media != null) {
final String pictureType = media.getPictureType();
boolean eqVideo = pictureType.startsWith(PictureConfig.VIDEO);
iv_play.setVisibility(eqVideo ? View.VISIBLE : View.GONE);
final String path;
if (media.isCut() && !media.isCompressed()) {
// 裁剪过
path = media.getCutPath();
} else if (media.isCompressed() || (media.isCut() && media.isCompressed())) {
// 压缩过,或者裁剪同时压缩过,以最终压缩过图片为准
path = media.getCompressPath();
} else {
path = media.getPath();
}
boolean isGif = PictureMimeType.isGif(pictureType);
final boolean eqLongImg = PictureMimeType.isLongImg(media);
imageView.setVisibility(eqLongImg && !isGif ? View.GONE : View.VISIBLE);
longImg.setVisibility(eqLongImg && !isGif ? View.VISIBLE : View.GONE);
// 压缩过的gif就不是gif了
if (isGif && !media.isCompressed()) {
RequestOptions gifOptions = new RequestOptions().override(480, 800).priority(Priority.HIGH).diskCacheStrategy(DiskCacheStrategy.NONE);
Glide.with(contentView.getContext()).asGif().load(path).apply(gifOptions).into(imageView);
} else {
RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL);
Glide.with(contentView.getContext()).asBitmap().load(path).apply(options).into(new SimpleTarget<Bitmap>(480, 800) {
@Override
public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
if (eqLongImg) {
displayLongPic(resource, longImg);
} else {
imageView.setImageBitmap(resource);
}
}
});
}
imageView.setOnViewTapListener(new OnViewTapListener() {
@Override
public void onViewTap(View view, float x, float y) {
if (onBackPressed != null) {
onBackPressed.onActivityBackPressed();
}
}
});
longImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (onBackPressed != null) {
onBackPressed.onActivityBackPressed();
}
}
});
iv_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("video_path", path);
intent.putExtras(bundle);
intent.setClass(mContext, PictureVideoPlayActivity.class);
mContext.startActivity(intent);
}
});
}
(container).addView(contentView, 0);
return contentView;
}
Aggregations