Search in sources :

Example 6 with GifDrawable

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();
}
Also used : GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable)

Example 7 with GifDrawable

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);
}
Also used : ClipboardManager(android.content.ClipboardManager) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) Gson(com.google.gson.Gson) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) ImageView(android.widget.ImageView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) Target(com.bumptech.glide.request.target.Target) ImageView(android.widget.ImageView) ClipData(android.content.ClipData) GlideException(com.bumptech.glide.load.engine.GlideException)

Example 8 with GifDrawable

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));
}
Also used : BytesResource(com.bumptech.glide.load.resource.bytes.BytesResource) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) ByteBuffer(java.nio.ByteBuffer)

Example 9 with GifDrawable

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;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) GifDrawable(com.bumptech.glide.load.resource.gif.GifDrawable) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) BadgedFourThreeImageView(io.plaidapp.ui.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) Shot(io.plaidapp.data.api.dribbble.model.Shot) ActivityOptions(android.app.ActivityOptions) NonNull(android.support.annotation.NonNull)

Example 10 with GifDrawable

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

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