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);
}
Aggregations