Search in sources :

Example 96 with TransitionDrawable

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);
}
Also used : Bitmap(android.graphics.Bitmap) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Resources(android.content.res.Resources) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SuppressLint(android.annotation.SuppressLint)

Aggregations

TransitionDrawable (android.graphics.drawable.TransitionDrawable)96 Drawable (android.graphics.drawable.Drawable)61 ColorDrawable (android.graphics.drawable.ColorDrawable)35 BitmapDrawable (android.graphics.drawable.BitmapDrawable)31 View (android.view.View)28 VelocityTracker (android.view.VelocityTracker)11 ImageView (android.widget.ImageView)10 Rect (android.graphics.Rect)9 Handler (android.os.Handler)8 Test (org.junit.Test)6 Bitmap (android.graphics.Bitmap)5 LayerDrawable (android.graphics.drawable.LayerDrawable)5 GradientDrawable (android.graphics.drawable.GradientDrawable)3 RippleDrawable (android.graphics.drawable.RippleDrawable)3 SuppressLint (android.annotation.SuppressLint)2 Intent (android.content.Intent)2 ColorStateList (android.content.res.ColorStateList)2 Resources (android.content.res.Resources)2 ContentObserver (android.database.ContentObserver)2 Canvas (android.graphics.Canvas)2