use of com.facebook.common.references.CloseableReference in project apps-android-wikipedia by wikimedia.
the class ImagePipelineBitmapGetter method get.
public void get() {
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(imageUrl)).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, WikipediaApp.getInstance());
dataSource.subscribe(new BitmapDataSubscriber(), UiThreadImmediateExecutorService.getInstance());
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class BitmapMemoryCacheProducer method wrapConsumer.
protected Consumer<CloseableReference<CloseableImage>> wrapConsumer(final Consumer<CloseableReference<CloseableImage>> consumer, final CacheKey cacheKey) {
return new DelegatingConsumer<CloseableReference<CloseableImage>, CloseableReference<CloseableImage>>(consumer) {
@Override
public void onNewResultImpl(CloseableReference<CloseableImage> newResult, boolean isLast) {
// ignore invalid intermediate results and forward the null result if last
if (newResult == null) {
if (isLast) {
getConsumer().onNewResult(null, true);
}
return;
}
// stateful results cannot be cached and are just forwarded
if (newResult.get().isStateful()) {
getConsumer().onNewResult(newResult, isLast);
return;
}
// forward the already cached result and don't cache the new result.
if (!isLast) {
CloseableReference<CloseableImage> currentCachedResult = mMemoryCache.get(cacheKey);
if (currentCachedResult != null) {
try {
QualityInfo newInfo = newResult.get().getQualityInfo();
QualityInfo cachedInfo = currentCachedResult.get().getQualityInfo();
if (cachedInfo.isOfFullQuality() || cachedInfo.getQuality() >= newInfo.getQuality()) {
getConsumer().onNewResult(currentCachedResult, false);
return;
}
} finally {
CloseableReference.closeSafely(currentCachedResult);
}
}
}
// cache and forward the new result
CloseableReference<CloseableImage> newCachedResult = mMemoryCache.cache(cacheKey, newResult);
try {
if (isLast) {
getConsumer().onProgressUpdate(1f);
}
getConsumer().onNewResult((newCachedResult != null) ? newCachedResult : newResult, isLast);
} finally {
CloseableReference.closeSafely(newCachedResult);
}
}
};
}
use of com.facebook.common.references.CloseableReference in project lzc_app_lib by httplzc.
the class BigImgDataRequestHelper method getHolderData.
// 获取holder 的catch
private void getHolderData(final WrapperUri wrapperUri) {
final Uri holderUri = wrapperUri.getLowUri();
if (holderUri == null)
return;
ImagePipeline imagePipeline = Fresco.getImagePipeline();
ImageRequest request = ImageRequestBuilder.newBuilderWithSource(holderUri).setResizeOptions(new ResizeOptions(ScreenData.widthPX / 3, ScreenData.heightPX / 3)).build();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(request, "");
dataSource.subscribe(new BaseDataSubscriber<CloseableReference<CloseableImage>>() {
@Override
protected void onNewResultImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
if (!dataSource.isFinished()) {
return;
}
CloseableReference<CloseableImage> ref = dataSource.getResult();
if (ref != null && ref.isValid()) {
try {
if (data.get(wrapperUri.getUri()) == null) {
holderData.put(holderUri, ref.clone());
if (imgDataLoadCompleteListener != null)
imgDataLoadCompleteListener.onHolderDataLoadComplete(wrapperUri);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
CloseableReference.closeSafely(ref);
}
}
}
@Override
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
}
}, UiThreadImmediateExecutorService.getInstance());
}
use of com.facebook.common.references.CloseableReference in project remusic by aa112901.
the class RadioDetailActivity method setAlbumart.
private void setAlbumart() {
albumTitle.setText(albumName);
albumArtSmall.setImageURI(Uri.parse(albumPath));
try {
ImageRequest imageRequest = ImageRequest.fromUri(albumPath);
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
File file = ((FileBinaryResource) resource).getFile();
if (file != null) {
new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(file, 300, 300));
return;
}
imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).setProgressiveRenderingEnabled(true).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, RadioDetailActivity.this);
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// No need to do any cleanup.
if (bitmap != null) {
new setBlurredAlbumArt().execute(bitmap);
}
;
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here.
}
}, CallerThreadExecutor.getInstance());
// drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src");
} catch (Exception e) {
}
}
use of com.facebook.common.references.CloseableReference in project ride-read-android by Ride-Read.
the class MapFragment method addMoment2Map.
private void addMoment2Map(final MapMoment moment) {
final LatLng latLng = new LatLng(moment.getLatitude(), moment.getLongitude());
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(moment.getPictures().get(0) + QiNiuUtils.CROP_SMALL_100)).setProgressiveRenderingEnabled(true).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, Utils.getAppContext());
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
addMomentMarker(latLng, bitmap, moment);
}
@Override
public void onFailureImpl(DataSource dataSource) {
}
}, CallerThreadExecutor.getInstance());
}
Aggregations