Reputation: 15327
This easy to achieve using Picasso
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
holder.mImageView.setImageBitmap(bitmap);
holder.mLoadingImageView.setVisibility(View.GONE);
holder.updatePalette();//the logic of generate diffrent background colors
Log.d(TAG, "on success");
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
holder.mLoadingImageView.setVisibility(View.GONE);
Log.d(TAG, "on error");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
holder.mLoadingImageView.setVisibility(View.VISIBLE);
}
});
and the holder
take care of that logic
(getting different colors for unloaded image) from updatePalette
function, here its code or the whole demo if you want
in glide what?
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.into(/*WHAT*/);
Any duplication would help.
Upvotes: 0
Views: 3963
Reputation: 943
You can achieve the same using Target or SimpleTarget (implements Target) in glide.
i.e.
Glide.load("http://somefakeurl.com/fakeImage.jpeg")
.asBitmap()
.fitCenter()
.into(new SimpleTarget(250, 250) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
// Image Loaded successfully.
}
@Override
public void onLoadStarted(Drawable placeholder){
// Image Loading starts
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable){
// Image Loading failed
}
});
}
Upvotes: 4
Reputation: 15327
lastly I did it
private ColorDrawable[] vibrantLightColorList =
{
new ColorDrawable(Color.parseColor("#9ACCCD")), new ColorDrawable(Color.parseColor("#8FD8A0")),
new ColorDrawable(Color.parseColor("#CBD890")), new ColorDrawable(Color.parseColor("#DACC8F")),
new ColorDrawable(Color.parseColor("#D9A790")), new ColorDrawable(Color.parseColor("#D18FD9")),
new ColorDrawable(Color.parseColor("#FF6772")), new ColorDrawable(Color.parseColor("#DDFB5C"))
};
then
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(getRandomDrawbleColor())
.into(holder.mImageView);
and
public ColorDrawable getRandomDrawbleColor() {
int idx = new Random().nextInt(vibrantLightColorList.length);
return vibrantLightColorList[idx];
}
Upvotes: 3
Reputation: 1354
Keep PlaceHolder Until The Image is Loading Using Picasso's placeholder function
Picasso.with(context)
.load("image_url")
.placeholder(R.drawable.ic_launcher)
.into(imageView);
Upvotes: 1
Reputation: 8562
Methods of setting the placeholder Image are same in Picasso
and Glid
In Glid
Glide.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
In Picasso
Picasso.with(holder.mImageView.getContext())
.load(item.getUrl())
.placeholder(R.drawable.placeholder)
.into(imageView)
Upvotes: 0