0

this by picasso

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.

bartonstanley
  • 1,167
  • 12
  • 25
Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92

4 Answers4

4

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
          }

      });
 }
Neeraj Kumar
  • 943
  • 4
  • 16
  • can I create my own target ? how to create MyTarget? please update the question to explain what to do function that I'm not interested in – Basheer AL-MOMANI Mar 18 '16 at 12:01
3

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];
}
Basheer AL-MOMANI
  • 14,473
  • 9
  • 96
  • 92
1

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);
Bajirao Shinde
  • 1,356
  • 1
  • 18
  • 26
0

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)
Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • the given image in placeholder will be fixed for all images – Basheer AL-MOMANI Mar 18 '16 at 12:04
  • You can also change the colors or drawable randomly using random integer, or seperate the setting of placeholder method and change that dynamically in each position with conditions where ever you used the adapter... – Shree Krishna Mar 19 '16 at 07:27