use of android.graphics.drawable.TransitionDrawable in project AndroidChromium by JackyAndroid.
the class SnippetArticleViewHolder method fadeThumbnailIn.
private void fadeThumbnailIn(SnippetArticle snippet, Bitmap thumbnail) {
mImageCallback = null;
// Nothing to do, we keep the placeholder.
if (thumbnail == null)
return;
// We need to crop and scale the downloaded bitmap, as the ImageView we set it on won't be
// able to do so when using a TransitionDrawable (as opposed to the straight bitmap).
// That's a limitation of TransitionDrawable, which doesn't handle layers of varying sizes.
Resources res = mThumbnailView.getResources();
int targetSize = res.getDimensionPixelSize(R.dimen.snippets_thumbnail_size);
Bitmap scaledThumbnail = ThumbnailUtils.extractThumbnail(thumbnail, targetSize, targetSize, ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
// Store the bitmap to skip the download task next time we display this snippet.
snippet.setThumbnailBitmap(scaledThumbnail);
// Cross-fade between the placeholder and the thumbnail.
Drawable[] layers = { mThumbnailView.getDrawable(), new BitmapDrawable(mThumbnailView.getResources(), scaledThumbnail) };
TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
mThumbnailView.setImageDrawable(transitionDrawable);
transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}
Aggregations