Search in sources :

Example 1 with GalleryImageView

use of com.yancy.gallerypick.widget.GalleryImageView 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

Canvas (android.graphics.Canvas)1 Drawable (android.graphics.drawable.Drawable)1 Uri (android.net.Uri)1 ProgressBarDrawable (com.facebook.drawee.drawable.ProgressBarDrawable)1 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)1 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)1 DraweeController (com.facebook.drawee.interfaces.DraweeController)1 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)1 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)1 GalleryImageView (com.yancy.gallerypick.widget.GalleryImageView)1