Search in sources :

Example 16 with GenericDraweeHierarchyBuilder

use of com.facebook.drawee.generic.GenericDraweeHierarchyBuilder in project ride-read-android by Ride-Read.

the class FrescoImgLoader method displayImage.

@Override
public void displayImage(Activity activity, Context context, String path, final GalleryImageView imageView, int width, int height) {
    GenericDraweeHierarchy hierarchy = // 占位图
    new GenericDraweeHierarchyBuilder(context.getResources()).setFadeDuration(300).setPlaceholderImage(R.mipmap.gallery_pick_photo).setFailureImage(// 加载失败图
    R.mipmap.gallery_pick_photo).setProgressBarImage(// loading
    new ProgressBarDrawable()).build();
    final DraweeHolder<GenericDraweeHierarchy> draweeHolder = DraweeHolder.create(hierarchy, context);
    imageView.setOnImageViewListener(new GalleryImageView.OnImageViewListener() {

        @Override
        public void onDraw(Canvas canvas) {
            Drawable drawable = draweeHolder.getHierarchy().getTopLevelDrawable();
            if (drawable == null) {
                imageView.setImageResource(R.mipmap.gallery_pick_photo);
            } else {
                imageView.setImageDrawable(drawable);
            }
        }

        @Override
        public boolean verifyDrawable(Drawable dr) {
            return dr == draweeHolder.getHierarchy().getTopLevelDrawable();
        }

        @Override
        public void onDetach() {
            draweeHolder.onDetach();
        }

        @Override
        public void onAttach() {
            draweeHolder.onAttach();
        }
    });
    Uri uri = new Uri.Builder().scheme(UriUtil.LOCAL_FILE_SCHEME).path(path).build();
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setResizeOptions(new ResizeOptions(width, height)).build();
    DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(draweeHolder.getController()).setImageRequest(imageRequest).build();
    draweeHolder.setController(controller);
}
Also used : GalleryImageView(com.yancy.gallerypick.widget.GalleryImageView) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) GenericDraweeHierarchyBuilder(com.facebook.drawee.generic.GenericDraweeHierarchyBuilder) DraweeController(com.facebook.drawee.interfaces.DraweeController) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) ResizeOptions(com.facebook.imagepipeline.common.ResizeOptions) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Aggregations

GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)16 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)12 RoundingParams (com.facebook.drawee.generic.RoundingParams)4 Resources (android.content.res.Resources)3 ProgressBarDrawable (com.facebook.drawee.drawable.ProgressBarDrawable)3 Canvas (android.graphics.Canvas)2 Drawable (android.graphics.drawable.Drawable)2 Uri (android.net.Uri)2 DraweeController (com.facebook.drawee.interfaces.DraweeController)2 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)2 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)2 InstrumentedDraweeView (com.facebook.samples.comparison.instrumentation.InstrumentedDraweeView)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 GFImageView (cn.finalteam.galleryfinal.widget.GFImageView)1 DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)1 FrescoHolder (com.facebook.samples.comparison.holders.FrescoHolder)1 VolleyDraweeHolder (com.facebook.samples.comparison.holders.VolleyDraweeHolder)1 GalleryImageView (com.yancy.gallerypick.widget.GalleryImageView)1