Search in sources :

Example 1 with GifDrawable

use of com.bumptech.glide.load.resource.gif.GifDrawable in project plaid by nickbutcher.

the class DribbbleTarget method onResourceReady.

@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
    super.onResourceReady(resource, animation);
    if (!autoplayGifs) {
        resource.stop();
    }
    BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView();
    if (resource instanceof GlideBitmapDrawable) {
        Palette.from(((GlideBitmapDrawable) resource).getBitmap()).clearFilters().generate(this);
    } else if (resource instanceof GifDrawable) {
        Bitmap image = ((GifDrawable) resource).getFirstFrame();
        Palette.from(image).clearFilters().generate(this);
        // look at the corner to determine the gif badge color
        int cornerSize = (int) (56 * getView().getContext().getResources().getDisplayMetrics().scaledDensity);
        Bitmap corner = Bitmap.createBitmap(image, image.getWidth() - cornerSize, image.getHeight() - cornerSize, cornerSize, cornerSize);
        boolean isDark = ColorUtils.isDark(corner);
        corner.recycle();
        badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(), isDark ? R.color.gif_badge_dark_image : R.color.gif_badge_light_image));
    }
}
Also used : BadgedFourThreeImageView(io.plaidapp.ui.widget.BadgedFourThreeImageView) Bitmap(android.graphics.Bitmap) GlideBitmapDrawable(com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Example 2 with GifDrawable

use of com.bumptech.glide.load.resource.gif.GifDrawable in project glide by bumptech.

the class DrawableResourceTest method testReturnsNewDrawableOnGet.

@Test
public void testReturnsNewDrawableOnGet() {
    GifDrawable expected = mock(GifDrawable.class);
    Drawable.ConstantState constantState = mock(Drawable.ConstantState.class);
    when(constantState.newDrawable()).thenReturn(expected);
    when(drawable.getConstantState()).thenReturn(constantState);
    assertEquals(expected, resource.get());
    verify(drawable).getConstantState();
    verify(constantState).newDrawable();
}
Also used : Drawable(android.graphics.drawable.Drawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) Test(org.junit.Test)

Example 3 with GifDrawable

use of com.bumptech.glide.load.resource.gif.GifDrawable in project glide by bumptech.

the class ReEncodingGifResourceEncoder method encode.

@Override
public boolean encode(Resource<GifDrawable> resource, File file, Options options) {
    GifDrawable drawable = resource.get();
    Transformation<Bitmap> transformation = drawable.getFrameTransformation();
    boolean isTransformed = !(transformation instanceof UnitTransformation);
    if (isTransformed && options.get(ENCODE_TRANSFORMATION)) {
        return encodeTransformedToFile(drawable, file);
    } else {
        return writeDataDirect(drawable.getBuffer(), file);
    }
}
Also used : Bitmap(android.graphics.Bitmap) UnitTransformation(com.bumptech.glide.load.resource.UnitTransformation) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Example 4 with GifDrawable

use of com.bumptech.glide.load.resource.gif.GifDrawable in project LookLook by xinghongfei.

the class DribbbleTarget method onResourceReady.

@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
    super.onResourceReady(resource, animation);
    if (!autoplayGifs) {
        resource.stop();
    }
    BadgedFourThreeImageView badgedImageView = (BadgedFourThreeImageView) getView();
    if (resource instanceof GlideBitmapDrawable) {
        Palette.from(((GlideBitmapDrawable) resource).getBitmap()).clearFilters().generate(this);
    } else if (resource instanceof GifDrawable) {
        Bitmap image = ((GifDrawable) resource).getFirstFrame();
        Palette.from(image).clearFilters().generate(this);
        // look at the corner to determine the gif badge color
        int cornerSize = (int) (56 * getView().getContext().getResources().getDisplayMetrics().scaledDensity);
        Bitmap corner = Bitmap.createBitmap(image, image.getWidth() - cornerSize, image.getHeight() - cornerSize, cornerSize, cornerSize);
        boolean isDark = ColorUtils.isDark(corner);
        corner.recycle();
        badgedImageView.setBadgeColor(ContextCompat.getColor(getView().getContext(), isDark ? R.color.gif_badge_dark_image : R.color.gif_badge_light_image));
    }
}
Also used : BadgedFourThreeImageView(com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView) Bitmap(android.graphics.Bitmap) GlideBitmapDrawable(com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Example 5 with GifDrawable

use of com.bumptech.glide.load.resource.gif.GifDrawable in project RichText by zzhoujay.

the class ImageTargetGif method recycle.

@Override
public void recycle() {
    Glide.clear(this);
    if (gifDrawableSoftReference != null) {
        GifDrawable gifDrawable = gifDrawableSoftReference.get();
        if (gifDrawable != null) {
            gifDrawable.setCallback(null);
            gifDrawable.stop();
        }
    }
}
Also used : GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Aggregations

GifDrawable (com.bumptech.glide.load.resource.gif.GifDrawable)10 Bitmap (android.graphics.Bitmap)5 Drawable (android.graphics.drawable.Drawable)3 GlideBitmapDrawable (com.bumptech.glide.load.resource.bitmap.GlideBitmapDrawable)3 View (android.view.View)2 BadgedFourThreeImageView (com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView)2 BadgedFourThreeImageView (io.plaidapp.ui.widget.BadgedFourThreeImageView)2 ActivityOptions (android.app.ActivityOptions)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Intent (android.content.Intent)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 NonNull (android.support.annotation.NonNull)1 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)1 RecyclerView (android.support.v7.widget.RecyclerView)1 MotionEvent (android.view.MotionEvent)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 BindView (butterknife.BindView)1