Search in sources :

Example 1 with RequestListener

use of com.bumptech.glide.request.RequestListener in project plaid by nickbutcher.

the class FeedAdapter method bindDribbbleShotHolder.

private void bindDribbbleShotHolder(final Shot shot, final DribbbleShotHolder holder, int position) {
    final int[] imageSize = shot.images.bestSize();
    Glide.with(host).load(shot.images.best()).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!shot.hasFadedIn) {
                holder.image.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator saturation = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f);
                saturation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        // just animating the color matrix does not invalidate the
                        // drawable so need this update listener.  Also have to create a
                        // new CMCF as the matrix is immutable :(
                        holder.image.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                saturation.setDuration(2000L);
                saturation.setInterpolator(getFastOutSlowInInterpolator(host));
                saturation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        holder.image.clearColorFilter();
                        holder.image.setHasTransientState(false);
                    }
                });
                saturation.start();
                shot.hasFadedIn = true;
            }
            return false;
        }

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }
    }).placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]).diskCacheStrategy(DiskCacheStrategy.SOURCE).fitCenter().override(imageSize[0], imageSize[1]).into(new DribbbleTarget(holder.image, false));
    // need both placeholder & background to prevent seeing through shot as it fades in
    holder.image.setBackground(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]);
    holder.image.showBadge(shot.animated);
    // need a unique transition name per shot, let's use it's url
    holder.image.setTransitionName(shot.html_url);
}
Also used : DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) RequestListener(com.bumptech.glide.request.RequestListener) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) Target(com.bumptech.glide.request.target.Target) DribbbleTarget(io.plaidapp.util.glide.DribbbleTarget) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObservableColorMatrix(io.plaidapp.util.ObservableColorMatrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 2 with RequestListener

use of com.bumptech.glide.request.RequestListener in project CloudReader by youlookwhat.

the class MovieDetailActivity method setImgHeaderBg.

/**
     * 加载titlebar背景
     */
private void setImgHeaderBg() {
    if (subjectsBean != null) {
        // 高斯模糊背景 原来 参数:12,5  23,4
        Glide.with(this).load(subjectsBean.getImages().getLarge()).error(R.drawable.stackblur_default).bitmapTransform(new BlurTransformation(this, 23, 4)).listener(new RequestListener<String, GlideDrawable>() {

            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                binding.titleToolBar.setBackgroundColor(Color.TRANSPARENT);
                binding.ivTitleHeadBg.setImageAlpha(0);
                binding.ivTitleHeadBg.setVisibility(View.VISIBLE);
                return false;
            }
        }).into(binding.ivTitleHeadBg);
    }
}
Also used : BlurTransformation(jp.wasabeef.glide.transformations.BlurTransformation) Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 3 with RequestListener

use of com.bumptech.glide.request.RequestListener in project Robot-Scouter by SUPERCILEX.

the class TeamDetailsDialog method updateUi.

private void updateUi() {
    if (mMedia != null && mName != null && mNameEditText != null && mMediaCapture != null && mWebsiteEditText != null) {
        Team team = mTeamHelper.getTeam();
        mMediaLoadProgress.setVisibility(View.VISIBLE);
        Glide.with(getContext()).load(team.getMedia()).apply(RequestOptions.circleCropTransform().error(R.drawable.ic_memory_grey_48dp).fallback(R.drawable.ic_memory_grey_48dp)).listener(new RequestListener<Drawable>() {

            @Override
            public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                mMediaLoadProgress.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                mMediaLoadProgress.setVisibility(View.GONE);
                return false;
            }
        }).into(mMedia);
        mName.setText(team.toString());
        mNameEditText.setText(team.getName());
        mMediaEditText.setText(team.getMedia());
        mWebsiteEditText.setText(team.getWebsite());
    }
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) Team(com.supercilex.robotscouter.data.model.Team) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 4 with RequestListener

use of com.bumptech.glide.request.RequestListener in project LookLook by xinghongfei.

the class MeiziAdapter method bindViewHolderNormal.

private void bindViewHolderNormal(final MeiziViewHolder holder, final int position) {
    final Meizi meizi = meiziItemes.get(holder.getAdapterPosition());
    holder.imageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            startDescribeActivity(meizi, holder);
        }
    });
    //        holder.textView.setText("视频");
    //        holder.textView.setOnClickListener(new View.OnClickListener() {
    //            @Override
    //            public void onClick(View view) {
    //                startDescribeActivity(meizi,holder);
    //            }
    //        });
    Glide.with(mContext).load(meizi.getUrl()).listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            if (!meizi.hasFadedIn) {
                holder.imageView.setHasTransientState(true);
                final ObservableColorMatrix cm = new ObservableColorMatrix();
                final ObjectAnimator animator = ObjectAnimator.ofFloat(cm, ObservableColorMatrix.SATURATION, 0f, 1f);
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator valueAnimator) {
                        holder.imageView.setColorFilter(new ColorMatrixColorFilter(cm));
                    }
                });
                animator.setDuration(2000L);
                animator.setInterpolator(new AccelerateInterpolator());
                animator.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        super.onAnimationEnd(animation);
                        holder.imageView.clearColorFilter();
                        holder.imageView.setHasTransientState(false);
                        animator.start();
                        meizi.hasFadedIn = true;
                    }
                });
            }
            return false;
        }
    }).diskCacheStrategy(DiskCacheStrategy.SOURCE).centerCrop().into(new DribbbleTarget(holder.imageView, false));
}
Also used : DribbbleTarget(com.looklook.xinghongfei.looklook.util.DribbbleTarget) RequestListener(com.bumptech.glide.request.RequestListener) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Meizi(com.looklook.xinghongfei.looklook.bean.meizi.Meizi) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) BadgedFourThreeImageView(com.looklook.xinghongfei.looklook.widget.BadgedFourThreeImageView) RecyclerView(android.support.v7.widget.RecyclerView) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) DribbbleTarget(com.looklook.xinghongfei.looklook.util.DribbbleTarget) Target(com.bumptech.glide.request.target.Target) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) ObservableColorMatrix(com.looklook.xinghongfei.looklook.util.ObservableColorMatrix) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 5 with RequestListener

use of com.bumptech.glide.request.RequestListener in project Shuttle by timusus.

the class ArtworkView method bindView.

@Override
public void bindView(ViewHolder holder) {
    super.bindView(holder);
    long time = System.currentTimeMillis();
    holder.textContainer.setBackground(null);
    holder.progressBar.setVisibility(View.VISIBLE);
    holder.lineTwo.setText(null);
    Glide.with(holder.itemView.getContext()).using(new TypeLoader(type, file), InputStream.class).from(ArtworkProvider.class).as(BitmapAndSize.class).sourceEncoder(new StreamEncoder()).decoder(new BitmapAndSizeDecoder(holder.itemView.getContext())).diskCacheStrategy(DiskCacheStrategy.NONE).load(artworkProvider).listener(new RequestListener<ArtworkProvider, BitmapAndSize>() {

        @Override
        public boolean onException(Exception e, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFirstResource) {
            if (glideListener != null) {
                if (holder.itemView.getHandler() != null) {
                    holder.itemView.getHandler().postDelayed(() -> glideListener.onArtworkLoadFailed(ArtworkView.this), System.currentTimeMillis() + 1000 - time);
                }
            }
            return false;
        }

        @Override
        public boolean onResourceReady(BitmapAndSize resource, ArtworkProvider model, Target<BitmapAndSize> target, boolean isFromMemoryCache, boolean isFirstResource) {
            return false;
        }
    }).into(new ImageViewTarget<BitmapAndSize>(((ViewHolder) holder).imageView) {

        @Override
        protected void setResource(BitmapAndSize resource) {
            holder.textContainer.setBackgroundResource(R.drawable.text_protection_scrim_reversed);
            holder.progressBar.setVisibility(View.GONE);
            holder.imageView.setImageBitmap(resource.bitmap);
            holder.lineTwo.setText(String.format("%sx%spx", resource.size.width, resource.size.height));
        }
    });
    holder.lineOne.setText(ArtworkModel.getTypeString(type));
    if (type == ArtworkProvider.Type.FOLDER && file != null) {
        holder.lineOne.setText(file.getName());
    }
    if (isCustom && file != null && file.getPath().contains("custom_artwork")) {
        holder.lineOne.setText(holder.itemView.getContext().getString(R.string.artwork_type_custom));
    }
    holder.checkView.setVisibility(isSelected() ? View.VISIBLE : View.GONE);
}
Also used : Target(com.bumptech.glide.request.target.Target) ImageViewTarget(com.bumptech.glide.request.target.ImageViewTarget) RequestListener(com.bumptech.glide.request.RequestListener) BitmapAndSizeDecoder(com.simplecity.amp_library.glide.utils.BitmapAndSizeDecoder) BaseViewHolder(com.simplecityapps.recycler_adapter.recyclerview.BaseViewHolder) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) BitmapAndSize(com.simplecity.amp_library.glide.utils.BitmapAndSize) TypeLoader(com.simplecity.amp_library.glide.loader.TypeLoader) StreamEncoder(com.bumptech.glide.load.model.StreamEncoder)

Aggregations

RequestListener (com.bumptech.glide.request.RequestListener)24 Target (com.bumptech.glide.request.target.Target)24 DataSource (com.bumptech.glide.load.DataSource)13 GlideException (com.bumptech.glide.load.engine.GlideException)13 Drawable (android.graphics.drawable.Drawable)12 Nullable (android.support.annotation.Nullable)9 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)9 View (android.view.View)7 Bitmap (android.graphics.Bitmap)4 ImageView (android.widget.ImageView)4 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)4 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)4 Animator (android.animation.Animator)3 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)3 ObjectAnimator (android.animation.ObjectAnimator)3 ValueAnimator (android.animation.ValueAnimator)3 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)3 RecyclerView (android.support.v7.widget.RecyclerView)3 Nullable (androidx.annotation.Nullable)3 Intent (android.content.Intent)2