iielse / imageviewer

A simple and customizable Android full-screen image viewer 一个简单且可自定义的Android全屏图像浏览器
MIT License
2.23k stars 310 forks source link

我的项目中使用 glide 的版本是 4.0 的,引入该框架的时候冲突了 #6

Closed ipuppy2 closed 7 years ago

ipuppy2 commented 7 years ago

您好,我在项目使用了 glide , 它的版本是 4.0 的, 如果我想使用您这个框架,我该怎么做?

iielse commented 7 years ago

你是说图片查看器吗? 按照readme的步骤使用 compile 'ch.ielse:imagewatcher:1.0.2'。 如果这样还不行的话,直接把lib项目的源码复制过去,改改配置吧。

iielse commented 7 years ago

@puppyLyx 你好啊,我今天也用了Glide4.0了发现Api有点小不一样。 要不你把代码复制一下吧先。 这样应该要把图片加载模块抽成接口提供出来,就能支持各种加载框架把

vImageWatcher = ImageWatcher.Helper.with(this) // 一般来讲, ImageWatcher 需要占据全屏的位置
                .setTranslucentStatus(!isTranslucentStatus ? Utils.calcStatusBarHeight(this) : 0) // 如果是透明状态栏,你需要给ImageWatcher标记 一个偏移值,以修正点击ImageView查看的启动动画的Y轴起点的不正确
                .setErrorImageRes(R.mipmap.error_picture) // 配置error图标 如果不介意使用lib自带的图标,并不一定要调用这个API
                .setOnPictureLongPressListener(this) // 长按图片的回调,你可以显示一个框继续提供一些复制,发送等功能
                .setLoader(new ImageWatcher.Loader() {
                    @Override
                    public void load(Context context, String url, final ImageWatcher.LoadCallback lc) {
                        Glide.with(context).load(url).asBitmap().into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                lc.onResourceReady(resource);
                            }

                            @Override
                            public void onLoadStarted(Drawable placeholder) {
                                lc.onLoadStarted(placeholder);
                            }

                            @Override
                            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                                lc.onLoadFailed(e, errorDrawable);
                            }
                        });
                    }
                })
                .create();

ImageWatcher

private Loader loader;

    public void setLoader(Loader l) {
        loader = l;
    }

    public  interface Loader {
        void load(Context context, String url, LoadCallback lc);
    }

    public interface LoadCallback {
        void onResourceReady(Bitmap resource);

        void onLoadStarted(Drawable placeholder);

        void onLoadFailed(Exception e, Drawable errorDrawable);
    }

    public ImageWatcher(Context context) {
        this(context, null);
    }

   ....
   setDefaultDisplayConfigs 方法内部

   loader.load(imageView.getContext(), mUrlList.get(pos), new LoadCallback() {
                @Override
                public void onResourceReady(Bitmap resource) {
                    final int sourceDefaultWidth, sourceDefaultHeight, sourceDefaultTranslateX, sourceDefaultTranslateY;
                    int resourceImageWidth = resource.getWidth();
                    int resourceImageHeight = resource.getHeight();
                    if (resourceImageWidth * 1f / resourceImageHeight > mWidth * 1f / mHeight) {
                        sourceDefaultWidth = mWidth;
                        sourceDefaultHeight = (int) (sourceDefaultWidth * 1f / resourceImageWidth * resourceImageHeight);
                        sourceDefaultTranslateX = 0;
                        sourceDefaultTranslateY = (mHeight - sourceDefaultHeight) / 2;
                        imageView.setTag(R.id.image_orientation, "horizontal");
                    } else {
                        sourceDefaultHeight = mHeight;
                        sourceDefaultWidth = (int) (sourceDefaultHeight * 1f / resourceImageHeight * resourceImageWidth);
                        sourceDefaultTranslateY = 0;
                        sourceDefaultTranslateX = (mWidth - sourceDefaultWidth) / 2;
                        imageView.setTag(R.id.image_orientation, "vertical");
                    }
                    imageView.setImageBitmap(resource);
                    notifyItemChangedState(pos, false, false);

                    ViewState vsDefault = ViewState.write(imageView, ViewState.STATE_DEFAULT).width(sourceDefaultWidth).height(sourceDefaultHeight)
                            .translationX(sourceDefaultTranslateX).translationY(sourceDefaultTranslateY);
                    if (isPlayEnterAnimation) {
                        animSourceViewStateTransform(imageView, vsDefault);
                    } else {
                        ViewState.restore(imageView, vsDefault.mTag);
                        imageView.setAlpha(0f);
                        imageView.animate().alpha(1).start();
                    }
                }

                @Override
                public void onLoadStarted(Drawable placeholder) {
                    notifyItemChangedState(pos, true, false);
                }

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    notifyItemChangedState(pos, false, imageView.getDrawable() == null);

                }
            });
   ....
iielse commented 7 years ago

就很难受,过几天可能更新一下吧。我再考虑考虑