Search in sources :

Example 26 with GlideException

use of com.bumptech.glide.load.engine.GlideException in project drift-sdk-android by Driftt.

the class ImageViewerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drift_sdk_activity_image_viewer);
    StatusBarColorizer.setActivityColor(this);
    getSupportActionBar().setTitle("Attachment");
    imageView = findViewById(R.id.drift_sdk_image_viewer_image_view);
    progressBar = findViewById(R.id.drift_sdk_image_viewer_progress_view);
    Intent intent = getIntent();
    if (intent.getExtras() != null) {
        String imageUriAsString = intent.getExtras().getString(IMAGE_URI);
        if (imageUriAsString == null || imageUriAsString.isEmpty()) {
            finish();
            return;
        }
        imageUri = Uri.parse(imageUriAsString);
    }
    Glide.with(this).load(imageUri).listener(new RequestListener<Drawable>() {

        @Override
        public boolean onLoadFailed(@Nullable GlideException e, Object o, Target<Drawable> target, boolean b) {
            progressBar.setVisibility(View.GONE);
            Toast.makeText(ImageViewerActivity.this, "Failed to load Image", Toast.LENGTH_LONG).show();
            finish();
            return false;
        }

        @Override
        public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> target, DataSource dataSource, boolean b) {
            progressBar.setVisibility(View.GONE);
            return false;
        }
    }).into(imageView);
}
Also used : Target(com.bumptech.glide.request.target.Target) RequestListener(com.bumptech.glide.request.RequestListener) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) GlideException(com.bumptech.glide.load.engine.GlideException) Nullable(android.support.annotation.Nullable) DataSource(com.bumptech.glide.load.DataSource)

Example 27 with GlideException

use of com.bumptech.glide.load.engine.GlideException 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 = GlideApp.with(this).load(result).decode(Bitmap.class);
    GlideApp.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) Target(com.bumptech.glide.request.target.Target) ImageView(android.widget.ImageView) ClipData(android.content.ClipData) GlideException(com.bumptech.glide.load.engine.GlideException)

Example 28 with GlideException

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

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 29 with GlideException

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

the class SingleRequestTest method testIsNotRunningAfterFailing.

@Test
public void testIsNotRunningAfterFailing() {
    SingleRequest<List> request = builder.build();
    request.begin();
    request.onLoadFailed(new GlideException("test"));
    assertFalse(request.isRunning());
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) GlideException(com.bumptech.glide.load.engine.GlideException) Test(org.junit.Test)

Example 30 with GlideException

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

the class SingleRequestTest method testErrorDrawableIsSetOnLoadFailed.

@Test
public void testErrorDrawableIsSetOnLoadFailed() {
    Drawable expected = new ColorDrawable(Color.RED);
    MockTarget target = new MockTarget();
    SingleRequest<List> request = builder.setErrorDrawable(expected).setTarget(target).build();
    request.onLoadFailed(new GlideException("test"));
    assertThat(target.currentPlaceholder).isEqualTo(expected);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) List(java.util.List) ArrayList(java.util.ArrayList) GlideException(com.bumptech.glide.load.engine.GlideException) Test(org.junit.Test)

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