use of com.facebook.common.references.CloseableReference in project remusic by aa112901.
the class AlbumsDetailActivity 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, AlbumsDetailActivity.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 remusic by aa112901.
the class SimpleWidgetProvider method pushUpdate.
// 更新所有的 widget
private synchronized void pushUpdate(final Context context, AppWidgetManager appWidgetManager, boolean updateProgress) {
pushAction(context, MediaService.SEND_PROGRESS);
RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.simple_control_widget_layout);
// 将按钮与点击事件绑定
remoteView.setOnClickPendingIntent(R.id.widget_play, getPendingIntent(context, R.id.widget_play));
remoteView.setOnClickPendingIntent(R.id.widget_pre, getPendingIntent(context, R.id.widget_pre));
remoteView.setOnClickPendingIntent(R.id.widget_next, getPendingIntent(context, R.id.widget_next));
remoteView.setOnClickPendingIntent(R.id.widget_love, getPendingIntent(context, R.id.widget_love));
remoteView.setTextViewText(R.id.widget_content, trackname == null && art == null ? "" : trackname + "-" + art);
remoteView.setProgressBar(R.id.widget_progress, (int) duration, (int) position, false);
isFav = false;
long[] favlists = PlaylistsManager.getInstance(context).getPlaylistIds(IConstants.FAV_PLAYLIST);
for (long i : favlists) {
if (currentId == i) {
isFav = true;
break;
}
}
if (isFav) {
remoteView.setImageViewResource(R.id.widget_love, R.drawable.widget_unstar_selector);
} else {
remoteView.setImageViewResource(R.id.widget_love, R.drawable.widget_star_selector);
}
if (isPlaying) {
remoteView.setImageViewResource(R.id.widget_play, R.drawable.widget_pause_selector);
} else {
remoteView.setImageViewResource(R.id.widget_play, R.drawable.widget_play_selector);
}
if (updateProgress) {
if (albumuri == null) {
remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
} else {
if (isTrackLocal) {
Bitmap bitmap = ImageUtils.getArtworkQuick(context, Uri.parse(albumuri), 160, 160);
if (bitmap != null) {
remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
} else {
remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
}
} else {
Bitmap bitmap = albumMap.get(albumuri);
if (bitmap != null)
remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
}
}
} else {
if (albumuri == null) {
remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
} else {
if (isTrackLocal) {
final Bitmap bitmap = ImageUtils.getArtworkQuick(context, Uri.parse(albumuri), 160, 160);
if (bitmap != null) {
remoteView.setImageViewBitmap(R.id.widget_image, bitmap);
} else {
remoteView.setImageViewResource(R.id.widget_image, R.drawable.placeholder_disk_210);
}
albumMap.clear();
} else {
if (albumMap.get(albumuri) != null) {
remoteView.setImageViewBitmap(R.id.widget_image, albumMap.get(albumuri));
// noBit = null;
} else {
Uri uri = Uri.parse(albumuri);
if (uri == null) {
noBit = BitmapFactory.decodeResource(context.getResources(), R.drawable.placeholder_disk_210);
albumMap.put(albumuri, noBit);
pushUpdate(context, AppWidgetManager.getInstance(context), false);
} else {
ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(uri).setProgressiveRenderingEnabled(true).build();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
dataSource.subscribe(new BaseBitmapDataSubscriber() {
@Override
public void onNewResultImpl(@Nullable Bitmap bitmap) {
// No need to do any cleanup.
if (bitmap != null) {
noBit = bitmap.copy(bitmap.getConfig(), true);
albumMap.put(albumuri, noBit);
}
pushUpdate(context, AppWidgetManager.getInstance(context), false);
}
@Override
public void onFailureImpl(DataSource dataSource) {
// No cleanup required here.
noBit = BitmapFactory.decodeResource(context.getResources(), R.drawable.placeholder_disk_210);
albumMap.put(albumuri, noBit);
pushUpdate(context, AppWidgetManager.getInstance(context), false);
}
}, CallerThreadExecutor.getInstance());
}
}
}
}
}
// 相当于获得所有本程序创建的appwidget
ComponentName componentName = new ComponentName(context, SimpleWidgetProvider.class);
appWidgetManager.updateAppWidget(componentName, remoteView);
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedRepeatedPostprocessorProducerTest method testNonStaticBitmapIsPassedOn.
@Test
public void testNonStaticBitmapIsPassedOn() {
RepeatedPostprocessorConsumer postprocessorConsumer = produceResults();
RepeatedPostprocessorRunner repeatedPostprocessorRunner = getRunner();
CloseableAnimatedImage sourceCloseableAnimatedImage = mock(CloseableAnimatedImage.class);
CloseableReference<CloseableImage> sourceCloseableImageRef = CloseableReference.<CloseableImage>of(sourceCloseableAnimatedImage);
postprocessorConsumer.onNewResult(sourceCloseableImageRef, Consumer.IS_LAST);
sourceCloseableImageRef.close();
mTestExecutorService.runUntilIdle();
mInOrder.verify(mConsumer).onNewResult(any(CloseableReference.class), eq(Consumer.NO_FLAGS));
mInOrder.verifyNoMoreInteractions();
assertEquals(1, mResults.size());
CloseableReference<CloseableImage> res0 = mResults.get(0);
assertTrue(CloseableReference.isValid(res0));
assertSame(sourceCloseableAnimatedImage, res0.get());
res0.close();
performCancelAndVerifyOnCancellation();
verify(sourceCloseableAnimatedImage).close();
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedSingleUsePostprocessorProducerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mTestExecutorService = new TestExecutorService(new FakeClock());
mPostprocessorProducer = new PostprocessorProducer(mInputProducer, mPlatformBitmapFactory, mTestExecutorService);
when(mImageRequest.getPostprocessor()).thenReturn(mPostprocessor);
when(mProducerContext.getId()).thenReturn(mRequestId);
when(mProducerContext.getProducerListener()).thenReturn(mProducerListener);
when(mProducerContext.getImageRequest()).thenReturn(mImageRequest);
mResults = new ArrayList<>();
when(mPostprocessor.getName()).thenReturn(POSTPROCESSOR_NAME);
when(mProducerListener.requiresExtraMap(eq(mProducerContext), eq(POSTPROCESSOR_NAME))).thenReturn(true);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
mResults.add(((CloseableReference<CloseableImage>) invocation.getArguments()[0]).clone());
return null;
}
}).when(mConsumer).onNewResult(any(CloseableReference.class), anyInt());
mInOrder = inOrder(mPostprocessor, mProducerListener, mConsumer);
mSourceBitmap = mock(Bitmap.class);
mSourceCloseableStaticBitmap = mock(CloseableStaticBitmap.class);
when(mSourceCloseableStaticBitmap.getUnderlyingBitmap()).thenReturn(mSourceBitmap);
mSourceCloseableImageRef = CloseableReference.<CloseableImage>of(mSourceCloseableStaticBitmap);
mDestinationBitmap = mock(Bitmap.class);
mDestinationCloseableBitmapRef = CloseableReference.of(mDestinationBitmap, mBitmapResourceReleaser);
}
use of com.facebook.common.references.CloseableReference in project fresco by facebook.
the class AnimatedImageFactoryImpl method getCloseableImage.
private CloseableImage getCloseableImage(ImageDecodeOptions options, AnimatedImage image, Bitmap.Config bitmapConfig) {
List<CloseableReference<Bitmap>> decodedFrames = null;
CloseableReference<Bitmap> previewBitmap = null;
try {
final int frameForPreview = options.useLastFrameForPreview ? image.getFrameCount() - 1 : 0;
if (options.forceStaticImage) {
return new CloseableStaticBitmap(createPreviewBitmap(image, bitmapConfig, frameForPreview), ImmutableQualityInfo.FULL_QUALITY, 0);
}
if (options.decodeAllFrames) {
decodedFrames = decodeAllFrames(image, bitmapConfig);
previewBitmap = CloseableReference.cloneOrNull(decodedFrames.get(frameForPreview));
}
if (options.decodePreviewFrame && previewBitmap == null) {
previewBitmap = createPreviewBitmap(image, bitmapConfig, frameForPreview);
}
AnimatedImageResult animatedImageResult = AnimatedImageResult.newBuilder(image).setPreviewBitmap(previewBitmap).setFrameForPreview(frameForPreview).setDecodedFrames(decodedFrames).setBitmapTransformation(options.bitmapTransformation).build();
return new CloseableAnimatedImage(animatedImageResult);
} finally {
CloseableReference.closeSafely(previewBitmap);
CloseableReference.closeSafely(decodedFrames);
}
}
Aggregations