use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.
the class FrescoUtil method resizeImage.
public static void resizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(path);
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
if (imageInfo == null) {
return;
}
final float width = imageInfo.getWidth();
final float height = imageInfo.getHeight();
if (width * height != 0.0f) {
final int viewHeight = (int) (height * viewWidth / width);
setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
}
}
};
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
use of com.facebook.imagepipeline.request.ImageRequest in project SherlockAdapter by EvilBT.
the class FrescoUtil method setWrapAndResizeImage.
public static void setWrapAndResizeImage(@NonNull final SimpleDraweeView view, @NonNull final String path, final int viewWidth, @Nullable final Point size) {
Preconditions.checkNotNull(view);
Preconditions.checkNotNull(path);
ControllerListener<ImageInfo> controllerListener = new BaseControllerListener<ImageInfo>() {
@Override
public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
if (imageInfo == null) {
return;
}
final float width = imageInfo.getWidth();
final float height = imageInfo.getHeight();
if (width * height != 0.0f) {
view.setAspectRatio(width / height);
final int viewHeight = (int) (height * viewWidth / width);
if (size != null) {
size.set(viewWidth, viewHeight);
}
setResizeImage(view, path, new ResizeOptions(viewWidth, viewHeight));
}
}
};
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(path)).build();
view.setController(Fresco.newDraweeControllerBuilder().setImageRequest(request).setOldController(view.getController()).setControllerListener(controllerListener).build());
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method downLoadImage.
@Override
public void downLoadImage(Context context, String url, final File saveFile, final ImageListener<File> imageListener) {
// 参考自https://github.com/hpdx/fresco-helper/blob/master/fresco-helper/src/main/java/com/facebook/fresco/helper/ImageLoader.java
Uri uri = Uri.parse(url);
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
ImageRequest imageRequest = builder.build();
// 获取未解码的图片数据
DataSource<CloseableReference<PooledByteBuffer>> dataSource = imagePipeline.fetchEncodedImage(imageRequest, context);
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<PooledByteBuffer>>() {
@Override
public void onNewResultImpl(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<PooledByteBuffer> imageReference = dataSource.getResult();
if (imageReference != null) {
final CloseableReference<PooledByteBuffer> closeableReference = imageReference.clone();
try {
PooledByteBuffer pooledByteBuffer = closeableReference.get();
InputStream inputStream = new PooledByteBufferInputStream(pooledByteBuffer);
OutputStream outputStream = new FileOutputStream(saveFile);
if (FileUtil.saveFile(inputStream, outputStream) && imageListener != null) {
imageListener.onSuccess(saveFile);
}
} catch (Exception e) {
if (imageListener != null) {
imageListener.onFail(e);
}
e.printStackTrace();
} finally {
imageReference.close();
closeableReference.close();
}
}
}
@Override
public void onProgressUpdate(DataSource<CloseableReference<PooledByteBuffer>> dataSource) {
int progress = (int) (dataSource.getProgress() * 100);
RingLog.d("fresco下载图片进度:" + progress);
}
@Override
public void onFailureImpl(DataSource dataSource) {
Throwable throwable = dataSource.getFailureCause();
if (imageListener != null) {
imageListener.onFail(throwable);
}
}
}, Executors.newSingleThreadExecutor());
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method load.
private void load(Uri uri, ImageView imageView, LoadOption loadOption) {
Preconditions.checkNotNull(imageView, "加载图片的控件不能为空!");
if (imageView instanceof SimpleDraweeView) {
SimpleDraweeView simpleDraweeView = (SimpleDraweeView) imageView;
setHierarchay(simpleDraweeView.getHierarchy(), loadOption);
ImageRequest imageRequest = getImageRequest(uri, simpleDraweeView, loadOption);
DraweeController draweeController = getController(imageRequest, simpleDraweeView.getController());
simpleDraweeView.setController(draweeController);
} else {
throw new IllegalArgumentException("Fresco加载图片的控件需为SimpleDraweeView");
}
}
use of com.facebook.imagepipeline.request.ImageRequest in project DevRing by LJYcoder.
the class FrescoManager method preLoad.
@Override
public void preLoad(String url) {
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(Preconditions.checkNotNull(url, "预加载的图片路径不能为空"))).build();
Fresco.getImagePipeline().prefetchToBitmapCache(imageRequest, null);
Fresco.getImagePipeline().prefetchToDiskCache(imageRequest, null);
}
Aggregations