Search in sources :

Example 6 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)

Example 7 with RequestListener

use of com.bumptech.glide.request.RequestListener in project xabber-android by redsolution.

the class ChatMessageAdapter method setUpImage.

private void setUpImage(MessageItem messageItem, final Message messageHolder) {
    messageHolder.messageImage.setVisibility(View.GONE);
    if (!messageItem.isImage() || !SettingsManager.connectionLoadImages()) {
        return;
    }
    if (messageItem.getFilePath() != null) {
        boolean result = FileManager.loadImageFromFile(context, messageItem.getFilePath(), messageHolder.messageImage);
        if (result) {
            messageHolder.messageImage.setVisibility(View.VISIBLE);
            messageHolder.messageText.setVisibility(View.GONE);
        } else {
            final String uniqueId = messageItem.getUniqueId();
            final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
            realm.executeTransactionAsync(new Realm.Transaction() {

                @Override
                public void execute(Realm realm) {
                    MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
                    if (first != null) {
                        first.setFilePath(null);
                    }
                }
            });
        }
    } else {
        final ViewGroup.LayoutParams layoutParams = messageHolder.messageImage.getLayoutParams();
        Integer imageWidth = messageItem.getImageWidth();
        Integer imageHeight = messageItem.getImageHeight();
        if (imageWidth != null && imageHeight != null) {
            FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
            Glide.with(context).load(messageItem.getText()).listener(new RequestListener<String, GlideDrawable>() {

                @Override
                public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                    messageHolder.messageImage.setVisibility(View.GONE);
                    messageHolder.messageText.setVisibility(View.VISIBLE);
                    return true;
                }

                @Override
                public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                    return false;
                }
            }).into(messageHolder.messageImage);
            messageHolder.messageImage.setVisibility(View.VISIBLE);
            messageHolder.messageText.setVisibility(View.GONE);
        } else {
            final String uniqueId = messageItem.getUniqueId();
            Glide.with(context).load(messageItem.getText()).asBitmap().into(new SimpleTarget<Bitmap>() {

                @Override
                public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                    final int width = resource.getWidth();
                    final int height = resource.getHeight();
                    if (width <= 0 || height <= 0) {
                        messageHolder.messageImage.setVisibility(View.GONE);
                        messageHolder.messageText.setVisibility(View.VISIBLE);
                        return;
                    }
                    final Realm realm = MessageDatabaseManager.getInstance().getRealmUiThread();
                    realm.executeTransactionAsync(new Realm.Transaction() {

                        @Override
                        public void execute(Realm realm) {
                            MessageItem first = realm.where(MessageItem.class).equalTo(MessageItem.Fields.UNIQUE_ID, uniqueId).findFirst();
                            if (first != null) {
                                first.setImageWidth(width);
                                first.setImageHeight(height);
                            }
                        }
                    });
                    FileManager.scaleImage(layoutParams, height, width);
                    messageHolder.messageImage.setImageBitmap(resource);
                    messageHolder.messageImage.setVisibility(View.VISIBLE);
                    messageHolder.messageText.setVisibility(View.GONE);
                }
            });
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RequestListener(com.bumptech.glide.request.RequestListener) ViewGroup(android.view.ViewGroup) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) Realm(io.realm.Realm) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 8 with RequestListener

use of com.bumptech.glide.request.RequestListener 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 9 with RequestListener

use of com.bumptech.glide.request.RequestListener in project Douya by DreaminginCodeZH.

the class ImageUtils method loadNavigationHeaderAvatar.

public static void loadNavigationHeaderAvatar(final ImageView view, final String url) {
    Context context = view.getContext();
    int size = context.getResources().getDimensionPixelSize(R.dimen.navigation_header_avatar_size);
    Glide.with(context).load(url).placeholder(R.drawable.avatar_icon_white_inactive_64dp).override(size, size).diskCacheStrategy(DiskCacheStrategy.ALL).dontAnimate().dontTransform().listener(new RequestListener<String, GlideDrawable>() {

        @Override
        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
            (e != null ? e : new NullPointerException()).printStackTrace();
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
            view.setTag(url);
            return false;
        }
    }).into(view);
}
Also used : Context(android.content.Context) Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) GlideDrawable(com.bumptech.glide.load.resource.drawable.GlideDrawable)

Example 10 with RequestListener

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

the class SlideShadeViewActivity method setData.

/**
     * 加载titlebar背景
     */
private void setData() {
    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)

Aggregations

RequestListener (com.bumptech.glide.request.RequestListener)11 Target (com.bumptech.glide.request.target.Target)11 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)8 BlurTransformation (jp.wasabeef.glide.transformations.BlurTransformation)4 Animator (android.animation.Animator)2 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)2 ObjectAnimator (android.animation.ObjectAnimator)2 ValueAnimator (android.animation.ValueAnimator)2 Bitmap (android.graphics.Bitmap)2 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)2 Drawable (android.graphics.drawable.Drawable)2 View (android.view.View)2 DataSource (com.bumptech.glide.load.DataSource)2 GlideException (com.bumptech.glide.load.engine.GlideException)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 Nullable (android.support.annotation.Nullable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 ViewGroup (android.view.ViewGroup)1