Search in sources :

Example 16 with GlideException

use of com.bumptech.glide.load.engine.GlideException 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 17 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project Camera-Roll-Android-App by kollerlukas.

the class AlbumHolder method loadImage.

void loadImage(final ImageView image) {
    if (album.getAlbumItems().size() == 0) {
        Glide.with(getContext()).load(R.drawable.error_placeholder).apply(new RequestOptions().skipMemoryCache(true)).into(image);
        return;
    }
    final AlbumItem coverImage = album.getAlbumItems().get(0);
    Glide.with(getContext()).asBitmap().load(coverImage.getPath()).listener(new RequestListener<Bitmap>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Bitmap> target, boolean isFirstResource) {
            coverImage.error = true;
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }

        @Override
        public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) {
            if (!coverImage.hasFadedIn) {
                coverImage.hasFadedIn = true;
                ColorFade.fadeSaturation(image);
            }
            if (image instanceof ParallaxImageView) {
                ((ParallaxImageView) image).setParallaxTranslation();
            }
            return false;
        }
    }).apply(coverImage.getGlideRequestOptions(getContext())).into(image);
}
Also used : Bitmap(android.graphics.Bitmap) RequestOptions(com.bumptech.glide.request.RequestOptions) ParallaxImageView(us.koller.cameraroll.ui.widget.ParallaxImageView) AlbumItem(us.koller.cameraroll.data.models.AlbumItem) GlideException(com.bumptech.glide.load.engine.GlideException) DataSource(com.bumptech.glide.load.DataSource)

Example 18 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project Rocket by mozilla-tw.

the class SingleRequest method onResourceReady.

/**
 * A callback method that should never be invoked directly.
 */
@SuppressWarnings("unchecked")
@Override
public void onResourceReady(Resource<?> resource, DataSource dataSource) {
    stateVerifier.throwIfRecycled();
    loadStatus = null;
    if (resource == null) {
        GlideException exception = new GlideException("Expected to receive a Resource<R> with an " + "object of " + transcodeClass + " inside, but instead got null.");
        onLoadFailed(exception);
        return;
    }
    Object received = resource.get();
    if (received == null || !transcodeClass.isAssignableFrom(received.getClass())) {
        releaseResource(resource);
        GlideException exception = new GlideException("Expected to receive an object of " + transcodeClass + " but instead" + " got " + (received != null ? received.getClass() : "") + "{" + received + "} inside" + " " + "Resource{" + resource + "}." + (received != null ? "" : " " + "To indicate failure return a null Resource " + "object, rather than a Resource object containing null data."));
        onLoadFailed(exception);
        return;
    }
    if (!canSetResource()) {
        releaseResource(resource);
        // We can't put the status to complete before asking canSetResource().
        status = Status.COMPLETE;
        return;
    }
    onResourceReady((Resource<R>) resource, (R) received, dataSource);
}
Also used : GlideException(com.bumptech.glide.load.engine.GlideException)

Example 19 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project BaseProject by feer921.

the class GlideImageLoader method addProgressListener.

private void addProgressListener() {
    if (getImageUrl() == null)
        return;
    final String url = getImageUrl();
    if (!url.startsWith(HTTP))
        return;
    internalProgressListener = new OnProgressListener() {

        @Override
        public void onProgress(String imageUrl, long bytesRead, long totalBytes, boolean isDone, GlideException exception) {
            if (totalBytes == 0)
                return;
            if (!url.equals(imageUrl))
                return;
            if (mLastBytesRead == bytesRead && mLastStatus == isDone)
                return;
            mLastBytesRead = bytesRead;
            mTotalBytes = totalBytes;
            mLastStatus = isDone;
            mainThreadCallback(bytesRead, totalBytes, isDone, exception);
            if (isDone) {
                ProgressManager.removeProgressListener(this);
            }
        }
    };
    ProgressManager.addProgressListener(internalProgressListener);
}
Also used : OnProgressListener(common.base.glide.progress.OnProgressListener) GlideException(com.bumptech.glide.load.engine.GlideException)

Example 20 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project MaterialViewPager by florent37.

the class MaterialViewPagerImageHelper method setImageUrl.

/**
 * change the image with a fade
 *
 * @param urlImage
 * @param fadeDuration TODO : remove Picasso
 */
public static void setImageUrl(final ImageView imageView, final String urlImage, final int fadeDuration) {
    final float alpha = ViewCompat.getAlpha(imageView);
    final ImageView viewToAnimate = imageView;
    // fade to alpha=0
    fadeOut(viewToAnimate, fadeDuration, new ViewPropertyAnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(View view) {
            super.onAnimationEnd(view);
            // change the image when alpha=0
            Glide.with(imageView.getContext()).load(urlImage).apply(new RequestOptions().centerCrop()).listener(new RequestListener<Drawable>() {

                @Override
                public boolean onLoadFailed(@Nullable 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) {
                    // then fade to alpha=1
                    new Handler(Looper.getMainLooper()) {
                    }.post(new Runnable() {

                        @Override
                        public void run() {
                            fadeIn(viewToAnimate, alpha, fadeDuration, new ViewPropertyAnimatorListenerAdapter());
                            if (imageLoadListener != null) {
                                imageLoadListener.OnImageLoad(imageView, ((BitmapDrawable) imageView.getDrawable()).getBitmap());
                            }
                        }
                    });
                    return false;
                }
            }).into(viewToAnimate);
        }
    });
}
Also used : RequestOptions(com.bumptech.glide.request.RequestOptions) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) DataSource(com.bumptech.glide.load.DataSource) ImageView(android.widget.ImageView) ViewPropertyAnimatorListenerAdapter(android.support.v4.view.ViewPropertyAnimatorListenerAdapter) GlideException(com.bumptech.glide.load.engine.GlideException)

Aggregations

GlideException (com.bumptech.glide.load.engine.GlideException)34 DataSource (com.bumptech.glide.load.DataSource)21 Drawable (android.graphics.drawable.Drawable)18 RequestListener (com.bumptech.glide.request.RequestListener)16 Target (com.bumptech.glide.request.target.Target)16 Nullable (android.support.annotation.Nullable)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Test (org.junit.Test)8 Bitmap (android.graphics.Bitmap)6 Nullable (androidx.annotation.Nullable)6 View (android.view.View)5 ImageView (android.widget.ImageView)5 RequestOptions (com.bumptech.glide.request.RequestOptions)5 Context (android.content.Context)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 Handler (android.os.Handler)2 CircleGradientDrawable (com.amaze.filemanager.ui.views.CircleGradientDrawable)2