use of com.bumptech.glide.load.resource.gif.GifDrawable in project BBS-Android by bdpqchen.
the class GlideImageGeter method recycle.
public void recycle() {
targets.clear();
for (GifDrawable gifDrawable : gifDrawables) {
gifDrawable.setCallback(null);
gifDrawable.recycle();
}
gifDrawables.clear();
}
use of com.bumptech.glide.load.resource.gif.GifDrawable in project glide by bumptech.
the class FullscreenActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fullscreen_activity);
String resultJson = getIntent().getStringExtra(EXTRA_RESULT_JSON);
final Api.GifResult result = new Gson().fromJson(resultJson, Api.GifResult.class);
ImageView gifView = (ImageView) findViewById(R.id.fullscreen_gif);
gifView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("giphy_url", result.images.original.url);
clipboard.setPrimaryClip(clip);
if (gifDrawable != null) {
if (gifDrawable.isRunning()) {
gifDrawable.stop();
} else {
gifDrawable.start();
}
}
}
});
RequestBuilder<Drawable> thumbnailRequest = Glide.with(this).load(result).apply(decodeTypeOf(Bitmap.class));
Glide.with(this).load(result.images.original.url).thumbnail(thumbnailRequest).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
if (resource instanceof GifDrawable) {
gifDrawable = (GifDrawable) resource;
} else {
gifDrawable = null;
}
return false;
}
}).into(gifView);
}
use of com.bumptech.glide.load.resource.gif.GifDrawable in project glide by bumptech.
the class GifDrawableBytesTranscoder method transcode.
@Override
public Resource<byte[]> transcode(Resource<GifDrawable> toTranscode) {
GifDrawable gifData = toTranscode.get();
ByteBuffer byteBuffer = gifData.getBuffer();
return new BytesResource(ByteBufferUtil.toBytes(byteBuffer));
}
use of com.bumptech.glide.load.resource.gif.GifDrawable in project plaid by nickbutcher.
the class FeedAdapter method createDribbbleShotHolder.
@NonNull
private DribbbleShotHolder createDribbbleShotHolder(ViewGroup parent) {
final DribbbleShotHolder holder = new DribbbleShotHolder(layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false));
holder.image.setBadgeColor(initialGifBadgeColor);
holder.image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setClass(host, DribbbleShot.class);
intent.putExtra(DribbbleShot.EXTRA_SHOT, (Shot) getItem(holder.getAdapterPosition()));
setGridItemContentTransitions(holder.image);
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(host, Pair.create(view, host.getString(R.string.transition_shot)), Pair.create(view, host.getString(R.string.transition_shot_background)));
host.startActivityForResult(intent, REQUEST_CODE_VIEW_SHOT, options.toBundle());
}
});
// play animated GIFs whilst touched
holder.image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// check if it's an event we care about, else bail fast
final int action = event.getAction();
if (!(action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL))
return false;
// get the image and check if it's an animated GIF
final Drawable drawable = holder.image.getDrawable();
if (drawable == null)
return false;
GifDrawable gif = null;
if (drawable instanceof GifDrawable) {
gif = (GifDrawable) drawable;
} else if (drawable instanceof TransitionDrawable) {
// we fade in images on load which uses a TransitionDrawable; check its layers
TransitionDrawable fadingIn = (TransitionDrawable) drawable;
for (int i = 0; i < fadingIn.getNumberOfLayers(); i++) {
if (fadingIn.getDrawable(i) instanceof GifDrawable) {
gif = (GifDrawable) fadingIn.getDrawable(i);
break;
}
}
}
if (gif == null)
return false;
// GIF found, start/stop it on press/lift
switch(action) {
case MotionEvent.ACTION_DOWN:
gif.start();
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
gif.stop();
break;
}
return false;
}
});
return holder;
}
use of com.bumptech.glide.load.resource.gif.GifDrawable in project LookLook by xinghongfei.
the class ImageTarget 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));
}
}
Aggregations