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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations