Search in sources :

Example 16 with RequestListener

use of com.bumptech.glide.request.RequestListener in project AmazeFileManager by TeamAmaze.

the class RecyclerAdapter method showRoundedThumbnail.

private void showRoundedThumbnail(ItemViewHolder viewHolder, IconDataParcelable iconData, ImageView view, OnImageProcessed errorListener) {
    if (iconData.isImageBroken()) {
        View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? viewHolder.genericIcon : viewHolder.iconLayout;
        viewHolder.genericIcon.setVisibility(View.VISIBLE);
        iconBackground.setBackgroundColor(grey_color);
        GlideApp.with(mainFrag).load(R.drawable.ic_broken_image_white_24dp).into(viewHolder.genericIcon);
        view.setVisibility(View.INVISIBLE);
        errorListener.onImageProcessed(true);
        return;
    }
    View iconBackground = getBoolean(PREFERENCE_USE_CIRCULAR_IMAGES) ? viewHolder.genericIcon : viewHolder.iconLayout;
    iconBackground.setBackgroundColor(iconSkinColor);
    viewHolder.genericIcon.setVisibility(View.VISIBLE);
    GlideApp.with(mainFrag).load(iconData.loadingImage).into(viewHolder.genericIcon);
    view.setVisibility(View.INVISIBLE);
    modelProvider.getPreloadRequestBuilder(iconData).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
            iconBackground.setBackgroundColor(grey_color);
            GlideApp.with(mainFrag).load(R.drawable.ic_broken_image_white_24dp).into(viewHolder.genericIcon);
            errorListener.onImageProcessed(true);
            return true;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            viewHolder.genericIcon.setImageDrawable(null);
            viewHolder.genericIcon.setVisibility(View.GONE);
            view.setVisibility(View.VISIBLE);
            errorListener.onImageProcessed(false);
            return false;
        }
    }).into(view);
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) CircleGradientDrawable(com.amaze.filemanager.ui.views.CircleGradientDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ImageView(android.widget.ImageView) View(android.view.View) RoundedImageView(com.amaze.filemanager.ui.views.RoundedImageView) RecyclerView(android.support.v7.widget.RecyclerView) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 17 with RequestListener

use of com.bumptech.glide.request.RequestListener in project Rocket by mozilla-tw.

the class TabTrayAdapter method loadCachedFavicon.

private void loadCachedFavicon(final Tab tab, final ViewHolder holder) {
    RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE).dontAnimate();
    Bitmap favicon = tab.getFavicon();
    FaviconModel model = new FaviconModel(tab.getUrl(), FavIconUtils.getFavIconType(holder.itemView.getResources(), favicon), favicon);
    requestManager.load(model).apply(options).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            loadGeneratedFavicon(tab, holder);
            return true;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            return false;
        }
    }).into(new SimpleTarget<Drawable>() {

        @Override
        public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
            updateFavicon(holder, resource);
        }
    });
}
Also used : RequestListener(com.bumptech.glide.request.RequestListener) RequestOptions(com.bumptech.glide.request.RequestOptions) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DataSource(com.bumptech.glide.load.DataSource) Bitmap(android.graphics.Bitmap) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Target(com.bumptech.glide.request.target.Target) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable)

Example 18 with RequestListener

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

the class ImageViewerFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // get params
    Bundle args = getArguments();
    if (args == null)
        return;
    String source;
    String uri = args.getString(IMAGE_URL);
    final String path = args.getString(IMAGE_PATH);
    if (path != null)
        source = path;
    else
        source = uri;
    final String attachmentId = args.getString(ATTACHMENT_ID);
    // find views
    ivPhoto = view.findViewById(R.id.ivPhoto);
    progressBar = view.findViewById(R.id.progressBar);
    // setup image
    progressBar.setVisibility(View.VISIBLE);
    Glide.with(getActivity()).load(source).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
            if (e != null)
                showError(e.toString());
            if (path != null)
                MessageManager.setAttachmentLocalPathToNull(attachmentId);
            progressBar.setVisibility(View.GONE);
            return false;
        }

        @Override
        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
            progressBar.setVisibility(View.GONE);
            return false;
        }
    }).into(ivPhoto);
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 19 with RequestListener

use of com.bumptech.glide.request.RequestListener in project Signal-Android by WhisperSystems.

the class AvatarPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    super.onCreate(savedInstanceState, ready);
    setTheme(R.style.TextSecure_MediaPreview);
    setContentView(R.layout.contact_photo_preview_activity);
    if (Build.VERSION.SDK_INT >= 21) {
        postponeEnterTransition();
        TransitionInflater inflater = TransitionInflater.from(this);
        getWindow().setSharedElementEnterTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_enter_transition_set));
        getWindow().setSharedElementReturnTransition(inflater.inflateTransition(R.transition.full_screen_avatar_image_return_transition_set));
    }
    Toolbar toolbar = findViewById(R.id.toolbar);
    EmojiTextView title = findViewById(R.id.title);
    ImageView avatar = findViewById(R.id.avatar);
    setSupportActionBar(toolbar);
    requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
    requireSupportActionBar().setDisplayShowTitleEnabled(false);
    Context context = getApplicationContext();
    RecipientId recipientId = RecipientId.from(getIntent().getStringExtra(RECIPIENT_ID_EXTRA));
    Recipient.live(recipientId).observe(this, recipient -> {
        ContactPhoto contactPhoto = recipient.isSelf() ? new ProfileContactPhoto(recipient, recipient.getProfileAvatar()) : recipient.getContactPhoto();
        FallbackContactPhoto fallbackPhoto = recipient.isSelf() ? new ResourceContactPhoto(R.drawable.ic_profile_outline_40, R.drawable.ic_profile_outline_20, R.drawable.ic_person_large) : recipient.getFallbackContactPhoto();
        Resources resources = this.getResources();
        GlideApp.with(this).asBitmap().load(contactPhoto).fallback(fallbackPhoto.asCallCard(this)).error(fallbackPhoto.asCallCard(this)).diskCacheStrategy(DiskCacheStrategy.ALL).addListener(new RequestListener<Bitmap>() {

            @Override
            public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
                Log.w(TAG, "Unable to load avatar, or avatar removed, closing");
                finish();
                return false;
            }

            @Override
            public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
                return false;
            }
        }).into(new CustomTarget<Bitmap>() {

            @Override
            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                avatar.setImageDrawable(RoundedBitmapDrawableFactory.create(resources, resource));
                if (Build.VERSION.SDK_INT >= 21) {
                    startPostponedEnterTransition();
                }
            }

            @Override
            public void onLoadCleared(@Nullable Drawable placeholder) {
            }
        });
        title.setText(recipient.getDisplayName(context));
    });
    FullscreenHelper fullscreenHelper = new FullscreenHelper(this);
    findViewById(android.R.id.content).setOnClickListener(v -> fullscreenHelper.toggleUiVisibility());
    fullscreenHelper.configureToolbarSpacer(findViewById(R.id.toolbar_cutout_spacer));
    fullscreenHelper.showAndHideWithSystemUI(getWindow(), findViewById(R.id.toolbar_layout));
}
Also used : Context(android.content.Context) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) TransitionInflater(android.transition.TransitionInflater) ContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ContactPhoto) ProfileContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ProfileContactPhoto) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) DataSource(com.bumptech.glide.load.DataSource) FallbackContactPhoto(org.thoughtcrime.securesms.contacts.avatars.FallbackContactPhoto) CustomTarget(com.bumptech.glide.request.target.CustomTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) ResourceContactPhoto(org.thoughtcrime.securesms.contacts.avatars.ResourceContactPhoto) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) ImageView(android.widget.ImageView) Resources(android.content.res.Resources) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 20 with RequestListener

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

the class FileMessageVH method setUpImage.

private void setUpImage(String imagePath, String imageUrl, final String uniqueId, Integer imageWidth, Integer imageHeight, Context context) {
    if (!SettingsManager.connectionLoadImages())
        return;
    if (imagePath != null) {
        boolean result = FileManager.loadImageFromFile(context, imagePath, messageImage);
        if (result) {
            messageImage.setVisibility(View.VISIBLE);
        } else {
            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 = messageImage.getLayoutParams();
        if (imageWidth != null && imageHeight != null) {
            FileManager.scaleImage(layoutParams, imageHeight, imageWidth);
            Glide.with(context).load(imageUrl).listener(new RequestListener<Drawable>() {

                @Override
                public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                    messageImage.setVisibility(View.GONE);
                    return true;
                }

                @Override
                public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                    return false;
                }
            }).into(messageImage);
            messageImage.setVisibility(View.VISIBLE);
        } else {
            Glide.with(context).asBitmap().load(imageUrl).placeholder(R.drawable.ic_recent_image_placeholder).error(R.drawable.ic_recent_image_placeholder).into(new CustomTarget<Bitmap>() {

                @Override
                public void onLoadStarted(@Nullable Drawable placeholder) {
                    super.onLoadStarted(placeholder);
                    messageImage.setImageDrawable(placeholder);
                    messageImage.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadFailed(@Nullable Drawable errorDrawable) {
                    super.onLoadFailed(errorDrawable);
                    messageImage.setImageDrawable(errorDrawable);
                    messageImage.setVisibility(View.VISIBLE);
                }

                @Override
                public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
                    final int width = resource.getWidth();
                    final int height = resource.getHeight();
                    if (width <= 0 || height <= 0) {
                        messageImage.setVisibility(View.GONE);
                        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);
                    messageImage.setImageBitmap(resource);
                    messageImage.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadCleared(@Nullable Drawable placeholder) {
                }
            });
        }
    }
}
Also used : MessageItem(com.xabber.android.data.database.messagerealm.MessageItem) RequestListener(com.bumptech.glide.request.RequestListener) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) DataSource(com.bumptech.glide.load.DataSource) CustomTarget(com.bumptech.glide.request.target.CustomTarget) Target(com.bumptech.glide.request.target.Target) Bitmap(android.graphics.Bitmap) Realm(io.realm.Realm) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(androidx.annotation.Nullable)

Aggregations

RequestListener (com.bumptech.glide.request.RequestListener)29 Target (com.bumptech.glide.request.target.Target)29 DataSource (com.bumptech.glide.load.DataSource)18 GlideException (com.bumptech.glide.load.engine.GlideException)18 Drawable (android.graphics.drawable.Drawable)16 Nullable (android.support.annotation.Nullable)9 GlideDrawable (com.bumptech.glide.load.resource.drawable.GlideDrawable)9 Bitmap (android.graphics.Bitmap)8 Nullable (androidx.annotation.Nullable)8 View (android.view.View)6 ImageView (android.widget.ImageView)5 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 Context (android.content.Context)3 RecyclerView (android.support.v7.widget.RecyclerView)3 CustomTarget (com.bumptech.glide.request.target.CustomTarget)3