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.
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];
}