-1

Picasso image loading library shows error while use with:

ColorDrawable cd = new ColorDrawable(ContextCompat.getColor(mContext,R.color.light_thirty_alpha));

 Picasso.with(mContext)
                .load(cd)
                .fit().centerCrop()
                .transform(new RoundedTransformation(5, 0))
                .error(cd)
                .placeholder(cd)
                .into(imageView_ovelay_slider);

It is showing error that cannot resolve method .load(colorDrawable). I already knows that it is not accept colorDrawable but I am asking can we cast colorDrawable to something else that accepts by .load().

Anant Shah
  • 3,744
  • 1
  • 35
  • 48
  • I already knows that it will does not accept colorDrawable in its load method that's why i have asked question how to deal with it if i want to use colorDrawable. So why downVote? Explain @Apurva – Anant Shah Jun 17 '16 at 07:49
  • You cannot use `ColorDrawable`. If you want to use it, you can fork the project add the new method and add the code to handle it. That's the only solution if you want to use `ColorDrawable`. – Prerak Sola Jun 17 '16 at 07:53

3 Answers3

0

If you look at the source code, you will see that, Picasso's load method can accept any one of the following parameters:

  • Uri
  • String
  • File
  • int (Resource Id)

It does not accept ColorDrawable

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67
0

.load method doesn't accepts ColorDrawable as parameter. Look at the official documentation for accepted parameters.

  1. load(File file) - image request using the specified image file.
  2. load(int resourceId) - mage request using the specified drawable resource ID.
  3. load(String path) - image request using the specified path.
  4. load(android.net.Uri uri) - image request using the specified URI.

http://square.github.io/picasso/2.x/picasso/

Alok Patel
  • 7,842
  • 5
  • 31
  • 47
0

Solution was so easy finally found by using

solution 1(worked & tested):

ColorDrawable cd = new ColorDrawable(ContextCompat.getColor(mContext,R.color.light_thirty_alpha));
        Picasso.with(mContext)
                .load(String.valueOf(cd))
                .fit().centerCrop()
                .transform(new RoundedTransformation(5, 0))
                .error(cd)
                .placeholder(cd)
                .into(imageView_ovelay_slider);

solution 2(worked & tested):

alternate way i found is to create shape drwable.xml file with radius.

<?xml version="1.0" encoding="utf-8"?>

<item>
    <shape android:shape="rectangle">
        <stroke
            android:width="0dp"
            android:height="0dp"
            android:color="@color/transparent" />

        <!-- apply button background transparent, full opacity -->
        <solid android:color="@color/box" />
        <corners android:radius="2.5dp" />

        <padding android:bottom="2dp"
            android:left="4dp"
            android:right="4dp"
            android:top="2dp" />
    </shape>
</item>

and use it as background drawable. Thank you @Prerak Sola & Alok

Anant Shah
  • 3,744
  • 1
  • 35
  • 48