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));
}
}
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();
}
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);
}
}
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));
}
}
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();
}
}
}
Aggregations