Skip to content

Instantly share code, notes, and snippets.

@OrenBochman
Last active September 9, 2018 15:31
Show Gist options
  • Save OrenBochman/098bd5e2a7b8389c50cfebe67ae057ae to your computer and use it in GitHub Desktop.
Save OrenBochman/098bd5e2a7b8389c50cfebe67ae057ae to your computer and use it in GitHub Desktop.
android images

Images - loading in Android

  1. using Asynctask
  2. using Glide
  3. using Picaso
// Using an AsyncTask to load the slow images in a background thread
new AsyncTask<ViewHolder, Void, Bitmap>() {
private ViewHolder v;
@Override
protected Bitmap doInBackground(ViewHolder... params) {
v = params[0];
return mFakeImageLoader.getImage();
}
@Override
protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
if (v.position == position) {
// If this item hasn't been recycled already, hide the
// progress and set and show the image
v.progress.setVisibility(View.GONE);
v.icon.setVisibility(View.VISIBLE);
v.icon.setImageBitmap(result);
}
}
}.execute(holder);
Glide.with(this)
.load(imageUrl)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.centerCrop()
.into(new GlideDrawableImageViewTarget(mDetailImage) {
@Override
public void onResourceReady(GlideDrawable resource,
GlideAnimation<? super GlideDrawable> animation) {
super.onResourceReady(resource, animation);
EspressoIdlingResource.decrement(); // App is idle.
}
}
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment