Search in sources :

Example 1 with OnViewTapListener

use of com.luck.picture.lib.weiui.library.photoview.OnViewTapListener 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;
}
Also used : OnViewTapListener(com.luck.picture.lib.weiui.library.photoview.OnViewTapListener) RequestOptions(vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions) Bundle(android.os.Bundle) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) PhotoView(com.luck.picture.lib.weiui.library.photoview.PhotoView) PhotoView(com.luck.picture.lib.weiui.library.photoview.PhotoView) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) SubsamplingScaleImageView(com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView) LocalMedia(com.luck.picture.lib.weiui.library.entity.LocalMedia) PictureVideoPlayActivity(com.luck.picture.lib.weiui.library.PictureVideoPlayActivity)

Aggregations

Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 PictureVideoPlayActivity (com.luck.picture.lib.weiui.library.PictureVideoPlayActivity)1 LocalMedia (com.luck.picture.lib.weiui.library.entity.LocalMedia)1 OnViewTapListener (com.luck.picture.lib.weiui.library.photoview.OnViewTapListener)1 PhotoView (com.luck.picture.lib.weiui.library.photoview.PhotoView)1 SubsamplingScaleImageView (com.luck.picture.lib.weiui.library.widget.longimage.SubsamplingScaleImageView)1 RequestOptions (vip.kuaifan.weiui.extend.integration.glide.request.RequestOptions)1