use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class DiskCacheReadProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mDiskCacheReadProducer = new DiskCacheReadProducer(mInputProducer, mDiskCachePolicy);
List<CacheKey> keys = new ArrayList<>(1);
keys.add(new SimpleCacheKey("http://dummy.uri"));
mCacheKey = new MultiCacheKey(keys);
mIntermediatePooledByteBuffer = mock(PooledByteBuffer.class);
mFinalPooledByteBuffer = mock(PooledByteBuffer.class);
mIntermediateImageReference = CloseableReference.of(mIntermediatePooledByteBuffer);
mFinalImageReference = CloseableReference.of(mFinalPooledByteBuffer);
mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
mFinalEncodedImage = new EncodedImage(mFinalImageReference);
mIsCancelled = ArgumentCaptor.forClass(AtomicBoolean.class);
mProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.FULL_FETCH, false, true, Priority.MEDIUM);
mLowestLevelProducerContext = new SettableProducerContext(mImageRequest, mRequestId, mProducerListener, mCallerContext, ImageRequest.RequestLevel.DISK_CACHE, false, true, Priority.MEDIUM);
when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
when(mImageRequest.getCacheChoice()).thenReturn(ImageRequest.CacheChoice.DEFAULT);
when(mImageRequest.isDiskCacheEnabled()).thenReturn(true);
}
use of com.facebook.cache.common.CacheKey in project fresco by facebook.
the class EncodedMemoryCacheProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mEncodedMemoryCacheProducer = new EncodedMemoryCacheProducer(mMemoryCache, mCacheKeyFactory, mInputProducer);
mPooledByteBuffer1 = mock(PooledByteBuffer.class);
mPooledByteBuffer2 = mock(PooledByteBuffer.class);
mFinalImageReference = CloseableReference.of(mPooledByteBuffer1);
mIntermediateImageReference = CloseableReference.of(mPooledByteBuffer2);
mFinalImageReferenceClone = mFinalImageReference.clone();
mFinalEncodedImage = new EncodedImage(mFinalImageReference);
mIntermediateEncodedImage = new EncodedImage(mIntermediateImageReference);
mFinalEncodedImageClone = new EncodedImage(mFinalImageReferenceClone);
List<CacheKey> list = new ArrayList<>();
list.add(new SimpleCacheKey("http://dummy.uri"));
mCacheKey = new MultiCacheKey(list);
when(mCacheKeyFactory.getEncodedCacheKey(mImageRequest, mCallerContext)).thenReturn(mCacheKey);
when(mMemoryCache.cache(mCacheKey, mFinalImageReference)).thenReturn(mFinalImageReferenceClone);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
when(mProducerContext.getCallerContext()).thenReturn(mCallerContext);
when(mProducerContext.getListener()).thenReturn(mProducerListener);
when(mProducerListener.requiresExtraMap(mRequestId)).thenReturn(true);
when(mProducerContext.getId()).thenReturn(mRequestId);
when(mProducerContext.getLowestPermittedRequestLevel()).thenReturn(ImageRequest.RequestLevel.FULL_FETCH);
}
use of com.facebook.cache.common.CacheKey in project BigImageViewer by Piasy.
the class FrescoImageLoader method getCacheFile.
private File getCacheFile(final ImageRequest request) {
FileCache mainFileCache = ImagePipelineFactory.getInstance().getMainFileCache();
final CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(request, // we don't need context, but avoid null
false);
File cacheFile = request.getSourceFile();
// http://crashes.to/s/ee10638fb31
if (mainFileCache.hasKey(cacheKey) && mainFileCache.getResource(cacheKey) != null) {
cacheFile = ((FileBinaryResource) mainFileCache.getResource(cacheKey)).getFile();
}
return cacheFile;
}
use of com.facebook.cache.common.CacheKey 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) {
}
}
Aggregations