alibaba / Virtualview-Android

A light way to build UI in custom XML.
http://tangram.pingguohe.net/
MIT License
1.46k stars 187 forks source link

VirtualViewApplication.ImageTarget.onBitmapLoaded中mImageBase可能为空 #68

Open Rysle opened 6 years ago

Rysle commented 6 years ago
private static class ImageTarget implements Target {

    ImageBase mImageBase;

    Listener mListener;

    public ImageTarget(ImageBase imageBase) {
        mImageBase = imageBase;
    }

    public ImageTarget(Listener listener) {
        mListener = listener;
    }

    @Override
    public void onBitmapLoaded(Bitmap bitmap, LoadedFrom from) {
        mImageBase.setBitmap(bitmap, true); <<<<<<<<<----------- HERE
        if (mListener != null) {
            mListener.onImageLoadSuccess(bitmap);
        }
        Log.d("VirtualViewApplication", "onBitmapLoaded " + from);
    }

    ...
}

使用的地方: VirtualViewApplication.onCreate()

        sVafContext.setImageLoaderAdapter(new IImageLoaderAdapter() {

            private List<ImageTarget> cache = new ArrayList<ImageTarget>();

            @Override
            public void getBitmap(String uri, int reqWidth, int reqHeight, final Listener lis) {
                RequestCreator requestCreator = Picasso.with(VirtualViewApplication.this).load(uri);
                Log.d("VirtualViewApplication", "getBitmap request width height " + reqHeight + " " + reqWidth);
                if (reqHeight > 0 || reqWidth > 0) {
                    requestCreator.resize(reqWidth, reqHeight);
                }
                ImageTarget imageTarget = new ImageTarget(lis);  <<<<<<<<<----------- HERE
                cache.add(imageTarget);
                requestCreator.into(imageTarget);
            }
        });